blob: 6e4d1a5df67e56e43f35fefd471e1cb706d9073a [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
225#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#ifdef FEAT_WINDOWS
249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200261# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200262# define PV_TMS OPT_WIN(WV_TMS)
263#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200264#ifdef FEAT_SIGNS
265# define PV_SCL OPT_WIN(WV_SCL)
266#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000267
268/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269typedef enum
270{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000271 PV_NONE = 0,
272 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273} idopt_T;
274
275/*
276 * Options local to a window have a value local to a buffer and global to all
277 * buffers. Indicate this by setting "var" to VAR_WIN.
278 */
279#define VAR_WIN ((char_u *)-1)
280
281/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000282 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283 * Only to be used in option.c!
284 */
285static int p_ai;
286static int p_bin;
287#ifdef FEAT_MBYTE
288static int p_bomb;
289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static char_u *p_bh;
291static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292static int p_bl;
293static int p_ci;
294#ifdef FEAT_CINDENT
295static int p_cin;
296static char_u *p_cink;
297static char_u *p_cino;
298#endif
299#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
300static char_u *p_cinw;
301#endif
302#ifdef FEAT_COMMENTS
303static char_u *p_com;
304#endif
305#ifdef FEAT_FOLDING
306static char_u *p_cms;
307#endif
308#ifdef FEAT_INS_EXPAND
309static char_u *p_cpt;
310#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000311#ifdef FEAT_COMPL_FUNC
312static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000313static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200316static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static int p_et;
318#ifdef FEAT_MBYTE
319static char_u *p_fenc;
320#endif
321static char_u *p_ff;
322static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000323static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324#ifdef FEAT_AUTOCMD
325static char_u *p_ft;
326#endif
327static long p_iminsert;
328static long p_imsearch;
329#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
330static char_u *p_inex;
331#endif
332#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
333static char_u *p_inde;
334static char_u *p_indk;
335#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000336#if defined(FEAT_EVAL)
337static char_u *p_fex;
338#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static int p_inf;
340static char_u *p_isk;
341#ifdef FEAT_CRYPT
342static char_u *p_key;
343#endif
344#ifdef FEAT_LISP
345static int p_lisp;
346#endif
347static int p_ml;
348static int p_ma;
349static int p_mod;
350static char_u *p_mps;
351static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000353#ifdef FEAT_TEXTOBJ
354static char_u *p_qe;
355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static int p_ro;
357#ifdef FEAT_SMARTINDENT
358static int p_si;
359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361static long p_sts;
362#if defined(FEAT_SEARCHPATH)
363static char_u *p_sua;
364#endif
365static long p_sw;
366static int p_swf;
367#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000368static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000370#endif
371#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000372static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000373static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000374static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375#endif
376static long p_ts;
377static long p_tw;
378static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200379#ifdef FEAT_PERSISTENT_UNDO
380static int p_udf;
381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382static long p_wm;
383#ifdef FEAT_KEYMAP
384static char_u *p_keymap;
385#endif
386
387/* Saved values for when 'bin' is set. */
388static int p_et_nobin;
389static int p_ml_nobin;
390static long p_tw_nobin;
391static long p_wm_nobin;
392
393/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200394static int p_ai_nopaste;
395static int p_et_nopaste;
396static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397static long p_tw_nopaste;
398static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399
400struct vimoption
401{
402 char *fullname; /* full option name */
403 char *shortname; /* permissible abbreviation */
404 long_u flags; /* see below */
405 char_u *var; /* global option: pointer to variable;
406 * window-local option: VAR_WIN;
407 * buffer-local option: global value */
408 idopt_T indir; /* global option: PV_NONE;
409 * local option: indirect option index */
410 char_u *def_val[2]; /* default values for variable (vi and vim) */
411#ifdef FEAT_EVAL
412 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000413# define SCRIPTID_INIT , 0
414#else
415# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416#endif
417};
418
419#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
420#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
421
422/*
423 * Flags
424 */
425#define P_BOOL 0x01 /* the option is boolean */
426#define P_NUM 0x02 /* the option is numeric */
427#define P_STRING 0x04 /* the option is a string */
428#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000429 must use free_string_option() when
430 assigning new value. Not set if default is
431 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
433 never be used for local or hidden options! */
434#define P_NODEFAULT 0x40 /* don't set to default value */
435#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
436 use vim_free() when assigning new value */
437#define P_WAS_SET 0x100 /* option has been set/reset */
438#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
439#define P_VI_DEF 0x400 /* Use Vi default for Vim */
440#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
441
442 /* when option changed, what to display: */
443#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100444#define P_RWIN 0x2000 /* redraw current window and recompute text */
445#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446#define P_RALL 0x6000 /* redraw all windows */
447#define P_RCLR 0x7000 /* clear and redraw all */
448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_COMMA 0x8000 /* comma separated list */
450#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
451 * commas */
452#define P_NODUP 0x20000L /* don't allow duplicate strings */
453#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200455#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
456#define P_GETTEXT 0x100000L /* expand default value with _() */
457#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
458#define P_NFNAME 0x400000L /* only normal file name chars allowed */
459#define P_INSECURE 0x800000L /* option was set from a modeline */
460#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100461 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200462#define P_NO_ML 0x2000000L /* not allowed in modeline */
463#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200464 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100465#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100466#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000467
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000468#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
469
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000470/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
471 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100472#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000473# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000474#else
475# define ISP_LATIN1 (char_u *)"@,161-255"
476#endif
477
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100478/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000479#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100480 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar21020352017-06-13 17:21:04 +0200481 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) \
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,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002776 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002777#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);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#endif
3275#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003278static char_u *option_expand(int opt_idx, char_u *val);
3279static void didset_options(void);
3280static void didset_options2(void);
3281static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003282#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003284#else
3285# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3286#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static void set_string_option_global(int opt_idx, char_u **varp);
3288static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3289static 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);
3290static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003291#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003295static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003297#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003298static char_u *did_set_spell_option(int is_spellfile);
3299static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003300#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003301#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003303#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003304static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3305static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3306static void check_redraw(long_u flags);
3307static int findoption(char_u *);
3308static int find_key_option(char_u *);
3309static void showoptions(int all, int opt_flags);
3310static int optval_default(struct vimoption *, char_u *varp);
3311static void showoneopt(struct vimoption *, int opt_flags);
3312static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3313static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3314static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3315static int istermoption(struct vimoption *);
3316static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3317static char_u *get_varp(struct vimoption *);
3318static void option_value2string(struct vimoption *, int opt_flags);
3319static void check_winopt(winopt_T *wop);
3320static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003322static void langmap_init(void);
3323static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003325static void paste_option_changed(void);
3326static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003327#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003328static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003330static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3331static int check_opt_strings(char_u *val, char **values, int);
3332static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003333#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003334static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003335#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336
3337/*
3338 * Initialize the options, first part.
3339 *
3340 * Called only once from main(), just after creating the first buffer.
3341 */
3342 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003343set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344{
3345 char_u *p;
3346 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003347 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348
3349#ifdef FEAT_LANGMAP
3350 langmap_init();
3351#endif
3352
3353 /* Be Vi compatible by default */
3354 p_cp = TRUE;
3355
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003356 /* Use POSIX compatibility when $VIM_POSIX is set. */
3357 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003358 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003359 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003360 set_string_default("shm", (char_u *)"A");
3361 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003362
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363 /*
3364 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003365 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003367 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003368#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003369 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003371 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372# endif
3373#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003374 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375 set_string_default("sh", p);
3376
3377#ifdef FEAT_WILDIGN
3378 /*
3379 * Set the default for 'backupskip' to include environment variables for
3380 * temp files.
3381 */
3382 {
3383# ifdef UNIX
3384 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3385# else
3386 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3387# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003388 int len;
3389 garray_T ga;
3390 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391
3392 ga_init2(&ga, 1, 100);
3393 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3394 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003395 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396# ifdef UNIX
3397 if (*names[n] == NUL)
3398 p = (char_u *)"/tmp";
3399 else
3400# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003401 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402 if (p != NULL && *p != NUL)
3403 {
3404 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003405 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406 if (ga_grow(&ga, len) == OK)
3407 {
3408 if (ga.ga_len > 0)
3409 STRCAT(ga.ga_data, ",");
3410 STRCAT(ga.ga_data, p);
3411 add_pathsep(ga.ga_data);
3412 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 ga.ga_len += len;
3414 }
3415 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003416 if (mustfree)
3417 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 }
3419 if (ga.ga_data != NULL)
3420 {
3421 set_string_default("bsk", ga.ga_data);
3422 vim_free(ga.ga_data);
3423 }
3424 }
3425#endif
3426
3427 /*
3428 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3429 */
3430 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003433#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3434 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3435#endif
3436 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003438 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003439 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440#else
3441# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003442 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003443 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003445 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446# endif
3447#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003449 opt_idx = findoption((char_u *)"maxmem");
3450 if (opt_idx >= 0)
3451 {
3452#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003453 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3454 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003455#endif
3456 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3457 }
3458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 }
3460
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461#ifdef FEAT_SEARCHPATH
3462 {
3463 char_u *cdpath;
3464 char_u *buf;
3465 int i;
3466 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003467 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468
3469 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003470 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471 if (cdpath != NULL)
3472 {
3473 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3474 if (buf != NULL)
3475 {
3476 buf[0] = ','; /* start with ",", current dir first */
3477 j = 1;
3478 for (i = 0; cdpath[i] != NUL; ++i)
3479 {
3480 if (vim_ispathlistsep(cdpath[i]))
3481 buf[j++] = ',';
3482 else
3483 {
3484 if (cdpath[i] == ' ' || cdpath[i] == ',')
3485 buf[j++] = '\\';
3486 buf[j++] = cdpath[i];
3487 }
3488 }
3489 buf[j] = NUL;
3490 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003491 if (opt_idx >= 0)
3492 {
3493 options[opt_idx].def_val[VI_DEFAULT] = buf;
3494 options[opt_idx].flags |= P_DEF_ALLOCED;
3495 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003496 else
3497 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003499 if (mustfree)
3500 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003501 }
3502 }
3503#endif
3504
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003505#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506 /* Set print encoding on platforms that don't default to latin1 */
3507 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003508# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509 (char_u *)"cp1252"
3510# else
3511# ifdef VMS
3512 (char_u *)"dec-mcs"
3513# else
3514# ifdef EBCDIC
3515 (char_u *)"ebcdic-uk"
3516# else
3517# ifdef MAC
3518 (char_u *)"mac-roman"
3519# else /* HPUX */
3520 (char_u *)"hp-roman8"
3521# endif
3522# endif
3523# endif
3524# endif
3525 );
3526#endif
3527
3528#ifdef FEAT_POSTSCRIPT
3529 /* 'printexpr' must be allocated to be able to evaluate it. */
3530 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003531# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003532 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533# else
3534# ifdef VMS
3535 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3536
3537# else
3538 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3539# endif
3540# endif
3541 );
3542#endif
3543
3544 /*
3545 * Set all the options (except the terminal options) to their default
3546 * value. Also set the global value for local options.
3547 */
3548 set_options_default(0);
3549
3550#ifdef FEAT_GUI
3551 if (found_reverse_arg)
3552 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3553#endif
3554
3555 curbuf->b_p_initialized = TRUE;
3556 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003557 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558 check_buf_options(curbuf);
3559 check_win_options(curwin);
3560 check_options();
3561
3562 /* Must be before option_expand(), because that one needs vim_isIDc() */
3563 didset_options();
3564
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003565#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003566 /* Use the current chartab for the generic chartab. This is not in
3567 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003568 init_spell_chartab();
3569#endif
3570
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571 /*
3572 * Expand environment variables and things like "~" for the defaults.
3573 * If option_expand() returns non-NULL the variable is expanded. This can
3574 * only happen for non-indirect options.
3575 * Also set the default to the expanded value, so ":set" does not list
3576 * them.
3577 * Don't set the P_ALLOCED flag, because we don't want to free the
3578 * default.
3579 */
3580 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3581 {
3582 if ((options[opt_idx].flags & P_GETTEXT)
3583 && options[opt_idx].var != NULL)
3584 p = (char_u *)_(*(char **)options[opt_idx].var);
3585 else
3586 p = option_expand(opt_idx, NULL);
3587 if (p != NULL && (p = vim_strsave(p)) != NULL)
3588 {
3589 *(char_u **)options[opt_idx].var = p;
3590 /* VIMEXP
3591 * Defaults for all expanded options are currently the same for Vi
3592 * and Vim. When this changes, add some code here! Also need to
3593 * split P_DEF_ALLOCED in two.
3594 */
3595 if (options[opt_idx].flags & P_DEF_ALLOCED)
3596 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3597 options[opt_idx].def_val[VI_DEFAULT] = p;
3598 options[opt_idx].flags |= P_DEF_ALLOCED;
3599 }
3600 }
3601
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602 save_file_ff(curbuf); /* Buffer is unchanged */
3603
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604#if defined(FEAT_ARABIC)
3605 /* Detect use of mlterm.
3606 * Mlterm is a terminal emulator akin to xterm that has some special
3607 * abilities (bidi namely).
3608 * NOTE: mlterm's author is being asked to 'set' a variable
3609 * instead of an environment variable due to inheritance.
3610 */
3611 if (mch_getenv((char_u *)"MLTERM") != NULL)
3612 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3613#endif
3614
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003615 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616
3617#ifdef FEAT_MBYTE
3618# if defined(WIN3264) && defined(FEAT_GETTEXT)
3619 /*
3620 * If $LANG isn't set, try to get a good value for it. This makes the
3621 * right language be used automatically. Don't do this for English.
3622 */
3623 if (mch_getenv((char_u *)"LANG") == NULL)
3624 {
3625 char buf[20];
3626
3627 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3628 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3629 * only the first two. */
3630 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3631 (LPTSTR)buf, 20);
3632 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3633 {
3634 /* There are a few exceptions (probably more) */
3635 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3636 STRCPY(buf, "zh_TW");
3637 else if (STRNICMP(buf, "chs", 3) == 0
3638 || STRNICMP(buf, "zhc", 3) == 0)
3639 STRCPY(buf, "zh_CN");
3640 else if (STRNICMP(buf, "jp", 2) == 0)
3641 STRCPY(buf, "ja");
3642 else
3643 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003644 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003645 }
3646 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003647# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003648# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003649 /* Moved to os_mac_conv.c to avoid dependency problems. */
3650 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003651# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652# endif
3653
3654 /* enc_locale() will try to find the encoding of the current locale. */
3655 p = enc_locale();
3656 if (p != NULL)
3657 {
3658 char_u *save_enc;
3659
3660 /* Try setting 'encoding' and check if the value is valid.
3661 * If not, go back to the default "latin1". */
3662 save_enc = p_enc;
3663 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003664 if (STRCMP(p_enc, "gb18030") == 0)
3665 {
3666 /* We don't support "gb18030", but "cp936" is a good substitute
3667 * for practical purposes, thus use that. It's not an alias to
3668 * still support conversion between gb18030 and utf-8. */
3669 p_enc = vim_strsave((char_u *)"cp936");
3670 vim_free(p);
3671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003672 if (mb_init() == NULL)
3673 {
3674 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003675 if (opt_idx >= 0)
3676 {
3677 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3678 options[opt_idx].flags |= P_DEF_ALLOCED;
3679 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003681#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003682 if (STRCMP(p_enc, "latin1") == 0
3683# ifdef FEAT_MBYTE
3684 || enc_utf8
3685# endif
3686 )
3687 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003688 /* Adjust the default for 'isprint' and 'iskeyword' to match
3689 * latin1. Also set the defaults for when 'nocompatible' is
3690 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003691 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003692 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003693 set_string_option_direct((char_u *)"isk", -1,
3694 ISK_LATIN1, OPT_FREE, SID_NONE);
3695 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003696 if (opt_idx >= 0)
3697 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003698 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003701 (void)init_chartab();
3702 }
3703#endif
3704
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705# if defined(WIN3264) && !defined(FEAT_GUI)
3706 /* Win32 console: When GetACP() returns a different value from
3707 * GetConsoleCP() set 'termencoding'. */
3708 if (GetACP() != GetConsoleCP())
3709 {
3710 char buf[50];
3711
3712 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3713 p_tenc = vim_strsave((char_u *)buf);
3714 if (p_tenc != NULL)
3715 {
3716 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003717 if (opt_idx >= 0)
3718 {
3719 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3720 options[opt_idx].flags |= P_DEF_ALLOCED;
3721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 convert_setup(&input_conv, p_tenc, p_enc);
3723 convert_setup(&output_conv, p_enc, p_tenc);
3724 }
3725 else
3726 p_tenc = empty_option;
3727 }
3728# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003729# if defined(WIN3264) && defined(FEAT_MBYTE)
3730 /* $HOME may have characters in active code page. */
3731 init_homedir();
3732# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 }
3734 else
3735 {
3736 vim_free(p_enc);
3737 p_enc = save_enc;
3738 }
3739 }
3740#endif
3741
3742#ifdef FEAT_MULTI_LANG
3743 /* Set the default for 'helplang'. */
3744 set_helplang_default(get_mess_lang());
3745#endif
3746}
3747
3748/*
3749 * Set an option to its default value.
3750 * This does not take care of side effects!
3751 */
3752 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003753set_option_default(
3754 int opt_idx,
3755 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3756 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757{
3758 char_u *varp; /* pointer to variable for current option */
3759 int dvi; /* index in def_val[] */
3760 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003761 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3763
3764 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3765 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003766 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767 {
3768 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3769 if (flags & P_STRING)
3770 {
3771 /* Use set_string_option_direct() for local options to handle
3772 * freeing and allocating the value. */
3773 if (options[opt_idx].indir != PV_NONE)
3774 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003775 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 else
3777 {
3778 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3779 free_string_option(*(char_u **)(varp));
3780 *(char_u **)varp = options[opt_idx].def_val[dvi];
3781 options[opt_idx].flags &= ~P_ALLOCED;
3782 }
3783 }
3784 else if (flags & P_NUM)
3785 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003786 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 win_comp_scroll(curwin);
3788 else
3789 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003790 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 /* May also set global value for local option. */
3792 if (both)
3793 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3794 *(long *)varp;
3795 }
3796 }
3797 else /* P_BOOL */
3798 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003799 /* the cast to long is required for Manx C, long_i is needed for
3800 * MSVC */
3801 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003802#ifdef UNIX
3803 /* 'modeline' defaults to off for root */
3804 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3805 *(int *)varp = FALSE;
3806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 /* May also set global value for local option. */
3808 if (both)
3809 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3810 *(int *)varp;
3811 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003812
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003813 /* The default value is not insecure. */
3814 flagsp = insecure_flag(opt_idx, opt_flags);
3815 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 }
3817
3818#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003819 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820#endif
3821}
3822
3823/*
3824 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003825 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 */
3827 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003828set_options_default(
3829 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830{
3831 int i;
3832#ifdef FEAT_WINDOWS
3833 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003834 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835#endif
3836
3837 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003838 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003839#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003840 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003841 || (TRUE
3842# if defined(FEAT_MBYTE)
3843 && options[i].var != (char_u *)&p_enc
3844# endif
3845# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003846 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003847 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003848# endif
3849 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003850#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003851 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 set_option_default(i, opt_flags, p_cp);
3853
3854#ifdef FEAT_WINDOWS
3855 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003856 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857 win_comp_scroll(wp);
3858#else
3859 win_comp_scroll(curwin);
3860#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003861#ifdef FEAT_CINDENT
3862 parse_cino(curbuf);
3863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864}
3865
3866/*
3867 * Set the Vi-default value of a string option.
3868 * Used for 'sh', 'backupskip' and 'term'.
3869 */
3870 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003871set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872{
3873 char_u *p;
3874 int opt_idx;
3875
3876 p = vim_strsave(val);
3877 if (p != NULL) /* we don't want a NULL */
3878 {
3879 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003880 if (opt_idx >= 0)
3881 {
3882 if (options[opt_idx].flags & P_DEF_ALLOCED)
3883 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3884 options[opt_idx].def_val[VI_DEFAULT] = p;
3885 options[opt_idx].flags |= P_DEF_ALLOCED;
3886 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 }
3888}
3889
3890/*
3891 * Set the Vi-default value of a number option.
3892 * Used for 'lines' and 'columns'.
3893 */
3894 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003895set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003897 int opt_idx;
3898
3899 opt_idx = findoption((char_u *)name);
3900 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003901 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902}
3903
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003904#if defined(EXITFREE) || defined(PROTO)
3905/*
3906 * Free all options.
3907 */
3908 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003909free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003910{
3911 int i;
3912
3913 for (i = 0; !istermoption(&options[i]); i++)
3914 {
3915 if (options[i].indir == PV_NONE)
3916 {
3917 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003918 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003919 free_string_option(*(char_u **)options[i].var);
3920 if (options[i].flags & P_DEF_ALLOCED)
3921 free_string_option(options[i].def_val[VI_DEFAULT]);
3922 }
3923 else if (options[i].var != VAR_WIN
3924 && (options[i].flags & P_STRING))
3925 /* buffer-local option: free global value */
3926 free_string_option(*(char_u **)options[i].var);
3927 }
3928}
3929#endif
3930
3931
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932/*
3933 * Initialize the options, part two: After getting Rows and Columns and
3934 * setting 'term'.
3935 */
3936 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003937set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003939 int idx;
3940
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 /*
3942 * 'scroll' defaults to half the window height. Note that this default is
3943 * wrong when the window height changes.
3944 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003945 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003946 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003947 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003948 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 comp_col();
3950
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003951 /*
3952 * 'window' is only for backwards compatibility with Vi.
3953 * Default is Rows - 1.
3954 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003955 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003956 p_window = Rows - 1;
3957 set_number_default("window", Rows - 1);
3958
Bram Moolenaarf740b292006-02-16 22:11:02 +00003959 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003960#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003961 /*
3962 * If 'background' wasn't set by the user, try guessing the value,
3963 * depending on the terminal name. Only need to check for terminals
3964 * with a dark background, that can handle color.
3965 */
3966 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003967 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3968 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003970 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 /* don't mark it as set, when starting the GUI it may be
3972 * changed again */
3973 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 }
3975#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003976
3977#ifdef CURSOR_SHAPE
3978 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3979#endif
3980#ifdef FEAT_MOUSESHAPE
3981 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3982#endif
3983#ifdef FEAT_PRINTER
3984 (void)parse_printoptions(); /* parse 'printoptions' default value */
3985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986}
3987
3988/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003989 * Return "dark" or "light" depending on the kind of terminal.
3990 * This is just guessing! Recognized are:
3991 * "linux" Linux console
3992 * "screen.linux" Linux console with screen
3993 * "cygwin" Cygwin shell
3994 * "putty" Putty program
3995 * We also check the COLORFGBG environment variable, which is set by
3996 * rxvt and derivatives. This variable contains either two or three
3997 * values separated by semicolons; we want the last value in either
3998 * case. If this value is 0-6 or 8, our background is dark.
3999 */
4000 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004001term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004002{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004003#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004004 /* DOS console nearly always black */
4005 return (char_u *)"dark";
4006#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004007 char_u *p;
4008
Bram Moolenaarf740b292006-02-16 22:11:02 +00004009 if (STRCMP(T_NAME, "linux") == 0
4010 || STRCMP(T_NAME, "screen.linux") == 0
4011 || STRCMP(T_NAME, "cygwin") == 0
4012 || STRCMP(T_NAME, "putty") == 0
4013 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4014 && (p = vim_strrchr(p, ';')) != NULL
4015 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4016 && p[2] == NUL))
4017 return (char_u *)"dark";
4018 return (char_u *)"light";
4019#endif
4020}
4021
4022/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 * Initialize the options, part three: After reading the .vimrc
4024 */
4025 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004026set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004027{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004028#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029/*
4030 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4031 * This is done after other initializations, where 'shell' might have been
4032 * set, but only if they have not been set before.
4033 */
4034 char_u *p;
4035 int idx_srr;
4036 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004037# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 int idx_sp;
4039 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004040# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041
4042 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004043 if (idx_srr < 0)
4044 do_srr = FALSE;
4045 else
4046 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004047# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004049 if (idx_sp < 0)
4050 do_sp = FALSE;
4051 else
4052 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004053# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004054 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 if (p != NULL)
4056 {
4057 /*
4058 * Default for p_sp is "| tee", for p_srr is ">".
4059 * For known shells it is changed here to include stderr.
4060 */
4061 if ( fnamecmp(p, "csh") == 0
4062 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004063# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 || fnamecmp(p, "csh.exe") == 0
4065 || fnamecmp(p, "tcsh.exe") == 0
4066# endif
4067 )
4068 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 if (do_sp)
4071 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004072# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004074# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004076# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4078 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 if (do_srr)
4081 {
4082 p_srr = (char_u *)">&";
4083 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4084 }
4085 }
4086 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004087 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 if ( fnamecmp(p, "sh") == 0
4089 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004090 || fnamecmp(p, "mksh") == 0
4091 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004093 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004095 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 || fnamecmp(p, "cmd") == 0
4098 || fnamecmp(p, "sh.exe") == 0
4099 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004100 || fnamecmp(p, "mksh.exe") == 0
4101 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004103 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 || fnamecmp(p, "bash.exe") == 0
4105 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004107 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004109# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 if (do_sp)
4111 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004112# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004114# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004116# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4118 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 if (do_srr)
4121 {
4122 p_srr = (char_u *)">%s 2>&1";
4123 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4124 }
4125 }
4126 vim_free(p);
4127 }
4128#endif
4129
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004130#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004132 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4133 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 * This is done after other initializations, where 'shell' might have been
4135 * set, but only if they have not been set before. Default for p_shcf is
4136 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004137 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004139 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 {
4141 int idx3;
4142
4143 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004144 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 {
4146 p_shcf = (char_u *)"-c";
4147 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4148 }
4149
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 /* Somehow Win32 requires the quotes around the redirection too */
4151 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004152 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 {
4154 p_sxq = (char_u *)"\"";
4155 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004158 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4159 {
4160 int idx3;
4161
4162 /*
4163 * cmd.exe on Windows will strip the first and last double quote given
4164 * on the command line, e.g. most of the time things like:
4165 * cmd /c "my path/to/echo" "my args to echo"
4166 * become:
4167 * my path/to/echo" "my args to echo
4168 * when executed.
4169 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004170 * To avoid this, set shellxquote to surround the command in
4171 * parenthesis. This appears to make most commands work, without
4172 * breaking commands that worked previously, such as
4173 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004174 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004175 idx3 = findoption((char_u *)"sxq");
4176 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4177 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004178 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004179 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4180 }
4181
Bram Moolenaara64ba222012-02-12 23:23:31 +01004182 idx3 = findoption((char_u *)"shcf");
4183 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4184 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004185 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004186 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4187 }
4188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189#endif
4190
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004191 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004192 {
4193 int idx_ffs = findoption((char_u *)"ffs");
4194
4195 /* Apply the first entry of 'fileformats' to the initial buffer. */
4196 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4197 set_fileformat(default_fileformat(), OPT_LOCAL);
4198 }
4199
Bram Moolenaar071d4272004-06-13 20:20:40 +00004200#ifdef FEAT_TITLE
4201 set_title_defaults();
4202#endif
4203}
4204
4205#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4206/*
4207 * When 'helplang' is still at its default value, set it to "lang".
4208 * Only the first two characters of "lang" are used.
4209 */
4210 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004211set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212{
4213 int idx;
4214
4215 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4216 return;
4217 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004218 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219 {
4220 if (options[idx].flags & P_ALLOCED)
4221 free_string_option(p_hlg);
4222 p_hlg = vim_strsave(lang);
4223 if (p_hlg == NULL)
4224 p_hlg = empty_option;
4225 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004226 {
4227 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4228 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4229 {
4230 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4231 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004234 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 options[idx].flags |= P_ALLOCED;
4236 }
4237}
4238#endif
4239
4240#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004241static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242
4243 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004244gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004245{
4246 if (gui_get_lightness(gui.back_pixel) < 127)
4247 return (char_u *)"dark";
4248 return (char_u *)"light";
4249}
4250
4251/*
4252 * Option initializations that can only be done after opening the GUI window.
4253 */
4254 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004255init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256{
4257 /* Set the 'background' option according to the lightness of the
4258 * background color, unless the user has set it already. */
4259 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4260 {
4261 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4262 highlight_changed();
4263 }
4264}
4265#endif
4266
4267#ifdef FEAT_TITLE
4268/*
4269 * 'title' and 'icon' only default to true if they have not been set or reset
4270 * in .vimrc and we can read the old value.
4271 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4272 * they can be reset. This reduces startup time when using X on a remote
4273 * machine.
4274 */
4275 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004276set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004277{
4278 int idx1;
4279 long val;
4280
4281 /*
4282 * If GUI is (going to be) used, we can always set the window title and
4283 * icon name. Saves a bit of time, because the X11 display server does
4284 * not need to be contacted.
4285 */
4286 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004287 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004288 {
4289#ifdef FEAT_GUI
4290 if (gui.starting || gui.in_use)
4291 val = TRUE;
4292 else
4293#endif
4294 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004295 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004296 p_title = val;
4297 }
4298 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004299 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004300 {
4301#ifdef FEAT_GUI
4302 if (gui.starting || gui.in_use)
4303 val = TRUE;
4304 else
4305#endif
4306 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004307 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004308 p_icon = val;
4309 }
4310}
4311#endif
4312
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004313#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4314 static void
4315trigger_optionsset_string(
4316 int opt_idx,
4317 int opt_flags,
4318 char_u *oldval,
4319 char_u *newval)
4320{
4321 if (oldval != NULL && newval != NULL)
4322 {
4323 char_u buf_type[7];
4324
4325 sprintf((char *)buf_type, "%s",
4326 (opt_flags & OPT_LOCAL) ? "local" : "global");
4327 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4328 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4329 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4330 apply_autocmds(EVENT_OPTIONSET,
4331 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4332 reset_v_option_vars();
4333 }
4334 vim_free(oldval);
4335 vim_free(newval);
4336}
4337#endif
4338
Bram Moolenaar071d4272004-06-13 20:20:40 +00004339/*
4340 * Parse 'arg' for option settings.
4341 *
4342 * 'arg' may be IObuff, but only when no errors can be present and option
4343 * does not need to be expanded with option_expand().
4344 * "opt_flags":
4345 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004346 * OPT_GLOBAL for ":setglobal"
4347 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004348 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004349 * OPT_WINONLY to only set window-local options
4350 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004351 *
4352 * returns FAIL if an error is detected, OK otherwise
4353 */
4354 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004355do_set(
4356 char_u *arg, /* option string (may be written to!) */
4357 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358{
4359 int opt_idx;
4360 char_u *errmsg;
4361 char_u errbuf[80];
4362 char_u *startarg;
4363 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4364 int nextchar; /* next non-white char after option name */
4365 int afterchar; /* character just after option name */
4366 int len;
4367 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004368 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004369 int key;
4370 long_u flags; /* flags for current option */
4371 char_u *varp = NULL; /* pointer to variable for current option */
4372 int did_show = FALSE; /* already showed one value */
4373 int adding; /* "opt+=arg" */
4374 int prepending; /* "opt^=arg" */
4375 int removing; /* "opt-=arg" */
4376 int cp_val = 0;
4377 char_u key_name[2];
4378
4379 if (*arg == NUL)
4380 {
4381 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004382 did_show = TRUE;
4383 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 }
4385
4386 while (*arg != NUL) /* loop to process all options */
4387 {
4388 errmsg = NULL;
4389 startarg = arg; /* remember for error message */
4390
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004391 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4392 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004393 {
4394 /*
4395 * ":set all" show all options.
4396 * ":set all&" set all options to their default value.
4397 */
4398 arg += 3;
4399 if (*arg == '&')
4400 {
4401 ++arg;
4402 /* Only for :set command set global value of local options. */
4403 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004404 didset_options();
4405 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004406 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004407 }
4408 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004409 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004411 did_show = TRUE;
4412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004413 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004414 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415 {
4416 showoptions(2, opt_flags);
4417 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004418 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004419 arg += 7;
4420 }
4421 else
4422 {
4423 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004424 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 {
4426 prefix = 0;
4427 arg += 2;
4428 }
4429 else if (STRNCMP(arg, "inv", 3) == 0)
4430 {
4431 prefix = 2;
4432 arg += 3;
4433 }
4434
4435 /* find end of name */
4436 key = 0;
4437 if (*arg == '<')
4438 {
4439 nextchar = 0;
4440 opt_idx = -1;
4441 /* look out for <t_>;> */
4442 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4443 len = 5;
4444 else
4445 {
4446 len = 1;
4447 while (arg[len] != NUL && arg[len] != '>')
4448 ++len;
4449 }
4450 if (arg[len] != '>')
4451 {
4452 errmsg = e_invarg;
4453 goto skip;
4454 }
4455 arg[len] = NUL; /* put NUL after name */
4456 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4457 opt_idx = findoption(arg + 1);
4458 arg[len++] = '>'; /* restore '>' */
4459 if (opt_idx == -1)
4460 key = find_key_option(arg + 1);
4461 }
4462 else
4463 {
4464 len = 0;
4465 /*
4466 * The two characters after "t_" may not be alphanumeric.
4467 */
4468 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4469 len = 4;
4470 else
4471 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4472 ++len;
4473 nextchar = arg[len];
4474 arg[len] = NUL; /* put NUL after name */
4475 opt_idx = findoption(arg);
4476 arg[len] = nextchar; /* restore nextchar */
4477 if (opt_idx == -1)
4478 key = find_key_option(arg);
4479 }
4480
4481 /* remember character after option name */
4482 afterchar = arg[len];
4483
4484 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004485 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004486 ++len;
4487
4488 adding = FALSE;
4489 prepending = FALSE;
4490 removing = FALSE;
4491 if (arg[len] != NUL && arg[len + 1] == '=')
4492 {
4493 if (arg[len] == '+')
4494 {
4495 adding = TRUE; /* "+=" */
4496 ++len;
4497 }
4498 else if (arg[len] == '^')
4499 {
4500 prepending = TRUE; /* "^=" */
4501 ++len;
4502 }
4503 else if (arg[len] == '-')
4504 {
4505 removing = TRUE; /* "-=" */
4506 ++len;
4507 }
4508 }
4509 nextchar = arg[len];
4510
4511 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4512 {
4513 errmsg = (char_u *)N_("E518: Unknown option");
4514 goto skip;
4515 }
4516
4517 if (opt_idx >= 0)
4518 {
4519 if (options[opt_idx].var == NULL) /* hidden option: skip */
4520 {
4521 /* Only give an error message when requesting the value of
4522 * a hidden option, ignore setting it. */
4523 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4524 && (!(options[opt_idx].flags & P_BOOL)
4525 || nextchar == '?'))
4526 errmsg = (char_u *)N_("E519: Option not supported");
4527 goto skip;
4528 }
4529
4530 flags = options[opt_idx].flags;
4531 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4532 }
4533 else
4534 {
4535 flags = P_STRING;
4536 if (key < 0)
4537 {
4538 key_name[0] = KEY2TERMCAP0(key);
4539 key_name[1] = KEY2TERMCAP1(key);
4540 }
4541 else
4542 {
4543 key_name[0] = KS_KEY;
4544 key_name[1] = (key & 0xff);
4545 }
4546 }
4547
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004548 /* Skip all options that are not window-local (used when showing
4549 * an already loaded buffer in a window). */
4550 if ((opt_flags & OPT_WINONLY)
4551 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4552 goto skip;
4553
Bram Moolenaara3227e22006-03-08 21:32:40 +00004554 /* Skip all options that are window-local (used for :vimgrep). */
4555 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4556 && options[opt_idx].var == VAR_WIN)
4557 goto skip;
4558
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004559 /* Disallow changing some options from modelines. */
4560 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004561 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004562 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004563 {
4564 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4565 goto skip;
4566 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004567#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004568 /* In diff mode some options are overruled. This avoids that
4569 * 'foldmethod' becomes "marker" instead of "diff" and that
4570 * "wrap" gets set. */
4571 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004572 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004573 && (
4574#ifdef FEAT_FOLDING
4575 options[opt_idx].indir == PV_FDM ||
4576#endif
4577 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004578 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004579#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004580 }
4581
4582#ifdef HAVE_SANDBOX
4583 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004584 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004585 {
4586 errmsg = (char_u *)_(e_sandbox);
4587 goto skip;
4588 }
4589#endif
4590
4591 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4592 {
4593 arg += len;
4594 cp_val = p_cp;
4595 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4596 {
4597 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4598 {
4599 cp_val = FALSE;
4600 arg += 3;
4601 }
4602 else /* "opt&vi": set to Vi default */
4603 {
4604 cp_val = TRUE;
4605 arg += 2;
4606 }
4607 }
4608 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004609 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004610 {
4611 errmsg = e_trailing;
4612 goto skip;
4613 }
4614 }
4615
4616 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004617 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4618 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619 */
4620 if (nextchar == '?'
4621 || (prefix == 1
4622 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4623 && !(flags & P_BOOL)))
4624 {
4625 /*
4626 * print value
4627 */
4628 if (did_show)
4629 msg_putchar('\n'); /* cursor below last one */
4630 else
4631 {
4632 gotocmdline(TRUE); /* cursor at status line */
4633 did_show = TRUE; /* remember that we did a line */
4634 }
4635 if (opt_idx >= 0)
4636 {
4637 showoneopt(&options[opt_idx], opt_flags);
4638#ifdef FEAT_EVAL
4639 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004640 {
4641 /* Mention where the option was last set. */
4642 if (varp == options[opt_idx].var)
4643 last_set_msg(options[opt_idx].scriptID);
4644 else if ((int)options[opt_idx].indir & PV_WIN)
4645 last_set_msg(curwin->w_p_scriptID[
4646 (int)options[opt_idx].indir & PV_MASK]);
4647 else if ((int)options[opt_idx].indir & PV_BUF)
4648 last_set_msg(curbuf->b_p_scriptID[
4649 (int)options[opt_idx].indir & PV_MASK]);
4650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651#endif
4652 }
4653 else
4654 {
4655 char_u *p;
4656
4657 p = find_termcode(key_name);
4658 if (p == NULL)
4659 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004660 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004661 goto skip;
4662 }
4663 else
4664 (void)show_one_termcode(key_name, p, TRUE);
4665 }
4666 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004667 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004668 errmsg = e_trailing;
4669 }
4670 else
4671 {
4672 if (flags & P_BOOL) /* boolean */
4673 {
4674 if (nextchar == '=' || nextchar == ':')
4675 {
4676 errmsg = e_invarg;
4677 goto skip;
4678 }
4679
4680 /*
4681 * ":set opt!": invert
4682 * ":set opt&": reset to default value
4683 * ":set opt<": reset to global value
4684 */
4685 if (nextchar == '!')
4686 value = *(int *)(varp) ^ 1;
4687 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004688 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004689 ((flags & P_VI_DEF) || cp_val)
4690 ? VI_DEFAULT : VIM_DEFAULT];
4691 else if (nextchar == '<')
4692 {
4693 /* For 'autoread' -1 means to use global value. */
4694 if ((int *)varp == &curbuf->b_p_ar
4695 && opt_flags == OPT_LOCAL)
4696 value = -1;
4697 else
4698 value = *(int *)get_varp_scope(&(options[opt_idx]),
4699 OPT_GLOBAL);
4700 }
4701 else
4702 {
4703 /*
4704 * ":set invopt": invert
4705 * ":set opt" or ":set noopt": set or reset
4706 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004707 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004708 {
4709 errmsg = e_trailing;
4710 goto skip;
4711 }
4712 if (prefix == 2) /* inv */
4713 value = *(int *)(varp) ^ 1;
4714 else
4715 value = prefix;
4716 }
4717
4718 errmsg = set_bool_option(opt_idx, varp, (int)value,
4719 opt_flags);
4720 }
4721 else /* numeric or string */
4722 {
4723 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4724 || prefix != 1)
4725 {
4726 errmsg = e_invarg;
4727 goto skip;
4728 }
4729
4730 if (flags & P_NUM) /* numeric */
4731 {
4732 /*
4733 * Different ways to set a number option:
4734 * & set to default value
4735 * < set to global value
4736 * <xx> accept special key codes for 'wildchar'
4737 * c accept any non-digit for 'wildchar'
4738 * [-]0-9 set number
4739 * other error
4740 */
4741 ++arg;
4742 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004743 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004744 ((flags & P_VI_DEF) || cp_val)
4745 ? VI_DEFAULT : VIM_DEFAULT];
4746 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004747 {
4748 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4749 * use the global value. */
4750 if ((long *)varp == &curbuf->b_p_ul
4751 && opt_flags == OPT_LOCAL)
4752 value = NO_LOCAL_UNDOLEVEL;
4753 else
4754 value = *(long *)get_varp_scope(
4755 &(options[opt_idx]), OPT_GLOBAL);
4756 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004757 else if (((long *)varp == &p_wc
4758 || (long *)varp == &p_wcm)
4759 && (*arg == '<'
4760 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004761 || (*arg != NUL
4762 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004763 && !VIM_ISDIGIT(*arg))))
4764 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004765 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004766 if (value == 0 && (long *)varp != &p_wcm)
4767 {
4768 errmsg = e_invarg;
4769 goto skip;
4770 }
4771 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004772 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4773 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004774 /* Allow negative (for 'undolevels'), octal and
4775 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004776 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4777 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004778 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004779 {
4780 errmsg = e_invarg;
4781 goto skip;
4782 }
4783 }
4784 else
4785 {
4786 errmsg = (char_u *)N_("E521: Number required after =");
4787 goto skip;
4788 }
4789
4790 if (adding)
4791 value = *(long *)varp + value;
4792 if (prepending)
4793 value = *(long *)varp * value;
4794 if (removing)
4795 value = *(long *)varp - value;
4796 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004797 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 }
4799 else if (opt_idx >= 0) /* string */
4800 {
4801 char_u *save_arg = NULL;
4802 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004803 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004805 char_u *origval = NULL;
4806#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4807 char_u *saved_origval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004808 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004810 unsigned newlen;
4811 int comma;
4812 int bs;
4813 int new_value_alloced; /* new string option
4814 was allocated */
4815
4816 /* When using ":set opt=val" for a global option
4817 * with a local value the local value will be
4818 * reset, use the global value here. */
4819 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004820 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004821 varp = options[opt_idx].var;
4822
4823 /* The old value is kept until we are sure that the
4824 * new value is valid. */
4825 oldval = *(char_u **)varp;
4826 if (nextchar == '&') /* set to default val */
4827 {
4828 newval = options[opt_idx].def_val[
4829 ((flags & P_VI_DEF) || cp_val)
4830 ? VI_DEFAULT : VIM_DEFAULT];
4831 if ((char_u **)varp == &p_bg)
4832 {
4833 /* guess the value of 'background' */
4834#ifdef FEAT_GUI
4835 if (gui.in_use)
4836 newval = gui_bg_default();
4837 else
4838#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004839 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004840 }
4841
4842 /* expand environment variables and ~ (since the
4843 * default value was already expanded, only
4844 * required when an environment variable was set
4845 * later */
4846 if (newval == NULL)
4847 newval = empty_option;
4848 else
4849 {
4850 s = option_expand(opt_idx, newval);
4851 if (s == NULL)
4852 s = newval;
4853 newval = vim_strsave(s);
4854 }
4855 new_value_alloced = TRUE;
4856 }
4857 else if (nextchar == '<') /* set to global val */
4858 {
4859 newval = vim_strsave(*(char_u **)get_varp_scope(
4860 &(options[opt_idx]), OPT_GLOBAL));
4861 new_value_alloced = TRUE;
4862 }
4863 else
4864 {
4865 ++arg; /* jump to after the '=' or ':' */
4866
4867 /*
4868 * Set 'keywordprg' to ":help" if an empty
4869 * value was passed to :set by the user.
4870 * Misuse errbuf[] for the resulting string.
4871 */
4872 if (varp == (char_u *)&p_kp
4873 && (*arg == NUL || *arg == ' '))
4874 {
4875 STRCPY(errbuf, ":help");
4876 save_arg = arg;
4877 arg = errbuf;
4878 }
4879 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004880 * Convert 'backspace' number to string, for
4881 * adding, prepending and removing string.
4882 */
4883 else if (varp == (char_u *)&p_bs
4884 && VIM_ISDIGIT(**(char_u **)varp))
4885 {
4886 i = getdigits((char_u **)varp);
4887 switch (i)
4888 {
4889 case 0:
4890 *(char_u **)varp = empty_option;
4891 break;
4892 case 1:
4893 *(char_u **)varp = vim_strsave(
4894 (char_u *)"indent,eol");
4895 break;
4896 case 2:
4897 *(char_u **)varp = vim_strsave(
4898 (char_u *)"indent,eol,start");
4899 break;
4900 }
4901 vim_free(oldval);
4902 oldval = *(char_u **)varp;
4903 }
4904 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004905 * Convert 'whichwrap' number to string, for
4906 * backwards compatibility with Vim 3.0.
4907 * Misuse errbuf[] for the resulting string.
4908 */
4909 else if (varp == (char_u *)&p_ww
4910 && VIM_ISDIGIT(*arg))
4911 {
4912 *errbuf = NUL;
4913 i = getdigits(&arg);
4914 if (i & 1)
4915 STRCAT(errbuf, "b,");
4916 if (i & 2)
4917 STRCAT(errbuf, "s,");
4918 if (i & 4)
4919 STRCAT(errbuf, "h,l,");
4920 if (i & 8)
4921 STRCAT(errbuf, "<,>,");
4922 if (i & 16)
4923 STRCAT(errbuf, "[,],");
4924 if (*errbuf != NUL) /* remove trailing , */
4925 errbuf[STRLEN(errbuf) - 1] = NUL;
4926 save_arg = arg;
4927 arg = errbuf;
4928 }
4929 /*
4930 * Remove '>' before 'dir' and 'bdir', for
4931 * backwards compatibility with version 3.0
4932 */
4933 else if ( *arg == '>'
4934 && (varp == (char_u *)&p_dir
4935 || varp == (char_u *)&p_bdir))
4936 {
4937 ++arg;
4938 }
4939
4940 /* When setting the local value of a global
4941 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004942 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004943 && (opt_flags & OPT_LOCAL))
4944 origval = *(char_u **)get_varp(
4945 &options[opt_idx]);
4946 else
4947 origval = oldval;
4948
4949 /*
4950 * Copy the new string into allocated memory.
4951 * Can't use set_string_option_direct(), because
4952 * we need to remove the backslashes.
4953 */
4954 /* get a bit too much */
4955 newlen = (unsigned)STRLEN(arg) + 1;
4956 if (adding || prepending || removing)
4957 newlen += (unsigned)STRLEN(origval) + 1;
4958 newval = alloc(newlen);
4959 if (newval == NULL) /* out of mem, don't change */
4960 break;
4961 s = newval;
4962
4963 /*
4964 * Copy the string, skip over escaped chars.
4965 * For MS-DOS and WIN32 backslashes before normal
4966 * file name characters are not removed, and keep
4967 * backslash at start, for "\\machine\path", but
4968 * do remove it for "\\\\machine\\path".
4969 * The reverse is found in ExpandOldSetting().
4970 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004971 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004972 {
4973 if (*arg == '\\' && arg[1] != NUL
4974#ifdef BACKSLASH_IN_FILENAME
4975 && !((flags & P_EXPAND)
4976 && vim_isfilec(arg[1])
4977 && (arg[1] != '\\'
4978 || (s == newval
4979 && arg[2] != '\\')))
4980#endif
4981 )
4982 ++arg; /* remove backslash */
4983#ifdef FEAT_MBYTE
4984 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004985 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004986 {
4987 /* copy multibyte char */
4988 mch_memmove(s, arg, (size_t)i);
4989 arg += i;
4990 s += i;
4991 }
4992 else
4993#endif
4994 *s++ = *arg++;
4995 }
4996 *s = NUL;
4997
4998 /*
4999 * Expand environment variables and ~.
5000 * Don't do it when adding without inserting a
5001 * comma.
5002 */
5003 if (!(adding || prepending || removing)
5004 || (flags & P_COMMA))
5005 {
5006 s = option_expand(opt_idx, newval);
5007 if (s != NULL)
5008 {
5009 vim_free(newval);
5010 newlen = (unsigned)STRLEN(s) + 1;
5011 if (adding || prepending || removing)
5012 newlen += (unsigned)STRLEN(origval) + 1;
5013 newval = alloc(newlen);
5014 if (newval == NULL)
5015 break;
5016 STRCPY(newval, s);
5017 }
5018 }
5019
5020 /* locate newval[] in origval[] when removing it
5021 * and when adding to avoid duplicates */
5022 i = 0; /* init for GCC */
5023 if (removing || (flags & P_NODUP))
5024 {
5025 i = (int)STRLEN(newval);
5026 bs = 0;
5027 for (s = origval; *s; ++s)
5028 {
5029 if ((!(flags & P_COMMA)
5030 || s == origval
5031 || (s[-1] == ',' && !(bs & 1)))
5032 && STRNCMP(s, newval, i) == 0
5033 && (!(flags & P_COMMA)
5034 || s[i] == ','
5035 || s[i] == NUL))
5036 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005037 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005038 * even number of backslashes or a single
5039 * backslash preceded by a comma before it
5040 * is recognized as a separator */
5041 if ((s > origval + 1
5042 && s[-1] == '\\'
5043 && s[-2] != ',')
5044 || (s == origval + 1
5045 && s[-1] == '\\'))
5046
Bram Moolenaar071d4272004-06-13 20:20:40 +00005047 ++bs;
5048 else
5049 bs = 0;
5050 }
5051
5052 /* do not add if already there */
5053 if ((adding || prepending) && *s)
5054 {
5055 prepending = FALSE;
5056 adding = FALSE;
5057 STRCPY(newval, origval);
5058 }
5059 }
5060
5061 /* concatenate the two strings; add a ',' if
5062 * needed */
5063 if (adding || prepending)
5064 {
5065 comma = ((flags & P_COMMA) && *origval != NUL
5066 && *newval != NUL);
5067 if (adding)
5068 {
5069 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005070 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005071 if (comma && i > 1
5072 && (flags & P_ONECOMMA) == P_ONECOMMA
5073 && origval[i - 1] == ','
5074 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005075 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005076 mch_memmove(newval + i + comma, newval,
5077 STRLEN(newval) + 1);
5078 mch_memmove(newval, origval, (size_t)i);
5079 }
5080 else
5081 {
5082 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005083 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005084 }
5085 if (comma)
5086 newval[i] = ',';
5087 }
5088
5089 /* Remove newval[] from origval[]. (Note: "i" has
5090 * been set above and is used here). */
5091 if (removing)
5092 {
5093 STRCPY(newval, origval);
5094 if (*s)
5095 {
5096 /* may need to remove a comma */
5097 if (flags & P_COMMA)
5098 {
5099 if (s == origval)
5100 {
5101 /* include comma after string */
5102 if (s[i] == ',')
5103 ++i;
5104 }
5105 else
5106 {
5107 /* include comma before string */
5108 --s;
5109 ++i;
5110 }
5111 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005112 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 }
5114 }
5115
5116 if (flags & P_FLAGLIST)
5117 {
5118 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005119 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005120 {
5121 /* if options have P_FLAGLIST and
5122 * P_ONECOMMA such as 'whichwrap' */
5123 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005124 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005125 if (*s != ',' && *(s + 1) == ','
5126 && vim_strchr(s + 2, *s) != NULL)
5127 {
5128 /* Remove the duplicated value and
5129 * the next comma. */
5130 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005131 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005132 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005133 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005134 else
5135 {
5136 if ((!(flags & P_COMMA) || *s != ',')
5137 && vim_strchr(s + 1, *s) != NULL)
5138 {
5139 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005140 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005141 }
5142 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005143 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005144 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005145 }
5146
5147 if (save_arg != NULL) /* number for 'whichwrap' */
5148 arg = save_arg;
5149 new_value_alloced = TRUE;
5150 }
5151
5152 /* Set the new value. */
5153 *(char_u **)(varp) = newval;
5154
Bram Moolenaar53744302015-07-17 17:38:22 +02005155#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005156 if (!starting
5157# ifdef FEAT_CRYPT
5158 && options[opt_idx].indir != PV_KEY
5159# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005160 && origval != NULL && newval != NULL)
5161 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005162 /* origval may be freed by
5163 * did_set_string_option(), make a copy. */
5164 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005165 /* newval (and varp) may become invalid if the
5166 * buffer is closed by autocommands. */
5167 saved_newval = vim_strsave(newval);
5168 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005169#endif
5170
Bram Moolenaar071d4272004-06-13 20:20:40 +00005171 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005172 * ":set" on local options. Note: when setting 'syntax'
5173 * or 'filetype' autocommands may be triggered that can
5174 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5176 new_value_alloced, oldval, errbuf, opt_flags);
5177
5178 /* If error detected, print the error message. */
5179 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005180 {
5181#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5182 vim_free(saved_origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005183 vim_free(saved_newval);
Bram Moolenaara9884962015-12-13 15:08:56 +01005184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005186 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005187#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005188 trigger_optionsset_string(opt_idx, opt_flags,
5189 saved_origval, saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005191 }
5192 else /* key code option */
5193 {
5194 char_u *p;
5195
5196 if (nextchar == '&')
5197 {
5198 if (add_termcap_entry(key_name, TRUE) == FAIL)
5199 errmsg = (char_u *)N_("E522: Not found in termcap");
5200 }
5201 else
5202 {
5203 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005204 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005205 if (*p == '\\' && p[1] != NUL)
5206 ++p;
5207 nextchar = *p;
5208 *p = NUL;
5209 add_termcode(key_name, arg, FALSE);
5210 *p = nextchar;
5211 }
5212 if (full_screen)
5213 ttest(FALSE);
5214 redraw_all_later(CLEAR);
5215 }
5216 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005217
Bram Moolenaar071d4272004-06-13 20:20:40 +00005218 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005219 did_set_option(opt_idx, opt_flags,
5220 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221 }
5222
5223skip:
5224 /*
5225 * Advance to next argument.
5226 * - skip until a blank found, taking care of backslashes
5227 * - skip blanks
5228 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5229 */
5230 for (i = 0; i < 2 ; ++i)
5231 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005232 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005233 if (*arg++ == '\\' && *arg != NUL)
5234 ++arg;
5235 arg = skipwhite(arg);
5236 if (*arg != '=')
5237 break;
5238 }
5239 }
5240
5241 if (errmsg != NULL)
5242 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005243 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005244 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245 if (i + (arg - startarg) < IOSIZE)
5246 {
5247 /* append the argument with the error */
5248 STRCAT(IObuff, ": ");
5249 mch_memmove(IObuff + i, startarg, (arg - startarg));
5250 IObuff[i + (arg - startarg)] = NUL;
5251 }
5252 /* make sure all characters are printable */
5253 trans_characters(IObuff, IOSIZE);
5254
5255 ++no_wait_return; /* wait_return done later */
5256 emsg(IObuff); /* show error highlighted */
5257 --no_wait_return;
5258
5259 return FAIL;
5260 }
5261
5262 arg = skipwhite(arg);
5263 }
5264
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005265theend:
5266 if (silent_mode && did_show)
5267 {
5268 /* After displaying option values in silent mode. */
5269 silent_mode = FALSE;
5270 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5271 msg_putchar('\n');
5272 cursor_on(); /* msg_start() switches it off */
5273 out_flush();
5274 silent_mode = TRUE;
5275 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5276 }
5277
Bram Moolenaar071d4272004-06-13 20:20:40 +00005278 return OK;
5279}
5280
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005281/*
5282 * Call this when an option has been given a new value through a user command.
5283 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5284 */
5285 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005286did_set_option(
5287 int opt_idx,
5288 int opt_flags, /* possibly with OPT_MODELINE */
5289 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005290{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005291 long_u *p;
5292
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005293 options[opt_idx].flags |= P_WAS_SET;
5294
5295 /* When an option is set in the sandbox, from a modeline or in secure mode
5296 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005297 * flag. */
5298 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005299 if (secure
5300#ifdef HAVE_SANDBOX
5301 || sandbox != 0
5302#endif
5303 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005304 *p = *p | P_INSECURE;
5305 else if (new_value)
5306 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005307}
5308
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005310illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005311{
5312 if (errbuf == NULL)
5313 return (char_u *)"";
5314 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005315 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 return errbuf;
5317}
5318
5319/*
5320 * Convert a key name or string into a key value.
5321 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005322 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005324 int
5325string_to_key(char_u *arg, int multi_byte)
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]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005331 if (multi_byte)
5332 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333 return *arg;
5334}
5335
5336#ifdef FEAT_CMDWIN
5337/*
5338 * Check value of 'cedit' and set cedit_key.
5339 * Returns NULL if value is OK, error message otherwise.
5340 */
5341 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005342check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343{
5344 int n;
5345
5346 if (*p_cedit == NUL)
5347 cedit_key = -1;
5348 else
5349 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005350 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351 if (vim_isprintc(n))
5352 return e_invarg;
5353 cedit_key = n;
5354 }
5355 return NULL;
5356}
5357#endif
5358
5359#ifdef FEAT_TITLE
5360/*
5361 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5362 * maketitle() to create and display it.
5363 * When switching the title or icon off, call mch_restore_title() to get
5364 * the old value back.
5365 */
5366 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005367did_set_title(
5368 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369{
5370 if (starting != NO_SCREEN
5371#ifdef FEAT_GUI
5372 && !gui.starting
5373#endif
5374 )
5375 {
5376 maketitle();
5377 if (icon)
5378 {
5379 if (!p_icon)
5380 mch_restore_title(2);
5381 }
5382 else
5383 {
5384 if (!p_title)
5385 mch_restore_title(1);
5386 }
5387 }
5388}
5389#endif
5390
5391/*
5392 * set_options_bin - called when 'bin' changes value.
5393 */
5394 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005395set_options_bin(
5396 int oldval,
5397 int newval,
5398 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005399{
5400 /*
5401 * The option values that are changed when 'bin' changes are
5402 * copied when 'bin is set and restored when 'bin' is reset.
5403 */
5404 if (newval)
5405 {
5406 if (!oldval) /* switched on */
5407 {
5408 if (!(opt_flags & OPT_GLOBAL))
5409 {
5410 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5411 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5412 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5413 curbuf->b_p_et_nobin = curbuf->b_p_et;
5414 }
5415 if (!(opt_flags & OPT_LOCAL))
5416 {
5417 p_tw_nobin = p_tw;
5418 p_wm_nobin = p_wm;
5419 p_ml_nobin = p_ml;
5420 p_et_nobin = p_et;
5421 }
5422 }
5423
5424 if (!(opt_flags & OPT_GLOBAL))
5425 {
5426 curbuf->b_p_tw = 0; /* no automatic line wrap */
5427 curbuf->b_p_wm = 0; /* no automatic line wrap */
5428 curbuf->b_p_ml = 0; /* no modelines */
5429 curbuf->b_p_et = 0; /* no expandtab */
5430 }
5431 if (!(opt_flags & OPT_LOCAL))
5432 {
5433 p_tw = 0;
5434 p_wm = 0;
5435 p_ml = FALSE;
5436 p_et = FALSE;
5437 p_bin = TRUE; /* needed when called for the "-b" argument */
5438 }
5439 }
5440 else if (oldval) /* switched off */
5441 {
5442 if (!(opt_flags & OPT_GLOBAL))
5443 {
5444 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5445 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5446 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5447 curbuf->b_p_et = curbuf->b_p_et_nobin;
5448 }
5449 if (!(opt_flags & OPT_LOCAL))
5450 {
5451 p_tw = p_tw_nobin;
5452 p_wm = p_wm_nobin;
5453 p_ml = p_ml_nobin;
5454 p_et = p_et_nobin;
5455 }
5456 }
5457}
5458
5459#ifdef FEAT_VIMINFO
5460/*
5461 * Find the parameter represented by the given character (eg ', :, ", or /),
5462 * and return its associated value in the 'viminfo' string.
5463 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005464 * If the parameter is not specified in the string or there is no following
5465 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005466 */
5467 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005468get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469{
5470 char_u *p;
5471
5472 p = find_viminfo_parameter(type);
5473 if (p != NULL && VIM_ISDIGIT(*p))
5474 return atoi((char *)p);
5475 return -1;
5476}
5477
5478/*
5479 * Find the parameter represented by the given character (eg ''', ':', '"', or
5480 * '/') in the 'viminfo' option and return a pointer to the string after it.
5481 * Return NULL if the parameter is not specified in the string.
5482 */
5483 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005484find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005485{
5486 char_u *p;
5487
5488 for (p = p_viminfo; *p; ++p)
5489 {
5490 if (*p == type)
5491 return p + 1;
5492 if (*p == 'n') /* 'n' is always the last one */
5493 break;
5494 p = vim_strchr(p, ','); /* skip until next ',' */
5495 if (p == NULL) /* hit the end without finding parameter */
5496 break;
5497 }
5498 return NULL;
5499}
5500#endif
5501
5502/*
5503 * Expand environment variables for some string options.
5504 * These string options cannot be indirect!
5505 * If "val" is NULL expand the current value of the option.
5506 * Return pointer to NameBuff, or NULL when not expanded.
5507 */
5508 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005509option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005510{
5511 /* if option doesn't need expansion nothing to do */
5512 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5513 return NULL;
5514
5515 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5516 * expand_env() would truncate the string. */
5517 if (val != NULL && STRLEN(val) > MAXPATHL)
5518 return NULL;
5519
5520 if (val == NULL)
5521 val = *(char_u **)options[opt_idx].var;
5522
5523 /*
5524 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5525 * Escape spaces when expanding 'tags', they are used to separate file
5526 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005527 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528 */
5529 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005530 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005531#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005532 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5533#endif
5534 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5536 return NULL;
5537
5538 return NameBuff;
5539}
5540
5541/*
5542 * After setting various option values: recompute variables that depend on
5543 * option values.
5544 */
5545 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005546didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547{
5548 /* initialize the table for 'iskeyword' et.al. */
5549 (void)init_chartab();
5550
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005551#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005553#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005555 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556#ifdef FEAT_SESSION
5557 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5558 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5559#endif
5560#ifdef FEAT_FOLDING
5561 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5562#endif
5563 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005564 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565#ifdef FEAT_VIRTUALEDIT
5566 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5567#endif
5568#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5569 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5570#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005571#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005572 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005573 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005574 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005575 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5578 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5579#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005580#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5582#endif
5583#ifdef FEAT_CMDWIN
5584 /* set cedit_key */
5585 (void)check_cedit();
5586#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005587#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005588 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005589#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005590#ifdef FEAT_LINEBREAK
5591 /* initialize the table for 'breakat'. */
5592 fill_breakat_flags();
5593#endif
5594
5595}
5596
5597/*
5598 * More side effects of setting options.
5599 */
5600 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005601didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005602{
5603 /* Initialize the highlight_attr[] table. */
5604 (void)highlight_changed();
5605
5606 /* Parse default for 'wildmode' */
5607 check_opt_wim();
5608
5609 (void)set_chars_option(&p_lcs);
5610#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5611 /* Parse default for 'fillchars'. */
5612 (void)set_chars_option(&p_fcs);
5613#endif
5614
5615#ifdef FEAT_CLIPBOARD
5616 /* Parse default for 'clipboard' */
5617 (void)check_clipboard_option();
5618#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005619}
5620
5621/*
5622 * Check for string options that are NULL (normally only termcap options).
5623 */
5624 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005625check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005626{
5627 int opt_idx;
5628
5629 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5630 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5631 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5632}
5633
5634/*
5635 * Check string options in a buffer for NULL value.
5636 */
5637 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005638check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640 check_string_option(&buf->b_p_bh);
5641 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005642#ifdef FEAT_MBYTE
5643 check_string_option(&buf->b_p_fenc);
5644#endif
5645 check_string_option(&buf->b_p_ff);
5646#ifdef FEAT_FIND_ID
5647 check_string_option(&buf->b_p_def);
5648 check_string_option(&buf->b_p_inc);
5649# ifdef FEAT_EVAL
5650 check_string_option(&buf->b_p_inex);
5651# endif
5652#endif
5653#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5654 check_string_option(&buf->b_p_inde);
5655 check_string_option(&buf->b_p_indk);
5656#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005657#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5658 check_string_option(&buf->b_p_bexpr);
5659#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005660#if defined(FEAT_CRYPT)
5661 check_string_option(&buf->b_p_cm);
5662#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005663 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005664#if defined(FEAT_EVAL)
5665 check_string_option(&buf->b_p_fex);
5666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667#ifdef FEAT_CRYPT
5668 check_string_option(&buf->b_p_key);
5669#endif
5670 check_string_option(&buf->b_p_kp);
5671 check_string_option(&buf->b_p_mps);
5672 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005673 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005674 check_string_option(&buf->b_p_isk);
5675#ifdef FEAT_COMMENTS
5676 check_string_option(&buf->b_p_com);
5677#endif
5678#ifdef FEAT_FOLDING
5679 check_string_option(&buf->b_p_cms);
5680#endif
5681 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005682#ifdef FEAT_TEXTOBJ
5683 check_string_option(&buf->b_p_qe);
5684#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685#ifdef FEAT_SYN_HL
5686 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005687 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005688#endif
5689#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005690 check_string_option(&buf->b_s.b_p_spc);
5691 check_string_option(&buf->b_s.b_p_spf);
5692 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693#endif
5694#ifdef FEAT_SEARCHPATH
5695 check_string_option(&buf->b_p_sua);
5696#endif
5697#ifdef FEAT_CINDENT
5698 check_string_option(&buf->b_p_cink);
5699 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005700 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701#endif
5702#ifdef FEAT_AUTOCMD
5703 check_string_option(&buf->b_p_ft);
5704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5706 check_string_option(&buf->b_p_cinw);
5707#endif
5708#ifdef FEAT_INS_EXPAND
5709 check_string_option(&buf->b_p_cpt);
5710#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005711#ifdef FEAT_COMPL_FUNC
5712 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005713 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715#ifdef FEAT_KEYMAP
5716 check_string_option(&buf->b_p_keymap);
5717#endif
5718#ifdef FEAT_QUICKFIX
5719 check_string_option(&buf->b_p_gp);
5720 check_string_option(&buf->b_p_mp);
5721 check_string_option(&buf->b_p_efm);
5722#endif
5723 check_string_option(&buf->b_p_ep);
5724 check_string_option(&buf->b_p_path);
5725 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005726 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727#ifdef FEAT_INS_EXPAND
5728 check_string_option(&buf->b_p_dict);
5729 check_string_option(&buf->b_p_tsr);
5730#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005731#ifdef FEAT_LISP
5732 check_string_option(&buf->b_p_lw);
5733#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005734 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005735#ifdef FEAT_MBYTE
5736 check_string_option(&buf->b_p_menc);
5737#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005738}
5739
5740/*
5741 * Free the string allocated for an option.
5742 * Checks for the string being empty_option. This may happen if we're out of
5743 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5744 * check_options().
5745 * Does NOT check for P_ALLOCED flag!
5746 */
5747 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005748free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005749{
5750 if (p != empty_option)
5751 vim_free(p);
5752}
5753
5754 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005755clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756{
5757 if (*pp != empty_option)
5758 vim_free(*pp);
5759 *pp = empty_option;
5760}
5761
5762 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005763check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764{
5765 if (*pp == NULL)
5766 *pp = empty_option;
5767}
5768
5769/*
5770 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5771 */
5772 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005773set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005774{
5775 int opt_idx;
5776
5777 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5778 if (options[opt_idx].var == (char_u *)p)
5779 {
5780 options[opt_idx].flags |= P_ALLOCED;
5781 return;
5782 }
5783 return; /* cannot happen: didn't find it! */
5784}
5785
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005786#if defined(FEAT_EVAL) || defined(PROTO)
5787/*
5788 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5789 * Return FALSE when it wasn't.
5790 * Return -1 for an unknown option.
5791 */
5792 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005793was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005794{
5795 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005796 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005797
5798 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005799 {
5800 flagp = insecure_flag(idx, opt_flags);
5801 return (*flagp & P_INSECURE) != 0;
5802 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005803 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005804 return -1;
5805}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005806
5807/*
5808 * Get a pointer to the flags used for the P_INSECURE flag of option
5809 * "opt_idx". For some local options a local flags field is used.
5810 */
5811 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005812insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005813{
5814 if (opt_flags & OPT_LOCAL)
5815 switch ((int)options[opt_idx].indir)
5816 {
5817#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005818 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005819#endif
5820#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005821# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005822 case PV_FDE: return &curwin->w_p_fde_flags;
5823 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005824# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005825# ifdef FEAT_BEVAL
5826 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5827# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005828# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005829 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005830# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005831 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005832# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005833 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005834# endif
5835#endif
5836 }
5837
5838 /* Nothing special, return global flags field. */
5839 return &options[opt_idx].flags;
5840}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005841#endif
5842
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005843#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005844static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005845
5846/*
5847 * Redraw the window title and/or tab page text later.
5848 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005849static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005850{
5851 need_maketitle = TRUE;
5852# ifdef FEAT_WINDOWS
5853 redraw_tabline = TRUE;
5854# endif
5855}
5856#endif
5857
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858/*
5859 * Set a string option to a new value (without checking the effect).
5860 * The string is copied into allocated memory.
5861 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005862 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005863 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864 */
5865 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005866set_string_option_direct(
5867 char_u *name,
5868 int opt_idx,
5869 char_u *val,
5870 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5871 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872{
5873 char_u *s;
5874 char_u **varp;
5875 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005877
Bram Moolenaar89d40322006-08-29 15:30:07 +00005878 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005880 idx = findoption(name);
5881 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005882 {
5883 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005884 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005886 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005887 }
5888
Bram Moolenaar89d40322006-08-29 15:30:07 +00005889 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890 return;
5891
5892 s = vim_strsave(val);
5893 if (s != NULL)
5894 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005895 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005897 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 free_string_option(*varp);
5899 *varp = s;
5900
5901 /* For buffer/window local option may also set the global value. */
5902 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904
Bram Moolenaar89d40322006-08-29 15:30:07 +00005905 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906
5907 /* When setting both values of a global option with a local value,
5908 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005909 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 {
5911 free_string_option(*varp);
5912 *varp = empty_option;
5913 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005914# ifdef FEAT_EVAL
5915 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005916 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005917 set_sid == 0 ? current_SID : set_sid);
5918# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 }
5920}
5921
5922/*
5923 * Set global value for string option when it's a local option.
5924 */
5925 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005926set_string_option_global(
5927 int opt_idx, /* option index */
5928 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929{
5930 char_u **p, *s;
5931
5932 /* the global value is always allocated */
5933 if (options[opt_idx].var == VAR_WIN)
5934 p = (char_u **)GLOBAL_WO(varp);
5935 else
5936 p = (char_u **)options[opt_idx].var;
5937 if (options[opt_idx].indir != PV_NONE
5938 && p != varp
5939 && (s = vim_strsave(*varp)) != NULL)
5940 {
5941 free_string_option(*p);
5942 *p = s;
5943 }
5944}
5945
5946/*
5947 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005948 *
5949 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005951 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005952set_string_option(
5953 int opt_idx,
5954 char_u *value,
5955 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956{
5957 char_u *s;
5958 char_u **varp;
5959 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005960#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5961 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005962 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005963#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005964 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965
5966 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005967 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005968
5969 s = vim_strsave(value);
5970 if (s != NULL)
5971 {
5972 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5973 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005974 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975 ? OPT_GLOBAL : OPT_LOCAL)
5976 : opt_flags);
5977 oldval = *varp;
5978 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005979
5980#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005981 if (!starting
5982# ifdef FEAT_CRYPT
5983 && options[opt_idx].indir != PV_KEY
5984# endif
5985 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005986 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005987 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005988 saved_newval = vim_strsave(s);
5989 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005990#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005991 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5992 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005993 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005994
Bram Moolenaar53744302015-07-17 17:38:22 +02005995#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005996 /* call autocommand after handling side effects */
5997 trigger_optionsset_string(opt_idx, opt_flags,
5998 saved_oldval, saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005999#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006001 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002}
6003
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006004#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006006 * Return TRUE if "val" is a valid 'filetype' name.
6007 * Also used for 'syntax' and 'keymap'.
6008 */
6009 static int
6010valid_filetype(char_u *val)
6011{
6012 char_u *s;
6013
6014 for (s = val; *s != NUL; ++s)
6015 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6016 return FALSE;
6017 return TRUE;
6018}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006019#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006020
6021/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006022 * Handle string options that need some action to perform when changed.
6023 * Returns NULL for success, or an error message for an error.
6024 */
6025 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006026did_set_string_option(
6027 int opt_idx, /* index in options[] table */
6028 char_u **varp, /* pointer to the option variable */
6029 int new_value_alloced, /* new value was allocated */
6030 char_u *oldval, /* previous value of the option */
6031 char_u *errbuf, /* buffer for errors, or NULL */
6032 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006033{
6034 char_u *errmsg = NULL;
6035 char_u *s, *p;
6036 int did_chartab = FALSE;
6037 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006038 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006039#ifdef FEAT_GUI
6040 /* set when changing an option that only requires a redraw in the GUI */
6041 int redraw_gui_only = FALSE;
6042#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006043#ifdef FEAT_AUTOCMD
6044 int ft_changed = FALSE;
6045#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006046
6047 /* Get the global option to compare with, otherwise we would have to check
6048 * two values for all local options. */
6049 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6050
6051 /* Disallow changing some options from secure mode */
6052 if ((secure
6053#ifdef HAVE_SANDBOX
6054 || sandbox != 0
6055#endif
6056 ) && (options[opt_idx].flags & P_SECURE))
6057 {
6058 errmsg = e_secure;
6059 }
6060
Bram Moolenaar7554da42016-11-25 22:04:13 +01006061 /* Check for a "normal" directory or file name in some options. Disallow a
6062 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006063 * are often illegal in a file name. Be more permissive if "secure" is off.
6064 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006065 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006066 && vim_strpbrk(*varp, (char_u *)(secure
6067 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006068 || ((options[opt_idx].flags & P_NDNAME)
6069 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006070 {
6071 errmsg = e_invarg;
6072 }
6073
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074 /* 'term' */
6075 else if (varp == &T_NAME)
6076 {
6077 if (T_NAME[0] == NUL)
6078 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6079#ifdef FEAT_GUI
6080 if (gui.in_use)
6081 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6082 else if (term_is_gui(T_NAME))
6083 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6084#endif
6085 else if (set_termname(T_NAME) == FAIL)
6086 errmsg = (char_u *)N_("E522: Not found in termcap");
6087 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006088 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006089 /* Screen colors may have changed. */
6090 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006091
6092 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6093 * P_ALLOCED flag on 'term'. */
6094 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006095 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006096 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097 }
6098
6099 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006100 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006102 char_u *bkc = p_bkc;
6103 unsigned int *flags = &bkc_flags;
6104
6105 if (opt_flags & OPT_LOCAL)
6106 {
6107 bkc = curbuf->b_p_bkc;
6108 flags = &curbuf->b_bkc_flags;
6109 }
6110
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006111 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6112 /* make the local value empty: use the global value */
6113 *flags = 0;
6114 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006116 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6117 errmsg = e_invarg;
6118 if ((((int)*flags & BKC_AUTO) != 0)
6119 + (((int)*flags & BKC_YES) != 0)
6120 + (((int)*flags & BKC_NO) != 0) != 1)
6121 {
6122 /* Must have exactly one of "auto", "yes" and "no". */
6123 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6124 errmsg = e_invarg;
6125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006126 }
6127 }
6128
6129 /* 'backupext' and 'patchmode' */
6130 else if (varp == &p_bex || varp == &p_pm)
6131 {
6132 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6133 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6134 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6135 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006136#ifdef FEAT_LINEBREAK
6137 /* 'breakindentopt' */
6138 else if (varp == &curwin->w_p_briopt)
6139 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006140 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006141 errmsg = e_invarg;
6142 }
6143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144
6145 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006146 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006148 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006149 */
6150 else if ( varp == &p_isi
6151 || varp == &(curbuf->b_p_isk)
6152 || varp == &p_isp
6153 || varp == &p_isf)
6154 {
6155 if (init_chartab() == FAIL)
6156 {
6157 did_chartab = TRUE; /* need to restore it below */
6158 errmsg = e_invarg; /* error in value */
6159 }
6160 }
6161
6162 /* 'helpfile' */
6163 else if (varp == &p_hf)
6164 {
6165 /* May compute new values for $VIM and $VIMRUNTIME */
6166 if (didset_vim)
6167 {
6168 vim_setenv((char_u *)"VIM", (char_u *)"");
6169 didset_vim = FALSE;
6170 }
6171 if (didset_vimruntime)
6172 {
6173 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6174 didset_vimruntime = FALSE;
6175 }
6176 }
6177
Bram Moolenaar1a384422010-07-14 19:53:30 +02006178#ifdef FEAT_SYN_HL
6179 /* 'colorcolumn' */
6180 else if (varp == &curwin->w_p_cc)
6181 errmsg = check_colorcolumn(curwin);
6182#endif
6183
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184#ifdef FEAT_MULTI_LANG
6185 /* 'helplang' */
6186 else if (varp == &p_hlg)
6187 {
6188 /* Check for "", "ab", "ab,cd", etc. */
6189 for (s = p_hlg; *s != NUL; s += 3)
6190 {
6191 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6192 {
6193 errmsg = e_invarg;
6194 break;
6195 }
6196 if (s[2] == NUL)
6197 break;
6198 }
6199 }
6200#endif
6201
6202 /* 'highlight' */
6203 else if (varp == &p_hl)
6204 {
6205 if (highlight_changed() == FAIL)
6206 errmsg = e_invarg; /* invalid flags */
6207 }
6208
6209 /* 'nrformats' */
6210 else if (gvarp == &p_nf)
6211 {
6212 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6213 errmsg = e_invarg;
6214 }
6215
6216#ifdef FEAT_SESSION
6217 /* 'sessionoptions' */
6218 else if (varp == &p_ssop)
6219 {
6220 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6221 errmsg = e_invarg;
6222 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6223 {
6224 /* Don't allow both "sesdir" and "curdir". */
6225 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6226 errmsg = e_invarg;
6227 }
6228 }
6229 /* 'viewoptions' */
6230 else if (varp == &p_vop)
6231 {
6232 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6233 errmsg = e_invarg;
6234 }
6235#endif
6236
6237 /* 'scrollopt' */
6238#ifdef FEAT_SCROLLBIND
6239 else if (varp == &p_sbo)
6240 {
6241 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6242 errmsg = e_invarg;
6243 }
6244#endif
6245
6246 /* 'ambiwidth' */
6247#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006248 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249 {
6250 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6251 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006252 else if (set_chars_option(&p_lcs) != NULL)
6253 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6254# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6255 else if (set_chars_option(&p_fcs) != NULL)
6256 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6257# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 }
6259#endif
6260
6261 /* 'background' */
6262 else if (varp == &p_bg)
6263 {
6264 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6265 {
6266#ifdef FEAT_EVAL
6267 int dark = (*p_bg == 'd');
6268#endif
6269
6270 init_highlight(FALSE, FALSE);
6271
6272#ifdef FEAT_EVAL
6273 if (dark != (*p_bg == 'd')
6274 && get_var_value((char_u *)"g:colors_name") != NULL)
6275 {
6276 /* The color scheme must have set 'background' back to another
6277 * value, that's not what we want here. Disable the color
6278 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006279 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006280 free_string_option(p_bg);
6281 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6282 check_string_option(&p_bg);
6283 init_highlight(FALSE, FALSE);
6284 }
6285#endif
6286 }
6287 else
6288 errmsg = e_invarg;
6289 }
6290
6291 /* 'wildmode' */
6292 else if (varp == &p_wim)
6293 {
6294 if (check_opt_wim() == FAIL)
6295 errmsg = e_invarg;
6296 }
6297
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006298#ifdef FEAT_CMDL_COMPL
6299 /* 'wildoptions' */
6300 else if (varp == &p_wop)
6301 {
6302 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6303 errmsg = e_invarg;
6304 }
6305#endif
6306
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307#ifdef FEAT_WAK
6308 /* 'winaltkeys' */
6309 else if (varp == &p_wak)
6310 {
6311 if (*p_wak == NUL
6312 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6313 errmsg = e_invarg;
6314# ifdef FEAT_MENU
6315# ifdef FEAT_GUI_MOTIF
6316 else if (gui.in_use)
6317 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6318# else
6319# ifdef FEAT_GUI_GTK
6320 else if (gui.in_use)
6321 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6322# endif
6323# endif
6324# endif
6325 }
6326#endif
6327
6328#ifdef FEAT_AUTOCMD
6329 /* 'eventignore' */
6330 else if (varp == &p_ei)
6331 {
6332 if (check_ei() == FAIL)
6333 errmsg = e_invarg;
6334 }
6335#endif
6336
6337#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006338 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6339 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6340 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006341 {
6342 if (gvarp == &p_fenc)
6343 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006344 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345 errmsg = e_modifiable;
6346 else if (vim_strchr(*varp, ',') != NULL)
6347 /* No comma allowed in 'fileencoding'; catches confusing it
6348 * with 'fileencodings'. */
6349 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006351 {
6352# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006353 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006354 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006356 /* Add 'fileencoding' to the swap file. */
6357 ml_setflags(curbuf);
6358 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359 }
6360 if (errmsg == NULL)
6361 {
6362 /* canonize the value, so that STRCMP() can be used on it */
6363 p = enc_canonize(*varp);
6364 if (p != NULL)
6365 {
6366 vim_free(*varp);
6367 *varp = p;
6368 }
6369 if (varp == &p_enc)
6370 {
6371 errmsg = mb_init();
6372# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006373 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374# endif
6375 }
6376 }
6377
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006378# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6380 {
6381 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6382 if (STRCMP(p_tenc, "utf-8") != 0)
6383 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6384 }
6385# endif
6386
6387 if (errmsg == NULL)
6388 {
6389# ifdef FEAT_KEYMAP
6390 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6391 * (with another encoding). */
6392 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6393 (void)keymap_init();
6394# endif
6395
6396 /* When 'termencoding' is not empty and 'encoding' changes or when
6397 * 'termencoding' changes, need to setup for keyboard input and
6398 * display output conversion. */
6399 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6400 {
6401 convert_setup(&input_conv, p_tenc, p_enc);
6402 convert_setup(&output_conv, p_enc, p_tenc);
6403 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006404
6405# if defined(WIN3264) && defined(FEAT_MBYTE)
6406 /* $HOME may have characters in active code page. */
6407 if (varp == &p_enc)
6408 init_homedir();
6409# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006410 }
6411 }
6412#endif
6413
6414#if defined(FEAT_POSTSCRIPT)
6415 else if (varp == &p_penc)
6416 {
6417 /* Canonize printencoding if VIM standard one */
6418 p = enc_canonize(p_penc);
6419 if (p != NULL)
6420 {
6421 vim_free(p_penc);
6422 p_penc = p;
6423 }
6424 else
6425 {
6426 /* Ensure lower case and '-' for '_' */
6427 for (s = p_penc; *s != NUL; s++)
6428 {
6429 if (*s == '_')
6430 *s = '-';
6431 else
6432 *s = TOLOWER_ASC(*s);
6433 }
6434 }
6435 }
6436#endif
6437
Bram Moolenaar9372a112005-12-06 19:59:18 +00006438#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 else if (varp == &p_imak)
6440 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006441 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006442 errmsg = e_invarg;
6443 }
6444#endif
6445
6446#ifdef FEAT_KEYMAP
6447 else if (varp == &curbuf->b_p_keymap)
6448 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006449 if (!valid_filetype(*varp))
6450 errmsg = e_invarg;
6451 else
6452 /* load or unload key mapping tables */
6453 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454
Bram Moolenaarfab06232009-03-04 03:13:35 +00006455 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006456 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006457 if (*curbuf->b_p_keymap != NUL)
6458 {
6459 /* Installed a new keymap, switch on using it. */
6460 curbuf->b_p_iminsert = B_IMODE_LMAP;
6461 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6462 curbuf->b_p_imsearch = B_IMODE_LMAP;
6463 }
6464 else
6465 {
6466 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6467 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6468 curbuf->b_p_iminsert = B_IMODE_NONE;
6469 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6470 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6471 }
6472 if ((opt_flags & OPT_LOCAL) == 0)
6473 {
6474 set_iminsert_global();
6475 set_imsearch_global();
6476 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477# ifdef FEAT_WINDOWS
6478 status_redraw_curbuf();
6479# endif
6480 }
6481 }
6482#endif
6483
6484 /* 'fileformat' */
6485 else if (gvarp == &p_ff)
6486 {
6487 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6488 errmsg = e_modifiable;
6489 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6490 errmsg = e_invarg;
6491 else
6492 {
6493 /* may also change 'textmode' */
6494 if (get_fileformat(curbuf) == EOL_DOS)
6495 curbuf->b_p_tx = TRUE;
6496 else
6497 curbuf->b_p_tx = FALSE;
6498#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006499 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006500#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006501 /* update flag in swap file */
6502 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006503 /* Redraw needed when switching to/from "mac": a CR in the text
6504 * will be displayed differently. */
6505 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6506 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006507 }
6508 }
6509
6510 /* 'fileformats' */
6511 else if (varp == &p_ffs)
6512 {
6513 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6514 errmsg = e_invarg;
6515 else
6516 {
6517 /* also change 'textauto' */
6518 if (*p_ffs == NUL)
6519 p_ta = FALSE;
6520 else
6521 p_ta = TRUE;
6522 }
6523 }
6524
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006525#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006526 /* 'cryptkey' */
6527 else if (gvarp == &p_key)
6528 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006529# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530 /* Make sure the ":set" command doesn't show the new value in the
6531 * history. */
6532 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006533# endif
6534 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6535 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006536 ml_set_crypt_key(curbuf, oldval,
6537 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006538 }
6539
6540 else if (gvarp == &p_cm)
6541 {
6542 if (opt_flags & OPT_LOCAL)
6543 p = curbuf->b_p_cm;
6544 else
6545 p = p_cm;
6546 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6547 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006548 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006549 errmsg = e_invarg;
6550 else
6551 {
6552 /* When setting the global value to empty, make it "zip". */
6553 if (*p_cm == NUL)
6554 {
6555 if (new_value_alloced)
6556 free_string_option(p_cm);
6557 p_cm = vim_strsave((char_u *)"zip");
6558 new_value_alloced = TRUE;
6559 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006560 /* When using ":set cm=name" the local value is going to be empty.
6561 * Do that here, otherwise the crypt functions will still use the
6562 * local value. */
6563 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6564 {
6565 free_string_option(curbuf->b_p_cm);
6566 curbuf->b_p_cm = empty_option;
6567 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006568
6569 /* Need to update the swapfile when the effective method changed.
6570 * Set "s" to the effective old value, "p" to the effective new
6571 * method and compare. */
6572 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6573 s = p_cm; /* was previously using the global value */
6574 else
6575 s = oldval;
6576 if (*curbuf->b_p_cm == NUL)
6577 p = p_cm; /* is now using the global value */
6578 else
6579 p = curbuf->b_p_cm;
6580 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006581 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006582
6583 /* If the global value changes need to update the swapfile for all
6584 * buffers using that value. */
6585 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6586 {
6587 buf_T *buf;
6588
Bram Moolenaar29323592016-07-24 22:04:11 +02006589 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006590 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006591 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006592 }
6593 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006594 }
6595#endif
6596
6597 /* 'matchpairs' */
6598 else if (gvarp == &p_mps)
6599 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006600#ifdef FEAT_MBYTE
6601 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006602 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006603 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006605 int x2 = -1;
6606 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006607
6608 if (*p != NUL)
6609 p += mb_ptr2len(p);
6610 if (*p != NUL)
6611 x2 = *p++;
6612 if (*p != NUL)
6613 {
6614 x3 = mb_ptr2char(p);
6615 p += mb_ptr2len(p);
6616 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006617 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006618 {
6619 errmsg = e_invarg;
6620 break;
6621 }
6622 if (*p == NUL)
6623 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006625 }
6626 else
6627#endif
6628 {
6629 /* Check for "x:y,x:y" */
6630 for (p = *varp; *p != NUL; p += 4)
6631 {
6632 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6633 {
6634 errmsg = e_invarg;
6635 break;
6636 }
6637 if (p[3] == NUL)
6638 break;
6639 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006640 }
6641 }
6642
6643#ifdef FEAT_COMMENTS
6644 /* 'comments' */
6645 else if (gvarp == &p_com)
6646 {
6647 for (s = *varp; *s; )
6648 {
6649 while (*s && *s != ':')
6650 {
6651 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6652 && !VIM_ISDIGIT(*s) && *s != '-')
6653 {
6654 errmsg = illegal_char(errbuf, *s);
6655 break;
6656 }
6657 ++s;
6658 }
6659 if (*s++ == NUL)
6660 errmsg = (char_u *)N_("E524: Missing colon");
6661 else if (*s == ',' || *s == NUL)
6662 errmsg = (char_u *)N_("E525: Zero length string");
6663 if (errmsg != NULL)
6664 break;
6665 while (*s && *s != ',')
6666 {
6667 if (*s == '\\' && s[1] != NUL)
6668 ++s;
6669 ++s;
6670 }
6671 s = skip_to_option_part(s);
6672 }
6673 }
6674#endif
6675
6676 /* 'listchars' */
6677 else if (varp == &p_lcs)
6678 {
6679 errmsg = set_chars_option(varp);
6680 }
6681
6682#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6683 /* 'fillchars' */
6684 else if (varp == &p_fcs)
6685 {
6686 errmsg = set_chars_option(varp);
6687 }
6688#endif
6689
6690#ifdef FEAT_CMDWIN
6691 /* 'cedit' */
6692 else if (varp == &p_cedit)
6693 {
6694 errmsg = check_cedit();
6695 }
6696#endif
6697
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006698 /* 'verbosefile' */
6699 else if (varp == &p_vfile)
6700 {
6701 verbose_stop();
6702 if (*p_vfile != NUL && verbose_open() == FAIL)
6703 errmsg = e_invarg;
6704 }
6705
Bram Moolenaar071d4272004-06-13 20:20:40 +00006706#ifdef FEAT_VIMINFO
6707 /* 'viminfo' */
6708 else if (varp == &p_viminfo)
6709 {
6710 for (s = p_viminfo; *s;)
6711 {
6712 /* Check it's a valid character */
6713 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6714 {
6715 errmsg = illegal_char(errbuf, *s);
6716 break;
6717 }
6718 if (*s == 'n') /* name is always last one */
6719 {
6720 break;
6721 }
6722 else if (*s == 'r') /* skip until next ',' */
6723 {
6724 while (*++s && *s != ',')
6725 ;
6726 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006727 else if (*s == '%')
6728 {
6729 /* optional number */
6730 while (vim_isdigit(*++s))
6731 ;
6732 }
6733 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006734 ++s; /* no extra chars */
6735 else /* must have a number */
6736 {
6737 while (vim_isdigit(*++s))
6738 ;
6739
6740 if (!VIM_ISDIGIT(*(s - 1)))
6741 {
6742 if (errbuf != NULL)
6743 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006744 sprintf((char *)errbuf,
6745 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006746 transchar_byte(*(s - 1)));
6747 errmsg = errbuf;
6748 }
6749 else
6750 errmsg = (char_u *)"";
6751 break;
6752 }
6753 }
6754 if (*s == ',')
6755 ++s;
6756 else if (*s)
6757 {
6758 if (errbuf != NULL)
6759 errmsg = (char_u *)N_("E527: Missing comma");
6760 else
6761 errmsg = (char_u *)"";
6762 break;
6763 }
6764 }
6765 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6766 errmsg = (char_u *)N_("E528: Must specify a ' value");
6767 }
6768#endif /* FEAT_VIMINFO */
6769
6770 /* terminal options */
6771 else if (istermoption(&options[opt_idx]) && full_screen)
6772 {
6773 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6774 if (varp == &T_CCO)
6775 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006776 int colors = atoi((char *)T_CCO);
6777
6778 /* Only reinitialize colors if t_Co value has really changed to
6779 * avoid expensive reload of colorscheme if t_Co is set to the
6780 * same value multiple times. */
6781 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006783 t_colors = colors;
6784 if (t_colors <= 1)
6785 {
6786 if (new_value_alloced)
6787 vim_free(T_CCO);
6788 T_CCO = empty_option;
6789 }
6790 /* We now have a different color setup, initialize it again. */
6791 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 }
6794 ttest(FALSE);
6795 if (varp == &T_ME)
6796 {
6797 out_str(T_ME);
6798 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006799#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006800 /* Since t_me has been set, this probably means that the user
6801 * wants to use this as default colors. Need to reset default
6802 * background/foreground colors. */
6803 mch_set_normal_colors();
6804#endif
6805 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006806 if (varp == &T_BE && termcap_active)
6807 {
6808 if (*T_BE == NUL)
6809 /* When clearing t_BE we assume the user no longer wants
6810 * bracketed paste, thus disable it by writing t_BD. */
6811 out_str(T_BD);
6812 else
6813 out_str(T_BE);
6814 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 }
6816
6817#ifdef FEAT_LINEBREAK
6818 /* 'showbreak' */
6819 else if (varp == &p_sbr)
6820 {
6821 for (s = p_sbr; *s; )
6822 {
6823 if (ptr2cells(s) != 1)
6824 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006825 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006826 }
6827 }
6828#endif
6829
6830#ifdef FEAT_GUI
6831 /* 'guifont' */
6832 else if (varp == &p_guifont)
6833 {
6834 if (gui.in_use)
6835 {
6836 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006837# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006838 /*
6839 * Put up a font dialog and let the user select a new value.
6840 * If this is cancelled go back to the old value but don't
6841 * give an error message.
6842 */
6843 if (STRCMP(p, "*") == 0)
6844 {
6845 p = gui_mch_font_dialog(oldval);
6846
6847 if (new_value_alloced)
6848 free_string_option(p_guifont);
6849
6850 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6851 new_value_alloced = TRUE;
6852 }
6853# endif
6854 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6855 {
6856# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6857 if (STRCMP(p_guifont, "*") == 0)
6858 {
6859 /* Dialog was cancelled: Keep the old value without giving
6860 * an error message. */
6861 if (new_value_alloced)
6862 free_string_option(p_guifont);
6863 p_guifont = vim_strsave(oldval);
6864 new_value_alloced = TRUE;
6865 }
6866 else
6867# endif
6868 errmsg = (char_u *)N_("E596: Invalid font(s)");
6869 }
6870 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006871 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006872 }
6873# ifdef FEAT_XFONTSET
6874 else if (varp == &p_guifontset)
6875 {
6876 if (STRCMP(p_guifontset, "*") == 0)
6877 errmsg = (char_u *)N_("E597: can't select fontset");
6878 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6879 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006880 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881 }
6882# endif
6883# ifdef FEAT_MBYTE
6884 else if (varp == &p_guifontwide)
6885 {
6886 if (STRCMP(p_guifontwide, "*") == 0)
6887 errmsg = (char_u *)N_("E533: can't select wide font");
6888 else if (gui_get_wide_font() == FAIL)
6889 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006890 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006891 }
6892# endif
6893#endif
6894
6895#ifdef CURSOR_SHAPE
6896 /* 'guicursor' */
6897 else if (varp == &p_guicursor)
6898 errmsg = parse_shape_opt(SHAPE_CURSOR);
6899#endif
6900
6901#ifdef FEAT_MOUSESHAPE
6902 /* 'mouseshape' */
6903 else if (varp == &p_mouseshape)
6904 {
6905 errmsg = parse_shape_opt(SHAPE_MOUSE);
6906 update_mouseshape(-1);
6907 }
6908#endif
6909
6910#ifdef FEAT_PRINTER
6911 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006912 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006913# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006914 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006915 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006916# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917#endif
6918
6919#ifdef FEAT_LANGMAP
6920 /* 'langmap' */
6921 else if (varp == &p_langmap)
6922 langmap_set();
6923#endif
6924
6925#ifdef FEAT_LINEBREAK
6926 /* 'breakat' */
6927 else if (varp == &p_breakat)
6928 fill_breakat_flags();
6929#endif
6930
6931#ifdef FEAT_TITLE
6932 /* 'titlestring' and 'iconstring' */
6933 else if (varp == &p_titlestring || varp == &p_iconstring)
6934 {
6935# ifdef FEAT_STL_OPT
6936 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6937
6938 /* NULL => statusline syntax */
6939 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6940 stl_syntax |= flagval;
6941 else
6942 stl_syntax &= ~flagval;
6943# endif
6944 did_set_title(varp == &p_iconstring);
6945
6946 }
6947#endif
6948
6949#ifdef FEAT_GUI
6950 /* 'guioptions' */
6951 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006952 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006954 redraw_gui_only = TRUE;
6955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006956#endif
6957
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006958#if defined(FEAT_GUI_TABLINE)
6959 /* 'guitablabel' */
6960 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006961 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006962 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006963 redraw_gui_only = TRUE;
6964 }
6965 /* 'guitabtooltip' */
6966 else if (varp == &p_gtt)
6967 {
6968 redraw_gui_only = TRUE;
6969 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006970#endif
6971
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6973 /* 'ttymouse' */
6974 else if (varp == &p_ttym)
6975 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006976 /* Switch the mouse off before changing the escape sequences used for
6977 * that. */
6978 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6980 errmsg = e_invarg;
6981 else
6982 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006983 if (termcap_active)
6984 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985 }
6986#endif
6987
Bram Moolenaar071d4272004-06-13 20:20:40 +00006988 /* 'selection' */
6989 else if (varp == &p_sel)
6990 {
6991 if (*p_sel == NUL
6992 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6993 errmsg = e_invarg;
6994 }
6995
6996 /* 'selectmode' */
6997 else if (varp == &p_slm)
6998 {
6999 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7000 errmsg = e_invarg;
7001 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002
7003#ifdef FEAT_BROWSE
7004 /* 'browsedir' */
7005 else if (varp == &p_bsdir)
7006 {
7007 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7008 && !mch_isdir(p_bsdir))
7009 errmsg = e_invarg;
7010 }
7011#endif
7012
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013 /* 'keymodel' */
7014 else if (varp == &p_km)
7015 {
7016 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7017 errmsg = e_invarg;
7018 else
7019 {
7020 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7021 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7022 }
7023 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007024
7025 /* 'mousemodel' */
7026 else if (varp == &p_mousem)
7027 {
7028 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7029 errmsg = e_invarg;
7030#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7031 else if (*p_mousem != *oldval)
7032 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7033 * to create or delete the popup menus. */
7034 gui_motif_update_mousemodel(root_menu);
7035#endif
7036 }
7037
7038 /* 'switchbuf' */
7039 else if (varp == &p_swb)
7040 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007041 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 errmsg = e_invarg;
7043 }
7044
7045 /* 'debug' */
7046 else if (varp == &p_debug)
7047 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007048 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 errmsg = e_invarg;
7050 }
7051
7052 /* 'display' */
7053 else if (varp == &p_dy)
7054 {
7055 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7056 errmsg = e_invarg;
7057 else
7058 (void)init_chartab();
7059
7060 }
7061
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007062#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063 /* 'eadirection' */
7064 else if (varp == &p_ead)
7065 {
7066 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7067 errmsg = e_invarg;
7068 }
7069#endif
7070
7071#ifdef FEAT_CLIPBOARD
7072 /* 'clipboard' */
7073 else if (varp == &p_cb)
7074 errmsg = check_clipboard_option();
7075#endif
7076
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007077#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007078 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7079 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007080 else if (varp == &(curwin->w_s->b_p_spl)
7081 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007082 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007083 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007084 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007085 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007086 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007087 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007088 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007089 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007090 /* 'spellsuggest' */
7091 else if (varp == &p_sps)
7092 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007093 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007094 errmsg = e_invarg;
7095 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007096 /* 'mkspellmem' */
7097 else if (varp == &p_msm)
7098 {
7099 if (spell_check_msm() != OK)
7100 errmsg = e_invarg;
7101 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007102#endif
7103
Bram Moolenaar071d4272004-06-13 20:20:40 +00007104 /* When 'bufhidden' is set, check for valid value. */
7105 else if (gvarp == &p_bh)
7106 {
7107 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7108 errmsg = e_invarg;
7109 }
7110
7111 /* When 'buftype' is set, check for valid value. */
7112 else if (gvarp == &p_bt)
7113 {
7114 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7115 errmsg = e_invarg;
7116 else
7117 {
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007118#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 if (curwin->w_status_height)
7120 {
7121 curwin->w_redr_status = TRUE;
7122 redraw_later(VALID);
7123 }
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007126#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007127 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129 }
7130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131
7132#ifdef FEAT_STL_OPT
7133 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007134 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135 {
7136 int wid;
7137
7138 if (varp == &p_ruf) /* reset ru_wid first */
7139 ru_wid = 0;
7140 s = *varp;
7141 if (varp == &p_ruf && *s == '%')
7142 {
7143 /* set ru_wid if 'ruf' starts with "%99(" */
7144 if (*++s == '-') /* ignore a '-' */
7145 s++;
7146 wid = getdigits(&s);
7147 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7148 ru_wid = wid;
7149 else
7150 errmsg = check_stl_option(p_ruf);
7151 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007152 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007153 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007155 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007156 comp_col();
7157 }
7158#endif
7159
7160#ifdef FEAT_INS_EXPAND
7161 /* check if it is a valid value for 'complete' -- Acevedo */
7162 else if (gvarp == &p_cpt)
7163 {
7164 for (s = *varp; *s;)
7165 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007166 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167 s++;
7168 if (!*s)
7169 break;
7170 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7171 {
7172 errmsg = illegal_char(errbuf, *s);
7173 break;
7174 }
7175 if (*++s != NUL && *s != ',' && *s != ' ')
7176 {
7177 if (s[-1] == 'k' || s[-1] == 's')
7178 {
7179 /* skip optional filename after 'k' and 's' */
7180 while (*s && *s != ',' && *s != ' ')
7181 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007182 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007183 ++s;
7184 ++s;
7185 }
7186 }
7187 else
7188 {
7189 if (errbuf != NULL)
7190 {
7191 sprintf((char *)errbuf,
7192 _("E535: Illegal character after <%c>"),
7193 *--s);
7194 errmsg = errbuf;
7195 }
7196 else
7197 errmsg = (char_u *)"";
7198 break;
7199 }
7200 }
7201 }
7202 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007203
7204 /* 'completeopt' */
7205 else if (varp == &p_cot)
7206 {
7207 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7208 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007209 else
7210 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007211 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212#endif /* FEAT_INS_EXPAND */
7213
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007214#ifdef FEAT_SIGNS
7215 /* 'signcolumn' */
7216 else if (varp == &curwin->w_p_scl)
7217 {
7218 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7219 errmsg = e_invarg;
7220 }
7221#endif
7222
Bram Moolenaar071d4272004-06-13 20:20:40 +00007223
7224#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007225 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007226 else if (varp == &p_toolbar)
7227 {
7228 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7229 &toolbar_flags, TRUE) != OK)
7230 errmsg = e_invarg;
7231 else
7232 {
7233 out_flush();
7234 gui_mch_show_toolbar((toolbar_flags &
7235 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7236 }
7237 }
7238#endif
7239
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007240#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007241 /* 'toolbariconsize': GTK+ 2 only */
7242 else if (varp == &p_tbis)
7243 {
7244 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7245 errmsg = e_invarg;
7246 else
7247 {
7248 out_flush();
7249 gui_mch_show_toolbar((toolbar_flags &
7250 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7251 }
7252 }
7253#endif
7254
7255 /* 'pastetoggle': translate key codes like in a mapping */
7256 else if (varp == &p_pt)
7257 {
7258 if (*p_pt)
7259 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007260 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261 if (p != NULL)
7262 {
7263 if (new_value_alloced)
7264 free_string_option(p_pt);
7265 p_pt = p;
7266 new_value_alloced = TRUE;
7267 }
7268 }
7269 }
7270
7271 /* 'backspace' */
7272 else if (varp == &p_bs)
7273 {
7274 if (VIM_ISDIGIT(*p_bs))
7275 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007276 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007277 errmsg = e_invarg;
7278 }
7279 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7280 errmsg = e_invarg;
7281 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007282 else if (varp == &p_bo)
7283 {
7284 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7285 errmsg = e_invarg;
7286 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007287
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007288 /* 'tagcase' */
7289 else if (gvarp == &p_tc)
7290 {
7291 unsigned int *flags;
7292
7293 if (opt_flags & OPT_LOCAL)
7294 {
7295 p = curbuf->b_p_tc;
7296 flags = &curbuf->b_tc_flags;
7297 }
7298 else
7299 {
7300 p = p_tc;
7301 flags = &tc_flags;
7302 }
7303
7304 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7305 /* make the local value empty: use the global value */
7306 *flags = 0;
7307 else if (*p == NUL
7308 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7309 errmsg = e_invarg;
7310 }
7311
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007312#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 /* 'casemap' */
7314 else if (varp == &p_cmp)
7315 {
7316 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7317 errmsg = e_invarg;
7318 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320
7321#ifdef FEAT_DIFF
7322 /* 'diffopt' */
7323 else if (varp == &p_dip)
7324 {
7325 if (diffopt_changed() == FAIL)
7326 errmsg = e_invarg;
7327 }
7328#endif
7329
7330#ifdef FEAT_FOLDING
7331 /* 'foldmethod' */
7332 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7333 {
7334 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7335 || *curwin->w_p_fdm == NUL)
7336 errmsg = e_invarg;
7337 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007338 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007339 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007340 if (foldmethodIsDiff(curwin))
7341 newFoldLevel();
7342 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343 }
7344# ifdef FEAT_EVAL
7345 /* 'foldexpr' */
7346 else if (varp == &curwin->w_p_fde)
7347 {
7348 if (foldmethodIsExpr(curwin))
7349 foldUpdateAll(curwin);
7350 }
7351# endif
7352 /* 'foldmarker' */
7353 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7354 {
7355 p = vim_strchr(*varp, ',');
7356 if (p == NULL)
7357 errmsg = (char_u *)N_("E536: comma required");
7358 else if (p == *varp || p[1] == NUL)
7359 errmsg = e_invarg;
7360 else if (foldmethodIsMarker(curwin))
7361 foldUpdateAll(curwin);
7362 }
7363 /* 'commentstring' */
7364 else if (gvarp == &p_cms)
7365 {
7366 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7367 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7368 }
7369 /* 'foldopen' */
7370 else if (varp == &p_fdo)
7371 {
7372 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7373 errmsg = e_invarg;
7374 }
7375 /* 'foldclose' */
7376 else if (varp == &p_fcl)
7377 {
7378 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7379 errmsg = e_invarg;
7380 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007381 /* 'foldignore' */
7382 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7383 {
7384 if (foldmethodIsIndent(curwin))
7385 foldUpdateAll(curwin);
7386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007387#endif
7388
7389#ifdef FEAT_VIRTUALEDIT
7390 /* 'virtualedit' */
7391 else if (varp == &p_ve)
7392 {
7393 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7394 errmsg = e_invarg;
7395 else if (STRCMP(p_ve, oldval) != 0)
7396 {
7397 /* Recompute cursor position in case the new 've' setting
7398 * changes something. */
7399 validate_virtcol();
7400 coladvance(curwin->w_virtcol);
7401 }
7402 }
7403#endif
7404
7405#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7406 else if (varp == &p_csqf)
7407 {
7408 if (p_csqf != NULL)
7409 {
7410 p = p_csqf;
7411 while (*p != NUL)
7412 {
7413 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7414 || p[1] == NUL
7415 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7416 || (p[2] != NUL && p[2] != ','))
7417 {
7418 errmsg = e_invarg;
7419 break;
7420 }
7421 else if (p[2] == NUL)
7422 break;
7423 else
7424 p += 3;
7425 }
7426 }
7427 }
7428#endif
7429
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007430#ifdef FEAT_CINDENT
7431 /* 'cinoptions' */
7432 else if (gvarp == &p_cino)
7433 {
7434 /* TODO: recognize errors */
7435 parse_cino(curbuf);
7436 }
7437#endif
7438
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007439#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007440 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007441 else if (varp == &p_rop && gui.in_use)
7442 {
7443 if (!gui_mch_set_rendering_options(p_rop))
7444 errmsg = e_invarg;
7445 }
7446#endif
7447
Bram Moolenaard0b51382016-11-04 15:23:45 +01007448#ifdef FEAT_AUTOCMD
7449 else if (gvarp == &p_ft)
7450 {
7451 if (!valid_filetype(*varp))
7452 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007453 else
7454 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007455 }
7456#endif
7457
7458#ifdef FEAT_SYN_HL
7459 else if (gvarp == &p_syn)
7460 {
7461 if (!valid_filetype(*varp))
7462 errmsg = e_invarg;
7463 }
7464#endif
7465
Bram Moolenaar825680f2017-07-22 17:04:02 +02007466#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007467 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007468 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007469 {
7470 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7471 errmsg = e_invarg;
7472 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007473 /* 'termsize' */
7474 else if (varp == &curwin->w_p_tms)
7475 {
7476 if (*curwin->w_p_tms != NUL)
7477 {
7478 p = skipdigits(curwin->w_p_tms);
7479 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7480 errmsg = e_invarg;
7481 }
7482 }
7483#endif
7484
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 /* Options that are a list of flags. */
7486 else
7487 {
7488 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007489 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007491 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007493 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007494 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007495 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007497#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007498 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007499 p = (char_u *)COCU_ALL;
7500#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007501 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502 {
7503#ifdef FEAT_MOUSE
7504 p = (char_u *)MOUSE_ALL;
7505#else
7506 if (*p_mouse != NUL)
7507 errmsg = (char_u *)N_("E538: No mouse support");
7508#endif
7509 }
7510#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007511 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007512 p = (char_u *)GO_ALL;
7513#endif
7514 if (p != NULL)
7515 {
7516 for (s = *varp; *s; ++s)
7517 if (vim_strchr(p, *s) == NULL)
7518 {
7519 errmsg = illegal_char(errbuf, *s);
7520 break;
7521 }
7522 }
7523 }
7524
7525 /*
7526 * If error detected, restore the previous value.
7527 */
7528 if (errmsg != NULL)
7529 {
7530 if (new_value_alloced)
7531 free_string_option(*varp);
7532 *varp = oldval;
7533 /*
7534 * When resetting some values, need to act on it.
7535 */
7536 if (did_chartab)
7537 (void)init_chartab();
7538 if (varp == &p_hl)
7539 (void)highlight_changed();
7540 }
7541 else
7542 {
7543#ifdef FEAT_EVAL
7544 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007545 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546#endif
7547 /*
7548 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007549 * Use "free_oldval", because recursiveness may change the flags under
7550 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007552 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007553 free_string_option(oldval);
7554 if (new_value_alloced)
7555 options[opt_idx].flags |= P_ALLOCED;
7556 else
7557 options[opt_idx].flags &= ~P_ALLOCED;
7558
7559 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007560 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007561 {
7562 /* global option with local value set to use global value; free
7563 * the local value and make it empty */
7564 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7565 free_string_option(*(char_u **)p);
7566 *(char_u **)p = empty_option;
7567 }
7568
7569 /* May set global value for local option. */
7570 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7571 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007572
7573#ifdef FEAT_AUTOCMD
7574 /*
7575 * Trigger the autocommand only after setting the flags.
7576 */
7577# ifdef FEAT_SYN_HL
7578 /* When 'syntax' is set, load the syntax of that name */
7579 if (varp == &(curbuf->b_p_syn))
7580 {
7581 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7582 curbuf->b_fname, TRUE, curbuf);
7583 }
7584# endif
7585 else if (varp == &(curbuf->b_p_ft))
7586 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007587 /* 'filetype' is set, trigger the FileType autocommand.
7588 * Skip this when called from a modeline and the filetype was
7589 * already set to this value. */
7590 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7591 {
7592 did_filetype = TRUE;
7593 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007594 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007595 /* Just in case the old "curbuf" is now invalid. */
7596 if (varp != &(curbuf->b_p_ft))
7597 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007598 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007599 }
7600#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007601#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007602 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007603 {
7604 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007605 char_u *q = curwin->w_s->b_p_spl;
7606
7607 /* Skip the first name if it is "cjk". */
7608 if (STRNCMP(q, "cjk,", 4) == 0)
7609 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007610
7611 /*
7612 * Source the spell/LANG.vim in 'runtimepath'.
7613 * They could set 'spellcapcheck' depending on the language.
7614 * Use the first name in 'spelllang' up to '_region' or
7615 * '.encoding'.
7616 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007617 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007618 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7619 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007620 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007621 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007622 }
7623#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007624 }
7625
7626#ifdef FEAT_MOUSE
7627 if (varp == &p_mouse)
7628 {
7629# ifdef FEAT_MOUSE_TTY
7630 if (*p_mouse == NUL)
7631 mch_setmouse(FALSE); /* switch mouse off */
7632 else
7633# endif
7634 setmouse(); /* in case 'mouse' changed */
7635 }
7636#endif
7637
Bram Moolenaar913077c2012-03-28 19:59:04 +02007638 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007639 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007640 curwin->w_set_curswant = TRUE;
7641
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007642#ifdef FEAT_GUI
7643 /* check redraw when it's not a GUI option or the GUI is active. */
7644 if (!redraw_gui_only || gui.in_use)
7645#endif
7646 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647
7648 return errmsg;
7649}
7650
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007651#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007652/*
7653 * Simple int comparison function for use with qsort()
7654 */
7655 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007656int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007657{
7658 return *(const int *)a - *(const int *)b;
7659}
7660
7661/*
7662 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7663 * Returns error message, NULL if it's OK.
7664 */
7665 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007666check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007667{
7668 char_u *s;
7669 int col;
7670 int count = 0;
7671 int color_cols[256];
7672 int i;
7673 int j = 0;
7674
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007675 if (wp->w_buffer == NULL)
7676 return NULL; /* buffer was closed */
7677
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007678 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007679 {
7680 if (*s == '-' || *s == '+')
7681 {
7682 /* -N and +N: add to 'textwidth' */
7683 col = (*s == '-') ? -1 : 1;
7684 ++s;
7685 if (!VIM_ISDIGIT(*s))
7686 return e_invarg;
7687 col = col * getdigits(&s);
7688 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007689 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007690 col += wp->w_buffer->b_p_tw;
7691 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007692 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007693 }
7694 else if (VIM_ISDIGIT(*s))
7695 col = getdigits(&s);
7696 else
7697 return e_invarg;
7698 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007699skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007700 if (*s == NUL)
7701 break;
7702 if (*s != ',')
7703 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007704 if (*++s == NUL)
7705 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007706 }
7707
7708 vim_free(wp->w_p_cc_cols);
7709 if (count == 0)
7710 wp->w_p_cc_cols = NULL;
7711 else
7712 {
7713 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7714 if (wp->w_p_cc_cols != NULL)
7715 {
7716 /* sort the columns for faster usage on screen redraw inside
7717 * win_line() */
7718 qsort(color_cols, count, sizeof(int), int_cmp);
7719
7720 for (i = 0; i < count; ++i)
7721 /* skip duplicates */
7722 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7723 wp->w_p_cc_cols[j++] = color_cols[i];
7724 wp->w_p_cc_cols[j] = -1; /* end marker */
7725 }
7726 }
7727
7728 return NULL; /* no error */
7729}
7730#endif
7731
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732/*
7733 * Handle setting 'listchars' or 'fillchars'.
7734 * Returns error message, NULL if it's OK.
7735 */
7736 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007737set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007738{
7739 int round, i, len, entries;
7740 char_u *p, *s;
7741 int c1, c2 = 0;
7742 struct charstab
7743 {
7744 int *cp;
7745 char *name;
7746 };
7747#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7748 static struct charstab filltab[] =
7749 {
7750 {&fill_stl, "stl"},
7751 {&fill_stlnc, "stlnc"},
7752 {&fill_vert, "vert"},
7753 {&fill_fold, "fold"},
7754 {&fill_diff, "diff"},
7755 };
7756#endif
7757 static struct charstab lcstab[] =
7758 {
7759 {&lcs_eol, "eol"},
7760 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007761 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007762 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007763 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 {&lcs_tab2, "tab"},
7765 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007766#ifdef FEAT_CONCEAL
7767 {&lcs_conceal, "conceal"},
7768#else
7769 {NULL, "conceal"},
7770#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007771 };
7772 struct charstab *tab;
7773
7774#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7775 if (varp == &p_lcs)
7776#endif
7777 {
7778 tab = lcstab;
7779 entries = sizeof(lcstab) / sizeof(struct charstab);
7780 }
7781#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7782 else
7783 {
7784 tab = filltab;
7785 entries = sizeof(filltab) / sizeof(struct charstab);
7786 }
7787#endif
7788
7789 /* first round: check for valid value, second round: assign values */
7790 for (round = 0; round <= 1; ++round)
7791 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007792 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007793 {
7794 /* After checking that the value is valid: set defaults: space for
7795 * 'fillchars', NUL for 'listchars' */
7796 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007797 if (tab[i].cp != NULL)
7798 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 if (varp == &p_lcs)
7800 lcs_tab1 = NUL;
7801#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7802 else
7803 fill_diff = '-';
7804#endif
7805 }
7806 p = *varp;
7807 while (*p)
7808 {
7809 for (i = 0; i < entries; ++i)
7810 {
7811 len = (int)STRLEN(tab[i].name);
7812 if (STRNCMP(p, tab[i].name, len) == 0
7813 && p[len] == ':'
7814 && p[len + 1] != NUL)
7815 {
7816 s = p + len + 1;
7817#ifdef FEAT_MBYTE
7818 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007819 if (mb_char2cells(c1) > 1)
7820 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007821#else
7822 c1 = *s++;
7823#endif
7824 if (tab[i].cp == &lcs_tab2)
7825 {
7826 if (*s == NUL)
7827 continue;
7828#ifdef FEAT_MBYTE
7829 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007830 if (mb_char2cells(c2) > 1)
7831 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007832#else
7833 c2 = *s++;
7834#endif
7835 }
7836 if (*s == ',' || *s == NUL)
7837 {
7838 if (round)
7839 {
7840 if (tab[i].cp == &lcs_tab2)
7841 {
7842 lcs_tab1 = c1;
7843 lcs_tab2 = c2;
7844 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007845 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 *(tab[i].cp) = c1;
7847
7848 }
7849 p = s;
7850 break;
7851 }
7852 }
7853 }
7854
7855 if (i == entries)
7856 return e_invarg;
7857 if (*p == ',')
7858 ++p;
7859 }
7860 }
7861
7862 return NULL; /* no error */
7863}
7864
7865#ifdef FEAT_STL_OPT
7866/*
7867 * Check validity of options with the 'statusline' format.
7868 * Return error message or NULL.
7869 */
7870 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007871check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007872{
7873 int itemcnt = 0;
7874 int groupdepth = 0;
7875 static char_u errbuf[80];
7876
7877 while (*s && itemcnt < STL_MAX_ITEM)
7878 {
7879 /* Check for valid keys after % sequences */
7880 while (*s && *s != '%')
7881 s++;
7882 if (!*s)
7883 break;
7884 s++;
7885 if (*s != '%' && *s != ')')
7886 ++itemcnt;
7887 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7888 {
7889 s++;
7890 continue;
7891 }
7892 if (*s == ')')
7893 {
7894 s++;
7895 if (--groupdepth < 0)
7896 break;
7897 continue;
7898 }
7899 if (*s == '-')
7900 s++;
7901 while (VIM_ISDIGIT(*s))
7902 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007903 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 continue;
7905 if (*s == '.')
7906 {
7907 s++;
7908 while (*s && VIM_ISDIGIT(*s))
7909 s++;
7910 }
7911 if (*s == '(')
7912 {
7913 groupdepth++;
7914 continue;
7915 }
7916 if (vim_strchr(STL_ALL, *s) == NULL)
7917 {
7918 return illegal_char(errbuf, *s);
7919 }
7920 if (*s == '{')
7921 {
7922 s++;
7923 while (*s != '}' && *s)
7924 s++;
7925 if (*s != '}')
7926 return (char_u *)N_("E540: Unclosed expression sequence");
7927 }
7928 }
7929 if (itemcnt >= STL_MAX_ITEM)
7930 return (char_u *)N_("E541: too many items");
7931 if (groupdepth != 0)
7932 return (char_u *)N_("E542: unbalanced groups");
7933 return NULL;
7934}
7935#endif
7936
7937#ifdef FEAT_CLIPBOARD
7938/*
7939 * Extract the items in the 'clipboard' option and set global values.
7940 */
7941 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007942check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007944 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007945 int new_autoselect_star = FALSE;
7946 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007948 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 regprog_T *new_exclude_prog = NULL;
7950 char_u *errmsg = NULL;
7951 char_u *p;
7952
7953 for (p = p_cb; *p != NUL; )
7954 {
7955 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7956 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007957 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 p += 7;
7959 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007960 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007961 && (p[11] == ',' || p[11] == NUL))
7962 {
7963 new_unnamed |= CLIP_UNNAMED_PLUS;
7964 p += 11;
7965 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007967 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007969 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970 p += 10;
7971 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007972 else if (STRNCMP(p, "autoselectplus", 14) == 0
7973 && (p[14] == ',' || p[14] == NUL))
7974 {
7975 new_autoselect_plus = TRUE;
7976 p += 14;
7977 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007979 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 {
7981 new_autoselectml = TRUE;
7982 p += 12;
7983 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007984 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7985 {
7986 new_html = TRUE;
7987 p += 4;
7988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007989 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7990 {
7991 p += 8;
7992 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7993 if (new_exclude_prog == NULL)
7994 errmsg = e_invarg;
7995 break;
7996 }
7997 else
7998 {
7999 errmsg = e_invarg;
8000 break;
8001 }
8002 if (*p == ',')
8003 ++p;
8004 }
8005 if (errmsg == NULL)
8006 {
8007 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008008 clip_autoselect_star = new_autoselect_star;
8009 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008011 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008012 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008014#ifdef FEAT_GUI_GTK
8015 if (gui.in_use)
8016 {
8017 gui_gtk_set_selection_targets();
8018 gui_gtk_set_dnd_targets();
8019 }
8020#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 }
8022 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008023 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024
8025 return errmsg;
8026}
8027#endif
8028
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008029#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008030 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008031did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008032{
8033 char_u *errmsg = NULL;
8034 win_T *wp;
8035 int l;
8036
8037 if (is_spellfile)
8038 {
8039 l = (int)STRLEN(curwin->w_s->b_p_spf);
8040 if (l > 0 && (l < 4
8041 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8042 errmsg = e_invarg;
8043 }
8044
8045 if (errmsg == NULL)
8046 {
8047 FOR_ALL_WINDOWS(wp)
8048 if (wp->w_buffer == curbuf && wp->w_p_spell)
8049 {
8050 errmsg = did_set_spelllang(wp);
8051# ifdef FEAT_WINDOWS
8052 break;
8053# endif
8054 }
8055 }
8056 return errmsg;
8057}
8058
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008059/*
8060 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8061 * Return error message when failed, NULL when OK.
8062 */
8063 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008064compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008065{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008066 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008067 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008068
Bram Moolenaar860cae12010-06-05 23:22:07 +02008069 if (*synblock->b_p_spc == NUL)
8070 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008071 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008072 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008073 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008074 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008075 if (re != NULL)
8076 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008077 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008078 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008079 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008080 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008081 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008082 return e_invarg;
8083 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008084 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008085 }
8086
Bram Moolenaar473de612013-06-08 18:19:48 +02008087 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008088 return NULL;
8089}
8090#endif
8091
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008092#if defined(FEAT_EVAL) || defined(PROTO)
8093/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008094 * Set the scriptID for an option, taking care of setting the buffer- or
8095 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008096 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008097 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008098set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008099{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008100 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8101 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008102
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008103 /* Remember where the option was set. For local options need to do that
8104 * in the buffer or window structure. */
8105 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008106 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008107 if (both || (opt_flags & OPT_LOCAL))
8108 {
8109 if (indir & PV_BUF)
8110 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8111 else if (indir & PV_WIN)
8112 curwin->w_p_scriptID[indir & PV_MASK] = id;
8113 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008114}
8115#endif
8116
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117/*
8118 * Set the value of a boolean option, and take care of side effects.
8119 * Returns NULL for success, or an error message for an error.
8120 */
8121 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008122set_bool_option(
8123 int opt_idx, /* index in options[] table */
8124 char_u *varp, /* pointer to the option variable */
8125 int value, /* new value */
8126 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127{
8128 int old_value = *(int *)varp;
8129
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130 /* Disallow changing some options from secure mode */
8131 if ((secure
8132#ifdef HAVE_SANDBOX
8133 || sandbox != 0
8134#endif
8135 ) && (options[opt_idx].flags & P_SECURE))
8136 return e_secure;
8137
8138 *(int *)varp = value; /* set the new value */
8139#ifdef FEAT_EVAL
8140 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008141 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142#endif
8143
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008144#ifdef FEAT_GUI
8145 need_mouse_correct = TRUE;
8146#endif
8147
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 /* May set global value for local option. */
8149 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8150 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8151
8152 /*
8153 * Handle side effects of changing a bool option.
8154 */
8155
8156 /* 'compatible' */
8157 if ((int *)varp == &p_cp)
8158 {
8159 compatible_set();
8160 }
8161
Bram Moolenaar920694c2016-08-21 17:45:02 +02008162#ifdef FEAT_LANGMAP
8163 if ((int *)varp == &p_lrm)
8164 /* 'langremap' -> !'langnoremap' */
8165 p_lnr = !p_lrm;
8166 else if ((int *)varp == &p_lnr)
8167 /* 'langnoremap' -> !'langremap' */
8168 p_lrm = !p_lnr;
8169#endif
8170
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008171#ifdef FEAT_PERSISTENT_UNDO
8172 /* 'undofile' */
8173 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8174 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008175 /* Only take action when the option was set. When reset we do not
8176 * delete the undo file, the option may be set again without making
8177 * any changes in between. */
8178 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008179 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008180 char_u hash[UNDO_HASH_SIZE];
8181 buf_T *save_curbuf = curbuf;
8182
Bram Moolenaar29323592016-07-24 22:04:11 +02008183 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008184 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008185 /* When 'undofile' is set globally: for every buffer, otherwise
8186 * only for the current buffer: Try to read in the undofile,
8187 * if one exists, the buffer wasn't changed and the buffer was
8188 * loaded */
8189 if ((curbuf == save_curbuf
8190 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8191 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8192 {
8193 u_compute_hash(hash);
8194 u_read_undo(NULL, hash, curbuf->b_fname);
8195 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008196 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008197 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008198 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008199 }
8200#endif
8201
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 else if ((int *)varp == &curbuf->b_p_ro)
8203 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008204 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8206 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008207
8208 /* when 'readonly' is set may give W10 again */
8209 if (curbuf->b_p_ro)
8210 curbuf->b_did_warn = FALSE;
8211
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008213 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214#endif
8215 }
8216
Bram Moolenaar9c449722010-07-20 18:44:27 +02008217#ifdef FEAT_GUI
8218 else if ((int *)varp == &p_mh)
8219 {
8220 if (!p_mh)
8221 gui_mch_mousehide(FALSE);
8222 }
8223#endif
8224
Bram Moolenaara539df02010-08-01 14:35:05 +02008225 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008226 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008227 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008228# ifdef FEAT_TERMINAL
8229 /* Cannot set 'modifiable' when in Terminal mode. */
8230 if (term_in_terminal_mode())
8231 {
8232 curbuf->b_p_ma = FALSE;
8233 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8234 }
8235# endif
8236# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008237 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008238# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008239 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008240#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241 /* when 'endofline' is changed, redraw the window title */
8242 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008243 {
8244 redraw_titles();
8245 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008246 /* when 'fixeol' is changed, redraw the window title */
8247 else if ((int *)varp == &curbuf->b_p_fixeol)
8248 {
8249 redraw_titles();
8250 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008251# ifdef FEAT_MBYTE
8252 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008253 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008254 {
8255 redraw_titles();
8256 }
8257# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008258#endif
8259
8260 /* when 'bin' is set also set some other options */
8261 else if ((int *)varp == &curbuf->b_p_bin)
8262 {
8263 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8264#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008265 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008266#endif
8267 }
8268
8269#ifdef FEAT_AUTOCMD
8270 /* when 'buflisted' changes, trigger autocommands */
8271 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8272 {
8273 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8274 NULL, NULL, TRUE, curbuf);
8275 }
8276#endif
8277
8278 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8279 else if ((int *)varp == &curbuf->b_p_swf)
8280 {
8281 if (curbuf->b_p_swf && p_uc)
8282 ml_open_file(curbuf); /* create the swap file */
8283 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008284 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8285 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008286 mf_close_file(curbuf, TRUE); /* remove the swap file */
8287 }
8288
8289 /* when 'terse' is set change 'shortmess' */
8290 else if ((int *)varp == &p_terse)
8291 {
8292 char_u *p;
8293
8294 p = vim_strchr(p_shm, SHM_SEARCH);
8295
8296 /* insert 's' in p_shm */
8297 if (p_terse && p == NULL)
8298 {
8299 STRCPY(IObuff, p_shm);
8300 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008301 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008302 }
8303 /* remove 's' from p_shm */
8304 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008305 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 }
8307
8308 /* when 'paste' is set or reset also change other options */
8309 else if ((int *)varp == &p_paste)
8310 {
8311 paste_option_changed();
8312 }
8313
8314 /* when 'insertmode' is set from an autocommand need to do work here */
8315 else if ((int *)varp == &p_im)
8316 {
8317 if (p_im)
8318 {
8319 if ((State & INSERT) == 0)
8320 need_start_insertmode = TRUE;
8321 stop_insert_mode = FALSE;
8322 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008323 /* only reset if it was set previously */
8324 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008325 {
8326 need_start_insertmode = FALSE;
8327 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008328 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008329 clear_cmdline = TRUE; /* remove "(insert)" */
8330 restart_edit = 0;
8331 }
8332 }
8333
8334 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8335 else if ((int *)varp == &p_ic && p_hls)
8336 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008337 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008338 }
8339
8340#ifdef FEAT_SEARCH_EXTRA
8341 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8342 else if ((int *)varp == &p_hls)
8343 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008344 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 }
8346#endif
8347
8348#ifdef FEAT_SCROLLBIND
8349 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8350 * at the end of normal_cmd() */
8351 else if ((int *)varp == &curwin->w_p_scb)
8352 {
8353 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008354 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008355 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008356 curwin->w_scbind_pos = curwin->w_topline;
8357 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008358 }
8359#endif
8360
8361#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8362 /* There can be only one window with 'previewwindow' set. */
8363 else if ((int *)varp == &curwin->w_p_pvw)
8364 {
8365 if (curwin->w_p_pvw)
8366 {
8367 win_T *win;
8368
Bram Moolenaar29323592016-07-24 22:04:11 +02008369 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 if (win->w_p_pvw && win != curwin)
8371 {
8372 curwin->w_p_pvw = FALSE;
8373 return (char_u *)N_("E590: A preview window already exists");
8374 }
8375 }
8376 }
8377#endif
8378
8379 /* when 'textmode' is set or reset also change 'fileformat' */
8380 else if ((int *)varp == &curbuf->b_p_tx)
8381 {
8382 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8383 }
8384
8385 /* when 'textauto' is set or reset also change 'fileformats' */
8386 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387 set_string_option_direct((char_u *)"ffs", -1,
8388 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008389 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390
8391 /*
8392 * When 'lisp' option changes include/exclude '-' in
8393 * keyword characters.
8394 */
8395#ifdef FEAT_LISP
8396 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8397 {
8398 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8399 }
8400#endif
8401
8402#ifdef FEAT_TITLE
8403 /* when 'title' changed, may need to change the title; same for 'icon' */
8404 else if ((int *)varp == &p_title)
8405 {
8406 did_set_title(FALSE);
8407 }
8408
8409 else if ((int *)varp == &p_icon)
8410 {
8411 did_set_title(TRUE);
8412 }
8413#endif
8414
8415 else if ((int *)varp == &curbuf->b_changed)
8416 {
8417 if (!value)
8418 save_file_ff(curbuf); /* Buffer is unchanged */
8419#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008420 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421#endif
8422#ifdef FEAT_AUTOCMD
8423 modified_was_set = value;
8424#endif
8425 }
8426
8427#ifdef BACKSLASH_IN_FILENAME
8428 else if ((int *)varp == &p_ssl)
8429 {
8430 if (p_ssl)
8431 {
8432 psepc = '/';
8433 psepcN = '\\';
8434 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008435 }
8436 else
8437 {
8438 psepc = '\\';
8439 psepcN = '/';
8440 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 }
8442
8443 /* need to adjust the file name arguments and buffer names. */
8444 buflist_slash_adjust();
8445 alist_slash_adjust();
8446# ifdef FEAT_EVAL
8447 scriptnames_slash_adjust();
8448# endif
8449 }
8450#endif
8451
8452 /* If 'wrap' is set, set w_leftcol to zero. */
8453 else if ((int *)varp == &curwin->w_p_wrap)
8454 {
8455 if (curwin->w_p_wrap)
8456 curwin->w_leftcol = 0;
8457 }
8458
8459#ifdef FEAT_WINDOWS
8460 else if ((int *)varp == &p_ea)
8461 {
8462 if (p_ea && !old_value)
8463 win_equal(curwin, FALSE, 0);
8464 }
8465#endif
8466
8467 else if ((int *)varp == &p_wiv)
8468 {
8469 /*
8470 * When 'weirdinvert' changed, set/reset 't_xs'.
8471 * Then set 'weirdinvert' according to value of 't_xs'.
8472 */
8473 if (p_wiv && !old_value)
8474 T_XS = (char_u *)"y";
8475 else if (!p_wiv && old_value)
8476 T_XS = empty_option;
8477 p_wiv = (*T_XS != NUL);
8478 }
8479
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008480#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008481 else if ((int *)varp == &p_beval)
8482 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008483 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008484 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008485 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486 gui_mch_disable_beval_area(balloonEval);
8487 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008488#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008490#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491 else if ((int *)varp == &p_acd)
8492 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008493 /* Change directories when the 'acd' option is set now. */
8494 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495 }
8496#endif
8497
8498#ifdef FEAT_DIFF
8499 /* 'diff' */
8500 else if ((int *)varp == &curwin->w_p_diff)
8501 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008502 /* May add or remove the buffer from the list of diff buffers. */
8503 diff_buf_adjust(curwin);
8504# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008505 if (foldmethodIsDiff(curwin))
8506 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008507# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008508 }
8509#endif
8510
8511#ifdef USE_IM_CONTROL
8512 /* 'imdisable' */
8513 else if ((int *)varp == &p_imdisable)
8514 {
8515 /* Only de-activate it here, it will be enabled when changing mode. */
8516 if (p_imdisable)
8517 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008518 else if (State & INSERT)
8519 /* When the option is set from an autocommand, it may need to take
8520 * effect right away. */
8521 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522 }
8523#endif
8524
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008525#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008526 /* 'spell' */
8527 else if ((int *)varp == &curwin->w_p_spell)
8528 {
8529 if (curwin->w_p_spell)
8530 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008531 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008532 if (errmsg != NULL)
8533 EMSG(_(errmsg));
8534 }
8535 }
8536#endif
8537
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538#ifdef FEAT_FKMAP
8539 else if ((int *)varp == &p_altkeymap)
8540 {
8541 if (old_value != p_altkeymap)
8542 {
8543 if (!p_altkeymap)
8544 {
8545 p_hkmap = p_fkmap;
8546 p_fkmap = 0;
8547 }
8548 else
8549 {
8550 p_fkmap = p_hkmap;
8551 p_hkmap = 0;
8552 }
8553 (void)init_chartab();
8554 }
8555 }
8556
8557 /*
8558 * In case some second language keymapping options have changed, check
8559 * and correct the setting in a consistent way.
8560 */
8561
8562 /*
8563 * If hkmap or fkmap are set, reset Arabic keymapping.
8564 */
8565 if ((p_hkmap || p_fkmap) && p_altkeymap)
8566 {
8567 p_altkeymap = p_fkmap;
8568# ifdef FEAT_ARABIC
8569 curwin->w_p_arab = FALSE;
8570# endif
8571 (void)init_chartab();
8572 }
8573
8574 /*
8575 * If hkmap set, reset Farsi keymapping.
8576 */
8577 if (p_hkmap && p_altkeymap)
8578 {
8579 p_altkeymap = 0;
8580 p_fkmap = 0;
8581# ifdef FEAT_ARABIC
8582 curwin->w_p_arab = FALSE;
8583# endif
8584 (void)init_chartab();
8585 }
8586
8587 /*
8588 * If fkmap set, reset Hebrew keymapping.
8589 */
8590 if (p_fkmap && !p_altkeymap)
8591 {
8592 p_altkeymap = 1;
8593 p_hkmap = 0;
8594# ifdef FEAT_ARABIC
8595 curwin->w_p_arab = FALSE;
8596# endif
8597 (void)init_chartab();
8598 }
8599#endif
8600
8601#ifdef FEAT_ARABIC
8602 if ((int *)varp == &curwin->w_p_arab)
8603 {
8604 if (curwin->w_p_arab)
8605 {
8606 /*
8607 * 'arabic' is set, handle various sub-settings.
8608 */
8609 if (!p_tbidi)
8610 {
8611 /* set rightleft mode */
8612 if (!curwin->w_p_rl)
8613 {
8614 curwin->w_p_rl = TRUE;
8615 changed_window_setting();
8616 }
8617
8618 /* Enable Arabic shaping (major part of what Arabic requires) */
8619 if (!p_arshape)
8620 {
8621 p_arshape = TRUE;
8622 redraw_later_clear();
8623 }
8624 }
8625
8626 /* Arabic requires a utf-8 encoding, inform the user if its not
8627 * set. */
8628 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008629 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008630 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8631
Bram Moolenaar8820b482017-03-16 17:23:31 +01008632 msg_source(HL_ATTR(HLF_W));
8633 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008634#ifdef FEAT_EVAL
8635 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8636#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008637 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638
8639# ifdef FEAT_MBYTE
8640 /* set 'delcombine' */
8641 p_deco = TRUE;
8642# endif
8643
8644# ifdef FEAT_KEYMAP
8645 /* Force-set the necessary keymap for arabic */
8646 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8647 OPT_LOCAL);
8648# endif
8649# ifdef FEAT_FKMAP
8650 p_altkeymap = 0;
8651 p_hkmap = 0;
8652 p_fkmap = 0;
8653 (void)init_chartab();
8654# endif
8655 }
8656 else
8657 {
8658 /*
8659 * 'arabic' is reset, handle various sub-settings.
8660 */
8661 if (!p_tbidi)
8662 {
8663 /* reset rightleft mode */
8664 if (curwin->w_p_rl)
8665 {
8666 curwin->w_p_rl = FALSE;
8667 changed_window_setting();
8668 }
8669
8670 /* 'arabicshape' isn't reset, it is a global option and
8671 * another window may still need it "on". */
8672 }
8673
8674 /* 'delcombine' isn't reset, it is a global option and another
8675 * window may still want it "on". */
8676
8677# ifdef FEAT_KEYMAP
8678 /* Revert to the default keymap */
8679 curbuf->b_p_iminsert = B_IMODE_NONE;
8680 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8681# endif
8682 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008683 }
8684
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008685#endif
8686
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008687#ifdef FEAT_TERMGUICOLORS
8688 /* 'termguicolors' */
8689 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008690 {
8691# ifdef FEAT_GUI
8692 if (!gui.in_use && !gui.starting)
8693# endif
8694 highlight_gui_started();
8695 }
8696#endif
8697
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698 /*
8699 * End of handling side effects for bool options.
8700 */
8701
Bram Moolenaar53744302015-07-17 17:38:22 +02008702 /* after handling side effects, call autocommand */
8703
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704 options[opt_idx].flags |= P_WAS_SET;
8705
Bram Moolenaar53744302015-07-17 17:38:22 +02008706#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8707 if (!starting)
8708 {
8709 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008710 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8711 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8712 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008713 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8714 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8715 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8716 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8717 reset_v_option_vars();
8718 }
8719#endif
8720
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008722 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008723 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008724 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008725 check_redraw(options[opt_idx].flags);
8726
8727 return NULL;
8728}
8729
8730/*
8731 * Set the value of a number option, and take care of side effects.
8732 * Returns NULL for success, or an error message for an error.
8733 */
8734 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008735set_num_option(
8736 int opt_idx, /* index in options[] table */
8737 char_u *varp, /* pointer to the option variable */
8738 long value, /* new value */
8739 char_u *errbuf, /* buffer for error messages */
8740 size_t errbuflen, /* length of "errbuf" */
8741 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742 OPT_MODELINE */
8743{
8744 char_u *errmsg = NULL;
8745 long old_value = *(long *)varp;
8746 long old_Rows = Rows; /* remember old Rows */
8747 long old_Columns = Columns; /* remember old Columns */
8748 long *pp = (long *)varp;
8749
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008750 /* Disallow changing some options from secure mode. */
8751 if ((secure
8752#ifdef HAVE_SANDBOX
8753 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008755 ) && (options[opt_idx].flags & P_SECURE))
8756 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757
8758 *pp = value;
8759#ifdef FEAT_EVAL
8760 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008761 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008763#ifdef FEAT_GUI
8764 need_mouse_correct = TRUE;
8765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008766
Bram Moolenaar14f24742012-08-08 18:01:05 +02008767 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008768 {
8769 errmsg = e_positive;
8770 curbuf->b_p_sw = curbuf->b_p_ts;
8771 }
8772
8773 /*
8774 * Number options that need some action when changed
8775 */
8776#ifdef FEAT_WINDOWS
8777 if (pp == &p_wh || pp == &p_hh)
8778 {
8779 if (p_wh < 1)
8780 {
8781 errmsg = e_positive;
8782 p_wh = 1;
8783 }
8784 if (p_wmh > p_wh)
8785 {
8786 errmsg = e_winheight;
8787 p_wh = p_wmh;
8788 }
8789 if (p_hh < 0)
8790 {
8791 errmsg = e_positive;
8792 p_hh = 0;
8793 }
8794
8795 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008796 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 {
8798 if (pp == &p_wh && curwin->w_height < p_wh)
8799 win_setheight((int)p_wh);
8800 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8801 win_setheight((int)p_hh);
8802 }
8803 }
8804
8805 /* 'winminheight' */
8806 else if (pp == &p_wmh)
8807 {
8808 if (p_wmh < 0)
8809 {
8810 errmsg = e_positive;
8811 p_wmh = 0;
8812 }
8813 if (p_wmh > p_wh)
8814 {
8815 errmsg = e_winheight;
8816 p_wmh = p_wh;
8817 }
8818 win_setminheight();
8819 }
8820
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008821# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008822 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 {
8824 if (p_wiw < 1)
8825 {
8826 errmsg = e_positive;
8827 p_wiw = 1;
8828 }
8829 if (p_wmw > p_wiw)
8830 {
8831 errmsg = e_winwidth;
8832 p_wiw = p_wmw;
8833 }
8834
8835 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008836 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 win_setwidth((int)p_wiw);
8838 }
8839
8840 /* 'winminwidth' */
8841 else if (pp == &p_wmw)
8842 {
8843 if (p_wmw < 0)
8844 {
8845 errmsg = e_positive;
8846 p_wmw = 0;
8847 }
8848 if (p_wmw > p_wiw)
8849 {
8850 errmsg = e_winwidth;
8851 p_wmw = p_wiw;
8852 }
8853 win_setminheight();
8854 }
8855# endif
8856
8857#endif
8858
8859#ifdef FEAT_WINDOWS
8860 /* (re)set last window status line */
8861 else if (pp == &p_ls)
8862 {
8863 last_status(FALSE);
8864 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008865
8866 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008867 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008868 {
8869 shell_new_rows(); /* recompute window positions and heights */
8870 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008871#endif
8872
8873#ifdef FEAT_GUI
8874 else if (pp == &p_linespace)
8875 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008876 /* Recompute gui.char_height and resize the Vim window to keep the
8877 * same number of lines. */
8878 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008879 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 }
8881#endif
8882
8883#ifdef FEAT_FOLDING
8884 /* 'foldlevel' */
8885 else if (pp == &curwin->w_p_fdl)
8886 {
8887 if (curwin->w_p_fdl < 0)
8888 curwin->w_p_fdl = 0;
8889 newFoldLevel();
8890 }
8891
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008892 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893 else if (pp == &curwin->w_p_fml)
8894 {
8895 foldUpdateAll(curwin);
8896 }
8897
8898 /* 'foldnestmax' */
8899 else if (pp == &curwin->w_p_fdn)
8900 {
8901 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8902 foldUpdateAll(curwin);
8903 }
8904
8905 /* 'foldcolumn' */
8906 else if (pp == &curwin->w_p_fdc)
8907 {
8908 if (curwin->w_p_fdc < 0)
8909 {
8910 errmsg = e_positive;
8911 curwin->w_p_fdc = 0;
8912 }
8913 else if (curwin->w_p_fdc > 12)
8914 {
8915 errmsg = e_invarg;
8916 curwin->w_p_fdc = 12;
8917 }
8918 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008919#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008921#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 /* 'shiftwidth' or 'tabstop' */
8923 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8924 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008925# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 if (foldmethodIsIndent(curwin))
8927 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008928# endif
8929# ifdef FEAT_CINDENT
8930 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8931 * parse 'cinoptions'. */
8932 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8933 parse_cino(curbuf);
8934# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008936#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008938#ifdef FEAT_MBYTE
8939 /* 'maxcombine' */
8940 else if (pp == &p_mco)
8941 {
8942 if (p_mco > MAX_MCO)
8943 p_mco = MAX_MCO;
8944 else if (p_mco < 0)
8945 p_mco = 0;
8946 screenclear(); /* will re-allocate the screen */
8947 }
8948#endif
8949
Bram Moolenaar071d4272004-06-13 20:20:40 +00008950 else if (pp == &curbuf->b_p_iminsert)
8951 {
8952 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8953 {
8954 errmsg = e_invarg;
8955 curbuf->b_p_iminsert = B_IMODE_NONE;
8956 }
8957 p_iminsert = curbuf->b_p_iminsert;
8958 if (termcap_active) /* don't do this in the alternate screen */
8959 showmode();
8960#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8961 /* Show/unshow value of 'keymap' in status lines. */
8962 status_redraw_curbuf();
8963#endif
8964 }
8965
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008966 else if (pp == &p_window)
8967 {
8968 if (p_window < 1)
8969 p_window = 1;
8970 else if (p_window >= Rows)
8971 p_window = Rows - 1;
8972 }
8973
Bram Moolenaar071d4272004-06-13 20:20:40 +00008974 else if (pp == &curbuf->b_p_imsearch)
8975 {
8976 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8977 {
8978 errmsg = e_invarg;
8979 curbuf->b_p_imsearch = B_IMODE_NONE;
8980 }
8981 p_imsearch = curbuf->b_p_imsearch;
8982 }
8983
8984#ifdef FEAT_TITLE
8985 /* if 'titlelen' has changed, redraw the title */
8986 else if (pp == &p_titlelen)
8987 {
8988 if (p_titlelen < 0)
8989 {
8990 errmsg = e_positive;
8991 p_titlelen = 85;
8992 }
8993 if (starting != NO_SCREEN && old_value != p_titlelen)
8994 need_maketitle = TRUE;
8995 }
8996#endif
8997
8998 /* if p_ch changed value, change the command line height */
8999 else if (pp == &p_ch)
9000 {
9001 if (p_ch < 1)
9002 {
9003 errmsg = e_positive;
9004 p_ch = 1;
9005 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009006 if (p_ch > Rows - min_rows() + 1)
9007 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009008
9009 /* Only compute the new window layout when startup has been
9010 * completed. Otherwise the frame sizes may be wrong. */
9011 if (p_ch != old_value && full_screen
9012#ifdef FEAT_GUI
9013 && !gui.starting
9014#endif
9015 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009016 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009017 }
9018
9019 /* when 'updatecount' changes from zero to non-zero, open swap files */
9020 else if (pp == &p_uc)
9021 {
9022 if (p_uc < 0)
9023 {
9024 errmsg = e_positive;
9025 p_uc = 100;
9026 }
9027 if (p_uc && !old_value)
9028 ml_open_files();
9029 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009030#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009031 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009032 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009033 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009034 {
9035 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009036 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009037 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009038 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009039 {
9040 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009041 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009042 }
9043 }
9044#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009045#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009046 else if (pp == &p_mzq)
9047 mzvim_reset_timer();
9048#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009049
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009050#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9051 /* 'pyxversion' */
9052 else if (pp == &p_pyx)
9053 {
9054 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9055 errmsg = e_invarg;
9056 }
9057#endif
9058
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059 /* sync undo before 'undolevels' changes */
9060 else if (pp == &p_ul)
9061 {
9062 /* use the old value, otherwise u_sync() may not work properly */
9063 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009064 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009065 p_ul = value;
9066 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009067 else if (pp == &curbuf->b_p_ul)
9068 {
9069 /* use the old value, otherwise u_sync() may not work properly */
9070 curbuf->b_p_ul = old_value;
9071 u_sync(TRUE);
9072 curbuf->b_p_ul = value;
9073 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009075#ifdef FEAT_LINEBREAK
9076 /* 'numberwidth' must be positive */
9077 else if (pp == &curwin->w_p_nuw)
9078 {
9079 if (curwin->w_p_nuw < 1)
9080 {
9081 errmsg = e_positive;
9082 curwin->w_p_nuw = 1;
9083 }
9084 if (curwin->w_p_nuw > 10)
9085 {
9086 errmsg = e_invarg;
9087 curwin->w_p_nuw = 10;
9088 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009089 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009090 }
9091#endif
9092
Bram Moolenaar1a384422010-07-14 19:53:30 +02009093 else if (pp == &curbuf->b_p_tw)
9094 {
9095 if (curbuf->b_p_tw < 0)
9096 {
9097 errmsg = e_positive;
9098 curbuf->b_p_tw = 0;
9099 }
9100#ifdef FEAT_SYN_HL
9101# ifdef FEAT_WINDOWS
9102 {
9103 win_T *wp;
9104 tabpage_T *tp;
9105
9106 FOR_ALL_TAB_WINDOWS(tp, wp)
9107 check_colorcolumn(wp);
9108 }
9109# else
9110 check_colorcolumn(curwin);
9111# endif
9112#endif
9113 }
9114
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115 /*
9116 * Check the bounds for numeric options here
9117 */
9118 if (Rows < min_rows() && full_screen)
9119 {
9120 if (errbuf != NULL)
9121 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009122 vim_snprintf((char *)errbuf, errbuflen,
9123 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009124 errmsg = errbuf;
9125 }
9126 Rows = min_rows();
9127 }
9128 if (Columns < MIN_COLUMNS && full_screen)
9129 {
9130 if (errbuf != NULL)
9131 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009132 vim_snprintf((char *)errbuf, errbuflen,
9133 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009134 errmsg = errbuf;
9135 }
9136 Columns = MIN_COLUMNS;
9137 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009138 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139
Bram Moolenaar071d4272004-06-13 20:20:40 +00009140 /*
9141 * If the screen (shell) height has been changed, assume it is the
9142 * physical screenheight.
9143 */
9144 if (old_Rows != Rows || old_Columns != Columns)
9145 {
9146 /* Changing the screen size is not allowed while updating the screen. */
9147 if (updating_screen)
9148 *pp = old_value;
9149 else if (full_screen
9150#ifdef FEAT_GUI
9151 && !gui.starting
9152#endif
9153 )
9154 set_shellsize((int)Columns, (int)Rows, TRUE);
9155 else
9156 {
9157 /* Postpone the resizing; check the size and cmdline position for
9158 * messages. */
9159 check_shellsize();
9160 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9161 cmdline_row = Rows - p_ch;
9162 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009163 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009164 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165 }
9166
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 if (curbuf->b_p_ts <= 0)
9168 {
9169 errmsg = e_positive;
9170 curbuf->b_p_ts = 8;
9171 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172 if (p_tm < 0)
9173 {
9174 errmsg = e_positive;
9175 p_tm = 0;
9176 }
9177 if ((curwin->w_p_scr <= 0
9178 || (curwin->w_p_scr > curwin->w_height
9179 && curwin->w_height > 0))
9180 && full_screen)
9181 {
9182 if (pp == &(curwin->w_p_scr))
9183 {
9184 if (curwin->w_p_scr != 0)
9185 errmsg = e_scroll;
9186 win_comp_scroll(curwin);
9187 }
9188 /* If 'scroll' became invalid because of a side effect silently adjust
9189 * it. */
9190 else if (curwin->w_p_scr <= 0)
9191 curwin->w_p_scr = 1;
9192 else /* curwin->w_p_scr > curwin->w_height */
9193 curwin->w_p_scr = curwin->w_height;
9194 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009195 if (p_hi < 0)
9196 {
9197 errmsg = e_positive;
9198 p_hi = 0;
9199 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009200 else if (p_hi > 10000)
9201 {
9202 errmsg = e_invarg;
9203 p_hi = 10000;
9204 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009205 if (p_re < 0 || p_re > 2)
9206 {
9207 errmsg = e_invarg;
9208 p_re = 0;
9209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009210 if (p_report < 0)
9211 {
9212 errmsg = e_positive;
9213 p_report = 1;
9214 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009215 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009216 {
9217 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9218 p_sj = Rows / 2;
9219 else
9220 {
9221 errmsg = e_scroll;
9222 p_sj = 1;
9223 }
9224 }
9225 if (p_so < 0 && full_screen)
9226 {
9227 errmsg = e_scroll;
9228 p_so = 0;
9229 }
9230 if (p_siso < 0 && full_screen)
9231 {
9232 errmsg = e_positive;
9233 p_siso = 0;
9234 }
9235#ifdef FEAT_CMDWIN
9236 if (p_cwh < 1)
9237 {
9238 errmsg = e_positive;
9239 p_cwh = 1;
9240 }
9241#endif
9242 if (p_ut < 0)
9243 {
9244 errmsg = e_positive;
9245 p_ut = 2000;
9246 }
9247 if (p_ss < 0)
9248 {
9249 errmsg = e_positive;
9250 p_ss = 0;
9251 }
9252
9253 /* May set global value for local option. */
9254 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9255 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9256
9257 options[opt_idx].flags |= P_WAS_SET;
9258
Bram Moolenaar53744302015-07-17 17:38:22 +02009259#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9260 if (!starting && errmsg == NULL)
9261 {
9262 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009263 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9264 vim_snprintf((char *)buf_new, 10, "%ld", value);
9265 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009266 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9267 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9268 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9269 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9270 reset_v_option_vars();
9271 }
9272#endif
9273
Bram Moolenaar071d4272004-06-13 20:20:40 +00009274 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009275 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009276 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009277 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278 check_redraw(options[opt_idx].flags);
9279
9280 return errmsg;
9281}
9282
9283/*
9284 * Called after an option changed: check if something needs to be redrawn.
9285 */
9286 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009287check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009288{
9289 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009290 int doclear = (flags & P_RCLR) == P_RCLR;
9291 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292
9293#ifdef FEAT_WINDOWS
9294 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9295 status_redraw_all();
9296#endif
9297
9298 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9299 changed_window_setting();
9300 if (flags & P_RBUF)
9301 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009302 if (flags & P_RWINONLY)
9303 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009304 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305 redraw_all_later(CLEAR);
9306 else if (all)
9307 redraw_all_later(NOT_VALID);
9308}
9309
9310/*
9311 * Find index for option 'arg'.
9312 * Return -1 if not found.
9313 */
9314 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009315findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316{
9317 int opt_idx;
9318 char *s, *p;
9319 static short quick_tab[27] = {0, 0}; /* quick access table */
9320 int is_term_opt;
9321
9322 /*
9323 * For first call: Initialize the quick-access table.
9324 * It contains the index for the first option that starts with a certain
9325 * letter. There are 26 letters, plus the first "t_" option.
9326 */
9327 if (quick_tab[1] == 0)
9328 {
9329 p = options[0].fullname;
9330 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9331 {
9332 if (s[0] != p[0])
9333 {
9334 if (s[0] == 't' && s[1] == '_')
9335 quick_tab[26] = opt_idx;
9336 else
9337 quick_tab[CharOrdLow(s[0])] = opt_idx;
9338 }
9339 p = s;
9340 }
9341 }
9342
9343 /*
9344 * Check for name starting with an illegal character.
9345 */
9346#ifdef EBCDIC
9347 if (!islower(arg[0]))
9348#else
9349 if (arg[0] < 'a' || arg[0] > 'z')
9350#endif
9351 return -1;
9352
9353 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9354 if (is_term_opt)
9355 opt_idx = quick_tab[26];
9356 else
9357 opt_idx = quick_tab[CharOrdLow(arg[0])];
9358 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9359 {
9360 if (STRCMP(arg, s) == 0) /* match full name */
9361 break;
9362 }
9363 if (s == NULL && !is_term_opt)
9364 {
9365 opt_idx = quick_tab[CharOrdLow(arg[0])];
9366 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9367 {
9368 s = options[opt_idx].shortname;
9369 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9370 break;
9371 s = NULL;
9372 }
9373 }
9374 if (s == NULL)
9375 opt_idx = -1;
9376 return opt_idx;
9377}
9378
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009379#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009380/*
9381 * Get the value for an option.
9382 *
9383 * Returns:
9384 * Number or Toggle option: 1, *numval gets value.
9385 * String option: 0, *stringval gets allocated string.
9386 * Hidden Number or Toggle option: -1.
9387 * hidden String option: -2.
9388 * unknown option: -3.
9389 */
9390 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009391get_option_value(
9392 char_u *name,
9393 long *numval,
9394 char_u **stringval, /* NULL when only checking existence */
9395 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396{
9397 int opt_idx;
9398 char_u *varp;
9399
9400 opt_idx = findoption(name);
9401 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009402 {
9403 int key;
9404
9405 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9406 && (key = find_key_option(name)) != 0)
9407 {
9408 char_u key_name[2];
9409 char_u *p;
9410
9411 if (key < 0)
9412 {
9413 key_name[0] = KEY2TERMCAP0(key);
9414 key_name[1] = KEY2TERMCAP1(key);
9415 }
9416 else
9417 {
9418 key_name[0] = KS_KEY;
9419 key_name[1] = (key & 0xff);
9420 }
9421 p = find_termcode(key_name);
9422 if (p != NULL)
9423 {
9424 if (stringval != NULL)
9425 *stringval = vim_strsave(p);
9426 return 0;
9427 }
9428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009429 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009430 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009431
9432 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9433
9434 if (options[opt_idx].flags & P_STRING)
9435 {
9436 if (varp == NULL) /* hidden option */
9437 return -2;
9438 if (stringval != NULL)
9439 {
9440#ifdef FEAT_CRYPT
9441 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009442 if ((char_u **)varp == &curbuf->b_p_key
9443 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009444 *stringval = vim_strsave((char_u *)"*****");
9445 else
9446#endif
9447 *stringval = vim_strsave(*(char_u **)(varp));
9448 }
9449 return 0;
9450 }
9451
9452 if (varp == NULL) /* hidden option */
9453 return -1;
9454 if (options[opt_idx].flags & P_NUM)
9455 *numval = *(long *)varp;
9456 else
9457 {
9458 /* Special case: 'modified' is b_changed, but we also want to consider
9459 * it set when 'ff' or 'fenc' changed. */
9460 if ((int *)varp == &curbuf->b_changed)
9461 *numval = curbufIsChanged();
9462 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009463 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009464 }
9465 return 1;
9466}
9467#endif
9468
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009469#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009470/*
9471 * Returns the option attributes and its value. Unlike the above function it
9472 * will return either global value or local value of the option depending on
9473 * what was requested, but it will never return global value if it was
9474 * requested to return local one and vice versa. Neither it will return
9475 * buffer-local value if it was requested to return window-local one.
9476 *
9477 * Pretends that option is absent if it is not present in the requested scope
9478 * (i.e. has no global, window-local or buffer-local value depending on
9479 * opt_type). Uses
9480 *
9481 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009482 * 0 hidden or unknown option, also option that does not have requested
9483 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009484 * see SOPT_* in vim.h for other flags
9485 *
9486 * Possible opt_type values: see SREQ_* in vim.h
9487 */
9488 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009489get_option_value_strict(
9490 char_u *name,
9491 long *numval,
9492 char_u **stringval, /* NULL when only obtaining attributes */
9493 int opt_type,
9494 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009495{
9496 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009497 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009498 struct vimoption *p;
9499 int r = 0;
9500
9501 opt_idx = findoption(name);
9502 if (opt_idx < 0)
9503 return 0;
9504
9505 p = &(options[opt_idx]);
9506
9507 /* Hidden option */
9508 if (p->var == NULL)
9509 return 0;
9510
9511 if (p->flags & P_BOOL)
9512 r |= SOPT_BOOL;
9513 else if (p->flags & P_NUM)
9514 r |= SOPT_NUM;
9515 else if (p->flags & P_STRING)
9516 r |= SOPT_STRING;
9517
9518 if (p->indir == PV_NONE)
9519 {
9520 if (opt_type == SREQ_GLOBAL)
9521 r |= SOPT_GLOBAL;
9522 else
9523 return 0; /* Did not request global-only option */
9524 }
9525 else
9526 {
9527 if (p->indir & PV_BOTH)
9528 r |= SOPT_GLOBAL;
9529 else if (opt_type == SREQ_GLOBAL)
9530 return 0; /* Requested global option */
9531
9532 if (p->indir & PV_WIN)
9533 {
9534 if (opt_type == SREQ_BUF)
9535 return 0; /* Did not request window-local option */
9536 else
9537 r |= SOPT_WIN;
9538 }
9539 else if (p->indir & PV_BUF)
9540 {
9541 if (opt_type == SREQ_WIN)
9542 return 0; /* Did not request buffer-local option */
9543 else
9544 r |= SOPT_BUF;
9545 }
9546 }
9547
9548 if (stringval == NULL)
9549 return r;
9550
9551 if (opt_type == SREQ_GLOBAL)
9552 varp = p->var;
9553 else
9554 {
9555 if (opt_type == SREQ_BUF)
9556 {
9557 /* Special case: 'modified' is b_changed, but we also want to
9558 * consider it set when 'ff' or 'fenc' changed. */
9559 if (p->indir == PV_MOD)
9560 {
9561 *numval = bufIsChanged((buf_T *) from);
9562 varp = NULL;
9563 }
9564#ifdef FEAT_CRYPT
9565 else if (p->indir == PV_KEY)
9566 {
9567 /* never return the value of the crypt key */
9568 *stringval = NULL;
9569 varp = NULL;
9570 }
9571#endif
9572 else
9573 {
9574 aco_save_T aco;
9575 aucmd_prepbuf(&aco, (buf_T *) from);
9576 varp = get_varp(p);
9577 aucmd_restbuf(&aco);
9578 }
9579 }
9580 else if (opt_type == SREQ_WIN)
9581 {
9582 win_T *save_curwin;
9583 save_curwin = curwin;
9584 curwin = (win_T *) from;
9585 curbuf = curwin->w_buffer;
9586 varp = get_varp(p);
9587 curwin = save_curwin;
9588 curbuf = curwin->w_buffer;
9589 }
9590 if (varp == p->var)
9591 return (r | SOPT_UNSET);
9592 }
9593
9594 if (varp != NULL)
9595 {
9596 if (p->flags & P_STRING)
9597 *stringval = vim_strsave(*(char_u **)(varp));
9598 else if (p->flags & P_NUM)
9599 *numval = *(long *) varp;
9600 else
9601 *numval = *(int *)varp;
9602 }
9603
9604 return r;
9605}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009606
9607/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009608 * Iterate over options. First argument is a pointer to a pointer to a
9609 * structure inside options[] array, second is option type like in the above
9610 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009611 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009612 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009613 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009614 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009615 * first argument to NULL.
9616 *
9617 * Returns full option name for current option on each call.
9618 */
9619 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009620option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009621{
9622 struct vimoption *ret = NULL;
9623 do
9624 {
9625 if (*option == NULL)
9626 *option = (void *) options;
9627 else if (((struct vimoption *) (*option))->fullname == NULL)
9628 {
9629 *option = NULL;
9630 return NULL;
9631 }
9632 else
9633 *option = (void *) (((struct vimoption *) (*option)) + 1);
9634
9635 ret = ((struct vimoption *) (*option));
9636
9637 /* Hidden option */
9638 if (ret->var == NULL)
9639 {
9640 ret = NULL;
9641 continue;
9642 }
9643
9644 switch (opt_type)
9645 {
9646 case SREQ_GLOBAL:
9647 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9648 ret = NULL;
9649 break;
9650 case SREQ_BUF:
9651 if (!(ret->indir & PV_BUF))
9652 ret = NULL;
9653 break;
9654 case SREQ_WIN:
9655 if (!(ret->indir & PV_WIN))
9656 ret = NULL;
9657 break;
9658 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009659 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009660 return NULL;
9661 }
9662 }
9663 while (ret == NULL);
9664
9665 return (char_u *)ret->fullname;
9666}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009667#endif
9668
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669/*
9670 * Set the value of option "name".
9671 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009672 *
9673 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009674 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009675 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009676set_option_value(
9677 char_u *name,
9678 long number,
9679 char_u *string,
9680 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681{
9682 int opt_idx;
9683 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009684 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009685
9686 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009687 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009688 {
9689 int key;
9690
9691 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9692 && (key = find_key_option(name)) != 0)
9693 {
9694 char_u key_name[2];
9695
9696 if (key < 0)
9697 {
9698 key_name[0] = KEY2TERMCAP0(key);
9699 key_name[1] = KEY2TERMCAP1(key);
9700 }
9701 else
9702 {
9703 key_name[0] = KS_KEY;
9704 key_name[1] = (key & 0xff);
9705 }
9706 add_termcode(key_name, string, FALSE);
9707 if (full_screen)
9708 ttest(FALSE);
9709 redraw_all_later(CLEAR);
9710 return NULL;
9711 }
9712
Bram Moolenaar071d4272004-06-13 20:20:40 +00009713 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009714 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715 else
9716 {
9717 flags = options[opt_idx].flags;
9718#ifdef HAVE_SANDBOX
9719 /* Disallow changing some options in the sandbox */
9720 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009721 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009722 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009723 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009726 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009727 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728 else
9729 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009730 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 if (varp != NULL) /* hidden option is not changed */
9732 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009733 if (number == 0 && string != NULL)
9734 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009735 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009736
9737 /* Either we are given a string or we are setting option
9738 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009739 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009740 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009741 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009742 {
9743 /* There's another character after zeros or the string
9744 * is empty. In both cases, we are trying to set a
9745 * num option using a string. */
9746 EMSG3(_("E521: Number required: &%s = '%s'"),
9747 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009748 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009749
9750 }
9751 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009753 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009754 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009756 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009757 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758 }
9759 }
9760 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009761 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762}
9763
9764/*
9765 * Get the terminal code for a terminal option.
9766 * Returns NULL when not found.
9767 */
9768 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009769get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770{
9771 int opt_idx;
9772 char_u *varp;
9773
9774 if (tname[0] != 't' || tname[1] != '_' ||
9775 tname[2] == NUL || tname[3] == NUL)
9776 return NULL;
9777 if ((opt_idx = findoption(tname)) >= 0)
9778 {
9779 varp = get_varp(&(options[opt_idx]));
9780 if (varp != NULL)
9781 varp = *(char_u **)(varp);
9782 return varp;
9783 }
9784 return find_termcode(tname + 2);
9785}
9786
9787 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009788get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009789{
9790 int i;
9791
9792 i = findoption((char_u *)"hl");
9793 if (i >= 0)
9794 return options[i].def_val[VI_DEFAULT];
9795 return (char_u *)NULL;
9796}
9797
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009798#if defined(FEAT_MBYTE) || defined(PROTO)
9799 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009800get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009801{
9802 int i;
9803
9804 i = findoption((char_u *)"enc");
9805 if (i >= 0)
9806 return options[i].def_val[VI_DEFAULT];
9807 return (char_u *)NULL;
9808}
9809#endif
9810
Bram Moolenaar071d4272004-06-13 20:20:40 +00009811/*
9812 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9813 */
9814 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009815find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816{
9817 int key;
9818 int modifiers;
9819
9820 /*
9821 * Don't use get_special_key_code() for t_xx, we don't want it to call
9822 * add_termcap_entry().
9823 */
9824 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9825 key = TERMCAP2KEY(arg[2], arg[3]);
9826 else
9827 {
9828 --arg; /* put arg at the '<' */
9829 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009830 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009831 if (modifiers) /* can't handle modifiers here */
9832 key = 0;
9833 }
9834 return key;
9835}
9836
9837/*
9838 * if 'all' == 0: show changed options
9839 * if 'all' == 1: show all normal options
9840 * if 'all' == 2: show all terminal options
9841 */
9842 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009843showoptions(
9844 int all,
9845 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009846{
9847 struct vimoption *p;
9848 int col;
9849 int isterm;
9850 char_u *varp;
9851 struct vimoption **items;
9852 int item_count;
9853 int run;
9854 int row, rows;
9855 int cols;
9856 int i;
9857 int len;
9858
9859#define INC 20
9860#define GAP 3
9861
9862 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9863 PARAM_COUNT));
9864 if (items == NULL)
9865 return;
9866
9867 /* Highlight title */
9868 if (all == 2)
9869 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9870 else if (opt_flags & OPT_GLOBAL)
9871 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9872 else if (opt_flags & OPT_LOCAL)
9873 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9874 else
9875 MSG_PUTS_TITLE(_("\n--- Options ---"));
9876
9877 /*
9878 * do the loop two times:
9879 * 1. display the short items
9880 * 2. display the long items (only strings and numbers)
9881 */
9882 for (run = 1; run <= 2 && !got_int; ++run)
9883 {
9884 /*
9885 * collect the items in items[]
9886 */
9887 item_count = 0;
9888 for (p = &options[0]; p->fullname != NULL; p++)
9889 {
9890 varp = NULL;
9891 isterm = istermoption(p);
9892 if (opt_flags != 0)
9893 {
9894 if (p->indir != PV_NONE && !isterm)
9895 varp = get_varp_scope(p, opt_flags);
9896 }
9897 else
9898 varp = get_varp(p);
9899 if (varp != NULL
9900 && ((all == 2 && isterm)
9901 || (all == 1 && !isterm)
9902 || (all == 0 && !optval_default(p, varp))))
9903 {
9904 if (p->flags & P_BOOL)
9905 len = 1; /* a toggle option fits always */
9906 else
9907 {
9908 option_value2string(p, opt_flags);
9909 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9910 }
9911 if ((len <= INC - GAP && run == 1) ||
9912 (len > INC - GAP && run == 2))
9913 items[item_count++] = p;
9914 }
9915 }
9916
9917 /*
9918 * display the items
9919 */
9920 if (run == 1)
9921 {
9922 cols = (Columns + GAP - 3) / INC;
9923 if (cols == 0)
9924 cols = 1;
9925 rows = (item_count + cols - 1) / cols;
9926 }
9927 else /* run == 2 */
9928 rows = item_count;
9929 for (row = 0; row < rows && !got_int; ++row)
9930 {
9931 msg_putchar('\n'); /* go to next line */
9932 if (got_int) /* 'q' typed in more */
9933 break;
9934 col = 0;
9935 for (i = row; i < item_count; i += rows)
9936 {
9937 msg_col = col; /* make columns */
9938 showoneopt(items[i], opt_flags);
9939 col += INC;
9940 }
9941 out_flush();
9942 ui_breakcheck();
9943 }
9944 }
9945 vim_free(items);
9946}
9947
9948/*
9949 * Return TRUE if option "p" has its default value.
9950 */
9951 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009952optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953{
9954 int dvi;
9955
9956 if (varp == NULL)
9957 return TRUE; /* hidden option is always at default */
9958 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9959 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009960 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009962 /* the cast to long is required for Manx C, long_i is
9963 * needed for MSVC */
9964 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965 /* P_STRING */
9966 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9967}
9968
9969/*
9970 * showoneopt: show the value of one option
9971 * must not be called with a hidden option!
9972 */
9973 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009974showoneopt(
9975 struct vimoption *p,
9976 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009978 char_u *varp;
9979 int save_silent = silent_mode;
9980
9981 silent_mode = FALSE;
9982 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983
9984 varp = get_varp_scope(p, opt_flags);
9985
9986 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9987 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9988 ? !curbufIsChanged() : !*(int *)varp))
9989 MSG_PUTS("no");
9990 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9991 MSG_PUTS("--");
9992 else
9993 MSG_PUTS(" ");
9994 MSG_PUTS(p->fullname);
9995 if (!(p->flags & P_BOOL))
9996 {
9997 msg_putchar('=');
9998 /* put value string in NameBuff */
9999 option_value2string(p, opt_flags);
10000 msg_outtrans(NameBuff);
10001 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010002
10003 silent_mode = save_silent;
10004 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010005}
10006
10007/*
10008 * Write modified options as ":set" commands to a file.
10009 *
10010 * There are three values for "opt_flags":
10011 * OPT_GLOBAL: Write global option values and fresh values of
10012 * buffer-local options (used for start of a session
10013 * file).
10014 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10015 * curwin (used for a vimrc file).
10016 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10017 * and local values for window-local options of
10018 * curwin. Local values are also written when at the
10019 * default value, because a modeline or autocommand
10020 * may have set them when doing ":edit file" and the
10021 * user has set them back at the default or fresh
10022 * value.
10023 * When "local_only" is TRUE, don't write fresh
10024 * values, only local values (for ":mkview").
10025 * (fresh value = value used for a new buffer or window for a local option).
10026 *
10027 * Return FAIL on error, OK otherwise.
10028 */
10029 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010030makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031{
10032 struct vimoption *p;
10033 char_u *varp; /* currently used value */
10034 char_u *varp_fresh; /* local value */
10035 char_u *varp_local = NULL; /* fresh value */
10036 char *cmd;
10037 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010038 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010039
10040 /*
10041 * The options that don't have a default (terminal name, columns, lines)
10042 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010043 * Do the loop over "options[]" twice: once for options with the
10044 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010045 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010046 for (pri = 1; pri >= 0; --pri)
10047 {
10048 for (p = &options[0]; !istermoption(p); p++)
10049 if (!(p->flags & P_NO_MKRC)
10050 && !istermoption(p)
10051 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052 {
10053 /* skip global option when only doing locals */
10054 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10055 continue;
10056
10057 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10058 * file, they are always buffer-specific. */
10059 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10060 continue;
10061
10062 /* Global values are only written when not at the default value. */
10063 varp = get_varp_scope(p, opt_flags);
10064 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10065 continue;
10066
10067 round = 2;
10068 if (p->indir != PV_NONE)
10069 {
10070 if (p->var == VAR_WIN)
10071 {
10072 /* skip window-local option when only doing globals */
10073 if (!(opt_flags & OPT_LOCAL))
10074 continue;
10075 /* When fresh value of window-local option is not at the
10076 * default, need to write it too. */
10077 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10078 {
10079 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10080 if (!optval_default(p, varp_fresh))
10081 {
10082 round = 1;
10083 varp_local = varp;
10084 varp = varp_fresh;
10085 }
10086 }
10087 }
10088 }
10089
10090 /* Round 1: fresh value for window-local options.
10091 * Round 2: other values */
10092 for ( ; round <= 2; varp = varp_local, ++round)
10093 {
10094 if (round == 1 || (opt_flags & OPT_GLOBAL))
10095 cmd = "set";
10096 else
10097 cmd = "setlocal";
10098
10099 if (p->flags & P_BOOL)
10100 {
10101 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10102 return FAIL;
10103 }
10104 else if (p->flags & P_NUM)
10105 {
10106 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10107 return FAIL;
10108 }
10109 else /* P_STRING */
10110 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010111#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10112 int do_endif = FALSE;
10113
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114 /* Don't set 'syntax' and 'filetype' again if the value is
10115 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010116 if (
10117# if defined(FEAT_SYN_HL)
10118 p->indir == PV_SYN
10119# if defined(FEAT_AUTOCMD)
10120 ||
10121# endif
10122# endif
10123# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010124 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010125# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010126 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127 {
10128 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10129 *(char_u **)(varp)) < 0
10130 || put_eol(fd) < 0)
10131 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010132 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010134#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010135 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10136 (p->flags & P_EXPAND) != 0) == FAIL)
10137 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010138#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10139 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140 {
10141 if (put_line(fd, "endif") == FAIL)
10142 return FAIL;
10143 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145 }
10146 }
10147 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149 return OK;
10150}
10151
10152#if defined(FEAT_FOLDING) || defined(PROTO)
10153/*
10154 * Generate set commands for the local fold options only. Used when
10155 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10156 */
10157 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010158makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159{
10160 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10161# ifdef FEAT_EVAL
10162 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10163 == FAIL
10164# endif
10165 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10166 == FAIL
10167 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10168 == FAIL
10169 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10170 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10171 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10172 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10173 )
10174 return FAIL;
10175
10176 return OK;
10177}
10178#endif
10179
10180 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010181put_setstring(
10182 FILE *fd,
10183 char *cmd,
10184 char *name,
10185 char_u **valuep,
10186 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187{
10188 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010189 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190
10191 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10192 return FAIL;
10193 if (*valuep != NULL)
10194 {
10195 /* Output 'pastetoggle' as key names. For other
10196 * options some characters have to be escaped with
10197 * CTRL-V or backslash */
10198 if (valuep == &p_pt)
10199 {
10200 s = *valuep;
10201 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010202 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203 return FAIL;
10204 }
10205 else if (expand)
10206 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010207 buf = alloc(MAXPATHL);
10208 if (buf == NULL)
10209 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10211 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010212 {
10213 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010215 }
10216 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217 }
10218 else if (put_escstr(fd, *valuep, 2) == FAIL)
10219 return FAIL;
10220 }
10221 if (put_eol(fd) < 0)
10222 return FAIL;
10223 return OK;
10224}
10225
10226 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010227put_setnum(
10228 FILE *fd,
10229 char *cmd,
10230 char *name,
10231 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232{
10233 long wc;
10234
10235 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10236 return FAIL;
10237 if (wc_use_keyname((char_u *)valuep, &wc))
10238 {
10239 /* print 'wildchar' and 'wildcharm' as a key name */
10240 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10241 return FAIL;
10242 }
10243 else if (fprintf(fd, "%ld", *valuep) < 0)
10244 return FAIL;
10245 if (put_eol(fd) < 0)
10246 return FAIL;
10247 return OK;
10248}
10249
10250 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010251put_setbool(
10252 FILE *fd,
10253 char *cmd,
10254 char *name,
10255 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256{
Bram Moolenaar893de922007-10-02 18:40:57 +000010257 if (value < 0) /* global/local option using global value */
10258 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10260 || put_eol(fd) < 0)
10261 return FAIL;
10262 return OK;
10263}
10264
10265/*
10266 * Clear all the terminal options.
10267 * If the option has been allocated, free the memory.
10268 * Terminal options are never hidden or indirect.
10269 */
10270 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010271clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273 /*
10274 * Reset a few things before clearing the old options. This may cause
10275 * outputting a few things that the terminal doesn't understand, but the
10276 * screen will be cleared later, so this is OK.
10277 */
10278#ifdef FEAT_MOUSE_TTY
10279 mch_setmouse(FALSE); /* switch mouse off */
10280#endif
10281#ifdef FEAT_TITLE
10282 mch_restore_title(3); /* restore window titles */
10283#endif
10284#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10285 /* When starting the GUI close the display opened for the clipboard.
10286 * After restoring the title, because that will need the display. */
10287 if (gui.starting)
10288 clear_xterm_clip();
10289#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010290 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010291
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010292 free_termoptions();
10293}
10294
10295 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010296free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010297{
10298 struct vimoption *p;
10299
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300 for (p = &options[0]; p->fullname != NULL; p++)
10301 if (istermoption(p))
10302 {
10303 if (p->flags & P_ALLOCED)
10304 free_string_option(*(char_u **)(p->var));
10305 if (p->flags & P_DEF_ALLOCED)
10306 free_string_option(p->def_val[VI_DEFAULT]);
10307 *(char_u **)(p->var) = empty_option;
10308 p->def_val[VI_DEFAULT] = empty_option;
10309 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10310 }
10311 clear_termcodes();
10312}
10313
10314/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010315 * Free the string for one term option, if it was allocated.
10316 * Set the string to empty_option and clear allocated flag.
10317 * "var" points to the option value.
10318 */
10319 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010320free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010321{
10322 struct vimoption *p;
10323
10324 for (p = &options[0]; p->fullname != NULL; p++)
10325 if (p->var == var)
10326 {
10327 if (p->flags & P_ALLOCED)
10328 free_string_option(*(char_u **)(p->var));
10329 *(char_u **)(p->var) = empty_option;
10330 p->flags &= ~P_ALLOCED;
10331 break;
10332 }
10333}
10334
10335/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010336 * Set the terminal option defaults to the current value.
10337 * Used after setting the terminal name.
10338 */
10339 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010340set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341{
10342 struct vimoption *p;
10343
10344 for (p = &options[0]; p->fullname != NULL; p++)
10345 {
10346 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10347 {
10348 if (p->flags & P_DEF_ALLOCED)
10349 {
10350 free_string_option(p->def_val[VI_DEFAULT]);
10351 p->flags &= ~P_DEF_ALLOCED;
10352 }
10353 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10354 if (p->flags & P_ALLOCED)
10355 {
10356 p->flags |= P_DEF_ALLOCED;
10357 p->flags &= ~P_ALLOCED; /* don't free the value now */
10358 }
10359 }
10360 }
10361}
10362
10363/*
10364 * return TRUE if 'p' starts with 't_'
10365 */
10366 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010367istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010368{
10369 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10370}
10371
10372/*
10373 * Compute columns for ruler and shown command. 'sc_col' is also used to
10374 * decide what the maximum length of a message on the status line can be.
10375 * If there is a status line for the last window, 'sc_col' is independent
10376 * of 'ru_col'.
10377 */
10378
10379#define COL_RULER 17 /* columns needed by standard ruler */
10380
10381 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010382comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383{
10384#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010385 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386
10387 sc_col = 0;
10388 ru_col = 0;
10389 if (p_ru)
10390 {
10391#ifdef FEAT_STL_OPT
10392 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10393#else
10394 ru_col = COL_RULER + 1;
10395#endif
10396 /* no last status line, adjust sc_col */
10397 if (!last_has_status)
10398 sc_col = ru_col;
10399 }
10400 if (p_sc)
10401 {
10402 sc_col += SHOWCMD_COLS;
10403 if (!p_ru || last_has_status) /* no need for separating space */
10404 ++sc_col;
10405 }
10406 sc_col = Columns - sc_col;
10407 ru_col = Columns - ru_col;
10408 if (sc_col <= 0) /* screen too narrow, will become a mess */
10409 sc_col = 1;
10410 if (ru_col <= 0)
10411 ru_col = 1;
10412#else
10413 sc_col = Columns;
10414 ru_col = Columns;
10415#endif
10416}
10417
10418/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010419 * Unset local option value, similar to ":set opt<".
10420 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010421 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010422unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010423{
10424 struct vimoption *p;
10425 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010426 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010427
10428 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010429 if (opt_idx < 0)
10430 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 p = &(options[opt_idx]);
10432
10433 switch ((int)p->indir)
10434 {
10435 /* global option with local value: use local value if it's been set */
10436 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010437 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010438 break;
10439 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010440 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010441 break;
10442 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010443 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010444 break;
10445 case PV_AR:
10446 buf->b_p_ar = -1;
10447 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010448 case PV_BKC:
10449 clear_string_option(&buf->b_p_bkc);
10450 buf->b_bkc_flags = 0;
10451 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010453 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010454 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010455 case PV_TC:
10456 clear_string_option(&buf->b_p_tc);
10457 buf->b_tc_flags = 0;
10458 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010459#ifdef FEAT_FIND_ID
10460 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010461 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010462 break;
10463 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010464 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010465 break;
10466#endif
10467#ifdef FEAT_INS_EXPAND
10468 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010469 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010470 break;
10471 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010472 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010473 break;
10474#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010475 case PV_FP:
10476 clear_string_option(&buf->b_p_fp);
10477 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010478#ifdef FEAT_QUICKFIX
10479 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010480 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010481 break;
10482 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010483 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010484 break;
10485 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010486 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010487 break;
10488#endif
10489#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10490 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010491 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010492 break;
10493#endif
10494#if defined(FEAT_CRYPT)
10495 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010496 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010497 break;
10498#endif
10499#ifdef FEAT_STL_OPT
10500 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010501 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010502 break;
10503#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010504 case PV_UL:
10505 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10506 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010507#ifdef FEAT_LISP
10508 case PV_LW:
10509 clear_string_option(&buf->b_p_lw);
10510 break;
10511#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010512#ifdef FEAT_MBYTE
10513 case PV_MENC:
10514 clear_string_option(&buf->b_p_menc);
10515 break;
10516#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010517 }
10518}
10519
10520/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521 * Get pointer to option variable, depending on local or global scope.
10522 */
10523 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010524get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010525{
10526 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10527 {
10528 if (p->var == VAR_WIN)
10529 return (char_u *)GLOBAL_WO(get_varp(p));
10530 return p->var;
10531 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010532 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533 {
10534 switch ((int)p->indir)
10535 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010536 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010538 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10539 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10540 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010542 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10543 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10544 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010545 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010546 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010547 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010549 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10550 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551#endif
10552#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010553 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10554 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010556#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10557 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10558#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010559#if defined(FEAT_CRYPT)
10560 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10561#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010562#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010563 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010564#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010565 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010566#ifdef FEAT_LISP
10567 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10568#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010569 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010570#ifdef FEAT_MBYTE
10571 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10572#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573 }
10574 return NULL; /* "cannot happen" */
10575 }
10576 return get_varp(p);
10577}
10578
10579/*
10580 * Get pointer to option variable.
10581 */
10582 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010583get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584{
10585 /* hidden option, always return NULL */
10586 if (p->var == NULL)
10587 return NULL;
10588
10589 switch ((int)p->indir)
10590 {
10591 case PV_NONE: return p->var;
10592
10593 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010594 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010596 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010598 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010600 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010602 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010604 case PV_TC: return *curbuf->b_p_tc != NUL
10605 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010606 case PV_BKC: return *curbuf->b_p_bkc != NUL
10607 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010609 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010611 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10613#endif
10614#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010615 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010617 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10619#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010620 case PV_FP: return *curbuf->b_p_fp != NUL
10621 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010622#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010623 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010624 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010625 case PV_GP: return *curbuf->b_p_gp != NUL
10626 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10627 case PV_MP: return *curbuf->b_p_mp != NUL
10628 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010630#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10631 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10632 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10633#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010634#if defined(FEAT_CRYPT)
10635 case PV_CM: return *curbuf->b_p_cm != NUL
10636 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10637#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010638#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010639 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010640 ? (char_u *)&(curwin->w_p_stl) : p->var;
10641#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010642 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10643 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010644#ifdef FEAT_LISP
10645 case PV_LW: return *curbuf->b_p_lw != NUL
10646 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10647#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010648#ifdef FEAT_MBYTE
10649 case PV_MENC: return *curbuf->b_p_menc != NUL
10650 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652
10653#ifdef FEAT_ARABIC
10654 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10655#endif
10656 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010657#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010658 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10659#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010660#ifdef FEAT_SYN_HL
10661 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10662 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010663 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010664#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010665#ifdef FEAT_DIFF
10666 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10667#endif
10668#ifdef FEAT_FOLDING
10669 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10670 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10671 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10672 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10673 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10674 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10675 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10676# ifdef FEAT_EVAL
10677 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10678 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10679# endif
10680 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10681#endif
10682 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010683 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010684#ifdef FEAT_LINEBREAK
10685 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10686#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010687#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010689 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10690#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10692 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10693#endif
10694#ifdef FEAT_RIGHTLEFT
10695 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10696 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10697#endif
10698 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10699 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10700#ifdef FEAT_LINEBREAK
10701 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010702 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10703 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704#endif
10705#ifdef FEAT_SCROLLBIND
10706 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10707#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010708#ifdef FEAT_CURSORBIND
10709 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10710#endif
10711#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010712 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10713 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10714#endif
10715#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010716 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010717 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719
10720 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10721 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10722#ifdef FEAT_MBYTE
10723 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10724#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010725 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10726 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10728 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10729#ifdef FEAT_CINDENT
10730 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10731 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10732 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10733#endif
10734#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10735 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10736#endif
10737#ifdef FEAT_COMMENTS
10738 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10739#endif
10740#ifdef FEAT_FOLDING
10741 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10742#endif
10743#ifdef FEAT_INS_EXPAND
10744 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10745#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010746#ifdef FEAT_COMPL_FUNC
10747 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010748 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010749#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010751 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10753#ifdef FEAT_MBYTE
10754 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10755#endif
10756 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10757#ifdef FEAT_AUTOCMD
10758 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10759#endif
10760 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010761 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10763 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10764 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10765 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10766#ifdef FEAT_FIND_ID
10767# ifdef FEAT_EVAL
10768 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10769# endif
10770#endif
10771#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10772 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10773 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10774#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010775#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010776 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778#ifdef FEAT_CRYPT
10779 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10780#endif
10781#ifdef FEAT_LISP
10782 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10783#endif
10784 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10785 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10786 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10787 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10788 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010790#ifdef FEAT_TEXTOBJ
10791 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10792#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010793 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10794#ifdef FEAT_SMARTINDENT
10795 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10799#ifdef FEAT_SEARCHPATH
10800 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10801#endif
10802 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10803#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010804 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010805 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10806#endif
10807#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010808 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10809 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10810 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811#endif
10812 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10813 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10814 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10815 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010816#ifdef FEAT_PERSISTENT_UNDO
10817 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10818#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10820#ifdef FEAT_KEYMAP
10821 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10822#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010823#ifdef FEAT_SIGNS
10824 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10825#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010826 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827 }
10828 /* always return a valid pointer to avoid a crash! */
10829 return (char_u *)&(curbuf->b_p_wm);
10830}
10831
10832/*
10833 * Get the value of 'equalprg', either the buffer-local one or the global one.
10834 */
10835 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010836get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837{
10838 if (*curbuf->b_p_ep == NUL)
10839 return p_ep;
10840 return curbuf->b_p_ep;
10841}
10842
10843#if defined(FEAT_WINDOWS) || defined(PROTO)
10844/*
10845 * Copy options from one window to another.
10846 * Used when splitting a window.
10847 */
10848 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010849win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850{
10851 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10852 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10853# ifdef FEAT_RIGHTLEFT
10854# ifdef FEAT_FKMAP
10855 /* Is this right? */
10856 wp_to->w_farsi = wp_from->w_farsi;
10857# endif
10858# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010859#if defined(FEAT_LINEBREAK)
10860 briopt_check(wp_to);
10861#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862}
10863#endif
10864
10865/*
10866 * Copy the options from one winopt_T to another.
10867 * Doesn't free the old option values in "to", use clear_winopt() for that.
10868 * The 'scroll' option is not copied, because it depends on the window height.
10869 * The 'previewwindow' option is reset, there can be only one preview window.
10870 */
10871 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010872copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873{
10874#ifdef FEAT_ARABIC
10875 to->wo_arab = from->wo_arab;
10876#endif
10877 to->wo_list = from->wo_list;
10878 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010879 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010880#ifdef FEAT_LINEBREAK
10881 to->wo_nuw = from->wo_nuw;
10882#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883#ifdef FEAT_RIGHTLEFT
10884 to->wo_rl = from->wo_rl;
10885 to->wo_rlc = vim_strsave(from->wo_rlc);
10886#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010887#ifdef FEAT_STL_OPT
10888 to->wo_stl = vim_strsave(from->wo_stl);
10889#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010891#ifdef FEAT_DIFF
10892 to->wo_wrap_save = from->wo_wrap_save;
10893#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894#ifdef FEAT_LINEBREAK
10895 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010896 to->wo_bri = from->wo_bri;
10897 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010898#endif
10899#ifdef FEAT_SCROLLBIND
10900 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010901 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010903#ifdef FEAT_CURSORBIND
10904 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010905 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010906#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010907#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010908 to->wo_spell = from->wo_spell;
10909#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010910#ifdef FEAT_SYN_HL
10911 to->wo_cuc = from->wo_cuc;
10912 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010913 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010914#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010915#ifdef FEAT_DIFF
10916 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010917 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010919#ifdef FEAT_CONCEAL
10920 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010921 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010922#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010923#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010924 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010925 to->wo_tms = vim_strsave(from->wo_tms);
10926#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010927#ifdef FEAT_FOLDING
10928 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010929 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010931 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932 to->wo_fdi = vim_strsave(from->wo_fdi);
10933 to->wo_fml = from->wo_fml;
10934 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010935 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010937 to->wo_fdm_save = from->wo_diff_saved
10938 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939 to->wo_fdn = from->wo_fdn;
10940# ifdef FEAT_EVAL
10941 to->wo_fde = vim_strsave(from->wo_fde);
10942 to->wo_fdt = vim_strsave(from->wo_fdt);
10943# endif
10944 to->wo_fmr = vim_strsave(from->wo_fmr);
10945#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010946#ifdef FEAT_SIGNS
10947 to->wo_scl = vim_strsave(from->wo_scl);
10948#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949 check_winopt(to); /* don't want NULL pointers */
10950}
10951
10952/*
10953 * Check string options in a window for a NULL value.
10954 */
10955 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010956check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957{
10958 check_winopt(&win->w_onebuf_opt);
10959 check_winopt(&win->w_allbuf_opt);
10960}
10961
10962/*
10963 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10964 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010965 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010966check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010967{
10968#ifdef FEAT_FOLDING
10969 check_string_option(&wop->wo_fdi);
10970 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010971 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010972# ifdef FEAT_EVAL
10973 check_string_option(&wop->wo_fde);
10974 check_string_option(&wop->wo_fdt);
10975# endif
10976 check_string_option(&wop->wo_fmr);
10977#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010978#ifdef FEAT_SIGNS
10979 check_string_option(&wop->wo_scl);
10980#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010981#ifdef FEAT_RIGHTLEFT
10982 check_string_option(&wop->wo_rlc);
10983#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010984#ifdef FEAT_STL_OPT
10985 check_string_option(&wop->wo_stl);
10986#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010987#ifdef FEAT_SYN_HL
10988 check_string_option(&wop->wo_cc);
10989#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010990#ifdef FEAT_CONCEAL
10991 check_string_option(&wop->wo_cocu);
10992#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010993#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010994 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010995 check_string_option(&wop->wo_tms);
10996#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010997#ifdef FEAT_LINEBREAK
10998 check_string_option(&wop->wo_briopt);
10999#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011000}
11001
11002/*
11003 * Free the allocated memory inside a winopt_T.
11004 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011005 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011006clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011007{
11008#ifdef FEAT_FOLDING
11009 clear_string_option(&wop->wo_fdi);
11010 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011011 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011012# ifdef FEAT_EVAL
11013 clear_string_option(&wop->wo_fde);
11014 clear_string_option(&wop->wo_fdt);
11015# endif
11016 clear_string_option(&wop->wo_fmr);
11017#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011018#ifdef FEAT_SIGNS
11019 clear_string_option(&wop->wo_scl);
11020#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011021#ifdef FEAT_LINEBREAK
11022 clear_string_option(&wop->wo_briopt);
11023#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011024#ifdef FEAT_RIGHTLEFT
11025 clear_string_option(&wop->wo_rlc);
11026#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011027#ifdef FEAT_STL_OPT
11028 clear_string_option(&wop->wo_stl);
11029#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011030#ifdef FEAT_SYN_HL
11031 clear_string_option(&wop->wo_cc);
11032#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011033#ifdef FEAT_CONCEAL
11034 clear_string_option(&wop->wo_cocu);
11035#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011036#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011037 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011038 clear_string_option(&wop->wo_tms);
11039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011040}
11041
11042/*
11043 * Copy global option values to local options for one buffer.
11044 * Used when creating a new buffer and sometimes when entering a buffer.
11045 * flags:
11046 * BCO_ENTER We will enter the buf buffer.
11047 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11048 * appropriate.
11049 * BCO_NOHELP Don't copy the values to a help buffer.
11050 */
11051 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011052buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011053{
11054 int should_copy = TRUE;
11055 char_u *save_p_isk = NULL; /* init for GCC */
11056 int dont_do_help;
11057 int did_isk = FALSE;
11058
11059 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011060 * Skip this when the option defaults have not been set yet. Happens when
11061 * main() allocates the first buffer.
11062 */
11063 if (p_cpo != NULL)
11064 {
11065 /*
11066 * Always copy when entering and 'cpo' contains 'S'.
11067 * Don't copy when already initialized.
11068 * Don't copy when 'cpo' contains 's' and not entering.
11069 * 'S' BCO_ENTER initialized 's' should_copy
11070 * yes yes X X TRUE
11071 * yes no yes X FALSE
11072 * no X yes X FALSE
11073 * X no no yes FALSE
11074 * X no no no TRUE
11075 * no yes no X TRUE
11076 */
11077 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11078 && (buf->b_p_initialized
11079 || (!(flags & BCO_ENTER)
11080 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11081 should_copy = FALSE;
11082
11083 if (should_copy || (flags & BCO_ALWAYS))
11084 {
11085 /* Don't copy the options specific to a help buffer when
11086 * BCO_NOHELP is given or the options were initialized already
11087 * (jumping back to a help file with CTRL-T or CTRL-O) */
11088 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11089 || buf->b_p_initialized;
11090 if (dont_do_help) /* don't free b_p_isk */
11091 {
11092 save_p_isk = buf->b_p_isk;
11093 buf->b_p_isk = NULL;
11094 }
11095 /*
11096 * Always free the allocated strings.
11097 * If not already initialized, set 'readonly' and copy 'fileformat'.
11098 */
11099 if (!buf->b_p_initialized)
11100 {
11101 free_buf_options(buf, TRUE);
11102 buf->b_p_ro = FALSE; /* don't copy readonly */
11103 buf->b_p_tx = p_tx;
11104#ifdef FEAT_MBYTE
11105 buf->b_p_fenc = vim_strsave(p_fenc);
11106#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011107 switch (*p_ffs)
11108 {
11109 case 'm':
11110 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11111 case 'd':
11112 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11113 case 'u':
11114 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11115 default:
11116 buf->b_p_ff = vim_strsave(p_ff);
11117 }
11118 if (buf->b_p_ff != NULL)
11119 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120 buf->b_p_bh = empty_option;
11121 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122 }
11123 else
11124 free_buf_options(buf, FALSE);
11125
11126 buf->b_p_ai = p_ai;
11127 buf->b_p_ai_nopaste = p_ai_nopaste;
11128 buf->b_p_sw = p_sw;
11129 buf->b_p_tw = p_tw;
11130 buf->b_p_tw_nopaste = p_tw_nopaste;
11131 buf->b_p_tw_nobin = p_tw_nobin;
11132 buf->b_p_wm = p_wm;
11133 buf->b_p_wm_nopaste = p_wm_nopaste;
11134 buf->b_p_wm_nobin = p_wm_nobin;
11135 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011136#ifdef FEAT_MBYTE
11137 buf->b_p_bomb = p_bomb;
11138#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011139 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140 buf->b_p_et = p_et;
11141 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011142 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011143 buf->b_p_ml = p_ml;
11144 buf->b_p_ml_nobin = p_ml_nobin;
11145 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011146 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147#ifdef FEAT_INS_EXPAND
11148 buf->b_p_cpt = vim_strsave(p_cpt);
11149#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011150#ifdef FEAT_COMPL_FUNC
11151 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011152 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154 buf->b_p_sts = p_sts;
11155 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011157#ifdef FEAT_COMMENTS
11158 buf->b_p_com = vim_strsave(p_com);
11159#endif
11160#ifdef FEAT_FOLDING
11161 buf->b_p_cms = vim_strsave(p_cms);
11162#endif
11163 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011164 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165 buf->b_p_nf = vim_strsave(p_nf);
11166 buf->b_p_mps = vim_strsave(p_mps);
11167#ifdef FEAT_SMARTINDENT
11168 buf->b_p_si = p_si;
11169#endif
11170 buf->b_p_ci = p_ci;
11171#ifdef FEAT_CINDENT
11172 buf->b_p_cin = p_cin;
11173 buf->b_p_cink = vim_strsave(p_cink);
11174 buf->b_p_cino = vim_strsave(p_cino);
11175#endif
11176#ifdef FEAT_AUTOCMD
11177 /* Don't copy 'filetype', it must be detected */
11178 buf->b_p_ft = empty_option;
11179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180 buf->b_p_pi = p_pi;
11181#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11182 buf->b_p_cinw = vim_strsave(p_cinw);
11183#endif
11184#ifdef FEAT_LISP
11185 buf->b_p_lisp = p_lisp;
11186#endif
11187#ifdef FEAT_SYN_HL
11188 /* Don't copy 'syntax', it must be set */
11189 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011190 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011191 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011192#endif
11193#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011194 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011195 (void)compile_cap_prog(&buf->b_s);
11196 buf->b_s.b_p_spf = vim_strsave(p_spf);
11197 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011198#endif
11199#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11200 buf->b_p_inde = vim_strsave(p_inde);
11201 buf->b_p_indk = vim_strsave(p_indk);
11202#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011203 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011204#if defined(FEAT_EVAL)
11205 buf->b_p_fex = vim_strsave(p_fex);
11206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011207#ifdef FEAT_CRYPT
11208 buf->b_p_key = vim_strsave(p_key);
11209#endif
11210#ifdef FEAT_SEARCHPATH
11211 buf->b_p_sua = vim_strsave(p_sua);
11212#endif
11213#ifdef FEAT_KEYMAP
11214 buf->b_p_keymap = vim_strsave(p_keymap);
11215 buf->b_kmap_state |= KEYMAP_INIT;
11216#endif
11217 /* This isn't really an option, but copying the langmap and IME
11218 * state from the current buffer is better than resetting it. */
11219 buf->b_p_iminsert = p_iminsert;
11220 buf->b_p_imsearch = p_imsearch;
11221
11222 /* options that are normally global but also have a local value
11223 * are not copied, start using the global value */
11224 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011225 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011226 buf->b_p_bkc = empty_option;
11227 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011228#ifdef FEAT_QUICKFIX
11229 buf->b_p_gp = empty_option;
11230 buf->b_p_mp = empty_option;
11231 buf->b_p_efm = empty_option;
11232#endif
11233 buf->b_p_ep = empty_option;
11234 buf->b_p_kp = empty_option;
11235 buf->b_p_path = empty_option;
11236 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011237 buf->b_p_tc = empty_option;
11238 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239#ifdef FEAT_FIND_ID
11240 buf->b_p_def = empty_option;
11241 buf->b_p_inc = empty_option;
11242# ifdef FEAT_EVAL
11243 buf->b_p_inex = vim_strsave(p_inex);
11244# endif
11245#endif
11246#ifdef FEAT_INS_EXPAND
11247 buf->b_p_dict = empty_option;
11248 buf->b_p_tsr = empty_option;
11249#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011250#ifdef FEAT_TEXTOBJ
11251 buf->b_p_qe = vim_strsave(p_qe);
11252#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011253#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11254 buf->b_p_bexpr = empty_option;
11255#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011256#if defined(FEAT_CRYPT)
11257 buf->b_p_cm = empty_option;
11258#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011259#ifdef FEAT_PERSISTENT_UNDO
11260 buf->b_p_udf = p_udf;
11261#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011262#ifdef FEAT_LISP
11263 buf->b_p_lw = empty_option;
11264#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011265#ifdef FEAT_MBYTE
11266 buf->b_p_menc = empty_option;
11267#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011268
11269 /*
11270 * Don't copy the options set by ex_help(), use the saved values,
11271 * when going from a help buffer to a non-help buffer.
11272 * Don't touch these at all when BCO_NOHELP is used and going from
11273 * or to a help buffer.
11274 */
11275 if (dont_do_help)
11276 buf->b_p_isk = save_p_isk;
11277 else
11278 {
11279 buf->b_p_isk = vim_strsave(p_isk);
11280 did_isk = TRUE;
11281 buf->b_p_ts = p_ts;
11282 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011283 if (buf->b_p_bt[0] == 'h')
11284 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011285 buf->b_p_ma = p_ma;
11286 }
11287 }
11288
11289 /*
11290 * When the options should be copied (ignoring BCO_ALWAYS), set the
11291 * flag that indicates that the options have been initialized.
11292 */
11293 if (should_copy)
11294 buf->b_p_initialized = TRUE;
11295 }
11296
11297 check_buf_options(buf); /* make sure we don't have NULLs */
11298 if (did_isk)
11299 (void)buf_init_chartab(buf, FALSE);
11300}
11301
11302/*
11303 * Reset the 'modifiable' option and its default value.
11304 */
11305 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011306reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011307{
11308 int opt_idx;
11309
11310 curbuf->b_p_ma = FALSE;
11311 p_ma = FALSE;
11312 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011313 if (opt_idx >= 0)
11314 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315}
11316
11317/*
11318 * Set the global value for 'iminsert' to the local value.
11319 */
11320 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011321set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322{
11323 p_iminsert = curbuf->b_p_iminsert;
11324}
11325
11326/*
11327 * Set the global value for 'imsearch' to the local value.
11328 */
11329 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011330set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331{
11332 p_imsearch = curbuf->b_p_imsearch;
11333}
11334
11335#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11336static int expand_option_idx = -1;
11337static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11338static int expand_option_flags = 0;
11339
11340 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011341set_context_in_set_cmd(
11342 expand_T *xp,
11343 char_u *arg,
11344 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011345{
11346 int nextchar;
11347 long_u flags = 0; /* init for GCC */
11348 int opt_idx = 0; /* init for GCC */
11349 char_u *p;
11350 char_u *s;
11351 int is_term_option = FALSE;
11352 int key;
11353
11354 expand_option_flags = opt_flags;
11355
11356 xp->xp_context = EXPAND_SETTINGS;
11357 if (*arg == NUL)
11358 {
11359 xp->xp_pattern = arg;
11360 return;
11361 }
11362 p = arg + STRLEN(arg) - 1;
11363 if (*p == ' ' && *(p - 1) != '\\')
11364 {
11365 xp->xp_pattern = p + 1;
11366 return;
11367 }
11368 while (p > arg)
11369 {
11370 s = p;
11371 /* count number of backslashes before ' ' or ',' */
11372 if (*p == ' ' || *p == ',')
11373 {
11374 while (s > arg && *(s - 1) == '\\')
11375 --s;
11376 }
11377 /* break at a space with an even number of backslashes */
11378 if (*p == ' ' && ((p - s) & 1) == 0)
11379 {
11380 ++p;
11381 break;
11382 }
11383 --p;
11384 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011385 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011386 {
11387 xp->xp_context = EXPAND_BOOL_SETTINGS;
11388 p += 2;
11389 }
11390 if (STRNCMP(p, "inv", 3) == 0)
11391 {
11392 xp->xp_context = EXPAND_BOOL_SETTINGS;
11393 p += 3;
11394 }
11395 xp->xp_pattern = arg = p;
11396 if (*arg == '<')
11397 {
11398 while (*p != '>')
11399 if (*p++ == NUL) /* expand terminal option name */
11400 return;
11401 key = get_special_key_code(arg + 1);
11402 if (key == 0) /* unknown name */
11403 {
11404 xp->xp_context = EXPAND_NOTHING;
11405 return;
11406 }
11407 nextchar = *++p;
11408 is_term_option = TRUE;
11409 expand_option_name[2] = KEY2TERMCAP0(key);
11410 expand_option_name[3] = KEY2TERMCAP1(key);
11411 }
11412 else
11413 {
11414 if (p[0] == 't' && p[1] == '_')
11415 {
11416 p += 2;
11417 if (*p != NUL)
11418 ++p;
11419 if (*p == NUL)
11420 return; /* expand option name */
11421 nextchar = *++p;
11422 is_term_option = TRUE;
11423 expand_option_name[2] = p[-2];
11424 expand_option_name[3] = p[-1];
11425 }
11426 else
11427 {
11428 /* Allow * wildcard */
11429 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11430 p++;
11431 if (*p == NUL)
11432 return;
11433 nextchar = *p;
11434 *p = NUL;
11435 opt_idx = findoption(arg);
11436 *p = nextchar;
11437 if (opt_idx == -1 || options[opt_idx].var == NULL)
11438 {
11439 xp->xp_context = EXPAND_NOTHING;
11440 return;
11441 }
11442 flags = options[opt_idx].flags;
11443 if (flags & P_BOOL)
11444 {
11445 xp->xp_context = EXPAND_NOTHING;
11446 return;
11447 }
11448 }
11449 }
11450 /* handle "-=" and "+=" */
11451 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11452 {
11453 ++p;
11454 nextchar = '=';
11455 }
11456 if ((nextchar != '=' && nextchar != ':')
11457 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11458 {
11459 xp->xp_context = EXPAND_UNSUCCESSFUL;
11460 return;
11461 }
11462 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11463 {
11464 xp->xp_context = EXPAND_OLD_SETTING;
11465 if (is_term_option)
11466 expand_option_idx = -1;
11467 else
11468 expand_option_idx = opt_idx;
11469 xp->xp_pattern = p + 1;
11470 return;
11471 }
11472 xp->xp_context = EXPAND_NOTHING;
11473 if (is_term_option || (flags & P_NUM))
11474 return;
11475
11476 xp->xp_pattern = p + 1;
11477
11478 if (flags & P_EXPAND)
11479 {
11480 p = options[opt_idx].var;
11481 if (p == (char_u *)&p_bdir
11482 || p == (char_u *)&p_dir
11483 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011484 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011485 || p == (char_u *)&p_rtp
11486#ifdef FEAT_SEARCHPATH
11487 || p == (char_u *)&p_cdpath
11488#endif
11489#ifdef FEAT_SESSION
11490 || p == (char_u *)&p_vdir
11491#endif
11492 )
11493 {
11494 xp->xp_context = EXPAND_DIRECTORIES;
11495 if (p == (char_u *)&p_path
11496#ifdef FEAT_SEARCHPATH
11497 || p == (char_u *)&p_cdpath
11498#endif
11499 )
11500 xp->xp_backslash = XP_BS_THREE;
11501 else
11502 xp->xp_backslash = XP_BS_ONE;
11503 }
11504 else
11505 {
11506 xp->xp_context = EXPAND_FILES;
11507 /* for 'tags' need three backslashes for a space */
11508 if (p == (char_u *)&p_tags)
11509 xp->xp_backslash = XP_BS_THREE;
11510 else
11511 xp->xp_backslash = XP_BS_ONE;
11512 }
11513 }
11514
11515 /* For an option that is a list of file names, find the start of the
11516 * last file name. */
11517 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11518 {
11519 /* count number of backslashes before ' ' or ',' */
11520 if (*p == ' ' || *p == ',')
11521 {
11522 s = p;
11523 while (s > xp->xp_pattern && *(s - 1) == '\\')
11524 --s;
11525 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11526 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11527 {
11528 xp->xp_pattern = p + 1;
11529 break;
11530 }
11531 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011532
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011533#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011534 /* for 'spellsuggest' start at "file:" */
11535 if (options[opt_idx].var == (char_u *)&p_sps
11536 && STRNCMP(p, "file:", 5) == 0)
11537 {
11538 xp->xp_pattern = p + 5;
11539 break;
11540 }
11541#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011542 }
11543
11544 return;
11545}
11546
11547 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011548ExpandSettings(
11549 expand_T *xp,
11550 regmatch_T *regmatch,
11551 int *num_file,
11552 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553{
11554 int num_normal = 0; /* Nr of matching non-term-code settings */
11555 int num_term = 0; /* Nr of matching terminal code settings */
11556 int opt_idx;
11557 int match;
11558 int count = 0;
11559 char_u *str;
11560 int loop;
11561 int is_term_opt;
11562 char_u name_buf[MAX_KEY_NAME_LEN];
11563 static char *(names[]) = {"all", "termcap"};
11564 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11565
11566 /* do this loop twice:
11567 * loop == 0: count the number of matching options
11568 * loop == 1: copy the matching options into allocated memory
11569 */
11570 for (loop = 0; loop <= 1; ++loop)
11571 {
11572 regmatch->rm_ic = ic;
11573 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11574 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011575 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11576 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011577 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11578 {
11579 if (loop == 0)
11580 num_normal++;
11581 else
11582 (*file)[count++] = vim_strsave((char_u *)names[match]);
11583 }
11584 }
11585 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11586 opt_idx++)
11587 {
11588 if (options[opt_idx].var == NULL)
11589 continue;
11590 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11591 && !(options[opt_idx].flags & P_BOOL))
11592 continue;
11593 is_term_opt = istermoption(&options[opt_idx]);
11594 if (is_term_opt && num_normal > 0)
11595 continue;
11596 match = FALSE;
11597 if (vim_regexec(regmatch, str, (colnr_T)0)
11598 || (options[opt_idx].shortname != NULL
11599 && vim_regexec(regmatch,
11600 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11601 match = TRUE;
11602 else if (is_term_opt)
11603 {
11604 name_buf[0] = '<';
11605 name_buf[1] = 't';
11606 name_buf[2] = '_';
11607 name_buf[3] = str[2];
11608 name_buf[4] = str[3];
11609 name_buf[5] = '>';
11610 name_buf[6] = NUL;
11611 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11612 {
11613 match = TRUE;
11614 str = name_buf;
11615 }
11616 }
11617 if (match)
11618 {
11619 if (loop == 0)
11620 {
11621 if (is_term_opt)
11622 num_term++;
11623 else
11624 num_normal++;
11625 }
11626 else
11627 (*file)[count++] = vim_strsave(str);
11628 }
11629 }
11630 /*
11631 * Check terminal key codes, these are not in the option table
11632 */
11633 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11634 {
11635 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11636 {
11637 if (!isprint(str[0]) || !isprint(str[1]))
11638 continue;
11639
11640 name_buf[0] = 't';
11641 name_buf[1] = '_';
11642 name_buf[2] = str[0];
11643 name_buf[3] = str[1];
11644 name_buf[4] = NUL;
11645
11646 match = FALSE;
11647 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11648 match = TRUE;
11649 else
11650 {
11651 name_buf[0] = '<';
11652 name_buf[1] = 't';
11653 name_buf[2] = '_';
11654 name_buf[3] = str[0];
11655 name_buf[4] = str[1];
11656 name_buf[5] = '>';
11657 name_buf[6] = NUL;
11658
11659 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11660 match = TRUE;
11661 }
11662 if (match)
11663 {
11664 if (loop == 0)
11665 num_term++;
11666 else
11667 (*file)[count++] = vim_strsave(name_buf);
11668 }
11669 }
11670
11671 /*
11672 * Check special key names.
11673 */
11674 regmatch->rm_ic = TRUE; /* ignore case here */
11675 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11676 {
11677 name_buf[0] = '<';
11678 STRCPY(name_buf + 1, str);
11679 STRCAT(name_buf, ">");
11680
11681 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11682 {
11683 if (loop == 0)
11684 num_term++;
11685 else
11686 (*file)[count++] = vim_strsave(name_buf);
11687 }
11688 }
11689 }
11690 if (loop == 0)
11691 {
11692 if (num_normal > 0)
11693 *num_file = num_normal;
11694 else if (num_term > 0)
11695 *num_file = num_term;
11696 else
11697 return OK;
11698 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11699 if (*file == NULL)
11700 {
11701 *file = (char_u **)"";
11702 return FAIL;
11703 }
11704 }
11705 }
11706 return OK;
11707}
11708
11709 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011710ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011711{
11712 char_u *var = NULL; /* init for GCC */
11713 char_u *buf;
11714
11715 *num_file = 0;
11716 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11717 if (*file == NULL)
11718 return FAIL;
11719
11720 /*
11721 * For a terminal key code expand_option_idx is < 0.
11722 */
11723 if (expand_option_idx < 0)
11724 {
11725 var = find_termcode(expand_option_name + 2);
11726 if (var == NULL)
11727 expand_option_idx = findoption(expand_option_name);
11728 }
11729
11730 if (expand_option_idx >= 0)
11731 {
11732 /* put string of option value in NameBuff */
11733 option_value2string(&options[expand_option_idx], expand_option_flags);
11734 var = NameBuff;
11735 }
11736 else if (var == NULL)
11737 var = (char_u *)"";
11738
11739 /* A backslash is required before some characters. This is the reverse of
11740 * what happens in do_set(). */
11741 buf = vim_strsave_escaped(var, escape_chars);
11742
11743 if (buf == NULL)
11744 {
11745 vim_free(*file);
11746 *file = NULL;
11747 return FAIL;
11748 }
11749
11750#ifdef BACKSLASH_IN_FILENAME
11751 /* For MS-Windows et al. we don't double backslashes at the start and
11752 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011753 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011754 if (var[0] == '\\' && var[1] == '\\'
11755 && expand_option_idx >= 0
11756 && (options[expand_option_idx].flags & P_EXPAND)
11757 && vim_isfilec(var[2])
11758 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011759 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011760#endif
11761
11762 *file[0] = buf;
11763 *num_file = 1;
11764 return OK;
11765}
11766#endif
11767
11768/*
11769 * Get the value for the numeric or string option *opp in a nice format into
11770 * NameBuff[]. Must not be called with a hidden option!
11771 */
11772 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011773option_value2string(
11774 struct vimoption *opp,
11775 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776{
11777 char_u *varp;
11778
11779 varp = get_varp_scope(opp, opt_flags);
11780
11781 if (opp->flags & P_NUM)
11782 {
11783 long wc = 0;
11784
11785 if (wc_use_keyname(varp, &wc))
11786 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11787 else if (wc != 0)
11788 STRCPY(NameBuff, transchar((int)wc));
11789 else
11790 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11791 }
11792 else /* P_STRING */
11793 {
11794 varp = *(char_u **)(varp);
11795 if (varp == NULL) /* just in case */
11796 NameBuff[0] = NUL;
11797#ifdef FEAT_CRYPT
11798 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011799 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011800 STRCPY(NameBuff, "*****");
11801#endif
11802 else if (opp->flags & P_EXPAND)
11803 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11804 /* Translate 'pastetoggle' into special key names */
11805 else if ((char_u **)opp->var == &p_pt)
11806 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11807 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011808 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011809 }
11810}
11811
11812/*
11813 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11814 * printed as a keyname.
11815 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11816 */
11817 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011818wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819{
11820 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11821 {
11822 *wcp = *(long *)varp;
11823 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11824 return TRUE;
11825 }
11826 return FALSE;
11827}
11828
Bram Moolenaar01615492015-02-03 13:00:38 +010011829#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011830/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011831 * Any character has an equivalent 'langmap' character. This is used for
11832 * keyboards that have a special language mode that sends characters above
11833 * 128 (although other characters can be translated too). The "to" field is a
11834 * Vim command character. This avoids having to switch the keyboard back to
11835 * ASCII mode when leaving Insert mode.
11836 *
11837 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11838 * commands.
11839 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11840 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11841 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011842 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011843# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011844/*
11845 * With multi-byte support use growarray for 'langmap' chars >= 256
11846 */
11847typedef struct
11848{
11849 int from;
11850 int to;
11851} langmap_entry_T;
11852
11853static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011854static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855
11856/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011857 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11858 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011860 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011861langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011862{
11863 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011864 int a = 0;
11865 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011866
11867 /* Do a binary search for an existing entry. */
11868 while (a != b)
11869 {
11870 int i = (a + b) / 2;
11871 int d = entries[i].from - from;
11872
11873 if (d == 0)
11874 {
11875 entries[i].to = to;
11876 return;
11877 }
11878 if (d < 0)
11879 a = i + 1;
11880 else
11881 b = i;
11882 }
11883
11884 if (ga_grow(&langmap_mapga, 1) != OK)
11885 return; /* out of memory */
11886
11887 /* insert new entry at position "a" */
11888 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11889 mch_memmove(entries + 1, entries,
11890 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11891 ++langmap_mapga.ga_len;
11892 entries[0].from = from;
11893 entries[0].to = to;
11894}
11895
11896/*
11897 * Apply 'langmap' to multi-byte character "c" and return the result.
11898 */
11899 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011900langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011901{
11902 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11903 int a = 0;
11904 int b = langmap_mapga.ga_len;
11905
11906 while (a != b)
11907 {
11908 int i = (a + b) / 2;
11909 int d = entries[i].from - c;
11910
11911 if (d == 0)
11912 return entries[i].to; /* found matching entry */
11913 if (d < 0)
11914 a = i + 1;
11915 else
11916 b = i;
11917 }
11918 return c; /* no entry found, return "c" unmodified */
11919}
11920# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921
11922 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011923langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011924{
11925 int i;
11926
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011927 for (i = 0; i < 256; i++)
11928 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11929# ifdef FEAT_MBYTE
11930 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11931# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932}
11933
11934/*
11935 * Called when langmap option is set; the language map can be
11936 * changed at any time!
11937 */
11938 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011939langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011940{
11941 char_u *p;
11942 char_u *p2;
11943 int from, to;
11944
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011945#ifdef FEAT_MBYTE
11946 ga_clear(&langmap_mapga); /* clear the previous map first */
11947#endif
11948 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011949
11950 for (p = p_langmap; p[0] != NUL; )
11951 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011952 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011953 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011954 {
11955 if (p2[0] == '\\' && p2[1] != NUL)
11956 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011957 }
11958 if (p2[0] == ';')
11959 ++p2; /* abcd;ABCD form, p2 points to A */
11960 else
11961 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11962 while (p[0])
11963 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011964 if (p[0] == ',')
11965 {
11966 ++p;
11967 break;
11968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011969 if (p[0] == '\\' && p[1] != NUL)
11970 ++p;
11971#ifdef FEAT_MBYTE
11972 from = (*mb_ptr2char)(p);
11973#else
11974 from = p[0];
11975#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011976 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977 if (p2 == NULL)
11978 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011979 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011980 if (p[0] != ',')
11981 {
11982 if (p[0] == '\\')
11983 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011984#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011985 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011986#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011987 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011988#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011990 }
11991 else
11992 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011993 if (p2[0] != ',')
11994 {
11995 if (p2[0] == '\\')
11996 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011997#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011998 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012000 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012003 }
12004 if (to == NUL)
12005 {
12006 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12007 transchar(from));
12008 return;
12009 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012010
12011#ifdef FEAT_MBYTE
12012 if (from >= 256)
12013 langmap_set_entry(from, to);
12014 else
12015#endif
12016 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012017
12018 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012019 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012020 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012022 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023 if (*p == ';')
12024 {
12025 p = p2;
12026 if (p[0] != NUL)
12027 {
12028 if (p[0] != ',')
12029 {
12030 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12031 return;
12032 }
12033 ++p;
12034 }
12035 break;
12036 }
12037 }
12038 }
12039 }
12040}
12041#endif
12042
12043/*
12044 * Return TRUE if format option 'x' is in effect.
12045 * Take care of no formatting when 'paste' is set.
12046 */
12047 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012048has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012049{
12050 if (p_paste)
12051 return FALSE;
12052 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12053}
12054
12055/*
12056 * Return TRUE if "x" is present in 'shortmess' option, or
12057 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12058 */
12059 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012060shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012062 return p_shm != NULL &&
12063 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012064 || (vim_strchr(p_shm, 'a') != NULL
12065 && vim_strchr((char_u *)SHM_A, x) != NULL));
12066}
12067
12068/*
12069 * paste_option_changed() - Called after p_paste was set or reset.
12070 */
12071 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012072paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012073{
12074 static int old_p_paste = FALSE;
12075 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012076 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077#ifdef FEAT_CMDL_INFO
12078 static int save_ru = 0;
12079#endif
12080#ifdef FEAT_RIGHTLEFT
12081 static int save_ri = 0;
12082 static int save_hkmap = 0;
12083#endif
12084 buf_T *buf;
12085
12086 if (p_paste)
12087 {
12088 /*
12089 * Paste switched from off to on.
12090 * Save the current values, so they can be restored later.
12091 */
12092 if (!old_p_paste)
12093 {
12094 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012095 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012096 {
12097 buf->b_p_tw_nopaste = buf->b_p_tw;
12098 buf->b_p_wm_nopaste = buf->b_p_wm;
12099 buf->b_p_sts_nopaste = buf->b_p_sts;
12100 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012101 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012102 }
12103
12104 /* save global options */
12105 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012106 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107#ifdef FEAT_CMDL_INFO
12108 save_ru = p_ru;
12109#endif
12110#ifdef FEAT_RIGHTLEFT
12111 save_ri = p_ri;
12112 save_hkmap = p_hkmap;
12113#endif
12114 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012115 p_ai_nopaste = p_ai;
12116 p_et_nopaste = p_et;
12117 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012118 p_tw_nopaste = p_tw;
12119 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 }
12121
12122 /*
12123 * Always set the option values, also when 'paste' is set when it is
12124 * already on.
12125 */
12126 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012127 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128 {
12129 buf->b_p_tw = 0; /* textwidth is 0 */
12130 buf->b_p_wm = 0; /* wrapmargin is 0 */
12131 buf->b_p_sts = 0; /* softtabstop is 0 */
12132 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012133 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012134 }
12135
12136 /* set global options */
12137 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012138 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139#ifdef FEAT_CMDL_INFO
12140# ifdef FEAT_WINDOWS
12141 if (p_ru)
12142 status_redraw_all(); /* redraw to remove the ruler */
12143# endif
12144 p_ru = 0; /* no ruler */
12145#endif
12146#ifdef FEAT_RIGHTLEFT
12147 p_ri = 0; /* no reverse insert */
12148 p_hkmap = 0; /* no Hebrew keyboard */
12149#endif
12150 /* set global values for local buffer options */
12151 p_tw = 0;
12152 p_wm = 0;
12153 p_sts = 0;
12154 p_ai = 0;
12155 }
12156
12157 /*
12158 * Paste switched from on to off: Restore saved values.
12159 */
12160 else if (old_p_paste)
12161 {
12162 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012163 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164 {
12165 buf->b_p_tw = buf->b_p_tw_nopaste;
12166 buf->b_p_wm = buf->b_p_wm_nopaste;
12167 buf->b_p_sts = buf->b_p_sts_nopaste;
12168 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012169 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170 }
12171
12172 /* restore global options */
12173 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012174 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175#ifdef FEAT_CMDL_INFO
12176# ifdef FEAT_WINDOWS
12177 if (p_ru != save_ru)
12178 status_redraw_all(); /* redraw to draw the ruler */
12179# endif
12180 p_ru = save_ru;
12181#endif
12182#ifdef FEAT_RIGHTLEFT
12183 p_ri = save_ri;
12184 p_hkmap = save_hkmap;
12185#endif
12186 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012187 p_ai = p_ai_nopaste;
12188 p_et = p_et_nopaste;
12189 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012190 p_tw = p_tw_nopaste;
12191 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012192 }
12193
12194 old_p_paste = p_paste;
12195}
12196
12197/*
12198 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12199 *
12200 * Reset 'compatible' and set the values for options that didn't get set yet
12201 * to the Vim defaults.
12202 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012203 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012204 */
12205 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012206vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012207{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012208 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012209 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012210 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211
12212 if (!option_was_set((char_u *)"cp"))
12213 {
12214 p_cp = FALSE;
12215 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12216 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12217 set_option_default(opt_idx, OPT_FREE, FALSE);
12218 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012219 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012220 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012221
12222 if (fname != NULL)
12223 {
12224 p = vim_getenv(envname, &dofree);
12225 if (p == NULL)
12226 {
12227 /* Set $MYVIMRC to the first vimrc file found. */
12228 p = FullName_save(fname, FALSE);
12229 if (p != NULL)
12230 {
12231 vim_setenv(envname, p);
12232 vim_free(p);
12233 }
12234 }
12235 else if (dofree)
12236 vim_free(p);
12237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012238}
12239
12240/*
12241 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12242 */
12243 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012244change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012245{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012246 int opt_idx;
12247
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248 if (p_cp != on)
12249 {
12250 p_cp = on;
12251 compatible_set();
12252 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012253 opt_idx = findoption((char_u *)"cp");
12254 if (opt_idx >= 0)
12255 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012256}
12257
12258/*
12259 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012260 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261 */
12262 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012263option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012264{
12265 int idx;
12266
12267 idx = findoption(name);
12268 if (idx < 0) /* unknown option */
12269 return FALSE;
12270 if (options[idx].flags & P_WAS_SET)
12271 return TRUE;
12272 return FALSE;
12273}
12274
12275/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012276 * Reset the flag indicating option "name" was set.
12277 */
12278 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012279reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012280{
12281 int idx = findoption(name);
12282
12283 if (idx >= 0)
12284 options[idx].flags &= ~P_WAS_SET;
12285}
12286
12287/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288 * compatible_set() - Called when 'compatible' has been set or unset.
12289 *
12290 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12291 * flag) to a Vi compatible value.
12292 * When 'compatible' is unset: Set all options that have a different default
12293 * for Vim (without the P_VI_DEF flag) to that default.
12294 */
12295 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012296compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012297{
12298 int opt_idx;
12299
12300 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12301 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12302 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12303 set_option_default(opt_idx, OPT_FREE, p_cp);
12304 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012305 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306}
12307
12308#ifdef FEAT_LINEBREAK
12309
12310# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12311 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012312 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012313# endif
12314
12315/*
12316 * fill_breakat_flags() -- called when 'breakat' changes value.
12317 */
12318 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012319fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012320{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012321 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012322 int i;
12323
12324 for (i = 0; i < 256; i++)
12325 breakat_flags[i] = FALSE;
12326
12327 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012328 for (p = p_breakat; *p; p++)
12329 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012330}
12331
12332# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012333 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012334# endif
12335
12336#endif
12337
12338/*
12339 * Check an option that can be a range of string values.
12340 *
12341 * Return OK for correct value, FAIL otherwise.
12342 * Empty is always OK.
12343 */
12344 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012345check_opt_strings(
12346 char_u *val,
12347 char **values,
12348 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012349{
12350 return opt_strings_flags(val, values, NULL, list);
12351}
12352
12353/*
12354 * Handle an option that can be a range of string values.
12355 * Set a flag in "*flagp" for each string present.
12356 *
12357 * Return OK for correct value, FAIL otherwise.
12358 * Empty is always OK.
12359 */
12360 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012361opt_strings_flags(
12362 char_u *val, /* new value */
12363 char **values, /* array of valid string values */
12364 unsigned *flagp,
12365 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012366{
12367 int i;
12368 int len;
12369 unsigned new_flags = 0;
12370
12371 while (*val)
12372 {
12373 for (i = 0; ; ++i)
12374 {
12375 if (values[i] == NULL) /* val not found in values[] */
12376 return FAIL;
12377
12378 len = (int)STRLEN(values[i]);
12379 if (STRNCMP(values[i], val, len) == 0
12380 && ((list && val[len] == ',') || val[len] == NUL))
12381 {
12382 val += len + (val[len] == ',');
12383 new_flags |= (1 << i);
12384 break; /* check next item in val list */
12385 }
12386 }
12387 }
12388 if (flagp != NULL)
12389 *flagp = new_flags;
12390
12391 return OK;
12392}
12393
12394/*
12395 * Read the 'wildmode' option, fill wim_flags[].
12396 */
12397 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012398check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012399{
12400 char_u new_wim_flags[4];
12401 char_u *p;
12402 int i;
12403 int idx = 0;
12404
12405 for (i = 0; i < 4; ++i)
12406 new_wim_flags[i] = 0;
12407
12408 for (p = p_wim; *p; ++p)
12409 {
12410 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12411 ;
12412 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12413 return FAIL;
12414 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12415 new_wim_flags[idx] |= WIM_LONGEST;
12416 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12417 new_wim_flags[idx] |= WIM_FULL;
12418 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12419 new_wim_flags[idx] |= WIM_LIST;
12420 else
12421 return FAIL;
12422 p += i;
12423 if (*p == NUL)
12424 break;
12425 if (*p == ',')
12426 {
12427 if (idx == 3)
12428 return FAIL;
12429 ++idx;
12430 }
12431 }
12432
12433 /* fill remaining entries with last flag */
12434 while (idx < 3)
12435 {
12436 new_wim_flags[idx + 1] = new_wim_flags[idx];
12437 ++idx;
12438 }
12439
12440 /* only when there are no errors, wim_flags[] is changed */
12441 for (i = 0; i < 4; ++i)
12442 wim_flags[i] = new_wim_flags[i];
12443 return OK;
12444}
12445
12446/*
12447 * Check if backspacing over something is allowed.
12448 */
12449 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012450can_bs(
12451 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012452{
12453 switch (*p_bs)
12454 {
12455 case '2': return TRUE;
12456 case '1': return (what != BS_START);
12457 case '0': return FALSE;
12458 }
12459 return vim_strchr(p_bs, what) != NULL;
12460}
12461
12462/*
12463 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12464 * the file must be considered changed when the value is different.
12465 */
12466 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012467save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012468{
12469 buf->b_start_ffc = *buf->b_p_ff;
12470 buf->b_start_eol = buf->b_p_eol;
12471#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012472 buf->b_start_bomb = buf->b_p_bomb;
12473
Bram Moolenaar071d4272004-06-13 20:20:40 +000012474 /* Only use free/alloc when necessary, they take time. */
12475 if (buf->b_start_fenc == NULL
12476 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12477 {
12478 vim_free(buf->b_start_fenc);
12479 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12480 }
12481#endif
12482}
12483
12484/*
12485 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12486 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012487 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12488 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012489 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012490 * When "ignore_empty" is true don't consider a new, empty buffer to be
12491 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012492 */
12493 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012494file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012495{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012496 /* In a buffer that was never loaded the options are not valid. */
12497 if (buf->b_flags & BF_NEVERLOADED)
12498 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012499 if (ignore_empty
12500 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012501 && buf->b_ml.ml_line_count == 1
12502 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12503 return FALSE;
12504 if (buf->b_start_ffc != *buf->b_p_ff)
12505 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012506 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507 return TRUE;
12508#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012509 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12510 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012511 if (buf->b_start_fenc == NULL)
12512 return (*buf->b_p_fenc != NUL);
12513 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12514#else
12515 return FALSE;
12516#endif
12517}
12518
12519/*
12520 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12521 */
12522 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012523check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012524{
12525 return check_opt_strings(p, p_ff_values, FALSE);
12526}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012527
12528/*
12529 * Return the effective shiftwidth value for current buffer, using the
12530 * 'tabstop' value when 'shiftwidth' is zero.
12531 */
12532 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012533get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012534{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012535 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012536}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012537
12538/*
12539 * Return the effective softtabstop value for the current buffer, using the
12540 * 'tabstop' value when 'softtabstop' is negative.
12541 */
12542 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012543get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012544{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012545 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012546}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012547
12548/*
12549 * Check matchpairs option for "*initc".
12550 * If there is a match set "*initc" to the matching character and "*findc" to
12551 * the opposite character. Set "*backwards" to the direction.
12552 * When "switchit" is TRUE swap the direction.
12553 */
12554 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012555find_mps_values(
12556 int *initc,
12557 int *findc,
12558 int *backwards,
12559 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012560{
12561 char_u *ptr;
12562
12563 ptr = curbuf->b_p_mps;
12564 while (*ptr != NUL)
12565 {
12566#ifdef FEAT_MBYTE
12567 if (has_mbyte)
12568 {
12569 char_u *prev;
12570
12571 if (mb_ptr2char(ptr) == *initc)
12572 {
12573 if (switchit)
12574 {
12575 *findc = *initc;
12576 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12577 *backwards = TRUE;
12578 }
12579 else
12580 {
12581 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12582 *backwards = FALSE;
12583 }
12584 return;
12585 }
12586 prev = ptr;
12587 ptr += mb_ptr2len(ptr) + 1;
12588 if (mb_ptr2char(ptr) == *initc)
12589 {
12590 if (switchit)
12591 {
12592 *findc = *initc;
12593 *initc = mb_ptr2char(prev);
12594 *backwards = FALSE;
12595 }
12596 else
12597 {
12598 *findc = mb_ptr2char(prev);
12599 *backwards = TRUE;
12600 }
12601 return;
12602 }
12603 ptr += mb_ptr2len(ptr);
12604 }
12605 else
12606#endif
12607 {
12608 if (*ptr == *initc)
12609 {
12610 if (switchit)
12611 {
12612 *backwards = TRUE;
12613 *findc = *initc;
12614 *initc = ptr[2];
12615 }
12616 else
12617 {
12618 *backwards = FALSE;
12619 *findc = ptr[2];
12620 }
12621 return;
12622 }
12623 ptr += 2;
12624 if (*ptr == *initc)
12625 {
12626 if (switchit)
12627 {
12628 *backwards = FALSE;
12629 *findc = *initc;
12630 *initc = ptr[-2];
12631 }
12632 else
12633 {
12634 *backwards = TRUE;
12635 *findc = ptr[-2];
12636 }
12637 return;
12638 }
12639 ++ptr;
12640 }
12641 if (*ptr == ',')
12642 ++ptr;
12643 }
12644}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012645
12646#if defined(FEAT_LINEBREAK) || defined(PROTO)
12647/*
12648 * This is called when 'breakindentopt' is changed and when a window is
12649 * initialized.
12650 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012651 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012652briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012653{
12654 char_u *p;
12655 int bri_shift = 0;
12656 long bri_min = 20;
12657 int bri_sbr = FALSE;
12658
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012659 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012660 while (*p != NUL)
12661 {
12662 if (STRNCMP(p, "shift:", 6) == 0
12663 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12664 {
12665 p += 6;
12666 bri_shift = getdigits(&p);
12667 }
12668 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12669 {
12670 p += 4;
12671 bri_min = getdigits(&p);
12672 }
12673 else if (STRNCMP(p, "sbr", 3) == 0)
12674 {
12675 p += 3;
12676 bri_sbr = TRUE;
12677 }
12678 if (*p != ',' && *p != NUL)
12679 return FAIL;
12680 if (*p == ',')
12681 ++p;
12682 }
12683
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012684 wp->w_p_brishift = bri_shift;
12685 wp->w_p_brimin = bri_min;
12686 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012687
12688 return OK;
12689}
12690#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012691
12692/*
12693 * Get the local or global value of 'backupcopy'.
12694 */
12695 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012696get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012697{
12698 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12699}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012700
12701#if defined(FEAT_SIGNS) || defined(PROTO)
12702/*
12703 * Return TRUE when window "wp" has a column to draw signs in.
12704 */
12705 int
12706signcolumn_on(win_T *wp)
12707{
12708 if (*wp->w_p_scl == 'n')
12709 return FALSE;
12710 if (*wp->w_p_scl == 'y')
12711 return TRUE;
12712 return (wp->w_buffer->b_signlist != NULL
12713# ifdef FEAT_NETBEANS_INTG
12714 || wp->w_buffer->b_has_sign_column
12715# endif
12716 );
12717}
12718#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012719
12720#if defined(FEAT_EVAL) || defined(PROTO)
12721/*
12722 * Get window or buffer local options.
12723 */
12724 dict_T *
12725get_winbuf_options(int bufopt)
12726{
12727 dict_T *d;
12728 int opt_idx;
12729
12730 d = dict_alloc();
12731 if (d == NULL)
12732 return NULL;
12733
12734 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12735 {
12736 struct vimoption *opt = &options[opt_idx];
12737
12738 if ((bufopt && (opt->indir & PV_BUF))
12739 || (!bufopt && (opt->indir & PV_WIN)))
12740 {
12741 char_u *varp = get_varp(opt);
12742
12743 if (varp != NULL)
12744 {
12745 if (opt->flags & P_STRING)
12746 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012747 else if (opt->flags & P_NUM)
12748 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012749 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012750 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012751 }
12752 }
12753 }
12754
12755 return d;
12756}
12757#endif