blob: 828d9eb46464903eb26031a47d1f3523ba2ec07b [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
225#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#ifdef FEAT_WINDOWS
249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200261# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200262# define PV_TMS OPT_WIN(WV_TMS)
263#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200264#ifdef FEAT_SIGNS
265# define PV_SCL OPT_WIN(WV_SCL)
266#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000267
268/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269typedef enum
270{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000271 PV_NONE = 0,
272 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273} idopt_T;
274
275/*
276 * Options local to a window have a value local to a buffer and global to all
277 * buffers. Indicate this by setting "var" to VAR_WIN.
278 */
279#define VAR_WIN ((char_u *)-1)
280
281/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000282 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283 * Only to be used in option.c!
284 */
285static int p_ai;
286static int p_bin;
287#ifdef FEAT_MBYTE
288static int p_bomb;
289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static char_u *p_bh;
291static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292static int p_bl;
293static int p_ci;
294#ifdef FEAT_CINDENT
295static int p_cin;
296static char_u *p_cink;
297static char_u *p_cino;
298#endif
299#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
300static char_u *p_cinw;
301#endif
302#ifdef FEAT_COMMENTS
303static char_u *p_com;
304#endif
305#ifdef FEAT_FOLDING
306static char_u *p_cms;
307#endif
308#ifdef FEAT_INS_EXPAND
309static char_u *p_cpt;
310#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000311#ifdef FEAT_COMPL_FUNC
312static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000313static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200316static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static int p_et;
318#ifdef FEAT_MBYTE
319static char_u *p_fenc;
320#endif
321static char_u *p_ff;
322static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000323static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324#ifdef FEAT_AUTOCMD
325static char_u *p_ft;
326#endif
327static long p_iminsert;
328static long p_imsearch;
329#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
330static char_u *p_inex;
331#endif
332#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
333static char_u *p_inde;
334static char_u *p_indk;
335#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000336#if defined(FEAT_EVAL)
337static char_u *p_fex;
338#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static int p_inf;
340static char_u *p_isk;
341#ifdef FEAT_CRYPT
342static char_u *p_key;
343#endif
344#ifdef FEAT_LISP
345static int p_lisp;
346#endif
347static int p_ml;
348static int p_ma;
349static int p_mod;
350static char_u *p_mps;
351static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000353#ifdef FEAT_TEXTOBJ
354static char_u *p_qe;
355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static int p_ro;
357#ifdef FEAT_SMARTINDENT
358static int p_si;
359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361static long p_sts;
362#if defined(FEAT_SEARCHPATH)
363static char_u *p_sua;
364#endif
365static long p_sw;
366static int p_swf;
367#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000368static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000370#endif
371#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000372static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000373static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000374static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375#endif
376static long p_ts;
377static long p_tw;
378static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200379#ifdef FEAT_PERSISTENT_UNDO
380static int p_udf;
381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382static long p_wm;
383#ifdef FEAT_KEYMAP
384static char_u *p_keymap;
385#endif
386
387/* Saved values for when 'bin' is set. */
388static int p_et_nobin;
389static int p_ml_nobin;
390static long p_tw_nobin;
391static long p_wm_nobin;
392
393/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200394static int p_ai_nopaste;
395static int p_et_nopaste;
396static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397static long p_tw_nopaste;
398static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399
400struct vimoption
401{
402 char *fullname; /* full option name */
403 char *shortname; /* permissible abbreviation */
404 long_u flags; /* see below */
405 char_u *var; /* global option: pointer to variable;
406 * window-local option: VAR_WIN;
407 * buffer-local option: global value */
408 idopt_T indir; /* global option: PV_NONE;
409 * local option: indirect option index */
410 char_u *def_val[2]; /* default values for variable (vi and vim) */
411#ifdef FEAT_EVAL
412 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000413# define SCRIPTID_INIT , 0
414#else
415# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416#endif
417};
418
419#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
420#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
421
422/*
423 * Flags
424 */
425#define P_BOOL 0x01 /* the option is boolean */
426#define P_NUM 0x02 /* the option is numeric */
427#define P_STRING 0x04 /* the option is a string */
428#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000429 must use free_string_option() when
430 assigning new value. Not set if default is
431 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
433 never be used for local or hidden options! */
434#define P_NODEFAULT 0x40 /* don't set to default value */
435#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
436 use vim_free() when assigning new value */
437#define P_WAS_SET 0x100 /* option has been set/reset */
438#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
439#define P_VI_DEF 0x400 /* Use Vi default for Vim */
440#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
441
442 /* when option changed, what to display: */
443#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100444#define P_RWIN 0x2000 /* redraw current window and recompute text */
445#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446#define P_RALL 0x6000 /* redraw all windows */
447#define P_RCLR 0x7000 /* clear and redraw all */
448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_COMMA 0x8000 /* comma separated list */
450#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
451 * commas */
452#define P_NODUP 0x20000L /* don't allow duplicate strings */
453#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200455#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
456#define P_GETTEXT 0x100000L /* expand default value with _() */
457#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
458#define P_NFNAME 0x400000L /* only normal file name chars allowed */
459#define P_INSECURE 0x800000L /* option was set from a modeline */
460#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100461 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200462#define P_NO_ML 0x2000000L /* not allowed in modeline */
463#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200464 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100465#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100466#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000467
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000468#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
469
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000470/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
471 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100472#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000473# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000474#else
475# define ISP_LATIN1 (char_u *)"@,161-255"
476#endif
477
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100478/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000479#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100480 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar21020352017-06-13 17:21:04 +0200481 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) \
Bram Moolenaar3633cf52017-07-31 22:29:35 +0200482 || defined(FEAT_CONCEAL) || defined(FEAT_QUICKFIX) \
483 || defined(FEAT_TERMINAL)
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200484# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000485#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100486# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000487#endif
488
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100489/* Default python version for pyx* commands */
490#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
491# define DEFAULT_PYTHON_VER 0
492#elif defined(FEAT_PYTHON3)
493# define DEFAULT_PYTHON_VER 3
494#elif defined(FEAT_PYTHON)
495# define DEFAULT_PYTHON_VER 2
496#else
497# define DEFAULT_PYTHON_VER 0
498#endif
499
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500/*
501 * options[] is initialized here.
502 * The order of the options MUST be alphabetic for ":set all" and findoption().
503 * All option names MUST start with a lowercase letter (for findoption()).
504 * Exception: "t_" options are at the end.
505 * The options with a NULL variable are 'hidden': a set command for them is
506 * ignored and they are not printed.
507 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100508static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200510 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511#ifdef FEAT_RIGHTLEFT
512 (char_u *)&p_aleph, PV_NONE,
513#else
514 (char_u *)NULL, PV_NONE,
515#endif
516 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100517#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 (char_u *)128L,
519#else
520 (char_u *)224L,
521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000522 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
524#if defined(FEAT_GUI) && defined(MACOS_X)
525 (char_u *)&p_antialias, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#else
528 (char_u *)NULL, PV_NONE,
529 {(char_u *)FALSE, (char_u *)FALSE}
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200532 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533#ifdef FEAT_ARABIC
534 (char_u *)VAR_WIN, PV_ARAB,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
540#ifdef FEAT_ARABIC
541 (char_u *)&p_arshape, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
547#ifdef FEAT_RIGHTLEFT
548 (char_u *)&p_ari, PV_NONE,
549#else
550 (char_u *)NULL, PV_NONE,
551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
554#ifdef FEAT_FKMAP
555 (char_u *)&p_altkeymap, PV_NONE,
556#else
557 (char_u *)NULL, PV_NONE,
558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
561#if defined(FEAT_MBYTE)
562 (char_u *)&p_ambw, PV_NONE,
563 {(char_u *)"single", (char_u *)0L}
564#else
565 (char_u *)NULL, PV_NONE,
566 {(char_u *)0L, (char_u *)0L}
567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100570#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100572 {(char_u *)FALSE, (char_u *)0L}
573#else
574 (char_u *)NULL, PV_NONE,
575 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100577 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autoindent", "ai", P_BOOL|P_VI_DEF,
579 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"autoprint", "ap", P_BOOL|P_VI_DEF,
582 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000585 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 {"autowrite", "aw", P_BOOL|P_VI_DEF,
588 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 {"autowriteall","awa", P_BOOL|P_VI_DEF,
591 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
594 (char_u *)&p_bg, PV_NONE,
595 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100596#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)"dark",
598#else
599 (char_u *)"light",
600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000601 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200602 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
606 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000607 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200608 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200609 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#ifdef UNIX
611 {(char_u *)"yes", (char_u *)"auto"}
612#else
613 {(char_u *)"auto", (char_u *)"auto"}
614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200616 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
617 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000620 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 (char_u *)&p_bex, PV_NONE,
622 {
623#ifdef VMS
624 (char_u *)"_",
625#else
626 (char_u *)"~",
627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200629 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630#ifdef FEAT_WILDIGN
631 (char_u *)&p_bsk, PV_NONE,
632 {(char_u *)"", (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100639#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100641 {(char_u *)600L, (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100646 SCRIPTID_INIT},
647 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
648#ifdef FEAT_BEVAL
649 (char_u *)&p_beval, PV_NONE,
650 {(char_u *)FALSE, (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
655 SCRIPTID_INIT},
656 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
657#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
658 (char_u *)&p_bexpr, PV_BEXPR,
659 {(char_u *)"", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"beautify", "bf", P_BOOL|P_VI_DEF,
666 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200668 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
669 (char_u *)&p_bo, PV_NONE,
670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
672 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000673 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000676 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
678#ifdef FEAT_MBYTE
679 (char_u *)&p_bomb, PV_BOMB,
680#else
681 (char_u *)NULL, PV_NONE,
682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000683 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
685#ifdef FEAT_LINEBREAK
686 (char_u *)&p_breakat, PV_NONE,
687 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
688#else
689 (char_u *)NULL, PV_NONE,
690 {(char_u *)0L, (char_u *)0L}
691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000692 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
694#ifdef FEAT_LINEBREAK
695 (char_u *)VAR_WIN, PV_BRI,
696 {(char_u *)FALSE, (char_u *)0L}
697#else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)0L, (char_u *)0L}
700#endif
701 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200702 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
703 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200704#ifdef FEAT_LINEBREAK
705 (char_u *)VAR_WIN, PV_BRIOPT,
706 {(char_u *)"", (char_u *)NULL}
707#else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)"", (char_u *)NULL}
710#endif
711 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
713#ifdef FEAT_BROWSE
714 (char_u *)&p_bsdir, PV_NONE,
715 {(char_u *)"last", (char_u *)0L}
716#else
717 (char_u *)NULL, PV_NONE,
718 {(char_u *)0L, (char_u *)0L}
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 (char_u *)&p_bh, PV_BH,
723 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
726 (char_u *)&p_bl, PV_BL,
727 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 (char_u *)&p_bt, PV_BT,
731 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000732 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200733 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000734#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735 (char_u *)&p_cmp, PV_NONE,
736 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000741 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
743#ifdef FEAT_SEARCHPATH
744 (char_u *)&p_cdpath, PV_NONE,
745 {(char_u *)",,", (char_u *)0L}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"cedit", NULL, P_STRING,
752#ifdef FEAT_CMDWIN
753 (char_u *)&p_cedit, PV_NONE,
754 {(char_u *)"", (char_u *)CTRL_F_STR}
755#else
756 (char_u *)NULL, PV_NONE,
757 {(char_u *)0L, (char_u *)0L}
758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000759 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
761#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
762 (char_u *)&p_ccv, PV_NONE,
763 {(char_u *)"", (char_u *)0L}
764#else
765 (char_u *)NULL, PV_NONE,
766 {(char_u *)0L, (char_u *)0L}
767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000768 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
770#ifdef FEAT_CINDENT
771 (char_u *)&p_cin, PV_CIN,
772#else
773 (char_u *)NULL, PV_NONE,
774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200776 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777#ifdef FEAT_CINDENT
778 (char_u *)&p_cink, PV_CINK,
779 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
780#else
781 (char_u *)NULL, PV_NONE,
782 {(char_u *)0L, (char_u *)0L}
783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200785 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_CINDENT
787 (char_u *)&p_cino, PV_CINO,
788#else
789 (char_u *)NULL, PV_NONE,
790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000791 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
794 (char_u *)&p_cinw, PV_CINW,
795 {(char_u *)"if,else,while,do,for,switch",
796 (char_u *)0L}
797#else
798 (char_u *)NULL, PV_NONE,
799 {(char_u *)0L, (char_u *)0L}
800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200802 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803#ifdef FEAT_CLIPBOARD
804 (char_u *)&p_cb, PV_NONE,
805# ifdef FEAT_XCLIPBOARD
806 {(char_u *)"autoselect,exclude:cons\\|linux",
807 (char_u *)0L}
808# else
809 {(char_u *)"", (char_u *)0L}
810# endif
811#else
812 (char_u *)NULL, PV_NONE,
813 {(char_u *)"", (char_u *)0L}
814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000815 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
817 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
820#ifdef FEAT_CMDWIN
821 (char_u *)&p_cwh, PV_NONE,
822#else
823 (char_u *)NULL, PV_NONE,
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200826 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200827#ifdef FEAT_SYN_HL
828 (char_u *)VAR_WIN, PV_CC,
829#else
830 (char_u *)NULL, PV_NONE,
831#endif
832 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
834 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200836 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
837 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_COMMENTS
839 (char_u *)&p_com, PV_COM,
840 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
841 (char_u *)0L}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)0L, (char_u *)0L}
845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000846 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200847 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848#ifdef FEAT_FOLDING
849 (char_u *)&p_cms, PV_CMS,
850 {(char_u *)"/*%s*/", (char_u *)0L}
851#else
852 (char_u *)NULL, PV_NONE,
853 {(char_u *)0L, (char_u *)0L}
854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000855 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000856 /* P_PRI_MKRC isn't needed here, optval_default()
857 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858 {"compatible", "cp", P_BOOL|P_RALL,
859 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000860 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200861 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862#ifdef FEAT_INS_EXPAND
863 (char_u *)&p_cpt, PV_CPT,
864 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
865#else
866 (char_u *)NULL, PV_NONE,
867 {(char_u *)0L, (char_u *)0L}
868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000869 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200872 (char_u *)VAR_WIN, PV_COCU,
873 {(char_u *)"", (char_u *)NULL}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)NULL, (char_u *)0L}
877#endif
878 SCRIPTID_INIT},
879 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
880#ifdef FEAT_CONCEAL
881 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200882#else
883 (char_u *)NULL, PV_NONE,
884#endif
885 {(char_u *)0L, (char_u *)0L}
886 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000887 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
888#ifdef FEAT_COMPL_FUNC
889 (char_u *)&p_cfu, PV_CFU,
890 {(char_u *)"", (char_u *)0L}
891#else
892 (char_u *)NULL, PV_NONE,
893 {(char_u *)0L, (char_u *)0L}
894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000895 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200896 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000897#ifdef FEAT_INS_EXPAND
898 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000899 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000900#else
901 (char_u *)NULL, PV_NONE,
902 {(char_u *)0L, (char_u *)0L}
903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"confirm", "cf", P_BOOL|P_VI_DEF,
906#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
907 (char_u *)&p_confirm, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
916 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
919 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
921 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200922 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200923#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200924 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200925 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200926#else
927 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200930 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_cspc, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csprg, PV_NONE,
941 {(char_u *)"cscope", (char_u *)0L}
942#else
943 (char_u *)NULL, PV_NONE,
944 {(char_u *)0L, (char_u *)0L}
945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000946 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200947 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
949 (char_u *)&p_csqf, PV_NONE,
950 {(char_u *)"", (char_u *)0L}
951#else
952 (char_u *)NULL, PV_NONE,
953 {(char_u *)0L, (char_u *)0L}
954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000955 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200956 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
957#ifdef FEAT_CSCOPE
958 (char_u *)&p_csre, PV_NONE,
959#else
960 (char_u *)NULL, PV_NONE,
961#endif
962 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
964#ifdef FEAT_CSCOPE
965 (char_u *)&p_cst, PV_NONE,
966#else
967 (char_u *)NULL, PV_NONE,
968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000969 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
971#ifdef FEAT_CSCOPE
972 (char_u *)&p_csto, PV_NONE,
973#else
974 (char_u *)NULL, PV_NONE,
975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000976 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
978#ifdef FEAT_CSCOPE
979 (char_u *)&p_csverbose, PV_NONE,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200984 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
985#ifdef FEAT_CURSORBIND
986 (char_u *)VAR_WIN, PV_CRBIND,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000991 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
992#ifdef FEAT_SYN_HL
993 (char_u *)VAR_WIN, PV_CUC,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100998 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000999#ifdef FEAT_SYN_HL
1000 (char_u *)VAR_WIN, PV_CUL,
1001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"debug", NULL, P_STRING|P_VI_DEF,
1006 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001008 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001010 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001011 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#else
1013 (char_u *)NULL, PV_NONE,
1014 {(char_u *)NULL, (char_u *)0L}
1015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1018#ifdef FEAT_MBYTE
1019 (char_u *)&p_deco, PV_NONE,
1020#else
1021 (char_u *)NULL, PV_NONE,
1022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001023 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001024 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001026 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027#else
1028 (char_u *)NULL, PV_NONE,
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1032#ifdef FEAT_DIFF
1033 (char_u *)VAR_WIN, PV_DIFF,
1034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001038 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1040 (char_u *)&p_dex, PV_NONE,
1041 {(char_u *)"", (char_u *)0L}
1042#else
1043 (char_u *)NULL, PV_NONE,
1044 {(char_u *)0L, (char_u *)0L}
1045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001047 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1048 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049#ifdef FEAT_DIFF
1050 (char_u *)&p_dip, PV_NONE,
1051 {(char_u *)"filler", (char_u *)NULL}
1052#else
1053 (char_u *)NULL, PV_NONE,
1054 {(char_u *)"", (char_u *)NULL}
1055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1058#ifdef FEAT_DIGRAPHS
1059 (char_u *)&p_dg, PV_NONE,
1060#else
1061 (char_u *)NULL, PV_NONE,
1062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001064 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1065 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001068 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001072#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 (char_u *)&p_ead, PV_NONE,
1074 {(char_u *)"both", (char_u *)0L}
1075#else
1076 (char_u *)NULL, PV_NONE,
1077 {(char_u *)NULL, (char_u *)0L}
1078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001079 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1081 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001083 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1084#if defined(FEAT_MBYTE)
1085 (char_u *)&p_emoji, PV_NONE,
1086 {(char_u *)TRUE, (char_u *)0L}
1087#else
1088 (char_u *)NULL, PV_NONE,
1089 {(char_u *)0L, (char_u *)0L}
1090#endif
1091 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001092 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093#ifdef FEAT_MBYTE
1094 (char_u *)&p_enc, PV_NONE,
1095 {(char_u *)ENC_DFLT, (char_u *)0L}
1096#else
1097 (char_u *)NULL, PV_NONE,
1098 {(char_u *)0L, (char_u *)0L}
1099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001100 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1102 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1105 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001108 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1111 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1114#ifdef FEAT_QUICKFIX
1115 (char_u *)&p_ef, PV_NONE,
1116 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1117#else
1118 (char_u *)NULL, PV_NONE,
1119 {(char_u *)NULL, (char_u *)0L}
1120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001122 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001124 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)NULL, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"esckeys", "ek", P_BOOL|P_VIM,
1132 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135#ifdef FEAT_AUTOCMD
1136 (char_u *)&p_ei, PV_NONE,
1137#else
1138 (char_u *)NULL, PV_NONE,
1139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1142 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1145 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1148 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149#ifdef FEAT_MBYTE
1150 (char_u *)&p_fenc, PV_FENC,
1151 {(char_u *)"", (char_u *)0L}
1152#else
1153 (char_u *)NULL, PV_NONE,
1154 {(char_u *)0L, (char_u *)0L}
1155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001157 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158#ifdef FEAT_MBYTE
1159 (char_u *)&p_fencs, PV_NONE,
1160 {(char_u *)"ucs-bom", (char_u *)0L}
1161#else
1162 (char_u *)NULL, PV_NONE,
1163 {(char_u *)0L, (char_u *)0L}
1164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001166 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1167 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001170 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1173 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001174 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1175 (char_u *)&p_fic, PV_NONE,
1176 {
1177#ifdef CASE_INSENSITIVE_FILENAME
1178 (char_u *)TRUE,
1179#else
1180 (char_u *)FALSE,
1181#endif
1182 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001183 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184#ifdef FEAT_AUTOCMD
1185 (char_u *)&p_ft, PV_FT,
1186 {(char_u *)"", (char_u *)0L}
1187#else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)0L, (char_u *)0L}
1190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001192 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1194 (char_u *)&p_fcs, PV_NONE,
1195 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1196#else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)"", (char_u *)0L}
1199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001201 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1202 (char_u *)&p_fixeol, PV_FIXEOL,
1203 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1205#ifdef FEAT_FKMAP
1206 (char_u *)&p_fkmap, PV_NONE,
1207#else
1208 (char_u *)NULL, PV_NONE,
1209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"flash", "fl", P_BOOL|P_VI_DEF,
1212 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001214 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001215#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001217 {(char_u *)"", (char_u *)0L}
1218#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)NULL, PV_NONE,
1220 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#endif
1222 SCRIPTID_INIT},
1223 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1224#ifdef FEAT_FOLDING
1225 (char_u *)VAR_WIN, PV_FDC,
1226 {(char_u *)FALSE, (char_u *)0L}
1227#else
1228 (char_u *)NULL, PV_NONE,
1229 {(char_u *)NULL, (char_u *)0L}
1230#endif
1231 SCRIPTID_INIT},
1232 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1233#ifdef FEAT_FOLDING
1234 (char_u *)VAR_WIN, PV_FEN,
1235 {(char_u *)TRUE, (char_u *)0L}
1236#else
1237 (char_u *)NULL, PV_NONE,
1238 {(char_u *)NULL, (char_u *)0L}
1239#endif
1240 SCRIPTID_INIT},
1241 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1242#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1243 (char_u *)VAR_WIN, PV_FDE,
1244 {(char_u *)"0", (char_u *)NULL}
1245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)NULL, (char_u *)0L}
1248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001251#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 {(char_u *)"#", (char_u *)NULL}
1254#else
1255 (char_u *)NULL, PV_NONE,
1256 {(char_u *)NULL, (char_u *)0L}
1257#endif
1258 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001260#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001262 {(char_u *)0L, (char_u *)0L}
1263#else
1264 (char_u *)NULL, PV_NONE,
1265 {(char_u *)NULL, (char_u *)0L}
1266#endif
1267 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001268 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001269#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001271 {(char_u *)-1L, (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)NULL, (char_u *)0L}
1275#endif
1276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001278 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001279#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001282#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 (char_u *)NULL, PV_NONE,
1284 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001286 SCRIPTID_INIT},
1287 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1288#ifdef FEAT_FOLDING
1289 (char_u *)VAR_WIN, PV_FDM,
1290 {(char_u *)"manual", (char_u *)NULL}
1291#else
1292 (char_u *)NULL, PV_NONE,
1293 {(char_u *)NULL, (char_u *)0L}
1294#endif
1295 SCRIPTID_INIT},
1296 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1297#ifdef FEAT_FOLDING
1298 (char_u *)VAR_WIN, PV_FML,
1299 {(char_u *)1L, (char_u *)0L}
1300#else
1301 (char_u *)NULL, PV_NONE,
1302 {(char_u *)NULL, (char_u *)0L}
1303#endif
1304 SCRIPTID_INIT},
1305 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1306#ifdef FEAT_FOLDING
1307 (char_u *)VAR_WIN, PV_FDN,
1308 {(char_u *)20L, (char_u *)0L}
1309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
1313 SCRIPTID_INIT},
1314 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1315#ifdef FEAT_FOLDING
1316 (char_u *)&p_fdo, PV_NONE,
1317 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1318 (char_u *)0L}
1319#else
1320 (char_u *)NULL, PV_NONE,
1321 {(char_u *)NULL, (char_u *)0L}
1322#endif
1323 SCRIPTID_INIT},
1324 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1325#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1326 (char_u *)VAR_WIN, PV_FDT,
1327 {(char_u *)"foldtext()", (char_u *)NULL}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)NULL, (char_u *)0L}
1331#endif
1332 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001333 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001334#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001335 (char_u *)&p_fex, PV_FEX,
1336 {(char_u *)"", (char_u *)0L}
1337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)0L, (char_u *)0L}
1340#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1343 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1345 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001346 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1347 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1349 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001351 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001353 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1354#ifdef HAVE_FSYNC
1355 (char_u *)&p_fs, PV_NONE,
1356 {(char_u *)TRUE, (char_u *)0L}
1357#else
1358 (char_u *)NULL, PV_NONE,
1359 {(char_u *)FALSE, (char_u *)0L}
1360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1363 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"graphic", "gr", P_BOOL|P_VI_DEF,
1366 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001368 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369#ifdef FEAT_QUICKFIX
1370 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372#else
1373 (char_u *)NULL, PV_NONE,
1374 {(char_u *)NULL, (char_u *)0L}
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1378#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001379 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {
1381# ifdef WIN3264
1382 /* may be changed to "grep -n" in os_win32.c */
1383 (char_u *)"findstr /n",
1384# else
1385# ifdef UNIX
1386 /* Add an extra file name so that grep will always
1387 * insert a file name in the match line. */
1388 (char_u *)"grep -n $* /dev/null",
1389# else
1390# ifdef VMS
1391 (char_u *)"SEARCH/NUMBERS ",
1392# else
1393 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394# endif
1395# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001403 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#ifdef CURSOR_SHAPE
1405 (char_u *)&p_guicursor, PV_NONE,
1406 {
1407# ifdef FEAT_GUI
1408 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001409# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1411# endif
1412 (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)NULL, (char_u *)0L}
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001418 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419#ifdef FEAT_GUI
1420 (char_u *)&p_guifont, PV_NONE,
1421 {(char_u *)"", (char_u *)0L}
1422#else
1423 (char_u *)NULL, PV_NONE,
1424 {(char_u *)NULL, (char_u *)0L}
1425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001427 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1429 (char_u *)&p_guifontset, PV_NONE,
1430 {(char_u *)"", (char_u *)0L}
1431#else
1432 (char_u *)NULL, PV_NONE,
1433 {(char_u *)NULL, (char_u *)0L}
1434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001436 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1438 (char_u *)&p_guifontwide, PV_NONE,
1439 {(char_u *)"", (char_u *)0L}
1440#else
1441 (char_u *)NULL, PV_NONE,
1442 {(char_u *)NULL, (char_u *)0L}
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001446#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 (char_u *)&p_ghr, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001453#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 (char_u *)&p_go, PV_NONE,
1455# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001456 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001458 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459# endif
1460#else
1461 (char_u *)NULL, PV_NONE,
1462 {(char_u *)NULL, (char_u *)0L}
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"guipty", NULL, P_BOOL|P_VI_DEF,
1466#if defined(FEAT_GUI)
1467 (char_u *)&p_guipty, PV_NONE,
1468#else
1469 (char_u *)NULL, PV_NONE,
1470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001472 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001473#if defined(FEAT_GUI_TABLINE)
1474 (char_u *)&p_gtl, PV_NONE,
1475 {(char_u *)"", (char_u *)0L}
1476#else
1477 (char_u *)NULL, PV_NONE,
1478 {(char_u *)NULL, (char_u *)0L}
1479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001481 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001482#if defined(FEAT_GUI_TABLINE)
1483 (char_u *)&p_gtt, PV_NONE,
1484 {(char_u *)"", (char_u *)0L}
1485#else
1486 (char_u *)NULL, PV_NONE,
1487 {(char_u *)NULL, (char_u *)0L}
1488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1491 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1494 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"helpheight", "hh", P_NUM|P_VI_DEF,
1498#ifdef FEAT_WINDOWS
1499 (char_u *)&p_hh, PV_NONE,
1500#else
1501 (char_u *)NULL, PV_NONE,
1502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001504 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505#ifdef FEAT_MULTI_LANG
1506 (char_u *)&p_hlg, PV_NONE,
1507 {(char_u *)"", (char_u *)0L}
1508#else
1509 (char_u *)NULL, PV_NONE,
1510 {(char_u *)0L, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {"hidden", "hid", P_BOOL|P_VI_DEF,
1514 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001516 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"history", "hi", P_NUM|P_VIM,
1521 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001522 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1524#ifdef FEAT_RIGHTLEFT
1525 (char_u *)&p_hkmap, PV_NONE,
1526#else
1527 (char_u *)NULL, PV_NONE,
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1531#ifdef FEAT_RIGHTLEFT
1532 (char_u *)&p_hkmapp, PV_NONE,
1533#else
1534 (char_u *)NULL, PV_NONE,
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1538 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"icon", NULL, P_BOOL|P_VI_DEF,
1541#ifdef FEAT_TITLE
1542 (char_u *)&p_icon, PV_NONE,
1543#else
1544 (char_u *)NULL, PV_NONE,
1545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 {"iconstring", NULL, P_STRING|P_VI_DEF,
1548#ifdef FEAT_TITLE
1549 (char_u *)&p_iconstring, PV_NONE,
1550#else
1551 (char_u *)NULL, PV_NONE,
1552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001553 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1555 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001557 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1558# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1559 (char_u *)&p_imaf, PV_NONE,
1560 {(char_u *)"", (char_u *)NULL}
1561# else
1562 (char_u *)NULL, PV_NONE,
1563 {(char_u *)NULL, (char_u *)0L}
1564# endif
1565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001567#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 (char_u *)&p_imak, PV_NONE,
1569#else
1570 (char_u *)NULL, PV_NONE,
1571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1574#ifdef USE_IM_CONTROL
1575 (char_u *)&p_imcmdline, PV_NONE,
1576#else
1577 (char_u *)NULL, PV_NONE,
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1581#ifdef USE_IM_CONTROL
1582 (char_u *)&p_imdisable, PV_NONE,
1583#else
1584 (char_u *)NULL, PV_NONE,
1585#endif
1586#ifdef __sgi
1587 {(char_u *)TRUE, (char_u *)0L}
1588#else
1589 {(char_u *)FALSE, (char_u *)0L}
1590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001592 {"iminsert", "imi", P_NUM|P_VI_DEF,
1593 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001595 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {"imsearch", "ims", P_NUM|P_VI_DEF,
1597 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001598 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001600 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001601#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001602 (char_u *)&p_imsf, PV_NONE,
1603 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001604#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001605 (char_u *)NULL, PV_NONE,
1606 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001607#endif
1608 SCRIPTID_INIT},
1609 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1610#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1611 (char_u *)&p_imst, PV_NONE,
1612 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1613#else
1614 (char_u *)NULL, PV_NONE,
1615 {(char_u *)0L, (char_u *)0L}
1616#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001617 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001618 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1619#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001620 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001621 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1622#else
1623 (char_u *)NULL, PV_NONE,
1624 {(char_u *)0L, (char_u *)0L}
1625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1628#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1629 (char_u *)&p_inex, PV_INEX,
1630 {(char_u *)"", (char_u *)0L}
1631#else
1632 (char_u *)NULL, PV_NONE,
1633 {(char_u *)0L, (char_u *)0L}
1634#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001635 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1637 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001638 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001639 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1640#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1641 (char_u *)&p_inde, PV_INDE,
1642 {(char_u *)"", (char_u *)0L}
1643#else
1644 (char_u *)NULL, PV_NONE,
1645 {(char_u *)0L, (char_u *)0L}
1646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001647 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001648 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1650 (char_u *)&p_indk, PV_INDK,
1651 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1652#else
1653 (char_u *)NULL, PV_NONE,
1654 {(char_u *)0L, (char_u *)0L}
1655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001656 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 {"infercase", "inf", P_BOOL|P_VI_DEF,
1658 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001659 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1661 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001662 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1664 (char_u *)&p_isf, PV_NONE,
1665 {
1666#ifdef BACKSLASH_IN_FILENAME
1667 /* Excluded are: & and ^ are special in cmd.exe
1668 * ( and ) are used in text separating fnames */
1669 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1670#else
1671# ifdef AMIGA
1672 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1673# else
1674# ifdef VMS
1675 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1676# else /* UNIX et al. */
1677# ifdef EBCDIC
1678 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1679# else
1680 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1681# endif
1682# endif
1683# endif
1684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001685 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1687 (char_u *)&p_isi, PV_NONE,
1688 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001689#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690 (char_u *)"@,48-57,_,128-167,224-235",
1691#else
1692# ifdef EBCDIC
1693 /* TODO: EBCDIC Check this! @ == isalpha()*/
1694 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1695 "112-120,128,140-142,156,158,172,"
1696 "174,186,191,203-207,219-225,235-239,"
1697 "251-254",
1698# else
1699 (char_u *)"@,48-57,_,192-255",
1700# endif
1701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001702 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1704 (char_u *)&p_isk, PV_ISK,
1705 {
1706#ifdef EBCDIC
1707 (char_u *)"@,240-249,_",
1708 /* TODO: EBCDIC Check this! @ == isalpha()*/
1709 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1710 "112-120,128,140-142,156,158,172,"
1711 "174,186,191,203-207,219-225,235-239,"
1712 "251-254",
1713#else
1714 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001715# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 (char_u *)"@,48-57,_,128-167,224-235"
1717# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001718 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719# endif
1720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1723 (char_u *)&p_isp, PV_NONE,
1724 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001725#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 || defined(VMS)
1727 (char_u *)"@,~-255",
1728#else
1729# ifdef EBCDIC
1730 /* all chars above 63 are printable */
1731 (char_u *)"63-255",
1732# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001733 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734# endif
1735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001736 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1738 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001739 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1741#ifdef FEAT_CRYPT
1742 (char_u *)&p_key, PV_KEY,
1743 {(char_u *)"", (char_u *)0L}
1744#else
1745 (char_u *)NULL, PV_NONE,
1746 {(char_u *)0L, (char_u *)0L}
1747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001748 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001749 {"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 +00001750#ifdef FEAT_KEYMAP
1751 (char_u *)&p_keymap, PV_KMAP,
1752 {(char_u *)"", (char_u *)0L}
1753#else
1754 (char_u *)NULL, PV_NONE,
1755 {(char_u *)"", (char_u *)0L}
1756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001757 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001758 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001762 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001764#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 (char_u *)":help",
1766#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001767# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001769# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001770# ifdef USEMAN_S
1771 (char_u *)"man -s",
1772# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001774# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775# endif
1776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001778 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779#ifdef FEAT_LANGMAP
1780 (char_u *)&p_langmap, PV_NONE,
1781 {(char_u *)"", /* unmatched } */
1782#else
1783 (char_u *)NULL, PV_NONE,
1784 {(char_u *)NULL,
1785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001786 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001787 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1789 (char_u *)&p_lm, PV_NONE,
1790#else
1791 (char_u *)NULL, PV_NONE,
1792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001794 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1795#ifdef FEAT_LANGMAP
1796 (char_u *)&p_lnr, PV_NONE,
1797#else
1798 (char_u *)NULL, PV_NONE,
1799#endif
1800 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001801 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1802#ifdef FEAT_LANGMAP
1803 (char_u *)&p_lrm, PV_NONE,
1804#else
1805 (char_u *)NULL, PV_NONE,
1806#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001807 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1809#ifdef FEAT_WINDOWS
1810 (char_u *)&p_ls, PV_NONE,
1811#else
1812 (char_u *)NULL, PV_NONE,
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1816 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1819#ifdef FEAT_LINEBREAK
1820 (char_u *)VAR_WIN, PV_LBR,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1826 (char_u *)&Rows, PV_NONE,
1827 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001828#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 (char_u *)25L,
1830#else
1831 (char_u *)24L,
1832#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001833 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1835#ifdef FEAT_GUI
1836 (char_u *)&p_linespace, PV_NONE,
1837#else
1838 (char_u *)NULL, PV_NONE,
1839#endif
1840#ifdef FEAT_GUI_W32
1841 {(char_u *)1L, (char_u *)0L}
1842#else
1843 {(char_u *)0L, (char_u *)0L}
1844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"lisp", NULL, P_BOOL|P_VI_DEF,
1847#ifdef FEAT_LISP
1848 (char_u *)&p_lisp, PV_LISP,
1849#else
1850 (char_u *)NULL, PV_NONE,
1851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001853 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001855 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1857#else
1858 (char_u *)NULL, PV_NONE,
1859 {(char_u *)"", (char_u *)0L}
1860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1863 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001865 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1869 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001871 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001872#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001873 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001874 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001875#else
1876 (char_u *)NULL, PV_NONE,
1877 {(char_u *)"", (char_u *)0L}
1878#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001879 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001880 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001881#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001882 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001883 {(char_u *)TRUE, (char_u *)0L}
1884#else
1885 (char_u *)NULL, PV_NONE,
1886 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001887#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"magic", NULL, P_BOOL|P_VI_DEF,
1890 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001892 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893#ifdef FEAT_QUICKFIX
1894 (char_u *)&p_mef, PV_NONE,
1895 {(char_u *)"", (char_u *)0L}
1896#else
1897 (char_u *)NULL, PV_NONE,
1898 {(char_u *)NULL, (char_u *)0L}
1899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001900 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001901 {"makeencoding","menc", P_STRING|P_VI_DEF,
1902#ifdef FEAT_MBYTE
1903 (char_u *)&p_menc, PV_MENC,
1904 {(char_u *)"", (char_u *)0L}
1905#else
1906 (char_u *)NULL, PV_NONE,
1907 {(char_u *)0L, (char_u *)0L}
1908#endif
1909 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1911#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001912 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913# ifdef VMS
1914 {(char_u *)"MMS", (char_u *)0L}
1915# else
1916 {(char_u *)"make", (char_u *)0L}
1917# endif
1918#else
1919 (char_u *)NULL, PV_NONE,
1920 {(char_u *)NULL, (char_u *)0L}
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001923 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1926 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"matchtime", "mat", P_NUM|P_VI_DEF,
1928 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001929 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001930 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001931#ifdef FEAT_MBYTE
1932 (char_u *)&p_mco, PV_NONE,
1933#else
1934 (char_u *)NULL, PV_NONE,
1935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001936 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1938#ifdef FEAT_EVAL
1939 (char_u *)&p_mfd, PV_NONE,
1940#else
1941 (char_u *)NULL, PV_NONE,
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1945 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"maxmem", "mm", P_NUM|P_VI_DEF,
1948 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1950 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001951 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1952 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1955 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1957 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {"menuitems", "mis", P_NUM|P_VI_DEF,
1959#ifdef FEAT_MENU
1960 (char_u *)&p_mis, PV_NONE,
1961#else
1962 (char_u *)NULL, PV_NONE,
1963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"mesg", NULL, P_BOOL|P_VI_DEF,
1966 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001968 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001969#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001970 (char_u *)&p_msm, PV_NONE,
1971 {(char_u *)"460000,2000,500", (char_u *)0L}
1972#else
1973 (char_u *)NULL, PV_NONE,
1974 {(char_u *)0L, (char_u *)0L}
1975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001976 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 {"modeline", "ml", P_BOOL|P_VIM,
1978 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001979 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"modelines", "mls", P_NUM|P_VI_DEF,
1981 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1984 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1987 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"more", NULL, P_BOOL|P_VIM,
1990 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1993 (char_u *)&p_mouse, PV_NONE,
1994 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001995#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 (char_u *)"a",
1997#else
1998 (char_u *)"",
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2002#ifdef FEAT_GUI
2003 (char_u *)&p_mousef, PV_NONE,
2004#else
2005 (char_u *)NULL, PV_NONE,
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2009#ifdef FEAT_GUI
2010 (char_u *)&p_mh, PV_NONE,
2011#else
2012 (char_u *)NULL, PV_NONE,
2013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002014 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002015 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2016 (char_u *)&p_mousem, PV_NONE,
2017 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002018#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019 (char_u *)"popup",
2020#else
2021# if defined(MACOS)
2022 (char_u *)"popup_setpos",
2023# else
2024 (char_u *)"extend",
2025# endif
2026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002027 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002028 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029#ifdef FEAT_MOUSESHAPE
2030 (char_u *)&p_mouseshape, PV_NONE,
2031 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)NULL, (char_u *)0L}
2035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2038 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002040 {"mzquantum", "mzq", P_NUM,
2041#ifdef FEAT_MZSCHEME
2042 (char_u *)&p_mzq, PV_NONE,
2043#else
2044 (char_u *)NULL, PV_NONE,
2045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047 {"novice", NULL, P_BOOL|P_VI_DEF,
2048 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002050 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002052 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2055 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002057 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2058#ifdef FEAT_LINEBREAK
2059 (char_u *)VAR_WIN, PV_NUW,
2060#else
2061 (char_u *)NULL, PV_NONE,
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002064 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002065#ifdef FEAT_COMPL_FUNC
2066 (char_u *)&p_ofu, PV_OFU,
2067 {(char_u *)"", (char_u *)0L}
2068#else
2069 (char_u *)NULL, PV_NONE,
2070 {(char_u *)0L, (char_u *)0L}
2071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 {"open", NULL, P_BOOL|P_VI_DEF,
2074 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002076 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002077#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002078 (char_u *)&p_odev, PV_NONE,
2079#else
2080 (char_u *)NULL, PV_NONE,
2081#endif
2082 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002084 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2085 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"optimize", "opt", P_BOOL|P_VI_DEF,
2088 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002092 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002093 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2094 |P_SECURE,
2095 (char_u *)&p_pp, PV_NONE,
2096 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2097 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {"paragraphs", "para", P_STRING|P_VI_DEF,
2099 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002100 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002102 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2106 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2109#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2110 (char_u *)&p_pex, PV_NONE,
2111 {(char_u *)"", (char_u *)0L}
2112#else
2113 (char_u *)NULL, PV_NONE,
2114 {(char_u *)0L, (char_u *)0L}
2115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002117 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002119 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002121 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002123#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 (char_u *)".,,",
2125#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002129 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002130#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002131 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002132 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002133#else
2134 (char_u *)NULL, PV_NONE,
2135 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002137 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2139 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002140 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002141 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2143 (char_u *)&p_pvh, PV_NONE,
2144#else
2145 (char_u *)NULL, PV_NONE,
2146#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2149#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2150 (char_u *)VAR_WIN, PV_PVW,
2151#else
2152 (char_u *)NULL, PV_NONE,
2153#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002155 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156#ifdef FEAT_PRINTER
2157 (char_u *)&p_pdev, PV_NONE,
2158 {(char_u *)"", (char_u *)0L}
2159#else
2160 (char_u *)NULL, PV_NONE,
2161 {(char_u *)NULL, (char_u *)0L}
2162#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002163 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164 {"printencoding", "penc", P_STRING|P_VI_DEF,
2165#ifdef FEAT_POSTSCRIPT
2166 (char_u *)&p_penc, PV_NONE,
2167 {(char_u *)"", (char_u *)0L}
2168#else
2169 (char_u *)NULL, PV_NONE,
2170 {(char_u *)NULL, (char_u *)0L}
2171#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002172 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002173 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174#ifdef FEAT_POSTSCRIPT
2175 (char_u *)&p_pexpr, PV_NONE,
2176 {(char_u *)"", (char_u *)0L}
2177#else
2178 (char_u *)NULL, PV_NONE,
2179 {(char_u *)NULL, (char_u *)0L}
2180#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002181 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 {"printfont", "pfn", P_STRING|P_VI_DEF,
2183#ifdef FEAT_PRINTER
2184 (char_u *)&p_pfn, PV_NONE,
2185 {
2186# ifdef MSWIN
2187 (char_u *)"Courier_New:h10",
2188# else
2189 (char_u *)"courier",
2190# endif
2191 (char_u *)0L}
2192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)NULL, (char_u *)0L}
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2198#ifdef FEAT_PRINTER
2199 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002200 /* untranslated to avoid problems when 'encoding'
2201 * is changed */
2202 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203#else
2204 (char_u *)NULL, PV_NONE,
2205 {(char_u *)NULL, (char_u *)0L}
2206#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002208 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2209#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2210 (char_u *)&p_pmcs, PV_NONE,
2211 {(char_u *)"", (char_u *)0L}
2212#else
2213 (char_u *)NULL, PV_NONE,
2214 {(char_u *)NULL, (char_u *)0L}
2215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002217 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2218#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2219 (char_u *)&p_pmfn, PV_NONE,
2220 {(char_u *)"", (char_u *)0L}
2221#else
2222 (char_u *)NULL, PV_NONE,
2223 {(char_u *)NULL, (char_u *)0L}
2224#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002226 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227#ifdef FEAT_PRINTER
2228 (char_u *)&p_popt, PV_NONE,
2229 {(char_u *)"", (char_u *)0L}
2230#else
2231 (char_u *)NULL, PV_NONE,
2232 {(char_u *)NULL, (char_u *)0L}
2233#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002235 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002236 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002238 {"pumheight", "ph", P_NUM|P_VI_DEF,
2239#ifdef FEAT_INS_EXPAND
2240 (char_u *)&p_ph, PV_NONE,
2241#else
2242 (char_u *)NULL, PV_NONE,
2243#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002245 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002246#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002247 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002248 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002249#else
2250 (char_u *)NULL, PV_NONE,
2251 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002252#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002253 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002254 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002255#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002256 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002257 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002258#else
2259 (char_u *)NULL, PV_NONE,
2260 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002261#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002262 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002263 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2264#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2265 (char_u *)&p_pyx, PV_NONE,
2266#else
2267 (char_u *)NULL, PV_NONE,
2268#endif
2269 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2270 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002271 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2272#ifdef FEAT_TEXTOBJ
2273 (char_u *)&p_qe, PV_QE,
2274 {(char_u *)"\\", (char_u *)0L}
2275#else
2276 (char_u *)NULL, PV_NONE,
2277 {(char_u *)NULL, (char_u *)0L}
2278#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2281 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"redraw", NULL, P_BOOL|P_VI_DEF,
2284 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002286 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2287#ifdef FEAT_RELTIME
2288 (char_u *)&p_rdt, PV_NONE,
2289#else
2290 (char_u *)NULL, PV_NONE,
2291#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002293 {"regexpengine", "re", P_NUM|P_VI_DEF,
2294 (char_u *)&p_re, PV_NONE,
2295 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002296 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2297 (char_u *)VAR_WIN, PV_RNU,
2298 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"remap", NULL, P_BOOL|P_VI_DEF,
2300 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002302 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002303#ifdef FEAT_RENDER_OPTIONS
2304 (char_u *)&p_rop, PV_NONE,
2305 {(char_u *)"", (char_u *)0L}
2306#else
2307 (char_u *)NULL, PV_NONE,
2308 {(char_u *)NULL, (char_u *)0L}
2309#endif
2310 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"report", NULL, P_NUM|P_VI_DEF,
2312 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002313 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2315#ifdef WIN3264
2316 (char_u *)&p_rs, PV_NONE,
2317#else
2318 (char_u *)NULL, PV_NONE,
2319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2322#ifdef FEAT_RIGHTLEFT
2323 (char_u *)&p_ri, PV_NONE,
2324#else
2325 (char_u *)NULL, PV_NONE,
2326#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2329#ifdef FEAT_RIGHTLEFT
2330 (char_u *)VAR_WIN, PV_RL,
2331#else
2332 (char_u *)NULL, PV_NONE,
2333#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002334 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2336#ifdef FEAT_RIGHTLEFT
2337 (char_u *)VAR_WIN, PV_RLC,
2338 {(char_u *)"search", (char_u *)NULL}
2339#else
2340 (char_u *)NULL, PV_NONE,
2341 {(char_u *)NULL, (char_u *)0L}
2342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002344 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002345#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002346 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002347 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002348#else
2349 (char_u *)NULL, PV_NONE,
2350 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002351#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002352 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2354#ifdef FEAT_CMDL_INFO
2355 (char_u *)&p_ru, PV_NONE,
2356#else
2357 (char_u *)NULL, PV_NONE,
2358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002359 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2361#ifdef FEAT_STL_OPT
2362 (char_u *)&p_ruf, PV_NONE,
2363#else
2364 (char_u *)NULL, PV_NONE,
2365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002367 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2368 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2371 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2373 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2376#ifdef FEAT_SCROLLBIND
2377 (char_u *)VAR_WIN, PV_SCBIND,
2378#else
2379 (char_u *)NULL, PV_NONE,
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2383 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2386 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002388 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389#ifdef FEAT_SCROLLBIND
2390 (char_u *)&p_sbo, PV_NONE,
2391 {(char_u *)"ver,jump", (char_u *)0L}
2392#else
2393 (char_u *)NULL, PV_NONE,
2394 {(char_u *)0L, (char_u *)0L}
2395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"sections", "sect", P_STRING|P_VI_DEF,
2398 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2400 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2402 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)"inclusive", (char_u *)0L}
2407 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002408 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002411 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412#ifdef FEAT_SESSION
2413 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002414 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415 (char_u *)0L}
2416#else
2417 (char_u *)NULL, PV_NONE,
2418 {(char_u *)0L, (char_u *)0L}
2419#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002420 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2422 (char_u *)&p_sh, PV_NONE,
2423 {
2424#ifdef VMS
2425 (char_u *)"-",
2426#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002427# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002429# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431# endif
2432#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002433 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2435 (char_u *)&p_shcf, PV_NONE,
2436 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002437#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 (char_u *)"/c",
2439#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2444#ifdef FEAT_QUICKFIX
2445 (char_u *)&p_sp, PV_NONE,
2446 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002447#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449#else
2450 (char_u *)">",
2451#endif
2452 (char_u *)0L}
2453#else
2454 (char_u *)NULL, PV_NONE,
2455 {(char_u *)0L, (char_u *)0L}
2456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002457 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2459 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2462 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002463 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2465#ifdef BACKSLASH_IN_FILENAME
2466 (char_u *)&p_ssl, PV_NONE,
2467#else
2468 (char_u *)NULL, PV_NONE,
2469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002471 {"shelltemp", "stmp", P_BOOL,
2472 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"shelltype", "st", P_NUM|P_VI_DEF,
2475#ifdef AMIGA
2476 (char_u *)&p_st, PV_NONE,
2477#else
2478 (char_u *)NULL, PV_NONE,
2479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002480 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2482 (char_u *)&p_sxq, PV_NONE,
2483 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002484#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 (char_u *)"\"",
2486#else
2487 (char_u *)"",
2488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002490 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2491 (char_u *)&p_sxe, PV_NONE,
2492 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002493#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002494 (char_u *)"\"&|<>()@^",
2495#else
2496 (char_u *)"",
2497#endif
2498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2500 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2503 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2506 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)"", (char_u *)"filnxtToO"}
2508 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2513#ifdef FEAT_LINEBREAK
2514 (char_u *)&p_sbr, PV_NONE,
2515#else
2516 (char_u *)NULL, PV_NONE,
2517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"showcmd", "sc", P_BOOL|P_VIM,
2520#ifdef FEAT_CMDL_INFO
2521 (char_u *)&p_sc, PV_NONE,
2522#else
2523 (char_u *)NULL, PV_NONE,
2524#endif
2525 {(char_u *)FALSE,
2526#ifdef UNIX
2527 (char_u *)FALSE
2528#else
2529 (char_u *)TRUE
2530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2533 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2536 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"showmode", "smd", P_BOOL|P_VIM,
2539 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002541 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2542#ifdef FEAT_WINDOWS
2543 (char_u *)&p_stal, PV_NONE,
2544#else
2545 (char_u *)NULL, PV_NONE,
2546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2549 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2552 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002554 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2555#ifdef FEAT_SIGNS
2556 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002557 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002558#else
2559 (char_u *)NULL, PV_NONE,
2560 {(char_u *)NULL, (char_u *)0L}
2561#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002562 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2564 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2567 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2570#ifdef FEAT_SMARTINDENT
2571 (char_u *)&p_si, PV_SI,
2572#else
2573 (char_u *)NULL, PV_NONE,
2574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2577 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2580 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2583 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002585 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002586#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002587 (char_u *)VAR_WIN, PV_SPELL,
2588#else
2589 (char_u *)NULL, PV_NONE,
2590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002592 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002593#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002594 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002595 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002596#else
2597 (char_u *)NULL, PV_NONE,
2598 {(char_u *)0L, (char_u *)0L}
2599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002601 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2602 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002603#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002604 (char_u *)&p_spf, PV_SPF,
2605 {(char_u *)"", (char_u *)0L}
2606#else
2607 (char_u *)NULL, PV_NONE,
2608 {(char_u *)0L, (char_u *)0L}
2609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002611 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2612 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002613#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002614 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002615 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002616#else
2617 (char_u *)NULL, PV_NONE,
2618 {(char_u *)0L, (char_u *)0L}
2619#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002621 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002622#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002623 (char_u *)&p_sps, PV_NONE,
2624 {(char_u *)"best", (char_u *)0L}
2625#else
2626 (char_u *)NULL, PV_NONE,
2627 {(char_u *)0L, (char_u *)0L}
2628#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2631#ifdef FEAT_WINDOWS
2632 (char_u *)&p_sb, PV_NONE,
2633#else
2634 (char_u *)NULL, PV_NONE,
2635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002638#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 (char_u *)&p_spr, PV_NONE,
2640#else
2641 (char_u *)NULL, PV_NONE,
2642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2645 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2648#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002649 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650#else
2651 (char_u *)NULL, PV_NONE,
2652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002654 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 (char_u *)&p_su, PV_NONE,
2656 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002658 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002659#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 (char_u *)&p_sua, PV_SUA,
2661 {(char_u *)"", (char_u *)0L}
2662#else
2663 (char_u *)NULL, PV_NONE,
2664 {(char_u *)0L, (char_u *)0L}
2665#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2668 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"swapsync", "sws", P_STRING|P_VI_DEF,
2671 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002673 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002676 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2677#ifdef FEAT_SYN_HL
2678 (char_u *)&p_smc, PV_SMC,
2679 {(char_u *)3000L, (char_u *)0L}
2680#else
2681 (char_u *)NULL, PV_NONE,
2682 {(char_u *)0L, (char_u *)0L}
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002685 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686#ifdef FEAT_SYN_HL
2687 (char_u *)&p_syn, PV_SYN,
2688 {(char_u *)"", (char_u *)0L}
2689#else
2690 (char_u *)NULL, PV_NONE,
2691 {(char_u *)0L, (char_u *)0L}
2692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002694 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2695#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002696 (char_u *)&p_tal, PV_NONE,
2697#else
2698 (char_u *)NULL, PV_NONE,
2699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002700 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002701 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2702#ifdef FEAT_WINDOWS
2703 (char_u *)&p_tpm, PV_NONE,
2704#else
2705 (char_u *)NULL, PV_NONE,
2706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2709 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2712 (char_u *)&p_tbs, PV_NONE,
2713#ifdef VMS /* binary searching doesn't appear to work on VMS */
2714 {(char_u *)0L, (char_u *)0L}
2715#else
2716 {(char_u *)TRUE, (char_u *)0L}
2717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002719 {"tagcase", "tc", P_STRING|P_VIM,
2720 (char_u *)&p_tc, PV_TC,
2721 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"taglength", "tl", P_NUM|P_VI_DEF,
2723 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"tagrelative", "tr", P_BOOL|P_VIM,
2726 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002728 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002729 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {
2731#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2732 (char_u *)"./tags,./TAGS,tags,TAGS",
2733#else
2734 (char_u *)"./tags,tags",
2735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002736 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002737 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2738 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002740 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002741#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002742 (char_u *)&p_tcldll, PV_NONE,
2743 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002744#else
2745 (char_u *)NULL, PV_NONE,
2746 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002747#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002749 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2750 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002751 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2753#ifdef FEAT_ARABIC
2754 (char_u *)&p_tbidi, PV_NONE,
2755#else
2756 (char_u *)NULL, PV_NONE,
2757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2760#ifdef FEAT_MBYTE
2761 (char_u *)&p_tenc, PV_NONE,
2762 {(char_u *)"", (char_u *)0L}
2763#else
2764 (char_u *)NULL, PV_NONE,
2765 {(char_u *)0L, (char_u *)0L}
2766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002768 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2769#ifdef FEAT_TERMGUICOLORS
2770 (char_u *)&p_tgc, PV_NONE,
2771 {(char_u *)FALSE, (char_u *)FALSE}
2772#else
2773 (char_u*)NULL, PV_NONE,
2774 {(char_u *)FALSE, (char_u *)FALSE}
2775#endif
2776 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002777 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2778#ifdef FEAT_TERMINAL
2779 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002780 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002781#else
2782 (char_u *)NULL, PV_NONE,
2783 {(char_u *)NULL, (char_u *)0L}
2784#endif
2785 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002786 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2787#ifdef FEAT_TERMINAL
2788 (char_u *)VAR_WIN, PV_TMS,
2789 {(char_u *)"", (char_u *)NULL}
2790#else
2791 (char_u *)NULL, PV_NONE,
2792 {(char_u *)NULL, (char_u *)0L}
2793#endif
2794 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 {"terse", NULL, P_BOOL|P_VI_DEF,
2796 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"textauto", "ta", P_BOOL|P_VIM,
2799 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2801 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2803 (char_u *)&p_tx, PV_TX,
2804 {
2805#ifdef USE_CRNL
2806 (char_u *)TRUE,
2807#else
2808 (char_u *)FALSE,
2809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002811 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002814 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002816 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817#else
2818 (char_u *)NULL, PV_NONE,
2819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2822 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002823 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"timeout", "to", P_BOOL|P_VI_DEF,
2825 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2828 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"title", NULL, P_BOOL|P_VI_DEF,
2831#ifdef FEAT_TITLE
2832 (char_u *)&p_title, PV_NONE,
2833#else
2834 (char_u *)NULL, PV_NONE,
2835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"titlelen", NULL, P_NUM|P_VI_DEF,
2838#ifdef FEAT_TITLE
2839 (char_u *)&p_titlelen, PV_NONE,
2840#else
2841 (char_u *)NULL, PV_NONE,
2842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002844 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845#ifdef FEAT_TITLE
2846 (char_u *)&p_titleold, PV_NONE,
2847 {(char_u *)N_("Thanks for flying Vim"),
2848 (char_u *)0L}
2849#else
2850 (char_u *)NULL, PV_NONE,
2851 {(char_u *)0L, (char_u *)0L}
2852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"titlestring", NULL, P_STRING|P_VI_DEF,
2855#ifdef FEAT_TITLE
2856 (char_u *)&p_titlestring, PV_NONE,
2857#else
2858 (char_u *)NULL, PV_NONE,
2859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002861 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002862#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002865#else
2866 (char_u *)NULL, PV_NONE,
2867 {(char_u *)0L, (char_u *)0L}
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002871#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002873 {(char_u *)"small", (char_u *)0L}
2874#else
2875 (char_u *)NULL, PV_NONE,
2876 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2880 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2883 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002884 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2886 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002887 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2889 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2892#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2893 (char_u *)&p_ttym, PV_NONE,
2894#else
2895 (char_u *)NULL, PV_NONE,
2896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2899 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2902 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002903 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002904 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2905 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002906#ifdef FEAT_PERSISTENT_UNDO
2907 (char_u *)&p_udir, PV_NONE,
2908 {(char_u *)".", (char_u *)0L}
2909#else
2910 (char_u *)NULL, PV_NONE,
2911 {(char_u *)0L, (char_u *)0L}
2912#endif
2913 SCRIPTID_INIT},
2914 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2915#ifdef FEAT_PERSISTENT_UNDO
2916 (char_u *)&p_udf, PV_UDF,
2917#else
2918 (char_u *)NULL, PV_NONE,
2919#endif
2920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002922 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002924#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 (char_u *)1000L,
2926#else
2927 (char_u *)100L,
2928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002930 {"undoreload", "ur", P_NUM|P_VI_DEF,
2931 (char_u *)&p_ur, PV_NONE,
2932 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 {"updatecount", "uc", P_NUM|P_VI_DEF,
2934 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"updatetime", "ut", P_NUM|P_VI_DEF,
2937 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 {"verbose", "vbs", P_NUM|P_VI_DEF,
2940 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002941 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002942 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2943 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2946#ifdef FEAT_SESSION
2947 (char_u *)&p_vdir, PV_NONE,
2948 {(char_u *)DFLT_VDIR, (char_u *)0L}
2949#else
2950 (char_u *)NULL, PV_NONE,
2951 {(char_u *)0L, (char_u *)0L}
2952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002953 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002954 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955#ifdef FEAT_SESSION
2956 (char_u *)&p_vop, PV_NONE,
2957 {(char_u *)"folds,options,cursor", (char_u *)0L}
2958#else
2959 (char_u *)NULL, PV_NONE,
2960 {(char_u *)0L, (char_u *)0L}
2961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002962 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002963 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964#ifdef FEAT_VIMINFO
2965 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002966#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002967 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968#else
2969# ifdef AMIGA
2970 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002971 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002973 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974# endif
2975#endif
2976#else
2977 (char_u *)NULL, PV_NONE,
2978 {(char_u *)0L, (char_u *)0L}
2979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002980 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002981 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2982#ifdef FEAT_VIMINFO
2983 (char_u *)&p_viminfofile, PV_NONE,
2984 {(char_u *)"", (char_u *)0L}
2985#else
2986 (char_u *)NULL, PV_NONE,
2987 {(char_u *)0L, (char_u *)0L}
2988#endif
2989 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002990 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2991 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992#ifdef FEAT_VIRTUALEDIT
2993 (char_u *)&p_ve, PV_NONE,
2994 {(char_u *)"", (char_u *)""}
2995#else
2996 (char_u *)NULL, PV_NONE,
2997 {(char_u *)0L, (char_u *)0L}
2998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3001 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003002 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 {"w300", NULL, P_NUM|P_VI_DEF,
3004 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003005 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 {"w1200", NULL, P_NUM|P_VI_DEF,
3007 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003008 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 {"w9600", NULL, P_NUM|P_VI_DEF,
3010 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 {"warn", NULL, P_BOOL|P_VI_DEF,
3013 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003014 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3016 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003017 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003018 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 {"wildchar", "wc", P_NUM|P_VIM,
3022 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003023 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3024 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003025 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003027 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003028 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029#ifdef FEAT_WILDIGN
3030 (char_u *)&p_wig, PV_NONE,
3031#else
3032 (char_u *)NULL, PV_NONE,
3033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003034 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003035 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3036 (char_u *)&p_wic, PV_NONE,
3037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3039#ifdef FEAT_WILDMENU
3040 (char_u *)&p_wmnu, PV_NONE,
3041#else
3042 (char_u *)NULL, PV_NONE,
3043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003044 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003045 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003047 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003048 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3049#ifdef FEAT_CMDL_COMPL
3050 (char_u *)&p_wop, PV_NONE,
3051 {(char_u *)"", (char_u *)0L}
3052#else
3053 (char_u *)NULL, PV_NONE,
3054 {(char_u *)NULL, (char_u *)0L}
3055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3058#ifdef FEAT_WAK
3059 (char_u *)&p_wak, PV_NONE,
3060 {(char_u *)"menu", (char_u *)0L}
3061#else
3062 (char_u *)NULL, PV_NONE,
3063 {(char_u *)NULL, (char_u *)0L}
3064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003067 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003068 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 {"winheight", "wh", P_NUM|P_VI_DEF,
3070#ifdef FEAT_WINDOWS
3071 (char_u *)&p_wh, PV_NONE,
3072#else
3073 (char_u *)NULL, PV_NONE,
3074#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003075 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003077#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 (char_u *)VAR_WIN, PV_WFH,
3079#else
3080 (char_u *)NULL, PV_NONE,
3081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003083 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003084#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003085 (char_u *)VAR_WIN, PV_WFW,
3086#else
3087 (char_u *)NULL, PV_NONE,
3088#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003089 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3091#ifdef FEAT_WINDOWS
3092 (char_u *)&p_wmh, PV_NONE,
3093#else
3094 (char_u *)NULL, PV_NONE,
3095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003096 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003098#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 (char_u *)&p_wmw, PV_NONE,
3100#else
3101 (char_u *)NULL, PV_NONE,
3102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003103 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003104 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003105#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003106 (char_u *)&p_winptydll, PV_NONE, {
3107# ifdef _WIN64
3108 (char_u *)"winpty64.dll",
3109# else
3110 (char_u *)"winpty32.dll",
3111# endif
3112 (char_u *)0L}
3113#else
3114 (char_u *)NULL, PV_NONE,
3115 {(char_u *)0L, (char_u *)0L}
3116#endif
3117 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003119#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120 (char_u *)&p_wiw, PV_NONE,
3121#else
3122 (char_u *)NULL, PV_NONE,
3123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003124 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3126 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003127 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3129 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003130 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3132 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003133 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 {"write", NULL, P_BOOL|P_VI_DEF,
3135 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003136 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 {"writeany", "wa", P_BOOL|P_VI_DEF,
3138 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003139 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3141 (char_u *)&p_wb, PV_NONE,
3142 {
3143#ifdef FEAT_WRITEBACKUP
3144 (char_u *)TRUE,
3145#else
3146 (char_u *)FALSE,
3147#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003148 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 {"writedelay", "wd", P_NUM|P_VI_DEF,
3150 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003151 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152
3153/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003154#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003156 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157
3158 p_term("t_AB", T_CAB)
3159 p_term("t_AF", T_CAF)
3160 p_term("t_AL", T_CAL)
3161 p_term("t_al", T_AL)
3162 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003163 p_term("t_BE", T_BE)
3164 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_cd", T_CD)
3166 p_term("t_ce", T_CE)
3167 p_term("t_cl", T_CL)
3168 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003169 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 p_term("t_Co", T_CCO)
3171 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003172 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003174#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 p_term("t_CV", T_CSV)
3176#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_da", T_DA)
3178 p_term("t_db", T_DB)
3179 p_term("t_DL", T_CDL)
3180 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003181 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003182 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003184 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_IE", T_CIE)
3186 p_term("t_IS", T_CIS)
3187 p_term("t_ke", T_KE)
3188 p_term("t_ks", T_KS)
3189 p_term("t_le", T_LE)
3190 p_term("t_mb", T_MB)
3191 p_term("t_md", T_MD)
3192 p_term("t_me", T_ME)
3193 p_term("t_mr", T_MR)
3194 p_term("t_ms", T_MS)
3195 p_term("t_nd", T_ND)
3196 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003197 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003198 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003200 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 p_term("t_RV", T_CRV)
3202 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003203 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003205 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003206 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003207 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003209 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003211 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 p_term("t_te", T_TE)
3213 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003214 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003215 p_term("t_ts", T_TS)
3216 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217 p_term("t_ue", T_UE)
3218 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003219 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220 p_term("t_vb", T_VB)
3221 p_term("t_ve", T_VE)
3222 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003223 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224 p_term("t_vs", T_VS)
3225 p_term("t_WP", T_CWP)
3226 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003227 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 p_term("t_xs", T_XS)
3229 p_term("t_ZH", T_CZH)
3230 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003231 p_term("t_8f", T_8F)
3232 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233
3234/* terminal key codes are not in here */
3235
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003236 /* end marker */
3237 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238};
3239
3240#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3241
3242#ifdef FEAT_MBYTE
3243static char *(p_ambw_values[]) = {"single", "double", NULL};
3244#endif
3245static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003246static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003248#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003249static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003250#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003251#ifdef FEAT_CMDL_COMPL
3252static char *(p_wop_values[]) = {"tagfile", NULL};
3253#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#ifdef FEAT_WAK
3255static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3256#endif
3257static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3259static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261#ifdef FEAT_BROWSE
3262static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3263#endif
3264#ifdef FEAT_SCROLLBIND
3265static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3266#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003267static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003268#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3270#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003271#ifdef FEAT_AUTOCMD
3272static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3273#else
3274static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003276static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3278#ifdef FEAT_FOLDING
3279static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003280# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003282# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283 NULL};
3284static char *(p_fcl_values[]) = {"all", NULL};
3285#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003286#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003287static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003288#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003289#ifdef FEAT_SIGNS
3290static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3291#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static void set_option_default(int, int opt_flags, int compatible);
3294static void set_options_default(int opt_flags);
3295static char_u *term_bg_default(void);
3296static void did_set_option(int opt_idx, int opt_flags, int new_value);
3297static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#endif
3301#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003304static char_u *option_expand(int opt_idx, char_u *val);
3305static void didset_options(void);
3306static void didset_options2(void);
3307static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003308#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003310#else
3311# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3312#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003313static void set_string_option_global(int opt_idx, char_u **varp);
3314static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3315static 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);
3316static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003317#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003318static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003321static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003323#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003324static char_u *did_set_spell_option(int is_spellfile);
3325static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003326#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003327#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003328static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003329#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003330static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3331static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3332static void check_redraw(long_u flags);
3333static int findoption(char_u *);
3334static int find_key_option(char_u *);
3335static void showoptions(int all, int opt_flags);
3336static int optval_default(struct vimoption *, char_u *varp);
3337static void showoneopt(struct vimoption *, int opt_flags);
3338static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3339static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3340static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3341static int istermoption(struct vimoption *);
3342static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3343static char_u *get_varp(struct vimoption *);
3344static void option_value2string(struct vimoption *, int opt_flags);
3345static void check_winopt(winopt_T *wop);
3346static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003348static void langmap_init(void);
3349static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003351static void paste_option_changed(void);
3352static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003354static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003356static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3357static int check_opt_strings(char_u *val, char **values, int);
3358static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003359#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003360static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003361#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362
3363/*
3364 * Initialize the options, first part.
3365 *
3366 * Called only once from main(), just after creating the first buffer.
3367 */
3368 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003369set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370{
3371 char_u *p;
3372 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003373 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374
3375#ifdef FEAT_LANGMAP
3376 langmap_init();
3377#endif
3378
3379 /* Be Vi compatible by default */
3380 p_cp = TRUE;
3381
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003382 /* Use POSIX compatibility when $VIM_POSIX is set. */
3383 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003384 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003385 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003386 set_string_default("shm", (char_u *)"A");
3387 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003388
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 /*
3390 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003391 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003393 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003394#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003395 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003397 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398# endif
3399#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003400 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401 set_string_default("sh", p);
3402
3403#ifdef FEAT_WILDIGN
3404 /*
3405 * Set the default for 'backupskip' to include environment variables for
3406 * temp files.
3407 */
3408 {
3409# ifdef UNIX
3410 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3411# else
3412 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3413# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003414 int len;
3415 garray_T ga;
3416 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417
3418 ga_init2(&ga, 1, 100);
3419 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3420 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003421 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422# ifdef UNIX
3423 if (*names[n] == NUL)
3424 p = (char_u *)"/tmp";
3425 else
3426# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003427 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428 if (p != NULL && *p != NUL)
3429 {
3430 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003431 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 if (ga_grow(&ga, len) == OK)
3433 {
3434 if (ga.ga_len > 0)
3435 STRCAT(ga.ga_data, ",");
3436 STRCAT(ga.ga_data, p);
3437 add_pathsep(ga.ga_data);
3438 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439 ga.ga_len += len;
3440 }
3441 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003442 if (mustfree)
3443 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444 }
3445 if (ga.ga_data != NULL)
3446 {
3447 set_string_default("bsk", ga.ga_data);
3448 vim_free(ga.ga_data);
3449 }
3450 }
3451#endif
3452
3453 /*
3454 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3455 */
3456 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003457 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003459#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3460 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3461#endif
3462 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003464 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003465 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466#else
3467# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003468 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003469 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003471 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472# endif
3473#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003475 opt_idx = findoption((char_u *)"maxmem");
3476 if (opt_idx >= 0)
3477 {
3478#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003479 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3480 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003481#endif
3482 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3483 }
3484 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003485 }
3486
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487#ifdef FEAT_SEARCHPATH
3488 {
3489 char_u *cdpath;
3490 char_u *buf;
3491 int i;
3492 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003493 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494
3495 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003496 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 if (cdpath != NULL)
3498 {
3499 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3500 if (buf != NULL)
3501 {
3502 buf[0] = ','; /* start with ",", current dir first */
3503 j = 1;
3504 for (i = 0; cdpath[i] != NUL; ++i)
3505 {
3506 if (vim_ispathlistsep(cdpath[i]))
3507 buf[j++] = ',';
3508 else
3509 {
3510 if (cdpath[i] == ' ' || cdpath[i] == ',')
3511 buf[j++] = '\\';
3512 buf[j++] = cdpath[i];
3513 }
3514 }
3515 buf[j] = NUL;
3516 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003517 if (opt_idx >= 0)
3518 {
3519 options[opt_idx].def_val[VI_DEFAULT] = buf;
3520 options[opt_idx].flags |= P_DEF_ALLOCED;
3521 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003522 else
3523 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003525 if (mustfree)
3526 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003527 }
3528 }
3529#endif
3530
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003531#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532 /* Set print encoding on platforms that don't default to latin1 */
3533 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003534# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003535 (char_u *)"cp1252"
3536# else
3537# ifdef VMS
3538 (char_u *)"dec-mcs"
3539# else
3540# ifdef EBCDIC
3541 (char_u *)"ebcdic-uk"
3542# else
3543# ifdef MAC
3544 (char_u *)"mac-roman"
3545# else /* HPUX */
3546 (char_u *)"hp-roman8"
3547# endif
3548# endif
3549# endif
3550# endif
3551 );
3552#endif
3553
3554#ifdef FEAT_POSTSCRIPT
3555 /* 'printexpr' must be allocated to be able to evaluate it. */
3556 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003557# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003558 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559# else
3560# ifdef VMS
3561 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3562
3563# else
3564 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3565# endif
3566# endif
3567 );
3568#endif
3569
3570 /*
3571 * Set all the options (except the terminal options) to their default
3572 * value. Also set the global value for local options.
3573 */
3574 set_options_default(0);
3575
3576#ifdef FEAT_GUI
3577 if (found_reverse_arg)
3578 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3579#endif
3580
3581 curbuf->b_p_initialized = TRUE;
3582 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003583 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584 check_buf_options(curbuf);
3585 check_win_options(curwin);
3586 check_options();
3587
3588 /* Must be before option_expand(), because that one needs vim_isIDc() */
3589 didset_options();
3590
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003591#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003592 /* Use the current chartab for the generic chartab. This is not in
3593 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003594 init_spell_chartab();
3595#endif
3596
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597 /*
3598 * Expand environment variables and things like "~" for the defaults.
3599 * If option_expand() returns non-NULL the variable is expanded. This can
3600 * only happen for non-indirect options.
3601 * Also set the default to the expanded value, so ":set" does not list
3602 * them.
3603 * Don't set the P_ALLOCED flag, because we don't want to free the
3604 * default.
3605 */
3606 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3607 {
3608 if ((options[opt_idx].flags & P_GETTEXT)
3609 && options[opt_idx].var != NULL)
3610 p = (char_u *)_(*(char **)options[opt_idx].var);
3611 else
3612 p = option_expand(opt_idx, NULL);
3613 if (p != NULL && (p = vim_strsave(p)) != NULL)
3614 {
3615 *(char_u **)options[opt_idx].var = p;
3616 /* VIMEXP
3617 * Defaults for all expanded options are currently the same for Vi
3618 * and Vim. When this changes, add some code here! Also need to
3619 * split P_DEF_ALLOCED in two.
3620 */
3621 if (options[opt_idx].flags & P_DEF_ALLOCED)
3622 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3623 options[opt_idx].def_val[VI_DEFAULT] = p;
3624 options[opt_idx].flags |= P_DEF_ALLOCED;
3625 }
3626 }
3627
Bram Moolenaar071d4272004-06-13 20:20:40 +00003628 save_file_ff(curbuf); /* Buffer is unchanged */
3629
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630#if defined(FEAT_ARABIC)
3631 /* Detect use of mlterm.
3632 * Mlterm is a terminal emulator akin to xterm that has some special
3633 * abilities (bidi namely).
3634 * NOTE: mlterm's author is being asked to 'set' a variable
3635 * instead of an environment variable due to inheritance.
3636 */
3637 if (mch_getenv((char_u *)"MLTERM") != NULL)
3638 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3639#endif
3640
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003641 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642
3643#ifdef FEAT_MBYTE
3644# if defined(WIN3264) && defined(FEAT_GETTEXT)
3645 /*
3646 * If $LANG isn't set, try to get a good value for it. This makes the
3647 * right language be used automatically. Don't do this for English.
3648 */
3649 if (mch_getenv((char_u *)"LANG") == NULL)
3650 {
3651 char buf[20];
3652
3653 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3654 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3655 * only the first two. */
3656 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3657 (LPTSTR)buf, 20);
3658 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3659 {
3660 /* There are a few exceptions (probably more) */
3661 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3662 STRCPY(buf, "zh_TW");
3663 else if (STRNICMP(buf, "chs", 3) == 0
3664 || STRNICMP(buf, "zhc", 3) == 0)
3665 STRCPY(buf, "zh_CN");
3666 else if (STRNICMP(buf, "jp", 2) == 0)
3667 STRCPY(buf, "ja");
3668 else
3669 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003670 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671 }
3672 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003673# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003674# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003675 /* Moved to os_mac_conv.c to avoid dependency problems. */
3676 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003677# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678# endif
3679
3680 /* enc_locale() will try to find the encoding of the current locale. */
3681 p = enc_locale();
3682 if (p != NULL)
3683 {
3684 char_u *save_enc;
3685
3686 /* Try setting 'encoding' and check if the value is valid.
3687 * If not, go back to the default "latin1". */
3688 save_enc = p_enc;
3689 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003690 if (STRCMP(p_enc, "gb18030") == 0)
3691 {
3692 /* We don't support "gb18030", but "cp936" is a good substitute
3693 * for practical purposes, thus use that. It's not an alias to
3694 * still support conversion between gb18030 and utf-8. */
3695 p_enc = vim_strsave((char_u *)"cp936");
3696 vim_free(p);
3697 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 if (mb_init() == NULL)
3699 {
3700 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003701 if (opt_idx >= 0)
3702 {
3703 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3704 options[opt_idx].flags |= P_DEF_ALLOCED;
3705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003707#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003708 if (STRCMP(p_enc, "latin1") == 0
3709# ifdef FEAT_MBYTE
3710 || enc_utf8
3711# endif
3712 )
3713 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003714 /* Adjust the default for 'isprint' and 'iskeyword' to match
3715 * latin1. Also set the defaults for when 'nocompatible' is
3716 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003717 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003718 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003719 set_string_option_direct((char_u *)"isk", -1,
3720 ISK_LATIN1, OPT_FREE, SID_NONE);
3721 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003722 if (opt_idx >= 0)
3723 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003724 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003725 if (opt_idx >= 0)
3726 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003727 (void)init_chartab();
3728 }
3729#endif
3730
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731# if defined(WIN3264) && !defined(FEAT_GUI)
3732 /* Win32 console: When GetACP() returns a different value from
3733 * GetConsoleCP() set 'termencoding'. */
3734 if (GetACP() != GetConsoleCP())
3735 {
3736 char buf[50];
3737
3738 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3739 p_tenc = vim_strsave((char_u *)buf);
3740 if (p_tenc != NULL)
3741 {
3742 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003743 if (opt_idx >= 0)
3744 {
3745 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3746 options[opt_idx].flags |= P_DEF_ALLOCED;
3747 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 convert_setup(&input_conv, p_tenc, p_enc);
3749 convert_setup(&output_conv, p_enc, p_tenc);
3750 }
3751 else
3752 p_tenc = empty_option;
3753 }
3754# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003755# if defined(WIN3264) && defined(FEAT_MBYTE)
3756 /* $HOME may have characters in active code page. */
3757 init_homedir();
3758# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 }
3760 else
3761 {
3762 vim_free(p_enc);
3763 p_enc = save_enc;
3764 }
3765 }
3766#endif
3767
3768#ifdef FEAT_MULTI_LANG
3769 /* Set the default for 'helplang'. */
3770 set_helplang_default(get_mess_lang());
3771#endif
3772}
3773
3774/*
3775 * Set an option to its default value.
3776 * This does not take care of side effects!
3777 */
3778 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003779set_option_default(
3780 int opt_idx,
3781 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3782 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783{
3784 char_u *varp; /* pointer to variable for current option */
3785 int dvi; /* index in def_val[] */
3786 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003787 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3789
3790 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3791 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003792 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 {
3794 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3795 if (flags & P_STRING)
3796 {
3797 /* Use set_string_option_direct() for local options to handle
3798 * freeing and allocating the value. */
3799 if (options[opt_idx].indir != PV_NONE)
3800 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003801 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802 else
3803 {
3804 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3805 free_string_option(*(char_u **)(varp));
3806 *(char_u **)varp = options[opt_idx].def_val[dvi];
3807 options[opt_idx].flags &= ~P_ALLOCED;
3808 }
3809 }
3810 else if (flags & P_NUM)
3811 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003812 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 win_comp_scroll(curwin);
3814 else
3815 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003816 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 /* May also set global value for local option. */
3818 if (both)
3819 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3820 *(long *)varp;
3821 }
3822 }
3823 else /* P_BOOL */
3824 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003825 /* the cast to long is required for Manx C, long_i is needed for
3826 * MSVC */
3827 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003828#ifdef UNIX
3829 /* 'modeline' defaults to off for root */
3830 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3831 *(int *)varp = FALSE;
3832#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 /* May also set global value for local option. */
3834 if (both)
3835 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3836 *(int *)varp;
3837 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003838
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003839 /* The default value is not insecure. */
3840 flagsp = insecure_flag(opt_idx, opt_flags);
3841 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842 }
3843
3844#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003845 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846#endif
3847}
3848
3849/*
3850 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003851 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 */
3853 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003854set_options_default(
3855 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856{
3857 int i;
3858#ifdef FEAT_WINDOWS
3859 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003860 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861#endif
3862
3863 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003864 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003865#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003866 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003867 || (TRUE
3868# if defined(FEAT_MBYTE)
3869 && options[i].var != (char_u *)&p_enc
3870# endif
3871# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003872 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003873 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003874# endif
3875 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003876#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003877 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878 set_option_default(i, opt_flags, p_cp);
3879
3880#ifdef FEAT_WINDOWS
3881 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003882 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883 win_comp_scroll(wp);
3884#else
3885 win_comp_scroll(curwin);
3886#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003887#ifdef FEAT_CINDENT
3888 parse_cino(curbuf);
3889#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890}
3891
3892/*
3893 * Set the Vi-default value of a string option.
3894 * Used for 'sh', 'backupskip' and 'term'.
3895 */
3896 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003897set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898{
3899 char_u *p;
3900 int opt_idx;
3901
3902 p = vim_strsave(val);
3903 if (p != NULL) /* we don't want a NULL */
3904 {
3905 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003906 if (opt_idx >= 0)
3907 {
3908 if (options[opt_idx].flags & P_DEF_ALLOCED)
3909 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3910 options[opt_idx].def_val[VI_DEFAULT] = p;
3911 options[opt_idx].flags |= P_DEF_ALLOCED;
3912 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 }
3914}
3915
3916/*
3917 * Set the Vi-default value of a number option.
3918 * Used for 'lines' and 'columns'.
3919 */
3920 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003921set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003923 int opt_idx;
3924
3925 opt_idx = findoption((char_u *)name);
3926 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003927 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928}
3929
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003930#if defined(EXITFREE) || defined(PROTO)
3931/*
3932 * Free all options.
3933 */
3934 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003935free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003936{
3937 int i;
3938
3939 for (i = 0; !istermoption(&options[i]); i++)
3940 {
3941 if (options[i].indir == PV_NONE)
3942 {
3943 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003944 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003945 free_string_option(*(char_u **)options[i].var);
3946 if (options[i].flags & P_DEF_ALLOCED)
3947 free_string_option(options[i].def_val[VI_DEFAULT]);
3948 }
3949 else if (options[i].var != VAR_WIN
3950 && (options[i].flags & P_STRING))
3951 /* buffer-local option: free global value */
3952 free_string_option(*(char_u **)options[i].var);
3953 }
3954}
3955#endif
3956
3957
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958/*
3959 * Initialize the options, part two: After getting Rows and Columns and
3960 * setting 'term'.
3961 */
3962 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003963set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003965 int idx;
3966
Bram Moolenaar071d4272004-06-13 20:20:40 +00003967 /*
3968 * 'scroll' defaults to half the window height. Note that this default is
3969 * wrong when the window height changes.
3970 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003971 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003972 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003973 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003974 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 comp_col();
3976
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003977 /*
3978 * 'window' is only for backwards compatibility with Vi.
3979 * Default is Rows - 1.
3980 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003981 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003982 p_window = Rows - 1;
3983 set_number_default("window", Rows - 1);
3984
Bram Moolenaarf740b292006-02-16 22:11:02 +00003985 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003986#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003987 /*
3988 * If 'background' wasn't set by the user, try guessing the value,
3989 * depending on the terminal name. Only need to check for terminals
3990 * with a dark background, that can handle color.
3991 */
3992 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003993 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3994 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003996 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003997 /* don't mark it as set, when starting the GUI it may be
3998 * changed again */
3999 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 }
4001#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004002
4003#ifdef CURSOR_SHAPE
4004 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4005#endif
4006#ifdef FEAT_MOUSESHAPE
4007 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4008#endif
4009#ifdef FEAT_PRINTER
4010 (void)parse_printoptions(); /* parse 'printoptions' default value */
4011#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012}
4013
4014/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004015 * Return "dark" or "light" depending on the kind of terminal.
4016 * This is just guessing! Recognized are:
4017 * "linux" Linux console
4018 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004019 * "cygwin.*" Cygwin shell
4020 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004021 * We also check the COLORFGBG environment variable, which is set by
4022 * rxvt and derivatives. This variable contains either two or three
4023 * values separated by semicolons; we want the last value in either
4024 * case. If this value is 0-6 or 8, our background is dark.
4025 */
4026 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004027term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004028{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004029#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004030 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004031 return (char_u *)"dark";
4032#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004033 char_u *p;
4034
Bram Moolenaarf740b292006-02-16 22:11:02 +00004035 if (STRCMP(T_NAME, "linux") == 0
4036 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004037 || STRNCMP(T_NAME, "cygwin", 6) == 0
4038 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004039 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4040 && (p = vim_strrchr(p, ';')) != NULL
4041 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4042 && p[2] == NUL))
4043 return (char_u *)"dark";
4044 return (char_u *)"light";
4045#endif
4046}
4047
4048/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 * Initialize the options, part three: After reading the .vimrc
4050 */
4051 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004052set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055/*
4056 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4057 * This is done after other initializations, where 'shell' might have been
4058 * set, but only if they have not been set before.
4059 */
4060 char_u *p;
4061 int idx_srr;
4062 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004063# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 int idx_sp;
4065 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004066# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067
4068 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004069 if (idx_srr < 0)
4070 do_srr = FALSE;
4071 else
4072 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004075 if (idx_sp < 0)
4076 do_sp = FALSE;
4077 else
4078 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004080 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 if (p != NULL)
4082 {
4083 /*
4084 * Default for p_sp is "| tee", for p_srr is ">".
4085 * For known shells it is changed here to include stderr.
4086 */
4087 if ( fnamecmp(p, "csh") == 0
4088 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 || fnamecmp(p, "csh.exe") == 0
4091 || fnamecmp(p, "tcsh.exe") == 0
4092# endif
4093 )
4094 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004095# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 if (do_sp)
4097 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004100# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004102# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4104 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004105# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 if (do_srr)
4107 {
4108 p_srr = (char_u *)">&";
4109 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4110 }
4111 }
4112 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004113 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 if ( fnamecmp(p, "sh") == 0
4115 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004116 || fnamecmp(p, "mksh") == 0
4117 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004119 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004121 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004122# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 || fnamecmp(p, "cmd") == 0
4124 || fnamecmp(p, "sh.exe") == 0
4125 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004126 || fnamecmp(p, "mksh.exe") == 0
4127 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004129 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 || fnamecmp(p, "bash.exe") == 0
4131 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004133 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004135# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 if (do_sp)
4137 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004138# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004140# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004142# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4144 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004145# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 if (do_srr)
4147 {
4148 p_srr = (char_u *)">%s 2>&1";
4149 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4150 }
4151 }
4152 vim_free(p);
4153 }
4154#endif
4155
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004156#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004158 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4159 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 * This is done after other initializations, where 'shell' might have been
4161 * set, but only if they have not been set before. Default for p_shcf is
4162 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004163 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004165 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 {
4167 int idx3;
4168
4169 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004170 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 {
4172 p_shcf = (char_u *)"-c";
4173 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4174 }
4175
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 /* Somehow Win32 requires the quotes around the redirection too */
4177 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004178 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 {
4180 p_sxq = (char_u *)"\"";
4181 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004184 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4185 {
4186 int idx3;
4187
4188 /*
4189 * cmd.exe on Windows will strip the first and last double quote given
4190 * on the command line, e.g. most of the time things like:
4191 * cmd /c "my path/to/echo" "my args to echo"
4192 * become:
4193 * my path/to/echo" "my args to echo
4194 * when executed.
4195 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004196 * To avoid this, set shellxquote to surround the command in
4197 * parenthesis. This appears to make most commands work, without
4198 * breaking commands that worked previously, such as
4199 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004200 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004201 idx3 = findoption((char_u *)"sxq");
4202 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4203 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004204 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004205 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4206 }
4207
Bram Moolenaara64ba222012-02-12 23:23:31 +01004208 idx3 = findoption((char_u *)"shcf");
4209 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4210 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004211 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004212 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4213 }
4214 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215#endif
4216
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004217 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004218 {
4219 int idx_ffs = findoption((char_u *)"ffs");
4220
4221 /* Apply the first entry of 'fileformats' to the initial buffer. */
4222 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4223 set_fileformat(default_fileformat(), OPT_LOCAL);
4224 }
4225
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226#ifdef FEAT_TITLE
4227 set_title_defaults();
4228#endif
4229}
4230
4231#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4232/*
4233 * When 'helplang' is still at its default value, set it to "lang".
4234 * Only the first two characters of "lang" are used.
4235 */
4236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004237set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238{
4239 int idx;
4240
4241 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4242 return;
4243 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004244 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004245 {
4246 if (options[idx].flags & P_ALLOCED)
4247 free_string_option(p_hlg);
4248 p_hlg = vim_strsave(lang);
4249 if (p_hlg == NULL)
4250 p_hlg = empty_option;
4251 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004252 {
4253 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4254 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4255 {
4256 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4257 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4258 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004260 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004261 options[idx].flags |= P_ALLOCED;
4262 }
4263}
4264#endif
4265
4266#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004267static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268
4269 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004270gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004271{
4272 if (gui_get_lightness(gui.back_pixel) < 127)
4273 return (char_u *)"dark";
4274 return (char_u *)"light";
4275}
4276
4277/*
4278 * Option initializations that can only be done after opening the GUI window.
4279 */
4280 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004281init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282{
4283 /* Set the 'background' option according to the lightness of the
4284 * background color, unless the user has set it already. */
4285 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4286 {
4287 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4288 highlight_changed();
4289 }
4290}
4291#endif
4292
4293#ifdef FEAT_TITLE
4294/*
4295 * 'title' and 'icon' only default to true if they have not been set or reset
4296 * in .vimrc and we can read the old value.
4297 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4298 * they can be reset. This reduces startup time when using X on a remote
4299 * machine.
4300 */
4301 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004302set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303{
4304 int idx1;
4305 long val;
4306
4307 /*
4308 * If GUI is (going to be) used, we can always set the window title and
4309 * icon name. Saves a bit of time, because the X11 display server does
4310 * not need to be contacted.
4311 */
4312 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004313 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314 {
4315#ifdef FEAT_GUI
4316 if (gui.starting || gui.in_use)
4317 val = TRUE;
4318 else
4319#endif
4320 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004321 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004322 p_title = val;
4323 }
4324 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004325 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004326 {
4327#ifdef FEAT_GUI
4328 if (gui.starting || gui.in_use)
4329 val = TRUE;
4330 else
4331#endif
4332 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004333 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 p_icon = val;
4335 }
4336}
4337#endif
4338
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004339#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4340 static void
4341trigger_optionsset_string(
4342 int opt_idx,
4343 int opt_flags,
4344 char_u *oldval,
4345 char_u *newval)
4346{
4347 if (oldval != NULL && newval != NULL)
4348 {
4349 char_u buf_type[7];
4350
4351 sprintf((char *)buf_type, "%s",
4352 (opt_flags & OPT_LOCAL) ? "local" : "global");
4353 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4354 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4355 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4356 apply_autocmds(EVENT_OPTIONSET,
4357 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4358 reset_v_option_vars();
4359 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004360}
4361#endif
4362
Bram Moolenaar071d4272004-06-13 20:20:40 +00004363/*
4364 * Parse 'arg' for option settings.
4365 *
4366 * 'arg' may be IObuff, but only when no errors can be present and option
4367 * does not need to be expanded with option_expand().
4368 * "opt_flags":
4369 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004370 * OPT_GLOBAL for ":setglobal"
4371 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004372 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004373 * OPT_WINONLY to only set window-local options
4374 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 *
4376 * returns FAIL if an error is detected, OK otherwise
4377 */
4378 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004379do_set(
4380 char_u *arg, /* option string (may be written to!) */
4381 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382{
4383 int opt_idx;
4384 char_u *errmsg;
4385 char_u errbuf[80];
4386 char_u *startarg;
4387 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4388 int nextchar; /* next non-white char after option name */
4389 int afterchar; /* character just after option name */
4390 int len;
4391 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004392 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004393 int key;
4394 long_u flags; /* flags for current option */
4395 char_u *varp = NULL; /* pointer to variable for current option */
4396 int did_show = FALSE; /* already showed one value */
4397 int adding; /* "opt+=arg" */
4398 int prepending; /* "opt^=arg" */
4399 int removing; /* "opt-=arg" */
4400 int cp_val = 0;
4401 char_u key_name[2];
4402
4403 if (*arg == NUL)
4404 {
4405 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004406 did_show = TRUE;
4407 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
4409
4410 while (*arg != NUL) /* loop to process all options */
4411 {
4412 errmsg = NULL;
4413 startarg = arg; /* remember for error message */
4414
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004415 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4416 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004417 {
4418 /*
4419 * ":set all" show all options.
4420 * ":set all&" set all options to their default value.
4421 */
4422 arg += 3;
4423 if (*arg == '&')
4424 {
4425 ++arg;
4426 /* Only for :set command set global value of local options. */
4427 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004428 didset_options();
4429 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004430 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004431 }
4432 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004433 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004434 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004435 did_show = TRUE;
4436 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004438 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439 {
4440 showoptions(2, opt_flags);
4441 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004442 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004443 arg += 7;
4444 }
4445 else
4446 {
4447 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004448 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004449 {
4450 prefix = 0;
4451 arg += 2;
4452 }
4453 else if (STRNCMP(arg, "inv", 3) == 0)
4454 {
4455 prefix = 2;
4456 arg += 3;
4457 }
4458
4459 /* find end of name */
4460 key = 0;
4461 if (*arg == '<')
4462 {
4463 nextchar = 0;
4464 opt_idx = -1;
4465 /* look out for <t_>;> */
4466 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4467 len = 5;
4468 else
4469 {
4470 len = 1;
4471 while (arg[len] != NUL && arg[len] != '>')
4472 ++len;
4473 }
4474 if (arg[len] != '>')
4475 {
4476 errmsg = e_invarg;
4477 goto skip;
4478 }
4479 arg[len] = NUL; /* put NUL after name */
4480 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4481 opt_idx = findoption(arg + 1);
4482 arg[len++] = '>'; /* restore '>' */
4483 if (opt_idx == -1)
4484 key = find_key_option(arg + 1);
4485 }
4486 else
4487 {
4488 len = 0;
4489 /*
4490 * The two characters after "t_" may not be alphanumeric.
4491 */
4492 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4493 len = 4;
4494 else
4495 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4496 ++len;
4497 nextchar = arg[len];
4498 arg[len] = NUL; /* put NUL after name */
4499 opt_idx = findoption(arg);
4500 arg[len] = nextchar; /* restore nextchar */
4501 if (opt_idx == -1)
4502 key = find_key_option(arg);
4503 }
4504
4505 /* remember character after option name */
4506 afterchar = arg[len];
4507
4508 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004509 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004510 ++len;
4511
4512 adding = FALSE;
4513 prepending = FALSE;
4514 removing = FALSE;
4515 if (arg[len] != NUL && arg[len + 1] == '=')
4516 {
4517 if (arg[len] == '+')
4518 {
4519 adding = TRUE; /* "+=" */
4520 ++len;
4521 }
4522 else if (arg[len] == '^')
4523 {
4524 prepending = TRUE; /* "^=" */
4525 ++len;
4526 }
4527 else if (arg[len] == '-')
4528 {
4529 removing = TRUE; /* "-=" */
4530 ++len;
4531 }
4532 }
4533 nextchar = arg[len];
4534
4535 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4536 {
4537 errmsg = (char_u *)N_("E518: Unknown option");
4538 goto skip;
4539 }
4540
4541 if (opt_idx >= 0)
4542 {
4543 if (options[opt_idx].var == NULL) /* hidden option: skip */
4544 {
4545 /* Only give an error message when requesting the value of
4546 * a hidden option, ignore setting it. */
4547 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4548 && (!(options[opt_idx].flags & P_BOOL)
4549 || nextchar == '?'))
4550 errmsg = (char_u *)N_("E519: Option not supported");
4551 goto skip;
4552 }
4553
4554 flags = options[opt_idx].flags;
4555 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4556 }
4557 else
4558 {
4559 flags = P_STRING;
4560 if (key < 0)
4561 {
4562 key_name[0] = KEY2TERMCAP0(key);
4563 key_name[1] = KEY2TERMCAP1(key);
4564 }
4565 else
4566 {
4567 key_name[0] = KS_KEY;
4568 key_name[1] = (key & 0xff);
4569 }
4570 }
4571
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004572 /* Skip all options that are not window-local (used when showing
4573 * an already loaded buffer in a window). */
4574 if ((opt_flags & OPT_WINONLY)
4575 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4576 goto skip;
4577
Bram Moolenaara3227e22006-03-08 21:32:40 +00004578 /* Skip all options that are window-local (used for :vimgrep). */
4579 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4580 && options[opt_idx].var == VAR_WIN)
4581 goto skip;
4582
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004583 /* Disallow changing some options from modelines. */
4584 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004585 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004586 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004587 {
4588 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4589 goto skip;
4590 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004591#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004592 /* In diff mode some options are overruled. This avoids that
4593 * 'foldmethod' becomes "marker" instead of "diff" and that
4594 * "wrap" gets set. */
4595 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004596 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004597 && (
4598#ifdef FEAT_FOLDING
4599 options[opt_idx].indir == PV_FDM ||
4600#endif
4601 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004602 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004603#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 }
4605
4606#ifdef HAVE_SANDBOX
4607 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004608 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004609 {
4610 errmsg = (char_u *)_(e_sandbox);
4611 goto skip;
4612 }
4613#endif
4614
4615 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4616 {
4617 arg += len;
4618 cp_val = p_cp;
4619 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4620 {
4621 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4622 {
4623 cp_val = FALSE;
4624 arg += 3;
4625 }
4626 else /* "opt&vi": set to Vi default */
4627 {
4628 cp_val = TRUE;
4629 arg += 2;
4630 }
4631 }
4632 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004633 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004634 {
4635 errmsg = e_trailing;
4636 goto skip;
4637 }
4638 }
4639
4640 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004641 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4642 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004643 */
4644 if (nextchar == '?'
4645 || (prefix == 1
4646 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4647 && !(flags & P_BOOL)))
4648 {
4649 /*
4650 * print value
4651 */
4652 if (did_show)
4653 msg_putchar('\n'); /* cursor below last one */
4654 else
4655 {
4656 gotocmdline(TRUE); /* cursor at status line */
4657 did_show = TRUE; /* remember that we did a line */
4658 }
4659 if (opt_idx >= 0)
4660 {
4661 showoneopt(&options[opt_idx], opt_flags);
4662#ifdef FEAT_EVAL
4663 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004664 {
4665 /* Mention where the option was last set. */
4666 if (varp == options[opt_idx].var)
4667 last_set_msg(options[opt_idx].scriptID);
4668 else if ((int)options[opt_idx].indir & PV_WIN)
4669 last_set_msg(curwin->w_p_scriptID[
4670 (int)options[opt_idx].indir & PV_MASK]);
4671 else if ((int)options[opt_idx].indir & PV_BUF)
4672 last_set_msg(curbuf->b_p_scriptID[
4673 (int)options[opt_idx].indir & PV_MASK]);
4674 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004675#endif
4676 }
4677 else
4678 {
4679 char_u *p;
4680
4681 p = find_termcode(key_name);
4682 if (p == NULL)
4683 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004684 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004685 goto skip;
4686 }
4687 else
4688 (void)show_one_termcode(key_name, p, TRUE);
4689 }
4690 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004691 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004692 errmsg = e_trailing;
4693 }
4694 else
4695 {
4696 if (flags & P_BOOL) /* boolean */
4697 {
4698 if (nextchar == '=' || nextchar == ':')
4699 {
4700 errmsg = e_invarg;
4701 goto skip;
4702 }
4703
4704 /*
4705 * ":set opt!": invert
4706 * ":set opt&": reset to default value
4707 * ":set opt<": reset to global value
4708 */
4709 if (nextchar == '!')
4710 value = *(int *)(varp) ^ 1;
4711 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004712 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004713 ((flags & P_VI_DEF) || cp_val)
4714 ? VI_DEFAULT : VIM_DEFAULT];
4715 else if (nextchar == '<')
4716 {
4717 /* For 'autoread' -1 means to use global value. */
4718 if ((int *)varp == &curbuf->b_p_ar
4719 && opt_flags == OPT_LOCAL)
4720 value = -1;
4721 else
4722 value = *(int *)get_varp_scope(&(options[opt_idx]),
4723 OPT_GLOBAL);
4724 }
4725 else
4726 {
4727 /*
4728 * ":set invopt": invert
4729 * ":set opt" or ":set noopt": set or reset
4730 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004731 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004732 {
4733 errmsg = e_trailing;
4734 goto skip;
4735 }
4736 if (prefix == 2) /* inv */
4737 value = *(int *)(varp) ^ 1;
4738 else
4739 value = prefix;
4740 }
4741
4742 errmsg = set_bool_option(opt_idx, varp, (int)value,
4743 opt_flags);
4744 }
4745 else /* numeric or string */
4746 {
4747 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4748 || prefix != 1)
4749 {
4750 errmsg = e_invarg;
4751 goto skip;
4752 }
4753
4754 if (flags & P_NUM) /* numeric */
4755 {
4756 /*
4757 * Different ways to set a number option:
4758 * & set to default value
4759 * < set to global value
4760 * <xx> accept special key codes for 'wildchar'
4761 * c accept any non-digit for 'wildchar'
4762 * [-]0-9 set number
4763 * other error
4764 */
4765 ++arg;
4766 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004767 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004768 ((flags & P_VI_DEF) || cp_val)
4769 ? VI_DEFAULT : VIM_DEFAULT];
4770 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004771 {
4772 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4773 * use the global value. */
4774 if ((long *)varp == &curbuf->b_p_ul
4775 && opt_flags == OPT_LOCAL)
4776 value = NO_LOCAL_UNDOLEVEL;
4777 else
4778 value = *(long *)get_varp_scope(
4779 &(options[opt_idx]), OPT_GLOBAL);
4780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004781 else if (((long *)varp == &p_wc
4782 || (long *)varp == &p_wcm)
4783 && (*arg == '<'
4784 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004785 || (*arg != NUL
4786 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004787 && !VIM_ISDIGIT(*arg))))
4788 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004789 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004790 if (value == 0 && (long *)varp != &p_wcm)
4791 {
4792 errmsg = e_invarg;
4793 goto skip;
4794 }
4795 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004796 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4797 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004798 /* Allow negative (for 'undolevels'), octal and
4799 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004800 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4801 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004802 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004803 {
4804 errmsg = e_invarg;
4805 goto skip;
4806 }
4807 }
4808 else
4809 {
4810 errmsg = (char_u *)N_("E521: Number required after =");
4811 goto skip;
4812 }
4813
4814 if (adding)
4815 value = *(long *)varp + value;
4816 if (prepending)
4817 value = *(long *)varp * value;
4818 if (removing)
4819 value = *(long *)varp - value;
4820 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004821 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 }
4823 else if (opt_idx >= 0) /* string */
4824 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004825 char_u *save_arg = NULL;
4826 char_u *s = NULL;
4827 char_u *oldval = NULL; /* previous value if *varp */
4828 char_u *newval;
4829 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004830#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004831 char_u *saved_origval = NULL;
4832 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004833#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004834 unsigned newlen;
4835 int comma;
4836 int bs;
4837 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004838 was allocated */
4839
4840 /* When using ":set opt=val" for a global option
4841 * with a local value the local value will be
4842 * reset, use the global value here. */
4843 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004844 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004845 varp = options[opt_idx].var;
4846
4847 /* The old value is kept until we are sure that the
4848 * new value is valid. */
4849 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004850
4851 /* When setting the local value of a global
4852 * option, the old value may be the global value. */
4853 if (((int)options[opt_idx].indir & PV_BOTH)
4854 && (opt_flags & OPT_LOCAL))
4855 origval = *(char_u **)get_varp(
4856 &options[opt_idx]);
4857 else
4858 origval = oldval;
4859
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 if (nextchar == '&') /* set to default val */
4861 {
4862 newval = options[opt_idx].def_val[
4863 ((flags & P_VI_DEF) || cp_val)
4864 ? VI_DEFAULT : VIM_DEFAULT];
4865 if ((char_u **)varp == &p_bg)
4866 {
4867 /* guess the value of 'background' */
4868#ifdef FEAT_GUI
4869 if (gui.in_use)
4870 newval = gui_bg_default();
4871 else
4872#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004873 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004874 }
4875
4876 /* expand environment variables and ~ (since the
4877 * default value was already expanded, only
4878 * required when an environment variable was set
4879 * later */
4880 if (newval == NULL)
4881 newval = empty_option;
4882 else
4883 {
4884 s = option_expand(opt_idx, newval);
4885 if (s == NULL)
4886 s = newval;
4887 newval = vim_strsave(s);
4888 }
4889 new_value_alloced = TRUE;
4890 }
4891 else if (nextchar == '<') /* set to global val */
4892 {
4893 newval = vim_strsave(*(char_u **)get_varp_scope(
4894 &(options[opt_idx]), OPT_GLOBAL));
4895 new_value_alloced = TRUE;
4896 }
4897 else
4898 {
4899 ++arg; /* jump to after the '=' or ':' */
4900
4901 /*
4902 * Set 'keywordprg' to ":help" if an empty
4903 * value was passed to :set by the user.
4904 * Misuse errbuf[] for the resulting string.
4905 */
4906 if (varp == (char_u *)&p_kp
4907 && (*arg == NUL || *arg == ' '))
4908 {
4909 STRCPY(errbuf, ":help");
4910 save_arg = arg;
4911 arg = errbuf;
4912 }
4913 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004914 * Convert 'backspace' number to string, for
4915 * adding, prepending and removing string.
4916 */
4917 else if (varp == (char_u *)&p_bs
4918 && VIM_ISDIGIT(**(char_u **)varp))
4919 {
4920 i = getdigits((char_u **)varp);
4921 switch (i)
4922 {
4923 case 0:
4924 *(char_u **)varp = empty_option;
4925 break;
4926 case 1:
4927 *(char_u **)varp = vim_strsave(
4928 (char_u *)"indent,eol");
4929 break;
4930 case 2:
4931 *(char_u **)varp = vim_strsave(
4932 (char_u *)"indent,eol,start");
4933 break;
4934 }
4935 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004936 if (origval == oldval)
4937 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004938 oldval = *(char_u **)varp;
4939 }
4940 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004941 * Convert 'whichwrap' number to string, for
4942 * backwards compatibility with Vim 3.0.
4943 * Misuse errbuf[] for the resulting string.
4944 */
4945 else if (varp == (char_u *)&p_ww
4946 && VIM_ISDIGIT(*arg))
4947 {
4948 *errbuf = NUL;
4949 i = getdigits(&arg);
4950 if (i & 1)
4951 STRCAT(errbuf, "b,");
4952 if (i & 2)
4953 STRCAT(errbuf, "s,");
4954 if (i & 4)
4955 STRCAT(errbuf, "h,l,");
4956 if (i & 8)
4957 STRCAT(errbuf, "<,>,");
4958 if (i & 16)
4959 STRCAT(errbuf, "[,],");
4960 if (*errbuf != NUL) /* remove trailing , */
4961 errbuf[STRLEN(errbuf) - 1] = NUL;
4962 save_arg = arg;
4963 arg = errbuf;
4964 }
4965 /*
4966 * Remove '>' before 'dir' and 'bdir', for
4967 * backwards compatibility with version 3.0
4968 */
4969 else if ( *arg == '>'
4970 && (varp == (char_u *)&p_dir
4971 || varp == (char_u *)&p_bdir))
4972 {
4973 ++arg;
4974 }
4975
Bram Moolenaar071d4272004-06-13 20:20:40 +00004976 /*
4977 * Copy the new string into allocated memory.
4978 * Can't use set_string_option_direct(), because
4979 * we need to remove the backslashes.
4980 */
4981 /* get a bit too much */
4982 newlen = (unsigned)STRLEN(arg) + 1;
4983 if (adding || prepending || removing)
4984 newlen += (unsigned)STRLEN(origval) + 1;
4985 newval = alloc(newlen);
4986 if (newval == NULL) /* out of mem, don't change */
4987 break;
4988 s = newval;
4989
4990 /*
4991 * Copy the string, skip over escaped chars.
4992 * For MS-DOS and WIN32 backslashes before normal
4993 * file name characters are not removed, and keep
4994 * backslash at start, for "\\machine\path", but
4995 * do remove it for "\\\\machine\\path".
4996 * The reverse is found in ExpandOldSetting().
4997 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004998 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004999 {
5000 if (*arg == '\\' && arg[1] != NUL
5001#ifdef BACKSLASH_IN_FILENAME
5002 && !((flags & P_EXPAND)
5003 && vim_isfilec(arg[1])
5004 && (arg[1] != '\\'
5005 || (s == newval
5006 && arg[2] != '\\')))
5007#endif
5008 )
5009 ++arg; /* remove backslash */
5010#ifdef FEAT_MBYTE
5011 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005012 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005013 {
5014 /* copy multibyte char */
5015 mch_memmove(s, arg, (size_t)i);
5016 arg += i;
5017 s += i;
5018 }
5019 else
5020#endif
5021 *s++ = *arg++;
5022 }
5023 *s = NUL;
5024
5025 /*
5026 * Expand environment variables and ~.
5027 * Don't do it when adding without inserting a
5028 * comma.
5029 */
5030 if (!(adding || prepending || removing)
5031 || (flags & P_COMMA))
5032 {
5033 s = option_expand(opt_idx, newval);
5034 if (s != NULL)
5035 {
5036 vim_free(newval);
5037 newlen = (unsigned)STRLEN(s) + 1;
5038 if (adding || prepending || removing)
5039 newlen += (unsigned)STRLEN(origval) + 1;
5040 newval = alloc(newlen);
5041 if (newval == NULL)
5042 break;
5043 STRCPY(newval, s);
5044 }
5045 }
5046
5047 /* locate newval[] in origval[] when removing it
5048 * and when adding to avoid duplicates */
5049 i = 0; /* init for GCC */
5050 if (removing || (flags & P_NODUP))
5051 {
5052 i = (int)STRLEN(newval);
5053 bs = 0;
5054 for (s = origval; *s; ++s)
5055 {
5056 if ((!(flags & P_COMMA)
5057 || s == origval
5058 || (s[-1] == ',' && !(bs & 1)))
5059 && STRNCMP(s, newval, i) == 0
5060 && (!(flags & P_COMMA)
5061 || s[i] == ','
5062 || s[i] == NUL))
5063 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005064 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005065 * even number of backslashes or a single
5066 * backslash preceded by a comma before it
5067 * is recognized as a separator */
5068 if ((s > origval + 1
5069 && s[-1] == '\\'
5070 && s[-2] != ',')
5071 || (s == origval + 1
5072 && s[-1] == '\\'))
5073
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 ++bs;
5075 else
5076 bs = 0;
5077 }
5078
5079 /* do not add if already there */
5080 if ((adding || prepending) && *s)
5081 {
5082 prepending = FALSE;
5083 adding = FALSE;
5084 STRCPY(newval, origval);
5085 }
5086 }
5087
5088 /* concatenate the two strings; add a ',' if
5089 * needed */
5090 if (adding || prepending)
5091 {
5092 comma = ((flags & P_COMMA) && *origval != NUL
5093 && *newval != NUL);
5094 if (adding)
5095 {
5096 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005097 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005098 if (comma && i > 1
5099 && (flags & P_ONECOMMA) == P_ONECOMMA
5100 && origval[i - 1] == ','
5101 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005102 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005103 mch_memmove(newval + i + comma, newval,
5104 STRLEN(newval) + 1);
5105 mch_memmove(newval, origval, (size_t)i);
5106 }
5107 else
5108 {
5109 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005110 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 }
5112 if (comma)
5113 newval[i] = ',';
5114 }
5115
5116 /* Remove newval[] from origval[]. (Note: "i" has
5117 * been set above and is used here). */
5118 if (removing)
5119 {
5120 STRCPY(newval, origval);
5121 if (*s)
5122 {
5123 /* may need to remove a comma */
5124 if (flags & P_COMMA)
5125 {
5126 if (s == origval)
5127 {
5128 /* include comma after string */
5129 if (s[i] == ',')
5130 ++i;
5131 }
5132 else
5133 {
5134 /* include comma before string */
5135 --s;
5136 ++i;
5137 }
5138 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005139 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005140 }
5141 }
5142
5143 if (flags & P_FLAGLIST)
5144 {
5145 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005146 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005147 {
5148 /* if options have P_FLAGLIST and
5149 * P_ONECOMMA such as 'whichwrap' */
5150 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005151 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005152 if (*s != ',' && *(s + 1) == ','
5153 && vim_strchr(s + 2, *s) != NULL)
5154 {
5155 /* Remove the duplicated value and
5156 * the next comma. */
5157 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005158 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005159 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005160 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005161 else
5162 {
5163 if ((!(flags & P_COMMA) || *s != ',')
5164 && vim_strchr(s + 1, *s) != NULL)
5165 {
5166 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005167 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005168 }
5169 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005170 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005171 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005172 }
5173
5174 if (save_arg != NULL) /* number for 'whichwrap' */
5175 arg = save_arg;
5176 new_value_alloced = TRUE;
5177 }
5178
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005179 /*
5180 * Set the new value.
5181 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182 *(char_u **)(varp) = newval;
5183
Bram Moolenaar53744302015-07-17 17:38:22 +02005184#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005185 if (!starting
5186# ifdef FEAT_CRYPT
5187 && options[opt_idx].indir != PV_KEY
5188# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005189 && origval != NULL && newval != NULL)
5190 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005191 /* origval may be freed by
5192 * did_set_string_option(), make a copy. */
5193 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005194 /* newval (and varp) may become invalid if the
5195 * buffer is closed by autocommands. */
5196 saved_newval = vim_strsave(newval);
5197 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005198#endif
5199
Bram Moolenaar071d4272004-06-13 20:20:40 +00005200 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005201 * ":set" on local options. Note: when setting 'syntax'
5202 * or 'filetype' autocommands may be triggered that can
5203 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005204 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5205 new_value_alloced, oldval, errbuf, opt_flags);
5206
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005207#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5208 if (errmsg == NULL)
5209 trigger_optionsset_string(opt_idx, opt_flags,
5210 saved_origval, saved_newval);
5211 vim_free(saved_origval);
5212 vim_free(saved_newval);
5213#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005214 /* If error detected, print the error message. */
5215 if (errmsg != NULL)
5216 goto skip;
5217 }
5218 else /* key code option */
5219 {
5220 char_u *p;
5221
5222 if (nextchar == '&')
5223 {
5224 if (add_termcap_entry(key_name, TRUE) == FAIL)
5225 errmsg = (char_u *)N_("E522: Not found in termcap");
5226 }
5227 else
5228 {
5229 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005230 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005231 if (*p == '\\' && p[1] != NUL)
5232 ++p;
5233 nextchar = *p;
5234 *p = NUL;
5235 add_termcode(key_name, arg, FALSE);
5236 *p = nextchar;
5237 }
5238 if (full_screen)
5239 ttest(FALSE);
5240 redraw_all_later(CLEAR);
5241 }
5242 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005243
Bram Moolenaar071d4272004-06-13 20:20:40 +00005244 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005245 did_set_option(opt_idx, opt_flags,
5246 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005247 }
5248
5249skip:
5250 /*
5251 * Advance to next argument.
5252 * - skip until a blank found, taking care of backslashes
5253 * - skip blanks
5254 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5255 */
5256 for (i = 0; i < 2 ; ++i)
5257 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005258 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005259 if (*arg++ == '\\' && *arg != NUL)
5260 ++arg;
5261 arg = skipwhite(arg);
5262 if (*arg != '=')
5263 break;
5264 }
5265 }
5266
5267 if (errmsg != NULL)
5268 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005269 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005270 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005271 if (i + (arg - startarg) < IOSIZE)
5272 {
5273 /* append the argument with the error */
5274 STRCAT(IObuff, ": ");
5275 mch_memmove(IObuff + i, startarg, (arg - startarg));
5276 IObuff[i + (arg - startarg)] = NUL;
5277 }
5278 /* make sure all characters are printable */
5279 trans_characters(IObuff, IOSIZE);
5280
5281 ++no_wait_return; /* wait_return done later */
5282 emsg(IObuff); /* show error highlighted */
5283 --no_wait_return;
5284
5285 return FAIL;
5286 }
5287
5288 arg = skipwhite(arg);
5289 }
5290
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005291theend:
5292 if (silent_mode && did_show)
5293 {
5294 /* After displaying option values in silent mode. */
5295 silent_mode = FALSE;
5296 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5297 msg_putchar('\n');
5298 cursor_on(); /* msg_start() switches it off */
5299 out_flush();
5300 silent_mode = TRUE;
5301 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5302 }
5303
Bram Moolenaar071d4272004-06-13 20:20:40 +00005304 return OK;
5305}
5306
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005307/*
5308 * Call this when an option has been given a new value through a user command.
5309 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5310 */
5311 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005312did_set_option(
5313 int opt_idx,
5314 int opt_flags, /* possibly with OPT_MODELINE */
5315 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005316{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005317 long_u *p;
5318
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005319 options[opt_idx].flags |= P_WAS_SET;
5320
5321 /* When an option is set in the sandbox, from a modeline or in secure mode
5322 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005323 * flag. */
5324 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005325 if (secure
5326#ifdef HAVE_SANDBOX
5327 || sandbox != 0
5328#endif
5329 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005330 *p = *p | P_INSECURE;
5331 else if (new_value)
5332 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005333}
5334
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005336illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337{
5338 if (errbuf == NULL)
5339 return (char_u *)"";
5340 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005341 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005342 return errbuf;
5343}
5344
5345/*
5346 * Convert a key name or string into a key value.
5347 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005348 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005350 int
5351string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352{
5353 if (*arg == '<')
5354 return find_key_option(arg + 1);
5355 if (*arg == '^')
5356 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005357 if (multi_byte)
5358 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359 return *arg;
5360}
5361
5362#ifdef FEAT_CMDWIN
5363/*
5364 * Check value of 'cedit' and set cedit_key.
5365 * Returns NULL if value is OK, error message otherwise.
5366 */
5367 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005368check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369{
5370 int n;
5371
5372 if (*p_cedit == NUL)
5373 cedit_key = -1;
5374 else
5375 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005376 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377 if (vim_isprintc(n))
5378 return e_invarg;
5379 cedit_key = n;
5380 }
5381 return NULL;
5382}
5383#endif
5384
5385#ifdef FEAT_TITLE
5386/*
5387 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5388 * maketitle() to create and display it.
5389 * When switching the title or icon off, call mch_restore_title() to get
5390 * the old value back.
5391 */
5392 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005393did_set_title(
5394 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395{
5396 if (starting != NO_SCREEN
5397#ifdef FEAT_GUI
5398 && !gui.starting
5399#endif
5400 )
5401 {
5402 maketitle();
5403 if (icon)
5404 {
5405 if (!p_icon)
5406 mch_restore_title(2);
5407 }
5408 else
5409 {
5410 if (!p_title)
5411 mch_restore_title(1);
5412 }
5413 }
5414}
5415#endif
5416
5417/*
5418 * set_options_bin - called when 'bin' changes value.
5419 */
5420 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005421set_options_bin(
5422 int oldval,
5423 int newval,
5424 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005425{
5426 /*
5427 * The option values that are changed when 'bin' changes are
5428 * copied when 'bin is set and restored when 'bin' is reset.
5429 */
5430 if (newval)
5431 {
5432 if (!oldval) /* switched on */
5433 {
5434 if (!(opt_flags & OPT_GLOBAL))
5435 {
5436 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5437 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5438 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5439 curbuf->b_p_et_nobin = curbuf->b_p_et;
5440 }
5441 if (!(opt_flags & OPT_LOCAL))
5442 {
5443 p_tw_nobin = p_tw;
5444 p_wm_nobin = p_wm;
5445 p_ml_nobin = p_ml;
5446 p_et_nobin = p_et;
5447 }
5448 }
5449
5450 if (!(opt_flags & OPT_GLOBAL))
5451 {
5452 curbuf->b_p_tw = 0; /* no automatic line wrap */
5453 curbuf->b_p_wm = 0; /* no automatic line wrap */
5454 curbuf->b_p_ml = 0; /* no modelines */
5455 curbuf->b_p_et = 0; /* no expandtab */
5456 }
5457 if (!(opt_flags & OPT_LOCAL))
5458 {
5459 p_tw = 0;
5460 p_wm = 0;
5461 p_ml = FALSE;
5462 p_et = FALSE;
5463 p_bin = TRUE; /* needed when called for the "-b" argument */
5464 }
5465 }
5466 else if (oldval) /* switched off */
5467 {
5468 if (!(opt_flags & OPT_GLOBAL))
5469 {
5470 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5471 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5472 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5473 curbuf->b_p_et = curbuf->b_p_et_nobin;
5474 }
5475 if (!(opt_flags & OPT_LOCAL))
5476 {
5477 p_tw = p_tw_nobin;
5478 p_wm = p_wm_nobin;
5479 p_ml = p_ml_nobin;
5480 p_et = p_et_nobin;
5481 }
5482 }
5483}
5484
5485#ifdef FEAT_VIMINFO
5486/*
5487 * Find the parameter represented by the given character (eg ', :, ", or /),
5488 * and return its associated value in the 'viminfo' string.
5489 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005490 * If the parameter is not specified in the string or there is no following
5491 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492 */
5493 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005494get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495{
5496 char_u *p;
5497
5498 p = find_viminfo_parameter(type);
5499 if (p != NULL && VIM_ISDIGIT(*p))
5500 return atoi((char *)p);
5501 return -1;
5502}
5503
5504/*
5505 * Find the parameter represented by the given character (eg ''', ':', '"', or
5506 * '/') in the 'viminfo' option and return a pointer to the string after it.
5507 * Return NULL if the parameter is not specified in the string.
5508 */
5509 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005510find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511{
5512 char_u *p;
5513
5514 for (p = p_viminfo; *p; ++p)
5515 {
5516 if (*p == type)
5517 return p + 1;
5518 if (*p == 'n') /* 'n' is always the last one */
5519 break;
5520 p = vim_strchr(p, ','); /* skip until next ',' */
5521 if (p == NULL) /* hit the end without finding parameter */
5522 break;
5523 }
5524 return NULL;
5525}
5526#endif
5527
5528/*
5529 * Expand environment variables for some string options.
5530 * These string options cannot be indirect!
5531 * If "val" is NULL expand the current value of the option.
5532 * Return pointer to NameBuff, or NULL when not expanded.
5533 */
5534 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005535option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536{
5537 /* if option doesn't need expansion nothing to do */
5538 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5539 return NULL;
5540
5541 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5542 * expand_env() would truncate the string. */
5543 if (val != NULL && STRLEN(val) > MAXPATHL)
5544 return NULL;
5545
5546 if (val == NULL)
5547 val = *(char_u **)options[opt_idx].var;
5548
5549 /*
5550 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5551 * Escape spaces when expanding 'tags', they are used to separate file
5552 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005553 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554 */
5555 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005556 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005557#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005558 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5559#endif
5560 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005561 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5562 return NULL;
5563
5564 return NameBuff;
5565}
5566
5567/*
5568 * After setting various option values: recompute variables that depend on
5569 * option values.
5570 */
5571 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005572didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573{
5574 /* initialize the table for 'iskeyword' et.al. */
5575 (void)init_chartab();
5576
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005577#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005579#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005580 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005581 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582#ifdef FEAT_SESSION
5583 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5584 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5585#endif
5586#ifdef FEAT_FOLDING
5587 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5588#endif
5589 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005590 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591#ifdef FEAT_VIRTUALEDIT
5592 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5593#endif
5594#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5595 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5596#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005597#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005598 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005599 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005600 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005601 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005603#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5604 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5605#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005606#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5608#endif
5609#ifdef FEAT_CMDWIN
5610 /* set cedit_key */
5611 (void)check_cedit();
5612#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005613#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005614 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005615#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005616#ifdef FEAT_LINEBREAK
5617 /* initialize the table for 'breakat'. */
5618 fill_breakat_flags();
5619#endif
5620
5621}
5622
5623/*
5624 * More side effects of setting options.
5625 */
5626 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005627didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005628{
5629 /* Initialize the highlight_attr[] table. */
5630 (void)highlight_changed();
5631
5632 /* Parse default for 'wildmode' */
5633 check_opt_wim();
5634
5635 (void)set_chars_option(&p_lcs);
5636#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5637 /* Parse default for 'fillchars'. */
5638 (void)set_chars_option(&p_fcs);
5639#endif
5640
5641#ifdef FEAT_CLIPBOARD
5642 /* Parse default for 'clipboard' */
5643 (void)check_clipboard_option();
5644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645}
5646
5647/*
5648 * Check for string options that are NULL (normally only termcap options).
5649 */
5650 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005651check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652{
5653 int opt_idx;
5654
5655 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5656 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5657 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5658}
5659
5660/*
5661 * Check string options in a buffer for NULL value.
5662 */
5663 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005664check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666 check_string_option(&buf->b_p_bh);
5667 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668#ifdef FEAT_MBYTE
5669 check_string_option(&buf->b_p_fenc);
5670#endif
5671 check_string_option(&buf->b_p_ff);
5672#ifdef FEAT_FIND_ID
5673 check_string_option(&buf->b_p_def);
5674 check_string_option(&buf->b_p_inc);
5675# ifdef FEAT_EVAL
5676 check_string_option(&buf->b_p_inex);
5677# endif
5678#endif
5679#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5680 check_string_option(&buf->b_p_inde);
5681 check_string_option(&buf->b_p_indk);
5682#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005683#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5684 check_string_option(&buf->b_p_bexpr);
5685#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005686#if defined(FEAT_CRYPT)
5687 check_string_option(&buf->b_p_cm);
5688#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005689 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005690#if defined(FEAT_EVAL)
5691 check_string_option(&buf->b_p_fex);
5692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693#ifdef FEAT_CRYPT
5694 check_string_option(&buf->b_p_key);
5695#endif
5696 check_string_option(&buf->b_p_kp);
5697 check_string_option(&buf->b_p_mps);
5698 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005699 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700 check_string_option(&buf->b_p_isk);
5701#ifdef FEAT_COMMENTS
5702 check_string_option(&buf->b_p_com);
5703#endif
5704#ifdef FEAT_FOLDING
5705 check_string_option(&buf->b_p_cms);
5706#endif
5707 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005708#ifdef FEAT_TEXTOBJ
5709 check_string_option(&buf->b_p_qe);
5710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711#ifdef FEAT_SYN_HL
5712 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005713 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005714#endif
5715#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005716 check_string_option(&buf->b_s.b_p_spc);
5717 check_string_option(&buf->b_s.b_p_spf);
5718 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719#endif
5720#ifdef FEAT_SEARCHPATH
5721 check_string_option(&buf->b_p_sua);
5722#endif
5723#ifdef FEAT_CINDENT
5724 check_string_option(&buf->b_p_cink);
5725 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005726 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727#endif
5728#ifdef FEAT_AUTOCMD
5729 check_string_option(&buf->b_p_ft);
5730#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5732 check_string_option(&buf->b_p_cinw);
5733#endif
5734#ifdef FEAT_INS_EXPAND
5735 check_string_option(&buf->b_p_cpt);
5736#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005737#ifdef FEAT_COMPL_FUNC
5738 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005739 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005740#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005741#ifdef FEAT_KEYMAP
5742 check_string_option(&buf->b_p_keymap);
5743#endif
5744#ifdef FEAT_QUICKFIX
5745 check_string_option(&buf->b_p_gp);
5746 check_string_option(&buf->b_p_mp);
5747 check_string_option(&buf->b_p_efm);
5748#endif
5749 check_string_option(&buf->b_p_ep);
5750 check_string_option(&buf->b_p_path);
5751 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005752 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753#ifdef FEAT_INS_EXPAND
5754 check_string_option(&buf->b_p_dict);
5755 check_string_option(&buf->b_p_tsr);
5756#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005757#ifdef FEAT_LISP
5758 check_string_option(&buf->b_p_lw);
5759#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005760 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005761#ifdef FEAT_MBYTE
5762 check_string_option(&buf->b_p_menc);
5763#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764}
5765
5766/*
5767 * Free the string allocated for an option.
5768 * Checks for the string being empty_option. This may happen if we're out of
5769 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5770 * check_options().
5771 * Does NOT check for P_ALLOCED flag!
5772 */
5773 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005774free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775{
5776 if (p != empty_option)
5777 vim_free(p);
5778}
5779
5780 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005781clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005782{
5783 if (*pp != empty_option)
5784 vim_free(*pp);
5785 *pp = empty_option;
5786}
5787
5788 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005789check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005790{
5791 if (*pp == NULL)
5792 *pp = empty_option;
5793}
5794
5795/*
5796 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5797 */
5798 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005799set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005800{
5801 int opt_idx;
5802
5803 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5804 if (options[opt_idx].var == (char_u *)p)
5805 {
5806 options[opt_idx].flags |= P_ALLOCED;
5807 return;
5808 }
5809 return; /* cannot happen: didn't find it! */
5810}
5811
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005812#if defined(FEAT_EVAL) || defined(PROTO)
5813/*
5814 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5815 * Return FALSE when it wasn't.
5816 * Return -1 for an unknown option.
5817 */
5818 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005819was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005820{
5821 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005822 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005823
5824 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005825 {
5826 flagp = insecure_flag(idx, opt_flags);
5827 return (*flagp & P_INSECURE) != 0;
5828 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005829 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005830 return -1;
5831}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005832
5833/*
5834 * Get a pointer to the flags used for the P_INSECURE flag of option
5835 * "opt_idx". For some local options a local flags field is used.
5836 */
5837 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005838insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005839{
5840 if (opt_flags & OPT_LOCAL)
5841 switch ((int)options[opt_idx].indir)
5842 {
5843#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005844 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005845#endif
5846#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005847# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005848 case PV_FDE: return &curwin->w_p_fde_flags;
5849 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005850# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005851# ifdef FEAT_BEVAL
5852 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5853# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005854# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005855 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005856# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005857 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005858# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005859 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005860# endif
5861#endif
5862 }
5863
5864 /* Nothing special, return global flags field. */
5865 return &options[opt_idx].flags;
5866}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005867#endif
5868
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005869#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005870static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005871
5872/*
5873 * Redraw the window title and/or tab page text later.
5874 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005875static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005876{
5877 need_maketitle = TRUE;
5878# ifdef FEAT_WINDOWS
5879 redraw_tabline = TRUE;
5880# endif
5881}
5882#endif
5883
Bram Moolenaar071d4272004-06-13 20:20:40 +00005884/*
5885 * Set a string option to a new value (without checking the effect).
5886 * The string is copied into allocated memory.
5887 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005888 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005889 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890 */
5891 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005892set_string_option_direct(
5893 char_u *name,
5894 int opt_idx,
5895 char_u *val,
5896 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5897 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898{
5899 char_u *s;
5900 char_u **varp;
5901 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005902 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005903
Bram Moolenaar89d40322006-08-29 15:30:07 +00005904 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005906 idx = findoption(name);
5907 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005908 {
5909 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005910 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005912 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 }
5914
Bram Moolenaar89d40322006-08-29 15:30:07 +00005915 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 return;
5917
5918 s = vim_strsave(val);
5919 if (s != NULL)
5920 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005921 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005922 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005923 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924 free_string_option(*varp);
5925 *varp = s;
5926
5927 /* For buffer/window local option may also set the global value. */
5928 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005929 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930
Bram Moolenaar89d40322006-08-29 15:30:07 +00005931 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932
5933 /* When setting both values of a global option with a local value,
5934 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005935 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936 {
5937 free_string_option(*varp);
5938 *varp = empty_option;
5939 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005940# ifdef FEAT_EVAL
5941 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005942 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005943 set_sid == 0 ? current_SID : set_sid);
5944# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005945 }
5946}
5947
5948/*
5949 * Set global value for string option when it's a local option.
5950 */
5951 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005952set_string_option_global(
5953 int opt_idx, /* option index */
5954 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955{
5956 char_u **p, *s;
5957
5958 /* the global value is always allocated */
5959 if (options[opt_idx].var == VAR_WIN)
5960 p = (char_u **)GLOBAL_WO(varp);
5961 else
5962 p = (char_u **)options[opt_idx].var;
5963 if (options[opt_idx].indir != PV_NONE
5964 && p != varp
5965 && (s = vim_strsave(*varp)) != NULL)
5966 {
5967 free_string_option(*p);
5968 *p = s;
5969 }
5970}
5971
5972/*
5973 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005974 *
5975 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005977 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005978set_string_option(
5979 int opt_idx,
5980 char_u *value,
5981 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005982{
5983 char_u *s;
5984 char_u **varp;
5985 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005986#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5987 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005988 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005989#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005990 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991
5992 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005993 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005994
5995 s = vim_strsave(value);
5996 if (s != NULL)
5997 {
5998 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5999 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006000 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001 ? OPT_GLOBAL : OPT_LOCAL)
6002 : opt_flags);
6003 oldval = *varp;
6004 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006005
6006#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006007 if (!starting
6008# ifdef FEAT_CRYPT
6009 && options[opt_idx].indir != PV_KEY
6010# endif
6011 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006012 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006013 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006014 saved_newval = vim_strsave(s);
6015 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006016#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006017 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6018 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006019 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006020
Bram Moolenaar53744302015-07-17 17:38:22 +02006021#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006022 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006023 if (r == NULL)
6024 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006025 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006026 vim_free(saved_oldval);
6027 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006029 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006030 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006031}
6032
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006033#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006034/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006035 * Return TRUE if "val" is a valid 'filetype' name.
6036 * Also used for 'syntax' and 'keymap'.
6037 */
6038 static int
6039valid_filetype(char_u *val)
6040{
6041 char_u *s;
6042
6043 for (s = val; *s != NUL; ++s)
6044 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6045 return FALSE;
6046 return TRUE;
6047}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006048#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006049
6050/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006051 * Handle string options that need some action to perform when changed.
6052 * Returns NULL for success, or an error message for an error.
6053 */
6054 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006055did_set_string_option(
6056 int opt_idx, /* index in options[] table */
6057 char_u **varp, /* pointer to the option variable */
6058 int new_value_alloced, /* new value was allocated */
6059 char_u *oldval, /* previous value of the option */
6060 char_u *errbuf, /* buffer for errors, or NULL */
6061 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006062{
6063 char_u *errmsg = NULL;
6064 char_u *s, *p;
6065 int did_chartab = FALSE;
6066 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006067 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006068#ifdef FEAT_GUI
6069 /* set when changing an option that only requires a redraw in the GUI */
6070 int redraw_gui_only = FALSE;
6071#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006072#ifdef FEAT_AUTOCMD
6073 int ft_changed = FALSE;
6074#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006075
6076 /* Get the global option to compare with, otherwise we would have to check
6077 * two values for all local options. */
6078 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6079
6080 /* Disallow changing some options from secure mode */
6081 if ((secure
6082#ifdef HAVE_SANDBOX
6083 || sandbox != 0
6084#endif
6085 ) && (options[opt_idx].flags & P_SECURE))
6086 {
6087 errmsg = e_secure;
6088 }
6089
Bram Moolenaar7554da42016-11-25 22:04:13 +01006090 /* Check for a "normal" directory or file name in some options. Disallow a
6091 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006092 * are often illegal in a file name. Be more permissive if "secure" is off.
6093 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006094 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006095 && vim_strpbrk(*varp, (char_u *)(secure
6096 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006097 || ((options[opt_idx].flags & P_NDNAME)
6098 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006099 {
6100 errmsg = e_invarg;
6101 }
6102
Bram Moolenaar071d4272004-06-13 20:20:40 +00006103 /* 'term' */
6104 else if (varp == &T_NAME)
6105 {
6106 if (T_NAME[0] == NUL)
6107 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6108#ifdef FEAT_GUI
6109 if (gui.in_use)
6110 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6111 else if (term_is_gui(T_NAME))
6112 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6113#endif
6114 else if (set_termname(T_NAME) == FAIL)
6115 errmsg = (char_u *)N_("E522: Not found in termcap");
6116 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006117 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006118 /* Screen colors may have changed. */
6119 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006120
6121 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6122 * P_ALLOCED flag on 'term'. */
6123 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006124 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006126 }
6127
6128 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006129 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006131 char_u *bkc = p_bkc;
6132 unsigned int *flags = &bkc_flags;
6133
6134 if (opt_flags & OPT_LOCAL)
6135 {
6136 bkc = curbuf->b_p_bkc;
6137 flags = &curbuf->b_bkc_flags;
6138 }
6139
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006140 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6141 /* make the local value empty: use the global value */
6142 *flags = 0;
6143 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006145 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6146 errmsg = e_invarg;
6147 if ((((int)*flags & BKC_AUTO) != 0)
6148 + (((int)*flags & BKC_YES) != 0)
6149 + (((int)*flags & BKC_NO) != 0) != 1)
6150 {
6151 /* Must have exactly one of "auto", "yes" and "no". */
6152 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6153 errmsg = e_invarg;
6154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006155 }
6156 }
6157
6158 /* 'backupext' and 'patchmode' */
6159 else if (varp == &p_bex || varp == &p_pm)
6160 {
6161 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6162 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6163 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6164 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006165#ifdef FEAT_LINEBREAK
6166 /* 'breakindentopt' */
6167 else if (varp == &curwin->w_p_briopt)
6168 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006169 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006170 errmsg = e_invarg;
6171 }
6172#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006173
6174 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006175 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006176 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006177 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006178 */
6179 else if ( varp == &p_isi
6180 || varp == &(curbuf->b_p_isk)
6181 || varp == &p_isp
6182 || varp == &p_isf)
6183 {
6184 if (init_chartab() == FAIL)
6185 {
6186 did_chartab = TRUE; /* need to restore it below */
6187 errmsg = e_invarg; /* error in value */
6188 }
6189 }
6190
6191 /* 'helpfile' */
6192 else if (varp == &p_hf)
6193 {
6194 /* May compute new values for $VIM and $VIMRUNTIME */
6195 if (didset_vim)
6196 {
6197 vim_setenv((char_u *)"VIM", (char_u *)"");
6198 didset_vim = FALSE;
6199 }
6200 if (didset_vimruntime)
6201 {
6202 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6203 didset_vimruntime = FALSE;
6204 }
6205 }
6206
Bram Moolenaar1a384422010-07-14 19:53:30 +02006207#ifdef FEAT_SYN_HL
6208 /* 'colorcolumn' */
6209 else if (varp == &curwin->w_p_cc)
6210 errmsg = check_colorcolumn(curwin);
6211#endif
6212
Bram Moolenaar071d4272004-06-13 20:20:40 +00006213#ifdef FEAT_MULTI_LANG
6214 /* 'helplang' */
6215 else if (varp == &p_hlg)
6216 {
6217 /* Check for "", "ab", "ab,cd", etc. */
6218 for (s = p_hlg; *s != NUL; s += 3)
6219 {
6220 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6221 {
6222 errmsg = e_invarg;
6223 break;
6224 }
6225 if (s[2] == NUL)
6226 break;
6227 }
6228 }
6229#endif
6230
6231 /* 'highlight' */
6232 else if (varp == &p_hl)
6233 {
6234 if (highlight_changed() == FAIL)
6235 errmsg = e_invarg; /* invalid flags */
6236 }
6237
6238 /* 'nrformats' */
6239 else if (gvarp == &p_nf)
6240 {
6241 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6242 errmsg = e_invarg;
6243 }
6244
6245#ifdef FEAT_SESSION
6246 /* 'sessionoptions' */
6247 else if (varp == &p_ssop)
6248 {
6249 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6250 errmsg = e_invarg;
6251 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6252 {
6253 /* Don't allow both "sesdir" and "curdir". */
6254 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6255 errmsg = e_invarg;
6256 }
6257 }
6258 /* 'viewoptions' */
6259 else if (varp == &p_vop)
6260 {
6261 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6262 errmsg = e_invarg;
6263 }
6264#endif
6265
6266 /* 'scrollopt' */
6267#ifdef FEAT_SCROLLBIND
6268 else if (varp == &p_sbo)
6269 {
6270 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6271 errmsg = e_invarg;
6272 }
6273#endif
6274
6275 /* 'ambiwidth' */
6276#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006277 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278 {
6279 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6280 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006281 else if (set_chars_option(&p_lcs) != NULL)
6282 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6283# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6284 else if (set_chars_option(&p_fcs) != NULL)
6285 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6286# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006287 }
6288#endif
6289
6290 /* 'background' */
6291 else if (varp == &p_bg)
6292 {
6293 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6294 {
6295#ifdef FEAT_EVAL
6296 int dark = (*p_bg == 'd');
6297#endif
6298
6299 init_highlight(FALSE, FALSE);
6300
6301#ifdef FEAT_EVAL
6302 if (dark != (*p_bg == 'd')
6303 && get_var_value((char_u *)"g:colors_name") != NULL)
6304 {
6305 /* The color scheme must have set 'background' back to another
6306 * value, that's not what we want here. Disable the color
6307 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006308 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006309 free_string_option(p_bg);
6310 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6311 check_string_option(&p_bg);
6312 init_highlight(FALSE, FALSE);
6313 }
6314#endif
6315 }
6316 else
6317 errmsg = e_invarg;
6318 }
6319
6320 /* 'wildmode' */
6321 else if (varp == &p_wim)
6322 {
6323 if (check_opt_wim() == FAIL)
6324 errmsg = e_invarg;
6325 }
6326
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006327#ifdef FEAT_CMDL_COMPL
6328 /* 'wildoptions' */
6329 else if (varp == &p_wop)
6330 {
6331 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6332 errmsg = e_invarg;
6333 }
6334#endif
6335
Bram Moolenaar071d4272004-06-13 20:20:40 +00006336#ifdef FEAT_WAK
6337 /* 'winaltkeys' */
6338 else if (varp == &p_wak)
6339 {
6340 if (*p_wak == NUL
6341 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6342 errmsg = e_invarg;
6343# ifdef FEAT_MENU
6344# ifdef FEAT_GUI_MOTIF
6345 else if (gui.in_use)
6346 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6347# else
6348# ifdef FEAT_GUI_GTK
6349 else if (gui.in_use)
6350 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6351# endif
6352# endif
6353# endif
6354 }
6355#endif
6356
6357#ifdef FEAT_AUTOCMD
6358 /* 'eventignore' */
6359 else if (varp == &p_ei)
6360 {
6361 if (check_ei() == FAIL)
6362 errmsg = e_invarg;
6363 }
6364#endif
6365
6366#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006367 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6368 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6369 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006370 {
6371 if (gvarp == &p_fenc)
6372 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006373 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374 errmsg = e_modifiable;
6375 else if (vim_strchr(*varp, ',') != NULL)
6376 /* No comma allowed in 'fileencoding'; catches confusing it
6377 * with 'fileencodings'. */
6378 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006380 {
6381# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006383 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006384# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006385 /* Add 'fileencoding' to the swap file. */
6386 ml_setflags(curbuf);
6387 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388 }
6389 if (errmsg == NULL)
6390 {
6391 /* canonize the value, so that STRCMP() can be used on it */
6392 p = enc_canonize(*varp);
6393 if (p != NULL)
6394 {
6395 vim_free(*varp);
6396 *varp = p;
6397 }
6398 if (varp == &p_enc)
6399 {
6400 errmsg = mb_init();
6401# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006402 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403# endif
6404 }
6405 }
6406
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006407# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6409 {
6410 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6411 if (STRCMP(p_tenc, "utf-8") != 0)
6412 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6413 }
6414# endif
6415
6416 if (errmsg == NULL)
6417 {
6418# ifdef FEAT_KEYMAP
6419 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6420 * (with another encoding). */
6421 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6422 (void)keymap_init();
6423# endif
6424
6425 /* When 'termencoding' is not empty and 'encoding' changes or when
6426 * 'termencoding' changes, need to setup for keyboard input and
6427 * display output conversion. */
6428 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6429 {
6430 convert_setup(&input_conv, p_tenc, p_enc);
6431 convert_setup(&output_conv, p_enc, p_tenc);
6432 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006433
6434# if defined(WIN3264) && defined(FEAT_MBYTE)
6435 /* $HOME may have characters in active code page. */
6436 if (varp == &p_enc)
6437 init_homedir();
6438# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 }
6440 }
6441#endif
6442
6443#if defined(FEAT_POSTSCRIPT)
6444 else if (varp == &p_penc)
6445 {
6446 /* Canonize printencoding if VIM standard one */
6447 p = enc_canonize(p_penc);
6448 if (p != NULL)
6449 {
6450 vim_free(p_penc);
6451 p_penc = p;
6452 }
6453 else
6454 {
6455 /* Ensure lower case and '-' for '_' */
6456 for (s = p_penc; *s != NUL; s++)
6457 {
6458 if (*s == '_')
6459 *s = '-';
6460 else
6461 *s = TOLOWER_ASC(*s);
6462 }
6463 }
6464 }
6465#endif
6466
Bram Moolenaar9372a112005-12-06 19:59:18 +00006467#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468 else if (varp == &p_imak)
6469 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006470 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006471 errmsg = e_invarg;
6472 }
6473#endif
6474
6475#ifdef FEAT_KEYMAP
6476 else if (varp == &curbuf->b_p_keymap)
6477 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006478 if (!valid_filetype(*varp))
6479 errmsg = e_invarg;
6480 else
6481 /* load or unload key mapping tables */
6482 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483
Bram Moolenaarfab06232009-03-04 03:13:35 +00006484 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006485 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006486 if (*curbuf->b_p_keymap != NUL)
6487 {
6488 /* Installed a new keymap, switch on using it. */
6489 curbuf->b_p_iminsert = B_IMODE_LMAP;
6490 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6491 curbuf->b_p_imsearch = B_IMODE_LMAP;
6492 }
6493 else
6494 {
6495 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6496 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6497 curbuf->b_p_iminsert = B_IMODE_NONE;
6498 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6499 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6500 }
6501 if ((opt_flags & OPT_LOCAL) == 0)
6502 {
6503 set_iminsert_global();
6504 set_imsearch_global();
6505 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006506# ifdef FEAT_WINDOWS
6507 status_redraw_curbuf();
6508# endif
6509 }
6510 }
6511#endif
6512
6513 /* 'fileformat' */
6514 else if (gvarp == &p_ff)
6515 {
6516 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6517 errmsg = e_modifiable;
6518 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6519 errmsg = e_invarg;
6520 else
6521 {
6522 /* may also change 'textmode' */
6523 if (get_fileformat(curbuf) == EOL_DOS)
6524 curbuf->b_p_tx = TRUE;
6525 else
6526 curbuf->b_p_tx = FALSE;
6527#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006528 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006530 /* update flag in swap file */
6531 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006532 /* Redraw needed when switching to/from "mac": a CR in the text
6533 * will be displayed differently. */
6534 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6535 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006536 }
6537 }
6538
6539 /* 'fileformats' */
6540 else if (varp == &p_ffs)
6541 {
6542 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6543 errmsg = e_invarg;
6544 else
6545 {
6546 /* also change 'textauto' */
6547 if (*p_ffs == NUL)
6548 p_ta = FALSE;
6549 else
6550 p_ta = TRUE;
6551 }
6552 }
6553
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006554#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 /* 'cryptkey' */
6556 else if (gvarp == &p_key)
6557 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006558# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006559 /* Make sure the ":set" command doesn't show the new value in the
6560 * history. */
6561 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006562# endif
6563 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6564 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006565 ml_set_crypt_key(curbuf, oldval,
6566 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006567 }
6568
6569 else if (gvarp == &p_cm)
6570 {
6571 if (opt_flags & OPT_LOCAL)
6572 p = curbuf->b_p_cm;
6573 else
6574 p = p_cm;
6575 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6576 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006577 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006578 errmsg = e_invarg;
6579 else
6580 {
6581 /* When setting the global value to empty, make it "zip". */
6582 if (*p_cm == NUL)
6583 {
6584 if (new_value_alloced)
6585 free_string_option(p_cm);
6586 p_cm = vim_strsave((char_u *)"zip");
6587 new_value_alloced = TRUE;
6588 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006589 /* When using ":set cm=name" the local value is going to be empty.
6590 * Do that here, otherwise the crypt functions will still use the
6591 * local value. */
6592 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6593 {
6594 free_string_option(curbuf->b_p_cm);
6595 curbuf->b_p_cm = empty_option;
6596 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006597
6598 /* Need to update the swapfile when the effective method changed.
6599 * Set "s" to the effective old value, "p" to the effective new
6600 * method and compare. */
6601 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6602 s = p_cm; /* was previously using the global value */
6603 else
6604 s = oldval;
6605 if (*curbuf->b_p_cm == NUL)
6606 p = p_cm; /* is now using the global value */
6607 else
6608 p = curbuf->b_p_cm;
6609 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006610 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006611
6612 /* If the global value changes need to update the swapfile for all
6613 * buffers using that value. */
6614 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6615 {
6616 buf_T *buf;
6617
Bram Moolenaar29323592016-07-24 22:04:11 +02006618 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006619 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006620 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006621 }
6622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623 }
6624#endif
6625
6626 /* 'matchpairs' */
6627 else if (gvarp == &p_mps)
6628 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006629#ifdef FEAT_MBYTE
6630 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006632 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006633 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006634 int x2 = -1;
6635 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006636
6637 if (*p != NUL)
6638 p += mb_ptr2len(p);
6639 if (*p != NUL)
6640 x2 = *p++;
6641 if (*p != NUL)
6642 {
6643 x3 = mb_ptr2char(p);
6644 p += mb_ptr2len(p);
6645 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006646 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006647 {
6648 errmsg = e_invarg;
6649 break;
6650 }
6651 if (*p == NUL)
6652 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006653 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006654 }
6655 else
6656#endif
6657 {
6658 /* Check for "x:y,x:y" */
6659 for (p = *varp; *p != NUL; p += 4)
6660 {
6661 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6662 {
6663 errmsg = e_invarg;
6664 break;
6665 }
6666 if (p[3] == NUL)
6667 break;
6668 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669 }
6670 }
6671
6672#ifdef FEAT_COMMENTS
6673 /* 'comments' */
6674 else if (gvarp == &p_com)
6675 {
6676 for (s = *varp; *s; )
6677 {
6678 while (*s && *s != ':')
6679 {
6680 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6681 && !VIM_ISDIGIT(*s) && *s != '-')
6682 {
6683 errmsg = illegal_char(errbuf, *s);
6684 break;
6685 }
6686 ++s;
6687 }
6688 if (*s++ == NUL)
6689 errmsg = (char_u *)N_("E524: Missing colon");
6690 else if (*s == ',' || *s == NUL)
6691 errmsg = (char_u *)N_("E525: Zero length string");
6692 if (errmsg != NULL)
6693 break;
6694 while (*s && *s != ',')
6695 {
6696 if (*s == '\\' && s[1] != NUL)
6697 ++s;
6698 ++s;
6699 }
6700 s = skip_to_option_part(s);
6701 }
6702 }
6703#endif
6704
6705 /* 'listchars' */
6706 else if (varp == &p_lcs)
6707 {
6708 errmsg = set_chars_option(varp);
6709 }
6710
6711#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6712 /* 'fillchars' */
6713 else if (varp == &p_fcs)
6714 {
6715 errmsg = set_chars_option(varp);
6716 }
6717#endif
6718
6719#ifdef FEAT_CMDWIN
6720 /* 'cedit' */
6721 else if (varp == &p_cedit)
6722 {
6723 errmsg = check_cedit();
6724 }
6725#endif
6726
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006727 /* 'verbosefile' */
6728 else if (varp == &p_vfile)
6729 {
6730 verbose_stop();
6731 if (*p_vfile != NUL && verbose_open() == FAIL)
6732 errmsg = e_invarg;
6733 }
6734
Bram Moolenaar071d4272004-06-13 20:20:40 +00006735#ifdef FEAT_VIMINFO
6736 /* 'viminfo' */
6737 else if (varp == &p_viminfo)
6738 {
6739 for (s = p_viminfo; *s;)
6740 {
6741 /* Check it's a valid character */
6742 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6743 {
6744 errmsg = illegal_char(errbuf, *s);
6745 break;
6746 }
6747 if (*s == 'n') /* name is always last one */
6748 {
6749 break;
6750 }
6751 else if (*s == 'r') /* skip until next ',' */
6752 {
6753 while (*++s && *s != ',')
6754 ;
6755 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006756 else if (*s == '%')
6757 {
6758 /* optional number */
6759 while (vim_isdigit(*++s))
6760 ;
6761 }
6762 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006763 ++s; /* no extra chars */
6764 else /* must have a number */
6765 {
6766 while (vim_isdigit(*++s))
6767 ;
6768
6769 if (!VIM_ISDIGIT(*(s - 1)))
6770 {
6771 if (errbuf != NULL)
6772 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006773 sprintf((char *)errbuf,
6774 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 transchar_byte(*(s - 1)));
6776 errmsg = errbuf;
6777 }
6778 else
6779 errmsg = (char_u *)"";
6780 break;
6781 }
6782 }
6783 if (*s == ',')
6784 ++s;
6785 else if (*s)
6786 {
6787 if (errbuf != NULL)
6788 errmsg = (char_u *)N_("E527: Missing comma");
6789 else
6790 errmsg = (char_u *)"";
6791 break;
6792 }
6793 }
6794 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6795 errmsg = (char_u *)N_("E528: Must specify a ' value");
6796 }
6797#endif /* FEAT_VIMINFO */
6798
6799 /* terminal options */
6800 else if (istermoption(&options[opt_idx]) && full_screen)
6801 {
6802 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6803 if (varp == &T_CCO)
6804 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006805 int colors = atoi((char *)T_CCO);
6806
6807 /* Only reinitialize colors if t_Co value has really changed to
6808 * avoid expensive reload of colorscheme if t_Co is set to the
6809 * same value multiple times. */
6810 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006811 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006812 t_colors = colors;
6813 if (t_colors <= 1)
6814 {
6815 if (new_value_alloced)
6816 vim_free(T_CCO);
6817 T_CCO = empty_option;
6818 }
6819 /* We now have a different color setup, initialize it again. */
6820 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 }
6823 ttest(FALSE);
6824 if (varp == &T_ME)
6825 {
6826 out_str(T_ME);
6827 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006828#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 /* Since t_me has been set, this probably means that the user
6830 * wants to use this as default colors. Need to reset default
6831 * background/foreground colors. */
6832 mch_set_normal_colors();
6833#endif
6834 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006835 if (varp == &T_BE && termcap_active)
6836 {
6837 if (*T_BE == NUL)
6838 /* When clearing t_BE we assume the user no longer wants
6839 * bracketed paste, thus disable it by writing t_BD. */
6840 out_str(T_BD);
6841 else
6842 out_str(T_BE);
6843 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844 }
6845
6846#ifdef FEAT_LINEBREAK
6847 /* 'showbreak' */
6848 else if (varp == &p_sbr)
6849 {
6850 for (s = p_sbr; *s; )
6851 {
6852 if (ptr2cells(s) != 1)
6853 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006854 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006855 }
6856 }
6857#endif
6858
6859#ifdef FEAT_GUI
6860 /* 'guifont' */
6861 else if (varp == &p_guifont)
6862 {
6863 if (gui.in_use)
6864 {
6865 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006866# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006867 /*
6868 * Put up a font dialog and let the user select a new value.
6869 * If this is cancelled go back to the old value but don't
6870 * give an error message.
6871 */
6872 if (STRCMP(p, "*") == 0)
6873 {
6874 p = gui_mch_font_dialog(oldval);
6875
6876 if (new_value_alloced)
6877 free_string_option(p_guifont);
6878
6879 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6880 new_value_alloced = TRUE;
6881 }
6882# endif
6883 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6884 {
6885# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6886 if (STRCMP(p_guifont, "*") == 0)
6887 {
6888 /* Dialog was cancelled: Keep the old value without giving
6889 * an error message. */
6890 if (new_value_alloced)
6891 free_string_option(p_guifont);
6892 p_guifont = vim_strsave(oldval);
6893 new_value_alloced = TRUE;
6894 }
6895 else
6896# endif
6897 errmsg = (char_u *)N_("E596: Invalid font(s)");
6898 }
6899 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006900 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006901 }
6902# ifdef FEAT_XFONTSET
6903 else if (varp == &p_guifontset)
6904 {
6905 if (STRCMP(p_guifontset, "*") == 0)
6906 errmsg = (char_u *)N_("E597: can't select fontset");
6907 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6908 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006909 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 }
6911# endif
6912# ifdef FEAT_MBYTE
6913 else if (varp == &p_guifontwide)
6914 {
6915 if (STRCMP(p_guifontwide, "*") == 0)
6916 errmsg = (char_u *)N_("E533: can't select wide font");
6917 else if (gui_get_wide_font() == FAIL)
6918 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006919 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920 }
6921# endif
6922#endif
6923
6924#ifdef CURSOR_SHAPE
6925 /* 'guicursor' */
6926 else if (varp == &p_guicursor)
6927 errmsg = parse_shape_opt(SHAPE_CURSOR);
6928#endif
6929
6930#ifdef FEAT_MOUSESHAPE
6931 /* 'mouseshape' */
6932 else if (varp == &p_mouseshape)
6933 {
6934 errmsg = parse_shape_opt(SHAPE_MOUSE);
6935 update_mouseshape(-1);
6936 }
6937#endif
6938
6939#ifdef FEAT_PRINTER
6940 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006941 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006942# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006943 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006944 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006945# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946#endif
6947
6948#ifdef FEAT_LANGMAP
6949 /* 'langmap' */
6950 else if (varp == &p_langmap)
6951 langmap_set();
6952#endif
6953
6954#ifdef FEAT_LINEBREAK
6955 /* 'breakat' */
6956 else if (varp == &p_breakat)
6957 fill_breakat_flags();
6958#endif
6959
6960#ifdef FEAT_TITLE
6961 /* 'titlestring' and 'iconstring' */
6962 else if (varp == &p_titlestring || varp == &p_iconstring)
6963 {
6964# ifdef FEAT_STL_OPT
6965 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6966
6967 /* NULL => statusline syntax */
6968 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6969 stl_syntax |= flagval;
6970 else
6971 stl_syntax &= ~flagval;
6972# endif
6973 did_set_title(varp == &p_iconstring);
6974
6975 }
6976#endif
6977
6978#ifdef FEAT_GUI
6979 /* 'guioptions' */
6980 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006981 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006983 redraw_gui_only = TRUE;
6984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985#endif
6986
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006987#if defined(FEAT_GUI_TABLINE)
6988 /* 'guitablabel' */
6989 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006990 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006991 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006992 redraw_gui_only = TRUE;
6993 }
6994 /* 'guitabtooltip' */
6995 else if (varp == &p_gtt)
6996 {
6997 redraw_gui_only = TRUE;
6998 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006999#endif
7000
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7002 /* 'ttymouse' */
7003 else if (varp == &p_ttym)
7004 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007005 /* Switch the mouse off before changing the escape sequences used for
7006 * that. */
7007 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7009 errmsg = e_invarg;
7010 else
7011 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007012 if (termcap_active)
7013 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 }
7015#endif
7016
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 /* 'selection' */
7018 else if (varp == &p_sel)
7019 {
7020 if (*p_sel == NUL
7021 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7022 errmsg = e_invarg;
7023 }
7024
7025 /* 'selectmode' */
7026 else if (varp == &p_slm)
7027 {
7028 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7029 errmsg = e_invarg;
7030 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007031
7032#ifdef FEAT_BROWSE
7033 /* 'browsedir' */
7034 else if (varp == &p_bsdir)
7035 {
7036 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7037 && !mch_isdir(p_bsdir))
7038 errmsg = e_invarg;
7039 }
7040#endif
7041
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 /* 'keymodel' */
7043 else if (varp == &p_km)
7044 {
7045 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7046 errmsg = e_invarg;
7047 else
7048 {
7049 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7050 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7051 }
7052 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007053
7054 /* 'mousemodel' */
7055 else if (varp == &p_mousem)
7056 {
7057 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7058 errmsg = e_invarg;
7059#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7060 else if (*p_mousem != *oldval)
7061 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7062 * to create or delete the popup menus. */
7063 gui_motif_update_mousemodel(root_menu);
7064#endif
7065 }
7066
7067 /* 'switchbuf' */
7068 else if (varp == &p_swb)
7069 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007070 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 errmsg = e_invarg;
7072 }
7073
7074 /* 'debug' */
7075 else if (varp == &p_debug)
7076 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007077 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 errmsg = e_invarg;
7079 }
7080
7081 /* 'display' */
7082 else if (varp == &p_dy)
7083 {
7084 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7085 errmsg = e_invarg;
7086 else
7087 (void)init_chartab();
7088
7089 }
7090
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007091#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007092 /* 'eadirection' */
7093 else if (varp == &p_ead)
7094 {
7095 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7096 errmsg = e_invarg;
7097 }
7098#endif
7099
7100#ifdef FEAT_CLIPBOARD
7101 /* 'clipboard' */
7102 else if (varp == &p_cb)
7103 errmsg = check_clipboard_option();
7104#endif
7105
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007106#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007107 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7108 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007109 else if (varp == &(curwin->w_s->b_p_spl)
7110 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007111 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007112 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007113 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007114 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007115 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007116 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007117 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007118 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007119 /* 'spellsuggest' */
7120 else if (varp == &p_sps)
7121 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007122 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007123 errmsg = e_invarg;
7124 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007125 /* 'mkspellmem' */
7126 else if (varp == &p_msm)
7127 {
7128 if (spell_check_msm() != OK)
7129 errmsg = e_invarg;
7130 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007131#endif
7132
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 /* When 'bufhidden' is set, check for valid value. */
7134 else if (gvarp == &p_bh)
7135 {
7136 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7137 errmsg = e_invarg;
7138 }
7139
7140 /* When 'buftype' is set, check for valid value. */
7141 else if (gvarp == &p_bt)
7142 {
7143 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7144 errmsg = e_invarg;
7145 else
7146 {
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007147#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 if (curwin->w_status_height)
7149 {
7150 curwin->w_redr_status = TRUE;
7151 redraw_later(VALID);
7152 }
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007155#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007156 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158 }
7159 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007160
7161#ifdef FEAT_STL_OPT
7162 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007163 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007164 {
7165 int wid;
7166
7167 if (varp == &p_ruf) /* reset ru_wid first */
7168 ru_wid = 0;
7169 s = *varp;
7170 if (varp == &p_ruf && *s == '%')
7171 {
7172 /* set ru_wid if 'ruf' starts with "%99(" */
7173 if (*++s == '-') /* ignore a '-' */
7174 s++;
7175 wid = getdigits(&s);
7176 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7177 ru_wid = wid;
7178 else
7179 errmsg = check_stl_option(p_ruf);
7180 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007181 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007182 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007183 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007184 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007185 comp_col();
7186 }
7187#endif
7188
7189#ifdef FEAT_INS_EXPAND
7190 /* check if it is a valid value for 'complete' -- Acevedo */
7191 else if (gvarp == &p_cpt)
7192 {
7193 for (s = *varp; *s;)
7194 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007195 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007196 s++;
7197 if (!*s)
7198 break;
7199 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7200 {
7201 errmsg = illegal_char(errbuf, *s);
7202 break;
7203 }
7204 if (*++s != NUL && *s != ',' && *s != ' ')
7205 {
7206 if (s[-1] == 'k' || s[-1] == 's')
7207 {
7208 /* skip optional filename after 'k' and 's' */
7209 while (*s && *s != ',' && *s != ' ')
7210 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007211 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212 ++s;
7213 ++s;
7214 }
7215 }
7216 else
7217 {
7218 if (errbuf != NULL)
7219 {
7220 sprintf((char *)errbuf,
7221 _("E535: Illegal character after <%c>"),
7222 *--s);
7223 errmsg = errbuf;
7224 }
7225 else
7226 errmsg = (char_u *)"";
7227 break;
7228 }
7229 }
7230 }
7231 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007232
7233 /* 'completeopt' */
7234 else if (varp == &p_cot)
7235 {
7236 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7237 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007238 else
7239 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007240 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007241#endif /* FEAT_INS_EXPAND */
7242
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007243#ifdef FEAT_SIGNS
7244 /* 'signcolumn' */
7245 else if (varp == &curwin->w_p_scl)
7246 {
7247 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7248 errmsg = e_invarg;
7249 }
7250#endif
7251
Bram Moolenaar071d4272004-06-13 20:20:40 +00007252
7253#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007254 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255 else if (varp == &p_toolbar)
7256 {
7257 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7258 &toolbar_flags, TRUE) != OK)
7259 errmsg = e_invarg;
7260 else
7261 {
7262 out_flush();
7263 gui_mch_show_toolbar((toolbar_flags &
7264 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7265 }
7266 }
7267#endif
7268
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007269#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007270 /* 'toolbariconsize': GTK+ 2 only */
7271 else if (varp == &p_tbis)
7272 {
7273 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7274 errmsg = e_invarg;
7275 else
7276 {
7277 out_flush();
7278 gui_mch_show_toolbar((toolbar_flags &
7279 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7280 }
7281 }
7282#endif
7283
7284 /* 'pastetoggle': translate key codes like in a mapping */
7285 else if (varp == &p_pt)
7286 {
7287 if (*p_pt)
7288 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007289 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007290 if (p != NULL)
7291 {
7292 if (new_value_alloced)
7293 free_string_option(p_pt);
7294 p_pt = p;
7295 new_value_alloced = TRUE;
7296 }
7297 }
7298 }
7299
7300 /* 'backspace' */
7301 else if (varp == &p_bs)
7302 {
7303 if (VIM_ISDIGIT(*p_bs))
7304 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007305 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007306 errmsg = e_invarg;
7307 }
7308 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7309 errmsg = e_invarg;
7310 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007311 else if (varp == &p_bo)
7312 {
7313 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7314 errmsg = e_invarg;
7315 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007316
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007317 /* 'tagcase' */
7318 else if (gvarp == &p_tc)
7319 {
7320 unsigned int *flags;
7321
7322 if (opt_flags & OPT_LOCAL)
7323 {
7324 p = curbuf->b_p_tc;
7325 flags = &curbuf->b_tc_flags;
7326 }
7327 else
7328 {
7329 p = p_tc;
7330 flags = &tc_flags;
7331 }
7332
7333 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7334 /* make the local value empty: use the global value */
7335 *flags = 0;
7336 else if (*p == NUL
7337 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7338 errmsg = e_invarg;
7339 }
7340
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007341#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007342 /* 'casemap' */
7343 else if (varp == &p_cmp)
7344 {
7345 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7346 errmsg = e_invarg;
7347 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007349
7350#ifdef FEAT_DIFF
7351 /* 'diffopt' */
7352 else if (varp == &p_dip)
7353 {
7354 if (diffopt_changed() == FAIL)
7355 errmsg = e_invarg;
7356 }
7357#endif
7358
7359#ifdef FEAT_FOLDING
7360 /* 'foldmethod' */
7361 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7362 {
7363 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7364 || *curwin->w_p_fdm == NUL)
7365 errmsg = e_invarg;
7366 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007367 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007369 if (foldmethodIsDiff(curwin))
7370 newFoldLevel();
7371 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007372 }
7373# ifdef FEAT_EVAL
7374 /* 'foldexpr' */
7375 else if (varp == &curwin->w_p_fde)
7376 {
7377 if (foldmethodIsExpr(curwin))
7378 foldUpdateAll(curwin);
7379 }
7380# endif
7381 /* 'foldmarker' */
7382 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7383 {
7384 p = vim_strchr(*varp, ',');
7385 if (p == NULL)
7386 errmsg = (char_u *)N_("E536: comma required");
7387 else if (p == *varp || p[1] == NUL)
7388 errmsg = e_invarg;
7389 else if (foldmethodIsMarker(curwin))
7390 foldUpdateAll(curwin);
7391 }
7392 /* 'commentstring' */
7393 else if (gvarp == &p_cms)
7394 {
7395 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7396 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7397 }
7398 /* 'foldopen' */
7399 else if (varp == &p_fdo)
7400 {
7401 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7402 errmsg = e_invarg;
7403 }
7404 /* 'foldclose' */
7405 else if (varp == &p_fcl)
7406 {
7407 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7408 errmsg = e_invarg;
7409 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007410 /* 'foldignore' */
7411 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7412 {
7413 if (foldmethodIsIndent(curwin))
7414 foldUpdateAll(curwin);
7415 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007416#endif
7417
7418#ifdef FEAT_VIRTUALEDIT
7419 /* 'virtualedit' */
7420 else if (varp == &p_ve)
7421 {
7422 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7423 errmsg = e_invarg;
7424 else if (STRCMP(p_ve, oldval) != 0)
7425 {
7426 /* Recompute cursor position in case the new 've' setting
7427 * changes something. */
7428 validate_virtcol();
7429 coladvance(curwin->w_virtcol);
7430 }
7431 }
7432#endif
7433
7434#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7435 else if (varp == &p_csqf)
7436 {
7437 if (p_csqf != NULL)
7438 {
7439 p = p_csqf;
7440 while (*p != NUL)
7441 {
7442 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7443 || p[1] == NUL
7444 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7445 || (p[2] != NUL && p[2] != ','))
7446 {
7447 errmsg = e_invarg;
7448 break;
7449 }
7450 else if (p[2] == NUL)
7451 break;
7452 else
7453 p += 3;
7454 }
7455 }
7456 }
7457#endif
7458
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007459#ifdef FEAT_CINDENT
7460 /* 'cinoptions' */
7461 else if (gvarp == &p_cino)
7462 {
7463 /* TODO: recognize errors */
7464 parse_cino(curbuf);
7465 }
7466#endif
7467
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007468#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007469 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007470 else if (varp == &p_rop && gui.in_use)
7471 {
7472 if (!gui_mch_set_rendering_options(p_rop))
7473 errmsg = e_invarg;
7474 }
7475#endif
7476
Bram Moolenaard0b51382016-11-04 15:23:45 +01007477#ifdef FEAT_AUTOCMD
7478 else if (gvarp == &p_ft)
7479 {
7480 if (!valid_filetype(*varp))
7481 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007482 else
7483 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007484 }
7485#endif
7486
7487#ifdef FEAT_SYN_HL
7488 else if (gvarp == &p_syn)
7489 {
7490 if (!valid_filetype(*varp))
7491 errmsg = e_invarg;
7492 }
7493#endif
7494
Bram Moolenaar825680f2017-07-22 17:04:02 +02007495#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007496 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007497 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007498 {
7499 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7500 errmsg = e_invarg;
7501 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007502 /* 'termsize' */
7503 else if (varp == &curwin->w_p_tms)
7504 {
7505 if (*curwin->w_p_tms != NUL)
7506 {
7507 p = skipdigits(curwin->w_p_tms);
7508 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7509 errmsg = e_invarg;
7510 }
7511 }
7512#endif
7513
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 /* Options that are a list of flags. */
7515 else
7516 {
7517 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007518 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007520 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007522 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007523 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007524 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007526#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007527 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007528 p = (char_u *)COCU_ALL;
7529#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007530 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007531 {
7532#ifdef FEAT_MOUSE
7533 p = (char_u *)MOUSE_ALL;
7534#else
7535 if (*p_mouse != NUL)
7536 errmsg = (char_u *)N_("E538: No mouse support");
7537#endif
7538 }
7539#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007540 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541 p = (char_u *)GO_ALL;
7542#endif
7543 if (p != NULL)
7544 {
7545 for (s = *varp; *s; ++s)
7546 if (vim_strchr(p, *s) == NULL)
7547 {
7548 errmsg = illegal_char(errbuf, *s);
7549 break;
7550 }
7551 }
7552 }
7553
7554 /*
7555 * If error detected, restore the previous value.
7556 */
7557 if (errmsg != NULL)
7558 {
7559 if (new_value_alloced)
7560 free_string_option(*varp);
7561 *varp = oldval;
7562 /*
7563 * When resetting some values, need to act on it.
7564 */
7565 if (did_chartab)
7566 (void)init_chartab();
7567 if (varp == &p_hl)
7568 (void)highlight_changed();
7569 }
7570 else
7571 {
7572#ifdef FEAT_EVAL
7573 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007574 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007575#endif
7576 /*
7577 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007578 * Use "free_oldval", because recursiveness may change the flags under
7579 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007580 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007581 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007582 free_string_option(oldval);
7583 if (new_value_alloced)
7584 options[opt_idx].flags |= P_ALLOCED;
7585 else
7586 options[opt_idx].flags &= ~P_ALLOCED;
7587
7588 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007589 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007590 {
7591 /* global option with local value set to use global value; free
7592 * the local value and make it empty */
7593 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7594 free_string_option(*(char_u **)p);
7595 *(char_u **)p = empty_option;
7596 }
7597
7598 /* May set global value for local option. */
7599 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7600 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007601
7602#ifdef FEAT_AUTOCMD
7603 /*
7604 * Trigger the autocommand only after setting the flags.
7605 */
7606# ifdef FEAT_SYN_HL
7607 /* When 'syntax' is set, load the syntax of that name */
7608 if (varp == &(curbuf->b_p_syn))
7609 {
7610 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7611 curbuf->b_fname, TRUE, curbuf);
7612 }
7613# endif
7614 else if (varp == &(curbuf->b_p_ft))
7615 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007616 /* 'filetype' is set, trigger the FileType autocommand.
7617 * Skip this when called from a modeline and the filetype was
7618 * already set to this value. */
7619 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7620 {
7621 did_filetype = TRUE;
7622 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007623 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007624 /* Just in case the old "curbuf" is now invalid. */
7625 if (varp != &(curbuf->b_p_ft))
7626 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007627 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007628 }
7629#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007630#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007631 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007632 {
7633 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007634 char_u *q = curwin->w_s->b_p_spl;
7635
7636 /* Skip the first name if it is "cjk". */
7637 if (STRNCMP(q, "cjk,", 4) == 0)
7638 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007639
7640 /*
7641 * Source the spell/LANG.vim in 'runtimepath'.
7642 * They could set 'spellcapcheck' depending on the language.
7643 * Use the first name in 'spelllang' up to '_region' or
7644 * '.encoding'.
7645 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007646 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007647 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7648 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007649 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007650 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007651 }
7652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007653 }
7654
7655#ifdef FEAT_MOUSE
7656 if (varp == &p_mouse)
7657 {
7658# ifdef FEAT_MOUSE_TTY
7659 if (*p_mouse == NUL)
7660 mch_setmouse(FALSE); /* switch mouse off */
7661 else
7662# endif
7663 setmouse(); /* in case 'mouse' changed */
7664 }
7665#endif
7666
Bram Moolenaar913077c2012-03-28 19:59:04 +02007667 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007668 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007669 curwin->w_set_curswant = TRUE;
7670
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007671#ifdef FEAT_GUI
7672 /* check redraw when it's not a GUI option or the GUI is active. */
7673 if (!redraw_gui_only || gui.in_use)
7674#endif
7675 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676
7677 return errmsg;
7678}
7679
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007680#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007681/*
7682 * Simple int comparison function for use with qsort()
7683 */
7684 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007685int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007686{
7687 return *(const int *)a - *(const int *)b;
7688}
7689
7690/*
7691 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7692 * Returns error message, NULL if it's OK.
7693 */
7694 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007695check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007696{
7697 char_u *s;
7698 int col;
7699 int count = 0;
7700 int color_cols[256];
7701 int i;
7702 int j = 0;
7703
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007704 if (wp->w_buffer == NULL)
7705 return NULL; /* buffer was closed */
7706
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007707 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007708 {
7709 if (*s == '-' || *s == '+')
7710 {
7711 /* -N and +N: add to 'textwidth' */
7712 col = (*s == '-') ? -1 : 1;
7713 ++s;
7714 if (!VIM_ISDIGIT(*s))
7715 return e_invarg;
7716 col = col * getdigits(&s);
7717 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007718 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007719 col += wp->w_buffer->b_p_tw;
7720 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007721 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007722 }
7723 else if (VIM_ISDIGIT(*s))
7724 col = getdigits(&s);
7725 else
7726 return e_invarg;
7727 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007728skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007729 if (*s == NUL)
7730 break;
7731 if (*s != ',')
7732 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007733 if (*++s == NUL)
7734 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007735 }
7736
7737 vim_free(wp->w_p_cc_cols);
7738 if (count == 0)
7739 wp->w_p_cc_cols = NULL;
7740 else
7741 {
7742 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7743 if (wp->w_p_cc_cols != NULL)
7744 {
7745 /* sort the columns for faster usage on screen redraw inside
7746 * win_line() */
7747 qsort(color_cols, count, sizeof(int), int_cmp);
7748
7749 for (i = 0; i < count; ++i)
7750 /* skip duplicates */
7751 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7752 wp->w_p_cc_cols[j++] = color_cols[i];
7753 wp->w_p_cc_cols[j] = -1; /* end marker */
7754 }
7755 }
7756
7757 return NULL; /* no error */
7758}
7759#endif
7760
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761/*
7762 * Handle setting 'listchars' or 'fillchars'.
7763 * Returns error message, NULL if it's OK.
7764 */
7765 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007766set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767{
7768 int round, i, len, entries;
7769 char_u *p, *s;
7770 int c1, c2 = 0;
7771 struct charstab
7772 {
7773 int *cp;
7774 char *name;
7775 };
7776#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7777 static struct charstab filltab[] =
7778 {
7779 {&fill_stl, "stl"},
7780 {&fill_stlnc, "stlnc"},
7781 {&fill_vert, "vert"},
7782 {&fill_fold, "fold"},
7783 {&fill_diff, "diff"},
7784 };
7785#endif
7786 static struct charstab lcstab[] =
7787 {
7788 {&lcs_eol, "eol"},
7789 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007790 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007792 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007793 {&lcs_tab2, "tab"},
7794 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007795#ifdef FEAT_CONCEAL
7796 {&lcs_conceal, "conceal"},
7797#else
7798 {NULL, "conceal"},
7799#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 };
7801 struct charstab *tab;
7802
7803#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7804 if (varp == &p_lcs)
7805#endif
7806 {
7807 tab = lcstab;
7808 entries = sizeof(lcstab) / sizeof(struct charstab);
7809 }
7810#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7811 else
7812 {
7813 tab = filltab;
7814 entries = sizeof(filltab) / sizeof(struct charstab);
7815 }
7816#endif
7817
7818 /* first round: check for valid value, second round: assign values */
7819 for (round = 0; round <= 1; ++round)
7820 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007821 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007822 {
7823 /* After checking that the value is valid: set defaults: space for
7824 * 'fillchars', NUL for 'listchars' */
7825 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007826 if (tab[i].cp != NULL)
7827 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828 if (varp == &p_lcs)
7829 lcs_tab1 = NUL;
7830#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7831 else
7832 fill_diff = '-';
7833#endif
7834 }
7835 p = *varp;
7836 while (*p)
7837 {
7838 for (i = 0; i < entries; ++i)
7839 {
7840 len = (int)STRLEN(tab[i].name);
7841 if (STRNCMP(p, tab[i].name, len) == 0
7842 && p[len] == ':'
7843 && p[len + 1] != NUL)
7844 {
7845 s = p + len + 1;
7846#ifdef FEAT_MBYTE
7847 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007848 if (mb_char2cells(c1) > 1)
7849 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850#else
7851 c1 = *s++;
7852#endif
7853 if (tab[i].cp == &lcs_tab2)
7854 {
7855 if (*s == NUL)
7856 continue;
7857#ifdef FEAT_MBYTE
7858 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007859 if (mb_char2cells(c2) > 1)
7860 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861#else
7862 c2 = *s++;
7863#endif
7864 }
7865 if (*s == ',' || *s == NUL)
7866 {
7867 if (round)
7868 {
7869 if (tab[i].cp == &lcs_tab2)
7870 {
7871 lcs_tab1 = c1;
7872 lcs_tab2 = c2;
7873 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007874 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875 *(tab[i].cp) = c1;
7876
7877 }
7878 p = s;
7879 break;
7880 }
7881 }
7882 }
7883
7884 if (i == entries)
7885 return e_invarg;
7886 if (*p == ',')
7887 ++p;
7888 }
7889 }
7890
7891 return NULL; /* no error */
7892}
7893
7894#ifdef FEAT_STL_OPT
7895/*
7896 * Check validity of options with the 'statusline' format.
7897 * Return error message or NULL.
7898 */
7899 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007900check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901{
7902 int itemcnt = 0;
7903 int groupdepth = 0;
7904 static char_u errbuf[80];
7905
7906 while (*s && itemcnt < STL_MAX_ITEM)
7907 {
7908 /* Check for valid keys after % sequences */
7909 while (*s && *s != '%')
7910 s++;
7911 if (!*s)
7912 break;
7913 s++;
7914 if (*s != '%' && *s != ')')
7915 ++itemcnt;
7916 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7917 {
7918 s++;
7919 continue;
7920 }
7921 if (*s == ')')
7922 {
7923 s++;
7924 if (--groupdepth < 0)
7925 break;
7926 continue;
7927 }
7928 if (*s == '-')
7929 s++;
7930 while (VIM_ISDIGIT(*s))
7931 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007932 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933 continue;
7934 if (*s == '.')
7935 {
7936 s++;
7937 while (*s && VIM_ISDIGIT(*s))
7938 s++;
7939 }
7940 if (*s == '(')
7941 {
7942 groupdepth++;
7943 continue;
7944 }
7945 if (vim_strchr(STL_ALL, *s) == NULL)
7946 {
7947 return illegal_char(errbuf, *s);
7948 }
7949 if (*s == '{')
7950 {
7951 s++;
7952 while (*s != '}' && *s)
7953 s++;
7954 if (*s != '}')
7955 return (char_u *)N_("E540: Unclosed expression sequence");
7956 }
7957 }
7958 if (itemcnt >= STL_MAX_ITEM)
7959 return (char_u *)N_("E541: too many items");
7960 if (groupdepth != 0)
7961 return (char_u *)N_("E542: unbalanced groups");
7962 return NULL;
7963}
7964#endif
7965
7966#ifdef FEAT_CLIPBOARD
7967/*
7968 * Extract the items in the 'clipboard' option and set global values.
7969 */
7970 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007971check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007973 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007974 int new_autoselect_star = FALSE;
7975 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007977 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978 regprog_T *new_exclude_prog = NULL;
7979 char_u *errmsg = NULL;
7980 char_u *p;
7981
7982 for (p = p_cb; *p != NUL; )
7983 {
7984 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7985 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007986 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007987 p += 7;
7988 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007989 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007990 && (p[11] == ',' || p[11] == NUL))
7991 {
7992 new_unnamed |= CLIP_UNNAMED_PLUS;
7993 p += 11;
7994 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007996 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007997 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007998 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 p += 10;
8000 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008001 else if (STRNCMP(p, "autoselectplus", 14) == 0
8002 && (p[14] == ',' || p[14] == NUL))
8003 {
8004 new_autoselect_plus = TRUE;
8005 p += 14;
8006 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008008 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009 {
8010 new_autoselectml = TRUE;
8011 p += 12;
8012 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008013 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8014 {
8015 new_html = TRUE;
8016 p += 4;
8017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8019 {
8020 p += 8;
8021 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8022 if (new_exclude_prog == NULL)
8023 errmsg = e_invarg;
8024 break;
8025 }
8026 else
8027 {
8028 errmsg = e_invarg;
8029 break;
8030 }
8031 if (*p == ',')
8032 ++p;
8033 }
8034 if (errmsg == NULL)
8035 {
8036 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008037 clip_autoselect_star = new_autoselect_star;
8038 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008039 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008040 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008041 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008043#ifdef FEAT_GUI_GTK
8044 if (gui.in_use)
8045 {
8046 gui_gtk_set_selection_targets();
8047 gui_gtk_set_dnd_targets();
8048 }
8049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008050 }
8051 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008052 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008053
8054 return errmsg;
8055}
8056#endif
8057
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008058#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008059 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008060did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008061{
8062 char_u *errmsg = NULL;
8063 win_T *wp;
8064 int l;
8065
8066 if (is_spellfile)
8067 {
8068 l = (int)STRLEN(curwin->w_s->b_p_spf);
8069 if (l > 0 && (l < 4
8070 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8071 errmsg = e_invarg;
8072 }
8073
8074 if (errmsg == NULL)
8075 {
8076 FOR_ALL_WINDOWS(wp)
8077 if (wp->w_buffer == curbuf && wp->w_p_spell)
8078 {
8079 errmsg = did_set_spelllang(wp);
8080# ifdef FEAT_WINDOWS
8081 break;
8082# endif
8083 }
8084 }
8085 return errmsg;
8086}
8087
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008088/*
8089 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8090 * Return error message when failed, NULL when OK.
8091 */
8092 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008093compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008094{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008095 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008096 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008097
Bram Moolenaar860cae12010-06-05 23:22:07 +02008098 if (*synblock->b_p_spc == NUL)
8099 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008100 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008101 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008102 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008103 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008104 if (re != NULL)
8105 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008106 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008107 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008108 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008109 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008110 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008111 return e_invarg;
8112 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008113 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008114 }
8115
Bram Moolenaar473de612013-06-08 18:19:48 +02008116 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008117 return NULL;
8118}
8119#endif
8120
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008121#if defined(FEAT_EVAL) || defined(PROTO)
8122/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008123 * Set the scriptID for an option, taking care of setting the buffer- or
8124 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008125 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008126 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008127set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008128{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008129 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8130 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008131
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008132 /* Remember where the option was set. For local options need to do that
8133 * in the buffer or window structure. */
8134 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008135 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008136 if (both || (opt_flags & OPT_LOCAL))
8137 {
8138 if (indir & PV_BUF)
8139 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8140 else if (indir & PV_WIN)
8141 curwin->w_p_scriptID[indir & PV_MASK] = id;
8142 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008143}
8144#endif
8145
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146/*
8147 * Set the value of a boolean option, and take care of side effects.
8148 * Returns NULL for success, or an error message for an error.
8149 */
8150 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008151set_bool_option(
8152 int opt_idx, /* index in options[] table */
8153 char_u *varp, /* pointer to the option variable */
8154 int value, /* new value */
8155 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156{
8157 int old_value = *(int *)varp;
8158
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159 /* Disallow changing some options from secure mode */
8160 if ((secure
8161#ifdef HAVE_SANDBOX
8162 || sandbox != 0
8163#endif
8164 ) && (options[opt_idx].flags & P_SECURE))
8165 return e_secure;
8166
8167 *(int *)varp = value; /* set the new value */
8168#ifdef FEAT_EVAL
8169 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008170 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171#endif
8172
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008173#ifdef FEAT_GUI
8174 need_mouse_correct = TRUE;
8175#endif
8176
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177 /* May set global value for local option. */
8178 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8179 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8180
8181 /*
8182 * Handle side effects of changing a bool option.
8183 */
8184
8185 /* 'compatible' */
8186 if ((int *)varp == &p_cp)
8187 {
8188 compatible_set();
8189 }
8190
Bram Moolenaar920694c2016-08-21 17:45:02 +02008191#ifdef FEAT_LANGMAP
8192 if ((int *)varp == &p_lrm)
8193 /* 'langremap' -> !'langnoremap' */
8194 p_lnr = !p_lrm;
8195 else if ((int *)varp == &p_lnr)
8196 /* 'langnoremap' -> !'langremap' */
8197 p_lrm = !p_lnr;
8198#endif
8199
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008200#ifdef FEAT_PERSISTENT_UNDO
8201 /* 'undofile' */
8202 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8203 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008204 /* Only take action when the option was set. When reset we do not
8205 * delete the undo file, the option may be set again without making
8206 * any changes in between. */
8207 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008208 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008209 char_u hash[UNDO_HASH_SIZE];
8210 buf_T *save_curbuf = curbuf;
8211
Bram Moolenaar29323592016-07-24 22:04:11 +02008212 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008213 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008214 /* When 'undofile' is set globally: for every buffer, otherwise
8215 * only for the current buffer: Try to read in the undofile,
8216 * if one exists, the buffer wasn't changed and the buffer was
8217 * loaded */
8218 if ((curbuf == save_curbuf
8219 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8220 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8221 {
8222 u_compute_hash(hash);
8223 u_read_undo(NULL, hash, curbuf->b_fname);
8224 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008225 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008226 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008227 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008228 }
8229#endif
8230
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231 else if ((int *)varp == &curbuf->b_p_ro)
8232 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008233 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8235 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008236
8237 /* when 'readonly' is set may give W10 again */
8238 if (curbuf->b_p_ro)
8239 curbuf->b_did_warn = FALSE;
8240
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008242 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008243#endif
8244 }
8245
Bram Moolenaar9c449722010-07-20 18:44:27 +02008246#ifdef FEAT_GUI
8247 else if ((int *)varp == &p_mh)
8248 {
8249 if (!p_mh)
8250 gui_mch_mousehide(FALSE);
8251 }
8252#endif
8253
Bram Moolenaara539df02010-08-01 14:35:05 +02008254 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008256 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008257# ifdef FEAT_TERMINAL
8258 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008259 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008260 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008261 {
8262 curbuf->b_p_ma = FALSE;
8263 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8264 }
8265# endif
8266# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008267 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008268# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008269 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008270#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008271 /* when 'endofline' is changed, redraw the window title */
8272 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008273 {
8274 redraw_titles();
8275 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008276 /* when 'fixeol' is changed, redraw the window title */
8277 else if ((int *)varp == &curbuf->b_p_fixeol)
8278 {
8279 redraw_titles();
8280 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008281# ifdef FEAT_MBYTE
8282 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008283 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008284 {
8285 redraw_titles();
8286 }
8287# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288#endif
8289
8290 /* when 'bin' is set also set some other options */
8291 else if ((int *)varp == &curbuf->b_p_bin)
8292 {
8293 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8294#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008295 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008296#endif
8297 }
8298
8299#ifdef FEAT_AUTOCMD
8300 /* when 'buflisted' changes, trigger autocommands */
8301 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8302 {
8303 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8304 NULL, NULL, TRUE, curbuf);
8305 }
8306#endif
8307
8308 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8309 else if ((int *)varp == &curbuf->b_p_swf)
8310 {
8311 if (curbuf->b_p_swf && p_uc)
8312 ml_open_file(curbuf); /* create the swap file */
8313 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008314 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8315 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 mf_close_file(curbuf, TRUE); /* remove the swap file */
8317 }
8318
8319 /* when 'terse' is set change 'shortmess' */
8320 else if ((int *)varp == &p_terse)
8321 {
8322 char_u *p;
8323
8324 p = vim_strchr(p_shm, SHM_SEARCH);
8325
8326 /* insert 's' in p_shm */
8327 if (p_terse && p == NULL)
8328 {
8329 STRCPY(IObuff, p_shm);
8330 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008331 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332 }
8333 /* remove 's' from p_shm */
8334 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008335 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008336 }
8337
8338 /* when 'paste' is set or reset also change other options */
8339 else if ((int *)varp == &p_paste)
8340 {
8341 paste_option_changed();
8342 }
8343
8344 /* when 'insertmode' is set from an autocommand need to do work here */
8345 else if ((int *)varp == &p_im)
8346 {
8347 if (p_im)
8348 {
8349 if ((State & INSERT) == 0)
8350 need_start_insertmode = TRUE;
8351 stop_insert_mode = FALSE;
8352 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008353 /* only reset if it was set previously */
8354 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008355 {
8356 need_start_insertmode = FALSE;
8357 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008358 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359 clear_cmdline = TRUE; /* remove "(insert)" */
8360 restart_edit = 0;
8361 }
8362 }
8363
8364 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8365 else if ((int *)varp == &p_ic && p_hls)
8366 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008367 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008368 }
8369
8370#ifdef FEAT_SEARCH_EXTRA
8371 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8372 else if ((int *)varp == &p_hls)
8373 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008374 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375 }
8376#endif
8377
8378#ifdef FEAT_SCROLLBIND
8379 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8380 * at the end of normal_cmd() */
8381 else if ((int *)varp == &curwin->w_p_scb)
8382 {
8383 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008384 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008386 curwin->w_scbind_pos = curwin->w_topline;
8387 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008388 }
8389#endif
8390
8391#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8392 /* There can be only one window with 'previewwindow' set. */
8393 else if ((int *)varp == &curwin->w_p_pvw)
8394 {
8395 if (curwin->w_p_pvw)
8396 {
8397 win_T *win;
8398
Bram Moolenaar29323592016-07-24 22:04:11 +02008399 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400 if (win->w_p_pvw && win != curwin)
8401 {
8402 curwin->w_p_pvw = FALSE;
8403 return (char_u *)N_("E590: A preview window already exists");
8404 }
8405 }
8406 }
8407#endif
8408
8409 /* when 'textmode' is set or reset also change 'fileformat' */
8410 else if ((int *)varp == &curbuf->b_p_tx)
8411 {
8412 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8413 }
8414
8415 /* when 'textauto' is set or reset also change 'fileformats' */
8416 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417 set_string_option_direct((char_u *)"ffs", -1,
8418 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008419 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420
8421 /*
8422 * When 'lisp' option changes include/exclude '-' in
8423 * keyword characters.
8424 */
8425#ifdef FEAT_LISP
8426 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8427 {
8428 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8429 }
8430#endif
8431
8432#ifdef FEAT_TITLE
8433 /* when 'title' changed, may need to change the title; same for 'icon' */
8434 else if ((int *)varp == &p_title)
8435 {
8436 did_set_title(FALSE);
8437 }
8438
8439 else if ((int *)varp == &p_icon)
8440 {
8441 did_set_title(TRUE);
8442 }
8443#endif
8444
8445 else if ((int *)varp == &curbuf->b_changed)
8446 {
8447 if (!value)
8448 save_file_ff(curbuf); /* Buffer is unchanged */
8449#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008450 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451#endif
8452#ifdef FEAT_AUTOCMD
8453 modified_was_set = value;
8454#endif
8455 }
8456
8457#ifdef BACKSLASH_IN_FILENAME
8458 else if ((int *)varp == &p_ssl)
8459 {
8460 if (p_ssl)
8461 {
8462 psepc = '/';
8463 psepcN = '\\';
8464 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008465 }
8466 else
8467 {
8468 psepc = '\\';
8469 psepcN = '/';
8470 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 }
8472
8473 /* need to adjust the file name arguments and buffer names. */
8474 buflist_slash_adjust();
8475 alist_slash_adjust();
8476# ifdef FEAT_EVAL
8477 scriptnames_slash_adjust();
8478# endif
8479 }
8480#endif
8481
8482 /* If 'wrap' is set, set w_leftcol to zero. */
8483 else if ((int *)varp == &curwin->w_p_wrap)
8484 {
8485 if (curwin->w_p_wrap)
8486 curwin->w_leftcol = 0;
8487 }
8488
8489#ifdef FEAT_WINDOWS
8490 else if ((int *)varp == &p_ea)
8491 {
8492 if (p_ea && !old_value)
8493 win_equal(curwin, FALSE, 0);
8494 }
8495#endif
8496
8497 else if ((int *)varp == &p_wiv)
8498 {
8499 /*
8500 * When 'weirdinvert' changed, set/reset 't_xs'.
8501 * Then set 'weirdinvert' according to value of 't_xs'.
8502 */
8503 if (p_wiv && !old_value)
8504 T_XS = (char_u *)"y";
8505 else if (!p_wiv && old_value)
8506 T_XS = empty_option;
8507 p_wiv = (*T_XS != NUL);
8508 }
8509
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008510#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511 else if ((int *)varp == &p_beval)
8512 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008513 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008514 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008515 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516 gui_mch_disable_beval_area(balloonEval);
8517 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008518#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008520#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 else if ((int *)varp == &p_acd)
8522 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008523 /* Change directories when the 'acd' option is set now. */
8524 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525 }
8526#endif
8527
8528#ifdef FEAT_DIFF
8529 /* 'diff' */
8530 else if ((int *)varp == &curwin->w_p_diff)
8531 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008532 /* May add or remove the buffer from the list of diff buffers. */
8533 diff_buf_adjust(curwin);
8534# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008535 if (foldmethodIsDiff(curwin))
8536 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008537# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 }
8539#endif
8540
8541#ifdef USE_IM_CONTROL
8542 /* 'imdisable' */
8543 else if ((int *)varp == &p_imdisable)
8544 {
8545 /* Only de-activate it here, it will be enabled when changing mode. */
8546 if (p_imdisable)
8547 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008548 else if (State & INSERT)
8549 /* When the option is set from an autocommand, it may need to take
8550 * effect right away. */
8551 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008552 }
8553#endif
8554
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008555#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008556 /* 'spell' */
8557 else if ((int *)varp == &curwin->w_p_spell)
8558 {
8559 if (curwin->w_p_spell)
8560 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008561 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008562 if (errmsg != NULL)
8563 EMSG(_(errmsg));
8564 }
8565 }
8566#endif
8567
Bram Moolenaar071d4272004-06-13 20:20:40 +00008568#ifdef FEAT_FKMAP
8569 else if ((int *)varp == &p_altkeymap)
8570 {
8571 if (old_value != p_altkeymap)
8572 {
8573 if (!p_altkeymap)
8574 {
8575 p_hkmap = p_fkmap;
8576 p_fkmap = 0;
8577 }
8578 else
8579 {
8580 p_fkmap = p_hkmap;
8581 p_hkmap = 0;
8582 }
8583 (void)init_chartab();
8584 }
8585 }
8586
8587 /*
8588 * In case some second language keymapping options have changed, check
8589 * and correct the setting in a consistent way.
8590 */
8591
8592 /*
8593 * If hkmap or fkmap are set, reset Arabic keymapping.
8594 */
8595 if ((p_hkmap || p_fkmap) && p_altkeymap)
8596 {
8597 p_altkeymap = p_fkmap;
8598# ifdef FEAT_ARABIC
8599 curwin->w_p_arab = FALSE;
8600# endif
8601 (void)init_chartab();
8602 }
8603
8604 /*
8605 * If hkmap set, reset Farsi keymapping.
8606 */
8607 if (p_hkmap && p_altkeymap)
8608 {
8609 p_altkeymap = 0;
8610 p_fkmap = 0;
8611# ifdef FEAT_ARABIC
8612 curwin->w_p_arab = FALSE;
8613# endif
8614 (void)init_chartab();
8615 }
8616
8617 /*
8618 * If fkmap set, reset Hebrew keymapping.
8619 */
8620 if (p_fkmap && !p_altkeymap)
8621 {
8622 p_altkeymap = 1;
8623 p_hkmap = 0;
8624# ifdef FEAT_ARABIC
8625 curwin->w_p_arab = FALSE;
8626# endif
8627 (void)init_chartab();
8628 }
8629#endif
8630
8631#ifdef FEAT_ARABIC
8632 if ((int *)varp == &curwin->w_p_arab)
8633 {
8634 if (curwin->w_p_arab)
8635 {
8636 /*
8637 * 'arabic' is set, handle various sub-settings.
8638 */
8639 if (!p_tbidi)
8640 {
8641 /* set rightleft mode */
8642 if (!curwin->w_p_rl)
8643 {
8644 curwin->w_p_rl = TRUE;
8645 changed_window_setting();
8646 }
8647
8648 /* Enable Arabic shaping (major part of what Arabic requires) */
8649 if (!p_arshape)
8650 {
8651 p_arshape = TRUE;
8652 redraw_later_clear();
8653 }
8654 }
8655
8656 /* Arabic requires a utf-8 encoding, inform the user if its not
8657 * set. */
8658 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008659 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008660 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8661
Bram Moolenaar8820b482017-03-16 17:23:31 +01008662 msg_source(HL_ATTR(HLF_W));
8663 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008664#ifdef FEAT_EVAL
8665 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8666#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008667 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668
8669# ifdef FEAT_MBYTE
8670 /* set 'delcombine' */
8671 p_deco = TRUE;
8672# endif
8673
8674# ifdef FEAT_KEYMAP
8675 /* Force-set the necessary keymap for arabic */
8676 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8677 OPT_LOCAL);
8678# endif
8679# ifdef FEAT_FKMAP
8680 p_altkeymap = 0;
8681 p_hkmap = 0;
8682 p_fkmap = 0;
8683 (void)init_chartab();
8684# endif
8685 }
8686 else
8687 {
8688 /*
8689 * 'arabic' is reset, handle various sub-settings.
8690 */
8691 if (!p_tbidi)
8692 {
8693 /* reset rightleft mode */
8694 if (curwin->w_p_rl)
8695 {
8696 curwin->w_p_rl = FALSE;
8697 changed_window_setting();
8698 }
8699
8700 /* 'arabicshape' isn't reset, it is a global option and
8701 * another window may still need it "on". */
8702 }
8703
8704 /* 'delcombine' isn't reset, it is a global option and another
8705 * window may still want it "on". */
8706
8707# ifdef FEAT_KEYMAP
8708 /* Revert to the default keymap */
8709 curbuf->b_p_iminsert = B_IMODE_NONE;
8710 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8711# endif
8712 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008713 }
8714
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008715#endif
8716
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008717#ifdef FEAT_TERMGUICOLORS
8718 /* 'termguicolors' */
8719 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008720 {
8721# ifdef FEAT_GUI
8722 if (!gui.in_use && !gui.starting)
8723# endif
8724 highlight_gui_started();
8725 }
8726#endif
8727
Bram Moolenaar071d4272004-06-13 20:20:40 +00008728 /*
8729 * End of handling side effects for bool options.
8730 */
8731
Bram Moolenaar53744302015-07-17 17:38:22 +02008732 /* after handling side effects, call autocommand */
8733
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734 options[opt_idx].flags |= P_WAS_SET;
8735
Bram Moolenaar53744302015-07-17 17:38:22 +02008736#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8737 if (!starting)
8738 {
8739 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008740 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8741 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8742 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008743 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8744 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8745 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8746 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8747 reset_v_option_vars();
8748 }
8749#endif
8750
Bram Moolenaar071d4272004-06-13 20:20:40 +00008751 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008752 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008753 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008754 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 check_redraw(options[opt_idx].flags);
8756
8757 return NULL;
8758}
8759
8760/*
8761 * Set the value of a number option, and take care of side effects.
8762 * Returns NULL for success, or an error message for an error.
8763 */
8764 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008765set_num_option(
8766 int opt_idx, /* index in options[] table */
8767 char_u *varp, /* pointer to the option variable */
8768 long value, /* new value */
8769 char_u *errbuf, /* buffer for error messages */
8770 size_t errbuflen, /* length of "errbuf" */
8771 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 OPT_MODELINE */
8773{
8774 char_u *errmsg = NULL;
8775 long old_value = *(long *)varp;
8776 long old_Rows = Rows; /* remember old Rows */
8777 long old_Columns = Columns; /* remember old Columns */
8778 long *pp = (long *)varp;
8779
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008780 /* Disallow changing some options from secure mode. */
8781 if ((secure
8782#ifdef HAVE_SANDBOX
8783 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008785 ) && (options[opt_idx].flags & P_SECURE))
8786 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787
8788 *pp = value;
8789#ifdef FEAT_EVAL
8790 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008791 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008792#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008793#ifdef FEAT_GUI
8794 need_mouse_correct = TRUE;
8795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796
Bram Moolenaar14f24742012-08-08 18:01:05 +02008797 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798 {
8799 errmsg = e_positive;
8800 curbuf->b_p_sw = curbuf->b_p_ts;
8801 }
8802
8803 /*
8804 * Number options that need some action when changed
8805 */
8806#ifdef FEAT_WINDOWS
8807 if (pp == &p_wh || pp == &p_hh)
8808 {
8809 if (p_wh < 1)
8810 {
8811 errmsg = e_positive;
8812 p_wh = 1;
8813 }
8814 if (p_wmh > p_wh)
8815 {
8816 errmsg = e_winheight;
8817 p_wh = p_wmh;
8818 }
8819 if (p_hh < 0)
8820 {
8821 errmsg = e_positive;
8822 p_hh = 0;
8823 }
8824
8825 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008826 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 {
8828 if (pp == &p_wh && curwin->w_height < p_wh)
8829 win_setheight((int)p_wh);
8830 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8831 win_setheight((int)p_hh);
8832 }
8833 }
8834
8835 /* 'winminheight' */
8836 else if (pp == &p_wmh)
8837 {
8838 if (p_wmh < 0)
8839 {
8840 errmsg = e_positive;
8841 p_wmh = 0;
8842 }
8843 if (p_wmh > p_wh)
8844 {
8845 errmsg = e_winheight;
8846 p_wmh = p_wh;
8847 }
8848 win_setminheight();
8849 }
8850
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008851# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008852 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853 {
8854 if (p_wiw < 1)
8855 {
8856 errmsg = e_positive;
8857 p_wiw = 1;
8858 }
8859 if (p_wmw > p_wiw)
8860 {
8861 errmsg = e_winwidth;
8862 p_wiw = p_wmw;
8863 }
8864
8865 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008866 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867 win_setwidth((int)p_wiw);
8868 }
8869
8870 /* 'winminwidth' */
8871 else if (pp == &p_wmw)
8872 {
8873 if (p_wmw < 0)
8874 {
8875 errmsg = e_positive;
8876 p_wmw = 0;
8877 }
8878 if (p_wmw > p_wiw)
8879 {
8880 errmsg = e_winwidth;
8881 p_wmw = p_wiw;
8882 }
8883 win_setminheight();
8884 }
8885# endif
8886
8887#endif
8888
8889#ifdef FEAT_WINDOWS
8890 /* (re)set last window status line */
8891 else if (pp == &p_ls)
8892 {
8893 last_status(FALSE);
8894 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008895
8896 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008897 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008898 {
8899 shell_new_rows(); /* recompute window positions and heights */
8900 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901#endif
8902
8903#ifdef FEAT_GUI
8904 else if (pp == &p_linespace)
8905 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008906 /* Recompute gui.char_height and resize the Vim window to keep the
8907 * same number of lines. */
8908 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008909 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910 }
8911#endif
8912
8913#ifdef FEAT_FOLDING
8914 /* 'foldlevel' */
8915 else if (pp == &curwin->w_p_fdl)
8916 {
8917 if (curwin->w_p_fdl < 0)
8918 curwin->w_p_fdl = 0;
8919 newFoldLevel();
8920 }
8921
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008922 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 else if (pp == &curwin->w_p_fml)
8924 {
8925 foldUpdateAll(curwin);
8926 }
8927
8928 /* 'foldnestmax' */
8929 else if (pp == &curwin->w_p_fdn)
8930 {
8931 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8932 foldUpdateAll(curwin);
8933 }
8934
8935 /* 'foldcolumn' */
8936 else if (pp == &curwin->w_p_fdc)
8937 {
8938 if (curwin->w_p_fdc < 0)
8939 {
8940 errmsg = e_positive;
8941 curwin->w_p_fdc = 0;
8942 }
8943 else if (curwin->w_p_fdc > 12)
8944 {
8945 errmsg = e_invarg;
8946 curwin->w_p_fdc = 12;
8947 }
8948 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008949#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008950
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008951#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952 /* 'shiftwidth' or 'tabstop' */
8953 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8954 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008955# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956 if (foldmethodIsIndent(curwin))
8957 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008958# endif
8959# ifdef FEAT_CINDENT
8960 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8961 * parse 'cinoptions'. */
8962 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8963 parse_cino(curbuf);
8964# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008966#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008967
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008968#ifdef FEAT_MBYTE
8969 /* 'maxcombine' */
8970 else if (pp == &p_mco)
8971 {
8972 if (p_mco > MAX_MCO)
8973 p_mco = MAX_MCO;
8974 else if (p_mco < 0)
8975 p_mco = 0;
8976 screenclear(); /* will re-allocate the screen */
8977 }
8978#endif
8979
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 else if (pp == &curbuf->b_p_iminsert)
8981 {
8982 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8983 {
8984 errmsg = e_invarg;
8985 curbuf->b_p_iminsert = B_IMODE_NONE;
8986 }
8987 p_iminsert = curbuf->b_p_iminsert;
8988 if (termcap_active) /* don't do this in the alternate screen */
8989 showmode();
8990#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8991 /* Show/unshow value of 'keymap' in status lines. */
8992 status_redraw_curbuf();
8993#endif
8994 }
8995
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008996#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8997 /* 'imstyle' */
8998 else if (pp == &p_imst)
8999 {
9000 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9001 errmsg = e_invarg;
9002 }
9003#endif
9004
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009005 else if (pp == &p_window)
9006 {
9007 if (p_window < 1)
9008 p_window = 1;
9009 else if (p_window >= Rows)
9010 p_window = Rows - 1;
9011 }
9012
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 else if (pp == &curbuf->b_p_imsearch)
9014 {
9015 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9016 {
9017 errmsg = e_invarg;
9018 curbuf->b_p_imsearch = B_IMODE_NONE;
9019 }
9020 p_imsearch = curbuf->b_p_imsearch;
9021 }
9022
9023#ifdef FEAT_TITLE
9024 /* if 'titlelen' has changed, redraw the title */
9025 else if (pp == &p_titlelen)
9026 {
9027 if (p_titlelen < 0)
9028 {
9029 errmsg = e_positive;
9030 p_titlelen = 85;
9031 }
9032 if (starting != NO_SCREEN && old_value != p_titlelen)
9033 need_maketitle = TRUE;
9034 }
9035#endif
9036
9037 /* if p_ch changed value, change the command line height */
9038 else if (pp == &p_ch)
9039 {
9040 if (p_ch < 1)
9041 {
9042 errmsg = e_positive;
9043 p_ch = 1;
9044 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009045 if (p_ch > Rows - min_rows() + 1)
9046 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009047
9048 /* Only compute the new window layout when startup has been
9049 * completed. Otherwise the frame sizes may be wrong. */
9050 if (p_ch != old_value && full_screen
9051#ifdef FEAT_GUI
9052 && !gui.starting
9053#endif
9054 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009055 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056 }
9057
9058 /* when 'updatecount' changes from zero to non-zero, open swap files */
9059 else if (pp == &p_uc)
9060 {
9061 if (p_uc < 0)
9062 {
9063 errmsg = e_positive;
9064 p_uc = 100;
9065 }
9066 if (p_uc && !old_value)
9067 ml_open_files();
9068 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009069#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009070 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009071 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009072 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009073 {
9074 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009075 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009076 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009077 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009078 {
9079 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009080 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009081 }
9082 }
9083#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009084#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009085 else if (pp == &p_mzq)
9086 mzvim_reset_timer();
9087#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009088
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009089#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9090 /* 'pyxversion' */
9091 else if (pp == &p_pyx)
9092 {
9093 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9094 errmsg = e_invarg;
9095 }
9096#endif
9097
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098 /* sync undo before 'undolevels' changes */
9099 else if (pp == &p_ul)
9100 {
9101 /* use the old value, otherwise u_sync() may not work properly */
9102 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009103 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009104 p_ul = value;
9105 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009106 else if (pp == &curbuf->b_p_ul)
9107 {
9108 /* use the old value, otherwise u_sync() may not work properly */
9109 curbuf->b_p_ul = old_value;
9110 u_sync(TRUE);
9111 curbuf->b_p_ul = value;
9112 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009113
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009114#ifdef FEAT_LINEBREAK
9115 /* 'numberwidth' must be positive */
9116 else if (pp == &curwin->w_p_nuw)
9117 {
9118 if (curwin->w_p_nuw < 1)
9119 {
9120 errmsg = e_positive;
9121 curwin->w_p_nuw = 1;
9122 }
9123 if (curwin->w_p_nuw > 10)
9124 {
9125 errmsg = e_invarg;
9126 curwin->w_p_nuw = 10;
9127 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009128 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009129 }
9130#endif
9131
Bram Moolenaar1a384422010-07-14 19:53:30 +02009132 else if (pp == &curbuf->b_p_tw)
9133 {
9134 if (curbuf->b_p_tw < 0)
9135 {
9136 errmsg = e_positive;
9137 curbuf->b_p_tw = 0;
9138 }
9139#ifdef FEAT_SYN_HL
9140# ifdef FEAT_WINDOWS
9141 {
9142 win_T *wp;
9143 tabpage_T *tp;
9144
9145 FOR_ALL_TAB_WINDOWS(tp, wp)
9146 check_colorcolumn(wp);
9147 }
9148# else
9149 check_colorcolumn(curwin);
9150# endif
9151#endif
9152 }
9153
Bram Moolenaar071d4272004-06-13 20:20:40 +00009154 /*
9155 * Check the bounds for numeric options here
9156 */
9157 if (Rows < min_rows() && full_screen)
9158 {
9159 if (errbuf != NULL)
9160 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009161 vim_snprintf((char *)errbuf, errbuflen,
9162 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009163 errmsg = errbuf;
9164 }
9165 Rows = min_rows();
9166 }
9167 if (Columns < MIN_COLUMNS && full_screen)
9168 {
9169 if (errbuf != NULL)
9170 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009171 vim_snprintf((char *)errbuf, errbuflen,
9172 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009173 errmsg = errbuf;
9174 }
9175 Columns = MIN_COLUMNS;
9176 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009177 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179 /*
9180 * If the screen (shell) height has been changed, assume it is the
9181 * physical screenheight.
9182 */
9183 if (old_Rows != Rows || old_Columns != Columns)
9184 {
9185 /* Changing the screen size is not allowed while updating the screen. */
9186 if (updating_screen)
9187 *pp = old_value;
9188 else if (full_screen
9189#ifdef FEAT_GUI
9190 && !gui.starting
9191#endif
9192 )
9193 set_shellsize((int)Columns, (int)Rows, TRUE);
9194 else
9195 {
9196 /* Postpone the resizing; check the size and cmdline position for
9197 * messages. */
9198 check_shellsize();
9199 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9200 cmdline_row = Rows - p_ch;
9201 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009202 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009203 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009204 }
9205
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206 if (curbuf->b_p_ts <= 0)
9207 {
9208 errmsg = e_positive;
9209 curbuf->b_p_ts = 8;
9210 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009211 if (p_tm < 0)
9212 {
9213 errmsg = e_positive;
9214 p_tm = 0;
9215 }
9216 if ((curwin->w_p_scr <= 0
9217 || (curwin->w_p_scr > curwin->w_height
9218 && curwin->w_height > 0))
9219 && full_screen)
9220 {
9221 if (pp == &(curwin->w_p_scr))
9222 {
9223 if (curwin->w_p_scr != 0)
9224 errmsg = e_scroll;
9225 win_comp_scroll(curwin);
9226 }
9227 /* If 'scroll' became invalid because of a side effect silently adjust
9228 * it. */
9229 else if (curwin->w_p_scr <= 0)
9230 curwin->w_p_scr = 1;
9231 else /* curwin->w_p_scr > curwin->w_height */
9232 curwin->w_p_scr = curwin->w_height;
9233 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009234 if (p_hi < 0)
9235 {
9236 errmsg = e_positive;
9237 p_hi = 0;
9238 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009239 else if (p_hi > 10000)
9240 {
9241 errmsg = e_invarg;
9242 p_hi = 10000;
9243 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009244 if (p_re < 0 || p_re > 2)
9245 {
9246 errmsg = e_invarg;
9247 p_re = 0;
9248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 if (p_report < 0)
9250 {
9251 errmsg = e_positive;
9252 p_report = 1;
9253 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009254 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 {
9256 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9257 p_sj = Rows / 2;
9258 else
9259 {
9260 errmsg = e_scroll;
9261 p_sj = 1;
9262 }
9263 }
9264 if (p_so < 0 && full_screen)
9265 {
9266 errmsg = e_scroll;
9267 p_so = 0;
9268 }
9269 if (p_siso < 0 && full_screen)
9270 {
9271 errmsg = e_positive;
9272 p_siso = 0;
9273 }
9274#ifdef FEAT_CMDWIN
9275 if (p_cwh < 1)
9276 {
9277 errmsg = e_positive;
9278 p_cwh = 1;
9279 }
9280#endif
9281 if (p_ut < 0)
9282 {
9283 errmsg = e_positive;
9284 p_ut = 2000;
9285 }
9286 if (p_ss < 0)
9287 {
9288 errmsg = e_positive;
9289 p_ss = 0;
9290 }
9291
9292 /* May set global value for local option. */
9293 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9294 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9295
9296 options[opt_idx].flags |= P_WAS_SET;
9297
Bram Moolenaar53744302015-07-17 17:38:22 +02009298#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9299 if (!starting && errmsg == NULL)
9300 {
9301 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009302 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9303 vim_snprintf((char *)buf_new, 10, "%ld", value);
9304 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009305 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9306 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9307 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9308 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9309 reset_v_option_vars();
9310 }
9311#endif
9312
Bram Moolenaar071d4272004-06-13 20:20:40 +00009313 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009314 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009315 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009316 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009317 check_redraw(options[opt_idx].flags);
9318
9319 return errmsg;
9320}
9321
9322/*
9323 * Called after an option changed: check if something needs to be redrawn.
9324 */
9325 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009326check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327{
9328 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009329 int doclear = (flags & P_RCLR) == P_RCLR;
9330 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331
9332#ifdef FEAT_WINDOWS
9333 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9334 status_redraw_all();
9335#endif
9336
9337 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9338 changed_window_setting();
9339 if (flags & P_RBUF)
9340 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009341 if (flags & P_RWINONLY)
9342 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009343 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009344 redraw_all_later(CLEAR);
9345 else if (all)
9346 redraw_all_later(NOT_VALID);
9347}
9348
9349/*
9350 * Find index for option 'arg'.
9351 * Return -1 if not found.
9352 */
9353 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009354findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355{
9356 int opt_idx;
9357 char *s, *p;
9358 static short quick_tab[27] = {0, 0}; /* quick access table */
9359 int is_term_opt;
9360
9361 /*
9362 * For first call: Initialize the quick-access table.
9363 * It contains the index for the first option that starts with a certain
9364 * letter. There are 26 letters, plus the first "t_" option.
9365 */
9366 if (quick_tab[1] == 0)
9367 {
9368 p = options[0].fullname;
9369 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9370 {
9371 if (s[0] != p[0])
9372 {
9373 if (s[0] == 't' && s[1] == '_')
9374 quick_tab[26] = opt_idx;
9375 else
9376 quick_tab[CharOrdLow(s[0])] = opt_idx;
9377 }
9378 p = s;
9379 }
9380 }
9381
9382 /*
9383 * Check for name starting with an illegal character.
9384 */
9385#ifdef EBCDIC
9386 if (!islower(arg[0]))
9387#else
9388 if (arg[0] < 'a' || arg[0] > 'z')
9389#endif
9390 return -1;
9391
9392 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9393 if (is_term_opt)
9394 opt_idx = quick_tab[26];
9395 else
9396 opt_idx = quick_tab[CharOrdLow(arg[0])];
9397 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9398 {
9399 if (STRCMP(arg, s) == 0) /* match full name */
9400 break;
9401 }
9402 if (s == NULL && !is_term_opt)
9403 {
9404 opt_idx = quick_tab[CharOrdLow(arg[0])];
9405 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9406 {
9407 s = options[opt_idx].shortname;
9408 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9409 break;
9410 s = NULL;
9411 }
9412 }
9413 if (s == NULL)
9414 opt_idx = -1;
9415 return opt_idx;
9416}
9417
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009418#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009419/*
9420 * Get the value for an option.
9421 *
9422 * Returns:
9423 * Number or Toggle option: 1, *numval gets value.
9424 * String option: 0, *stringval gets allocated string.
9425 * Hidden Number or Toggle option: -1.
9426 * hidden String option: -2.
9427 * unknown option: -3.
9428 */
9429 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009430get_option_value(
9431 char_u *name,
9432 long *numval,
9433 char_u **stringval, /* NULL when only checking existence */
9434 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009435{
9436 int opt_idx;
9437 char_u *varp;
9438
9439 opt_idx = findoption(name);
9440 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009441 {
9442 int key;
9443
9444 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9445 && (key = find_key_option(name)) != 0)
9446 {
9447 char_u key_name[2];
9448 char_u *p;
9449
9450 if (key < 0)
9451 {
9452 key_name[0] = KEY2TERMCAP0(key);
9453 key_name[1] = KEY2TERMCAP1(key);
9454 }
9455 else
9456 {
9457 key_name[0] = KS_KEY;
9458 key_name[1] = (key & 0xff);
9459 }
9460 p = find_termcode(key_name);
9461 if (p != NULL)
9462 {
9463 if (stringval != NULL)
9464 *stringval = vim_strsave(p);
9465 return 0;
9466 }
9467 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009468 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009469 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009470
9471 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9472
9473 if (options[opt_idx].flags & P_STRING)
9474 {
9475 if (varp == NULL) /* hidden option */
9476 return -2;
9477 if (stringval != NULL)
9478 {
9479#ifdef FEAT_CRYPT
9480 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009481 if ((char_u **)varp == &curbuf->b_p_key
9482 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009483 *stringval = vim_strsave((char_u *)"*****");
9484 else
9485#endif
9486 *stringval = vim_strsave(*(char_u **)(varp));
9487 }
9488 return 0;
9489 }
9490
9491 if (varp == NULL) /* hidden option */
9492 return -1;
9493 if (options[opt_idx].flags & P_NUM)
9494 *numval = *(long *)varp;
9495 else
9496 {
9497 /* Special case: 'modified' is b_changed, but we also want to consider
9498 * it set when 'ff' or 'fenc' changed. */
9499 if ((int *)varp == &curbuf->b_changed)
9500 *numval = curbufIsChanged();
9501 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009502 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009503 }
9504 return 1;
9505}
9506#endif
9507
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009508#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009509/*
9510 * Returns the option attributes and its value. Unlike the above function it
9511 * will return either global value or local value of the option depending on
9512 * what was requested, but it will never return global value if it was
9513 * requested to return local one and vice versa. Neither it will return
9514 * buffer-local value if it was requested to return window-local one.
9515 *
9516 * Pretends that option is absent if it is not present in the requested scope
9517 * (i.e. has no global, window-local or buffer-local value depending on
9518 * opt_type). Uses
9519 *
9520 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009521 * 0 hidden or unknown option, also option that does not have requested
9522 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009523 * see SOPT_* in vim.h for other flags
9524 *
9525 * Possible opt_type values: see SREQ_* in vim.h
9526 */
9527 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009528get_option_value_strict(
9529 char_u *name,
9530 long *numval,
9531 char_u **stringval, /* NULL when only obtaining attributes */
9532 int opt_type,
9533 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009534{
9535 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009536 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009537 struct vimoption *p;
9538 int r = 0;
9539
9540 opt_idx = findoption(name);
9541 if (opt_idx < 0)
9542 return 0;
9543
9544 p = &(options[opt_idx]);
9545
9546 /* Hidden option */
9547 if (p->var == NULL)
9548 return 0;
9549
9550 if (p->flags & P_BOOL)
9551 r |= SOPT_BOOL;
9552 else if (p->flags & P_NUM)
9553 r |= SOPT_NUM;
9554 else if (p->flags & P_STRING)
9555 r |= SOPT_STRING;
9556
9557 if (p->indir == PV_NONE)
9558 {
9559 if (opt_type == SREQ_GLOBAL)
9560 r |= SOPT_GLOBAL;
9561 else
9562 return 0; /* Did not request global-only option */
9563 }
9564 else
9565 {
9566 if (p->indir & PV_BOTH)
9567 r |= SOPT_GLOBAL;
9568 else if (opt_type == SREQ_GLOBAL)
9569 return 0; /* Requested global option */
9570
9571 if (p->indir & PV_WIN)
9572 {
9573 if (opt_type == SREQ_BUF)
9574 return 0; /* Did not request window-local option */
9575 else
9576 r |= SOPT_WIN;
9577 }
9578 else if (p->indir & PV_BUF)
9579 {
9580 if (opt_type == SREQ_WIN)
9581 return 0; /* Did not request buffer-local option */
9582 else
9583 r |= SOPT_BUF;
9584 }
9585 }
9586
9587 if (stringval == NULL)
9588 return r;
9589
9590 if (opt_type == SREQ_GLOBAL)
9591 varp = p->var;
9592 else
9593 {
9594 if (opt_type == SREQ_BUF)
9595 {
9596 /* Special case: 'modified' is b_changed, but we also want to
9597 * consider it set when 'ff' or 'fenc' changed. */
9598 if (p->indir == PV_MOD)
9599 {
9600 *numval = bufIsChanged((buf_T *) from);
9601 varp = NULL;
9602 }
9603#ifdef FEAT_CRYPT
9604 else if (p->indir == PV_KEY)
9605 {
9606 /* never return the value of the crypt key */
9607 *stringval = NULL;
9608 varp = NULL;
9609 }
9610#endif
9611 else
9612 {
9613 aco_save_T aco;
9614 aucmd_prepbuf(&aco, (buf_T *) from);
9615 varp = get_varp(p);
9616 aucmd_restbuf(&aco);
9617 }
9618 }
9619 else if (opt_type == SREQ_WIN)
9620 {
9621 win_T *save_curwin;
9622 save_curwin = curwin;
9623 curwin = (win_T *) from;
9624 curbuf = curwin->w_buffer;
9625 varp = get_varp(p);
9626 curwin = save_curwin;
9627 curbuf = curwin->w_buffer;
9628 }
9629 if (varp == p->var)
9630 return (r | SOPT_UNSET);
9631 }
9632
9633 if (varp != NULL)
9634 {
9635 if (p->flags & P_STRING)
9636 *stringval = vim_strsave(*(char_u **)(varp));
9637 else if (p->flags & P_NUM)
9638 *numval = *(long *) varp;
9639 else
9640 *numval = *(int *)varp;
9641 }
9642
9643 return r;
9644}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009645
9646/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009647 * Iterate over options. First argument is a pointer to a pointer to a
9648 * structure inside options[] array, second is option type like in the above
9649 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009650 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009651 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009652 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009653 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009654 * first argument to NULL.
9655 *
9656 * Returns full option name for current option on each call.
9657 */
9658 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009659option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009660{
9661 struct vimoption *ret = NULL;
9662 do
9663 {
9664 if (*option == NULL)
9665 *option = (void *) options;
9666 else if (((struct vimoption *) (*option))->fullname == NULL)
9667 {
9668 *option = NULL;
9669 return NULL;
9670 }
9671 else
9672 *option = (void *) (((struct vimoption *) (*option)) + 1);
9673
9674 ret = ((struct vimoption *) (*option));
9675
9676 /* Hidden option */
9677 if (ret->var == NULL)
9678 {
9679 ret = NULL;
9680 continue;
9681 }
9682
9683 switch (opt_type)
9684 {
9685 case SREQ_GLOBAL:
9686 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9687 ret = NULL;
9688 break;
9689 case SREQ_BUF:
9690 if (!(ret->indir & PV_BUF))
9691 ret = NULL;
9692 break;
9693 case SREQ_WIN:
9694 if (!(ret->indir & PV_WIN))
9695 ret = NULL;
9696 break;
9697 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009698 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009699 return NULL;
9700 }
9701 }
9702 while (ret == NULL);
9703
9704 return (char_u *)ret->fullname;
9705}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009706#endif
9707
Bram Moolenaar071d4272004-06-13 20:20:40 +00009708/*
9709 * Set the value of option "name".
9710 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009711 *
9712 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009713 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009714 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009715set_option_value(
9716 char_u *name,
9717 long number,
9718 char_u *string,
9719 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720{
9721 int opt_idx;
9722 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009723 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009724
9725 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009726 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009727 {
9728 int key;
9729
9730 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9731 && (key = find_key_option(name)) != 0)
9732 {
9733 char_u key_name[2];
9734
9735 if (key < 0)
9736 {
9737 key_name[0] = KEY2TERMCAP0(key);
9738 key_name[1] = KEY2TERMCAP1(key);
9739 }
9740 else
9741 {
9742 key_name[0] = KS_KEY;
9743 key_name[1] = (key & 0xff);
9744 }
9745 add_termcode(key_name, string, FALSE);
9746 if (full_screen)
9747 ttest(FALSE);
9748 redraw_all_later(CLEAR);
9749 return NULL;
9750 }
9751
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009754 else
9755 {
9756 flags = options[opt_idx].flags;
9757#ifdef HAVE_SANDBOX
9758 /* Disallow changing some options in the sandbox */
9759 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009760 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009761 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009762 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009763 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009765 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009766 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767 else
9768 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009769 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770 if (varp != NULL) /* hidden option is not changed */
9771 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009772 if (number == 0 && string != NULL)
9773 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009774 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009775
9776 /* Either we are given a string or we are setting option
9777 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009778 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009779 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009780 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009781 {
9782 /* There's another character after zeros or the string
9783 * is empty. In both cases, we are trying to set a
9784 * num option using a string. */
9785 EMSG3(_("E521: Number required: &%s = '%s'"),
9786 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009787 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009788
9789 }
9790 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009791 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009792 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009793 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009794 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009795 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009796 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009797 }
9798 }
9799 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009800 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009801}
9802
9803/*
9804 * Get the terminal code for a terminal option.
9805 * Returns NULL when not found.
9806 */
9807 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009808get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009809{
9810 int opt_idx;
9811 char_u *varp;
9812
9813 if (tname[0] != 't' || tname[1] != '_' ||
9814 tname[2] == NUL || tname[3] == NUL)
9815 return NULL;
9816 if ((opt_idx = findoption(tname)) >= 0)
9817 {
9818 varp = get_varp(&(options[opt_idx]));
9819 if (varp != NULL)
9820 varp = *(char_u **)(varp);
9821 return varp;
9822 }
9823 return find_termcode(tname + 2);
9824}
9825
9826 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009827get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009828{
9829 int i;
9830
9831 i = findoption((char_u *)"hl");
9832 if (i >= 0)
9833 return options[i].def_val[VI_DEFAULT];
9834 return (char_u *)NULL;
9835}
9836
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009837#if defined(FEAT_MBYTE) || defined(PROTO)
9838 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009839get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009840{
9841 int i;
9842
9843 i = findoption((char_u *)"enc");
9844 if (i >= 0)
9845 return options[i].def_val[VI_DEFAULT];
9846 return (char_u *)NULL;
9847}
9848#endif
9849
Bram Moolenaar071d4272004-06-13 20:20:40 +00009850/*
9851 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9852 */
9853 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009854find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009855{
9856 int key;
9857 int modifiers;
9858
9859 /*
9860 * Don't use get_special_key_code() for t_xx, we don't want it to call
9861 * add_termcap_entry().
9862 */
9863 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9864 key = TERMCAP2KEY(arg[2], arg[3]);
9865 else
9866 {
9867 --arg; /* put arg at the '<' */
9868 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009869 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 if (modifiers) /* can't handle modifiers here */
9871 key = 0;
9872 }
9873 return key;
9874}
9875
9876/*
9877 * if 'all' == 0: show changed options
9878 * if 'all' == 1: show all normal options
9879 * if 'all' == 2: show all terminal options
9880 */
9881 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009882showoptions(
9883 int all,
9884 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009885{
9886 struct vimoption *p;
9887 int col;
9888 int isterm;
9889 char_u *varp;
9890 struct vimoption **items;
9891 int item_count;
9892 int run;
9893 int row, rows;
9894 int cols;
9895 int i;
9896 int len;
9897
9898#define INC 20
9899#define GAP 3
9900
9901 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9902 PARAM_COUNT));
9903 if (items == NULL)
9904 return;
9905
9906 /* Highlight title */
9907 if (all == 2)
9908 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9909 else if (opt_flags & OPT_GLOBAL)
9910 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9911 else if (opt_flags & OPT_LOCAL)
9912 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9913 else
9914 MSG_PUTS_TITLE(_("\n--- Options ---"));
9915
9916 /*
9917 * do the loop two times:
9918 * 1. display the short items
9919 * 2. display the long items (only strings and numbers)
9920 */
9921 for (run = 1; run <= 2 && !got_int; ++run)
9922 {
9923 /*
9924 * collect the items in items[]
9925 */
9926 item_count = 0;
9927 for (p = &options[0]; p->fullname != NULL; p++)
9928 {
9929 varp = NULL;
9930 isterm = istermoption(p);
9931 if (opt_flags != 0)
9932 {
9933 if (p->indir != PV_NONE && !isterm)
9934 varp = get_varp_scope(p, opt_flags);
9935 }
9936 else
9937 varp = get_varp(p);
9938 if (varp != NULL
9939 && ((all == 2 && isterm)
9940 || (all == 1 && !isterm)
9941 || (all == 0 && !optval_default(p, varp))))
9942 {
9943 if (p->flags & P_BOOL)
9944 len = 1; /* a toggle option fits always */
9945 else
9946 {
9947 option_value2string(p, opt_flags);
9948 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9949 }
9950 if ((len <= INC - GAP && run == 1) ||
9951 (len > INC - GAP && run == 2))
9952 items[item_count++] = p;
9953 }
9954 }
9955
9956 /*
9957 * display the items
9958 */
9959 if (run == 1)
9960 {
9961 cols = (Columns + GAP - 3) / INC;
9962 if (cols == 0)
9963 cols = 1;
9964 rows = (item_count + cols - 1) / cols;
9965 }
9966 else /* run == 2 */
9967 rows = item_count;
9968 for (row = 0; row < rows && !got_int; ++row)
9969 {
9970 msg_putchar('\n'); /* go to next line */
9971 if (got_int) /* 'q' typed in more */
9972 break;
9973 col = 0;
9974 for (i = row; i < item_count; i += rows)
9975 {
9976 msg_col = col; /* make columns */
9977 showoneopt(items[i], opt_flags);
9978 col += INC;
9979 }
9980 out_flush();
9981 ui_breakcheck();
9982 }
9983 }
9984 vim_free(items);
9985}
9986
9987/*
9988 * Return TRUE if option "p" has its default value.
9989 */
9990 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009991optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992{
9993 int dvi;
9994
9995 if (varp == NULL)
9996 return TRUE; /* hidden option is always at default */
9997 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9998 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009999 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010000 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010001 /* the cast to long is required for Manx C, long_i is
10002 * needed for MSVC */
10003 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004 /* P_STRING */
10005 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10006}
10007
10008/*
10009 * showoneopt: show the value of one option
10010 * must not be called with a hidden option!
10011 */
10012 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010013showoneopt(
10014 struct vimoption *p,
10015 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010017 char_u *varp;
10018 int save_silent = silent_mode;
10019
10020 silent_mode = FALSE;
10021 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010022
10023 varp = get_varp_scope(p, opt_flags);
10024
10025 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10026 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10027 ? !curbufIsChanged() : !*(int *)varp))
10028 MSG_PUTS("no");
10029 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10030 MSG_PUTS("--");
10031 else
10032 MSG_PUTS(" ");
10033 MSG_PUTS(p->fullname);
10034 if (!(p->flags & P_BOOL))
10035 {
10036 msg_putchar('=');
10037 /* put value string in NameBuff */
10038 option_value2string(p, opt_flags);
10039 msg_outtrans(NameBuff);
10040 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010041
10042 silent_mode = save_silent;
10043 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010044}
10045
10046/*
10047 * Write modified options as ":set" commands to a file.
10048 *
10049 * There are three values for "opt_flags":
10050 * OPT_GLOBAL: Write global option values and fresh values of
10051 * buffer-local options (used for start of a session
10052 * file).
10053 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10054 * curwin (used for a vimrc file).
10055 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10056 * and local values for window-local options of
10057 * curwin. Local values are also written when at the
10058 * default value, because a modeline or autocommand
10059 * may have set them when doing ":edit file" and the
10060 * user has set them back at the default or fresh
10061 * value.
10062 * When "local_only" is TRUE, don't write fresh
10063 * values, only local values (for ":mkview").
10064 * (fresh value = value used for a new buffer or window for a local option).
10065 *
10066 * Return FAIL on error, OK otherwise.
10067 */
10068 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010069makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070{
10071 struct vimoption *p;
10072 char_u *varp; /* currently used value */
10073 char_u *varp_fresh; /* local value */
10074 char_u *varp_local = NULL; /* fresh value */
10075 char *cmd;
10076 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010077 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010078
10079 /*
10080 * The options that don't have a default (terminal name, columns, lines)
10081 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010082 * Do the loop over "options[]" twice: once for options with the
10083 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010084 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010085 for (pri = 1; pri >= 0; --pri)
10086 {
10087 for (p = &options[0]; !istermoption(p); p++)
10088 if (!(p->flags & P_NO_MKRC)
10089 && !istermoption(p)
10090 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010091 {
10092 /* skip global option when only doing locals */
10093 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10094 continue;
10095
10096 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10097 * file, they are always buffer-specific. */
10098 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10099 continue;
10100
10101 /* Global values are only written when not at the default value. */
10102 varp = get_varp_scope(p, opt_flags);
10103 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10104 continue;
10105
10106 round = 2;
10107 if (p->indir != PV_NONE)
10108 {
10109 if (p->var == VAR_WIN)
10110 {
10111 /* skip window-local option when only doing globals */
10112 if (!(opt_flags & OPT_LOCAL))
10113 continue;
10114 /* When fresh value of window-local option is not at the
10115 * default, need to write it too. */
10116 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10117 {
10118 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10119 if (!optval_default(p, varp_fresh))
10120 {
10121 round = 1;
10122 varp_local = varp;
10123 varp = varp_fresh;
10124 }
10125 }
10126 }
10127 }
10128
10129 /* Round 1: fresh value for window-local options.
10130 * Round 2: other values */
10131 for ( ; round <= 2; varp = varp_local, ++round)
10132 {
10133 if (round == 1 || (opt_flags & OPT_GLOBAL))
10134 cmd = "set";
10135 else
10136 cmd = "setlocal";
10137
10138 if (p->flags & P_BOOL)
10139 {
10140 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10141 return FAIL;
10142 }
10143 else if (p->flags & P_NUM)
10144 {
10145 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10146 return FAIL;
10147 }
10148 else /* P_STRING */
10149 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010150#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10151 int do_endif = FALSE;
10152
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153 /* Don't set 'syntax' and 'filetype' again if the value is
10154 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010155 if (
10156# if defined(FEAT_SYN_HL)
10157 p->indir == PV_SYN
10158# if defined(FEAT_AUTOCMD)
10159 ||
10160# endif
10161# endif
10162# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010163 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010164# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010165 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166 {
10167 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10168 *(char_u **)(varp)) < 0
10169 || put_eol(fd) < 0)
10170 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010171 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010173#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10175 (p->flags & P_EXPAND) != 0) == FAIL)
10176 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010177#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10178 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 {
10180 if (put_line(fd, "endif") == FAIL)
10181 return FAIL;
10182 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010183#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184 }
10185 }
10186 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010187 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 return OK;
10189}
10190
10191#if defined(FEAT_FOLDING) || defined(PROTO)
10192/*
10193 * Generate set commands for the local fold options only. Used when
10194 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10195 */
10196 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010197makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198{
10199 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10200# ifdef FEAT_EVAL
10201 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10202 == FAIL
10203# endif
10204 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10205 == FAIL
10206 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10207 == FAIL
10208 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10209 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10210 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10211 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10212 )
10213 return FAIL;
10214
10215 return OK;
10216}
10217#endif
10218
10219 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010220put_setstring(
10221 FILE *fd,
10222 char *cmd,
10223 char *name,
10224 char_u **valuep,
10225 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226{
10227 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010228 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229
10230 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10231 return FAIL;
10232 if (*valuep != NULL)
10233 {
10234 /* Output 'pastetoggle' as key names. For other
10235 * options some characters have to be escaped with
10236 * CTRL-V or backslash */
10237 if (valuep == &p_pt)
10238 {
10239 s = *valuep;
10240 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010241 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242 return FAIL;
10243 }
10244 else if (expand)
10245 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010246 buf = alloc(MAXPATHL);
10247 if (buf == NULL)
10248 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010249 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10250 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010251 {
10252 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010254 }
10255 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 }
10257 else if (put_escstr(fd, *valuep, 2) == FAIL)
10258 return FAIL;
10259 }
10260 if (put_eol(fd) < 0)
10261 return FAIL;
10262 return OK;
10263}
10264
10265 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010266put_setnum(
10267 FILE *fd,
10268 char *cmd,
10269 char *name,
10270 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271{
10272 long wc;
10273
10274 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10275 return FAIL;
10276 if (wc_use_keyname((char_u *)valuep, &wc))
10277 {
10278 /* print 'wildchar' and 'wildcharm' as a key name */
10279 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10280 return FAIL;
10281 }
10282 else if (fprintf(fd, "%ld", *valuep) < 0)
10283 return FAIL;
10284 if (put_eol(fd) < 0)
10285 return FAIL;
10286 return OK;
10287}
10288
10289 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010290put_setbool(
10291 FILE *fd,
10292 char *cmd,
10293 char *name,
10294 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010295{
Bram Moolenaar893de922007-10-02 18:40:57 +000010296 if (value < 0) /* global/local option using global value */
10297 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10299 || put_eol(fd) < 0)
10300 return FAIL;
10301 return OK;
10302}
10303
10304/*
10305 * Clear all the terminal options.
10306 * If the option has been allocated, free the memory.
10307 * Terminal options are never hidden or indirect.
10308 */
10309 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010310clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312 /*
10313 * Reset a few things before clearing the old options. This may cause
10314 * outputting a few things that the terminal doesn't understand, but the
10315 * screen will be cleared later, so this is OK.
10316 */
10317#ifdef FEAT_MOUSE_TTY
10318 mch_setmouse(FALSE); /* switch mouse off */
10319#endif
10320#ifdef FEAT_TITLE
10321 mch_restore_title(3); /* restore window titles */
10322#endif
10323#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10324 /* When starting the GUI close the display opened for the clipboard.
10325 * After restoring the title, because that will need the display. */
10326 if (gui.starting)
10327 clear_xterm_clip();
10328#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010329 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010331 free_termoptions();
10332}
10333
10334 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010335free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010336{
10337 struct vimoption *p;
10338
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339 for (p = &options[0]; p->fullname != NULL; p++)
10340 if (istermoption(p))
10341 {
10342 if (p->flags & P_ALLOCED)
10343 free_string_option(*(char_u **)(p->var));
10344 if (p->flags & P_DEF_ALLOCED)
10345 free_string_option(p->def_val[VI_DEFAULT]);
10346 *(char_u **)(p->var) = empty_option;
10347 p->def_val[VI_DEFAULT] = empty_option;
10348 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10349 }
10350 clear_termcodes();
10351}
10352
10353/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010354 * Free the string for one term option, if it was allocated.
10355 * Set the string to empty_option and clear allocated flag.
10356 * "var" points to the option value.
10357 */
10358 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010359free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010360{
10361 struct vimoption *p;
10362
10363 for (p = &options[0]; p->fullname != NULL; p++)
10364 if (p->var == var)
10365 {
10366 if (p->flags & P_ALLOCED)
10367 free_string_option(*(char_u **)(p->var));
10368 *(char_u **)(p->var) = empty_option;
10369 p->flags &= ~P_ALLOCED;
10370 break;
10371 }
10372}
10373
10374/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375 * Set the terminal option defaults to the current value.
10376 * Used after setting the terminal name.
10377 */
10378 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010379set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010380{
10381 struct vimoption *p;
10382
10383 for (p = &options[0]; p->fullname != NULL; p++)
10384 {
10385 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10386 {
10387 if (p->flags & P_DEF_ALLOCED)
10388 {
10389 free_string_option(p->def_val[VI_DEFAULT]);
10390 p->flags &= ~P_DEF_ALLOCED;
10391 }
10392 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10393 if (p->flags & P_ALLOCED)
10394 {
10395 p->flags |= P_DEF_ALLOCED;
10396 p->flags &= ~P_ALLOCED; /* don't free the value now */
10397 }
10398 }
10399 }
10400}
10401
10402/*
10403 * return TRUE if 'p' starts with 't_'
10404 */
10405 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010406istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407{
10408 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10409}
10410
10411/*
10412 * Compute columns for ruler and shown command. 'sc_col' is also used to
10413 * decide what the maximum length of a message on the status line can be.
10414 * If there is a status line for the last window, 'sc_col' is independent
10415 * of 'ru_col'.
10416 */
10417
10418#define COL_RULER 17 /* columns needed by standard ruler */
10419
10420 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010421comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010422{
10423#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010424 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010425
10426 sc_col = 0;
10427 ru_col = 0;
10428 if (p_ru)
10429 {
10430#ifdef FEAT_STL_OPT
10431 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10432#else
10433 ru_col = COL_RULER + 1;
10434#endif
10435 /* no last status line, adjust sc_col */
10436 if (!last_has_status)
10437 sc_col = ru_col;
10438 }
10439 if (p_sc)
10440 {
10441 sc_col += SHOWCMD_COLS;
10442 if (!p_ru || last_has_status) /* no need for separating space */
10443 ++sc_col;
10444 }
10445 sc_col = Columns - sc_col;
10446 ru_col = Columns - ru_col;
10447 if (sc_col <= 0) /* screen too narrow, will become a mess */
10448 sc_col = 1;
10449 if (ru_col <= 0)
10450 ru_col = 1;
10451#else
10452 sc_col = Columns;
10453 ru_col = Columns;
10454#endif
10455}
10456
10457/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010458 * Unset local option value, similar to ":set opt<".
10459 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010460 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010461unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010462{
10463 struct vimoption *p;
10464 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010465 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466
10467 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010468 if (opt_idx < 0)
10469 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010470 p = &(options[opt_idx]);
10471
10472 switch ((int)p->indir)
10473 {
10474 /* global option with local value: use local value if it's been set */
10475 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010476 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010477 break;
10478 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010479 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010480 break;
10481 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010482 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010483 break;
10484 case PV_AR:
10485 buf->b_p_ar = -1;
10486 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010487 case PV_BKC:
10488 clear_string_option(&buf->b_p_bkc);
10489 buf->b_bkc_flags = 0;
10490 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010491 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010492 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010493 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010494 case PV_TC:
10495 clear_string_option(&buf->b_p_tc);
10496 buf->b_tc_flags = 0;
10497 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010498#ifdef FEAT_FIND_ID
10499 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010500 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010501 break;
10502 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010503 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010504 break;
10505#endif
10506#ifdef FEAT_INS_EXPAND
10507 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010508 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010509 break;
10510 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010511 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010512 break;
10513#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010514 case PV_FP:
10515 clear_string_option(&buf->b_p_fp);
10516 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010517#ifdef FEAT_QUICKFIX
10518 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010519 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010520 break;
10521 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010522 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010523 break;
10524 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010525 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010526 break;
10527#endif
10528#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10529 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010530 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010531 break;
10532#endif
10533#if defined(FEAT_CRYPT)
10534 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010535 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010536 break;
10537#endif
10538#ifdef FEAT_STL_OPT
10539 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010540 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010541 break;
10542#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010543 case PV_UL:
10544 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10545 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010546#ifdef FEAT_LISP
10547 case PV_LW:
10548 clear_string_option(&buf->b_p_lw);
10549 break;
10550#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010551#ifdef FEAT_MBYTE
10552 case PV_MENC:
10553 clear_string_option(&buf->b_p_menc);
10554 break;
10555#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010556 }
10557}
10558
10559/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560 * Get pointer to option variable, depending on local or global scope.
10561 */
10562 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010563get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564{
10565 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10566 {
10567 if (p->var == VAR_WIN)
10568 return (char_u *)GLOBAL_WO(get_varp(p));
10569 return p->var;
10570 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010571 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572 {
10573 switch ((int)p->indir)
10574 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010575 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010577 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10578 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10579 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010581 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10582 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10583 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010584 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010585 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010586 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010588 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10589 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590#endif
10591#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010592 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10593 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010595#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10596 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10597#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010598#if defined(FEAT_CRYPT)
10599 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10600#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010601#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010602 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010603#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010604 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010605#ifdef FEAT_LISP
10606 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10607#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010608 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010609#ifdef FEAT_MBYTE
10610 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10611#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612 }
10613 return NULL; /* "cannot happen" */
10614 }
10615 return get_varp(p);
10616}
10617
10618/*
10619 * Get pointer to option variable.
10620 */
10621 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010622get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010623{
10624 /* hidden option, always return NULL */
10625 if (p->var == NULL)
10626 return NULL;
10627
10628 switch ((int)p->indir)
10629 {
10630 case PV_NONE: return p->var;
10631
10632 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010633 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010635 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010637 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010638 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010639 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010640 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010641 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010643 case PV_TC: return *curbuf->b_p_tc != NUL
10644 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010645 case PV_BKC: return *curbuf->b_p_bkc != NUL
10646 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010648 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010649 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010650 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10652#endif
10653#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010654 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010656 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10658#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010659 case PV_FP: return *curbuf->b_p_fp != NUL
10660 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010661#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010662 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010664 case PV_GP: return *curbuf->b_p_gp != NUL
10665 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10666 case PV_MP: return *curbuf->b_p_mp != NUL
10667 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010669#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10670 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10671 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10672#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010673#if defined(FEAT_CRYPT)
10674 case PV_CM: return *curbuf->b_p_cm != NUL
10675 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10676#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010677#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010678 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010679 ? (char_u *)&(curwin->w_p_stl) : p->var;
10680#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010681 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10682 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010683#ifdef FEAT_LISP
10684 case PV_LW: return *curbuf->b_p_lw != NUL
10685 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10686#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010687#ifdef FEAT_MBYTE
10688 case PV_MENC: return *curbuf->b_p_menc != NUL
10689 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10690#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691
10692#ifdef FEAT_ARABIC
10693 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10694#endif
10695 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010696#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010697 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10698#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010699#ifdef FEAT_SYN_HL
10700 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10701 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010702 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704#ifdef FEAT_DIFF
10705 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10706#endif
10707#ifdef FEAT_FOLDING
10708 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10709 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10710 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10711 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10712 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10713 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10714 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10715# ifdef FEAT_EVAL
10716 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10717 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10718# endif
10719 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10720#endif
10721 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010722 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010723#ifdef FEAT_LINEBREAK
10724 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10725#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010726#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010728 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10729#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10731 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10732#endif
10733#ifdef FEAT_RIGHTLEFT
10734 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10735 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10736#endif
10737 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10738 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10739#ifdef FEAT_LINEBREAK
10740 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010741 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10742 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743#endif
10744#ifdef FEAT_SCROLLBIND
10745 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10746#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010747#ifdef FEAT_CURSORBIND
10748 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10749#endif
10750#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010751 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10752 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10753#endif
10754#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010755 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010756 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010758
10759 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10760 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10761#ifdef FEAT_MBYTE
10762 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10763#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10765 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10767 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10768#ifdef FEAT_CINDENT
10769 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10770 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10771 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10772#endif
10773#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10774 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10775#endif
10776#ifdef FEAT_COMMENTS
10777 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10778#endif
10779#ifdef FEAT_FOLDING
10780 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10781#endif
10782#ifdef FEAT_INS_EXPAND
10783 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10784#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010785#ifdef FEAT_COMPL_FUNC
10786 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010787 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010790 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10792#ifdef FEAT_MBYTE
10793 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10794#endif
10795 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10796#ifdef FEAT_AUTOCMD
10797 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10798#endif
10799 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010800 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10802 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10803 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10804 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10805#ifdef FEAT_FIND_ID
10806# ifdef FEAT_EVAL
10807 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10808# endif
10809#endif
10810#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10811 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10812 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10813#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010814#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010815 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817#ifdef FEAT_CRYPT
10818 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10819#endif
10820#ifdef FEAT_LISP
10821 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10822#endif
10823 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10824 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10825 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10826 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10827 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010829#ifdef FEAT_TEXTOBJ
10830 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10831#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10833#ifdef FEAT_SMARTINDENT
10834 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10835#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10838#ifdef FEAT_SEARCHPATH
10839 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10840#endif
10841 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10842#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010843 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010844 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10845#endif
10846#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010847 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10848 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10849 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850#endif
10851 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10852 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10853 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10854 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010855#ifdef FEAT_PERSISTENT_UNDO
10856 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10857#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10859#ifdef FEAT_KEYMAP
10860 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10861#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010862#ifdef FEAT_SIGNS
10863 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10864#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010865 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866 }
10867 /* always return a valid pointer to avoid a crash! */
10868 return (char_u *)&(curbuf->b_p_wm);
10869}
10870
10871/*
10872 * Get the value of 'equalprg', either the buffer-local one or the global one.
10873 */
10874 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010875get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876{
10877 if (*curbuf->b_p_ep == NUL)
10878 return p_ep;
10879 return curbuf->b_p_ep;
10880}
10881
10882#if defined(FEAT_WINDOWS) || defined(PROTO)
10883/*
10884 * Copy options from one window to another.
10885 * Used when splitting a window.
10886 */
10887 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010888win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010889{
10890 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10891 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10892# ifdef FEAT_RIGHTLEFT
10893# ifdef FEAT_FKMAP
10894 /* Is this right? */
10895 wp_to->w_farsi = wp_from->w_farsi;
10896# endif
10897# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010898#if defined(FEAT_LINEBREAK)
10899 briopt_check(wp_to);
10900#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901}
10902#endif
10903
10904/*
10905 * Copy the options from one winopt_T to another.
10906 * Doesn't free the old option values in "to", use clear_winopt() for that.
10907 * The 'scroll' option is not copied, because it depends on the window height.
10908 * The 'previewwindow' option is reset, there can be only one preview window.
10909 */
10910 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010911copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010912{
10913#ifdef FEAT_ARABIC
10914 to->wo_arab = from->wo_arab;
10915#endif
10916 to->wo_list = from->wo_list;
10917 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010918 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010919#ifdef FEAT_LINEBREAK
10920 to->wo_nuw = from->wo_nuw;
10921#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922#ifdef FEAT_RIGHTLEFT
10923 to->wo_rl = from->wo_rl;
10924 to->wo_rlc = vim_strsave(from->wo_rlc);
10925#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010926#ifdef FEAT_STL_OPT
10927 to->wo_stl = vim_strsave(from->wo_stl);
10928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010930#ifdef FEAT_DIFF
10931 to->wo_wrap_save = from->wo_wrap_save;
10932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933#ifdef FEAT_LINEBREAK
10934 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010935 to->wo_bri = from->wo_bri;
10936 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010937#endif
10938#ifdef FEAT_SCROLLBIND
10939 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010940 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010942#ifdef FEAT_CURSORBIND
10943 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010944 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010945#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010946#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010947 to->wo_spell = from->wo_spell;
10948#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010949#ifdef FEAT_SYN_HL
10950 to->wo_cuc = from->wo_cuc;
10951 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010952 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010953#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954#ifdef FEAT_DIFF
10955 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010956 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010958#ifdef FEAT_CONCEAL
10959 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010960 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010961#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010962#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010963 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010964 to->wo_tms = vim_strsave(from->wo_tms);
10965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010966#ifdef FEAT_FOLDING
10967 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010968 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010969 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010970 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971 to->wo_fdi = vim_strsave(from->wo_fdi);
10972 to->wo_fml = from->wo_fml;
10973 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010974 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010976 to->wo_fdm_save = from->wo_diff_saved
10977 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010978 to->wo_fdn = from->wo_fdn;
10979# ifdef FEAT_EVAL
10980 to->wo_fde = vim_strsave(from->wo_fde);
10981 to->wo_fdt = vim_strsave(from->wo_fdt);
10982# endif
10983 to->wo_fmr = vim_strsave(from->wo_fmr);
10984#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010985#ifdef FEAT_SIGNS
10986 to->wo_scl = vim_strsave(from->wo_scl);
10987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988 check_winopt(to); /* don't want NULL pointers */
10989}
10990
10991/*
10992 * Check string options in a window for a NULL value.
10993 */
10994 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010995check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010996{
10997 check_winopt(&win->w_onebuf_opt);
10998 check_winopt(&win->w_allbuf_opt);
10999}
11000
11001/*
11002 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11003 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011004 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011005check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011006{
11007#ifdef FEAT_FOLDING
11008 check_string_option(&wop->wo_fdi);
11009 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011010 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011011# ifdef FEAT_EVAL
11012 check_string_option(&wop->wo_fde);
11013 check_string_option(&wop->wo_fdt);
11014# endif
11015 check_string_option(&wop->wo_fmr);
11016#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011017#ifdef FEAT_SIGNS
11018 check_string_option(&wop->wo_scl);
11019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020#ifdef FEAT_RIGHTLEFT
11021 check_string_option(&wop->wo_rlc);
11022#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011023#ifdef FEAT_STL_OPT
11024 check_string_option(&wop->wo_stl);
11025#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011026#ifdef FEAT_SYN_HL
11027 check_string_option(&wop->wo_cc);
11028#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011029#ifdef FEAT_CONCEAL
11030 check_string_option(&wop->wo_cocu);
11031#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011032#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011033 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011034 check_string_option(&wop->wo_tms);
11035#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011036#ifdef FEAT_LINEBREAK
11037 check_string_option(&wop->wo_briopt);
11038#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011039}
11040
11041/*
11042 * Free the allocated memory inside a winopt_T.
11043 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011044 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011045clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011046{
11047#ifdef FEAT_FOLDING
11048 clear_string_option(&wop->wo_fdi);
11049 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011050 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051# ifdef FEAT_EVAL
11052 clear_string_option(&wop->wo_fde);
11053 clear_string_option(&wop->wo_fdt);
11054# endif
11055 clear_string_option(&wop->wo_fmr);
11056#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011057#ifdef FEAT_SIGNS
11058 clear_string_option(&wop->wo_scl);
11059#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011060#ifdef FEAT_LINEBREAK
11061 clear_string_option(&wop->wo_briopt);
11062#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063#ifdef FEAT_RIGHTLEFT
11064 clear_string_option(&wop->wo_rlc);
11065#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011066#ifdef FEAT_STL_OPT
11067 clear_string_option(&wop->wo_stl);
11068#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011069#ifdef FEAT_SYN_HL
11070 clear_string_option(&wop->wo_cc);
11071#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011072#ifdef FEAT_CONCEAL
11073 clear_string_option(&wop->wo_cocu);
11074#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011075#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011076 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011077 clear_string_option(&wop->wo_tms);
11078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079}
11080
11081/*
11082 * Copy global option values to local options for one buffer.
11083 * Used when creating a new buffer and sometimes when entering a buffer.
11084 * flags:
11085 * BCO_ENTER We will enter the buf buffer.
11086 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11087 * appropriate.
11088 * BCO_NOHELP Don't copy the values to a help buffer.
11089 */
11090 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011091buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011092{
11093 int should_copy = TRUE;
11094 char_u *save_p_isk = NULL; /* init for GCC */
11095 int dont_do_help;
11096 int did_isk = FALSE;
11097
11098 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099 * Skip this when the option defaults have not been set yet. Happens when
11100 * main() allocates the first buffer.
11101 */
11102 if (p_cpo != NULL)
11103 {
11104 /*
11105 * Always copy when entering and 'cpo' contains 'S'.
11106 * Don't copy when already initialized.
11107 * Don't copy when 'cpo' contains 's' and not entering.
11108 * 'S' BCO_ENTER initialized 's' should_copy
11109 * yes yes X X TRUE
11110 * yes no yes X FALSE
11111 * no X yes X FALSE
11112 * X no no yes FALSE
11113 * X no no no TRUE
11114 * no yes no X TRUE
11115 */
11116 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11117 && (buf->b_p_initialized
11118 || (!(flags & BCO_ENTER)
11119 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11120 should_copy = FALSE;
11121
11122 if (should_copy || (flags & BCO_ALWAYS))
11123 {
11124 /* Don't copy the options specific to a help buffer when
11125 * BCO_NOHELP is given or the options were initialized already
11126 * (jumping back to a help file with CTRL-T or CTRL-O) */
11127 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11128 || buf->b_p_initialized;
11129 if (dont_do_help) /* don't free b_p_isk */
11130 {
11131 save_p_isk = buf->b_p_isk;
11132 buf->b_p_isk = NULL;
11133 }
11134 /*
11135 * Always free the allocated strings.
11136 * If not already initialized, set 'readonly' and copy 'fileformat'.
11137 */
11138 if (!buf->b_p_initialized)
11139 {
11140 free_buf_options(buf, TRUE);
11141 buf->b_p_ro = FALSE; /* don't copy readonly */
11142 buf->b_p_tx = p_tx;
11143#ifdef FEAT_MBYTE
11144 buf->b_p_fenc = vim_strsave(p_fenc);
11145#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011146 switch (*p_ffs)
11147 {
11148 case 'm':
11149 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11150 case 'd':
11151 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11152 case 'u':
11153 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11154 default:
11155 buf->b_p_ff = vim_strsave(p_ff);
11156 }
11157 if (buf->b_p_ff != NULL)
11158 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011159 buf->b_p_bh = empty_option;
11160 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011161 }
11162 else
11163 free_buf_options(buf, FALSE);
11164
11165 buf->b_p_ai = p_ai;
11166 buf->b_p_ai_nopaste = p_ai_nopaste;
11167 buf->b_p_sw = p_sw;
11168 buf->b_p_tw = p_tw;
11169 buf->b_p_tw_nopaste = p_tw_nopaste;
11170 buf->b_p_tw_nobin = p_tw_nobin;
11171 buf->b_p_wm = p_wm;
11172 buf->b_p_wm_nopaste = p_wm_nopaste;
11173 buf->b_p_wm_nobin = p_wm_nobin;
11174 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011175#ifdef FEAT_MBYTE
11176 buf->b_p_bomb = p_bomb;
11177#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011178 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011179 buf->b_p_et = p_et;
11180 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011181 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011182 buf->b_p_ml = p_ml;
11183 buf->b_p_ml_nobin = p_ml_nobin;
11184 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011185 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011186#ifdef FEAT_INS_EXPAND
11187 buf->b_p_cpt = vim_strsave(p_cpt);
11188#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011189#ifdef FEAT_COMPL_FUNC
11190 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011191 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011192#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011193 buf->b_p_sts = p_sts;
11194 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196#ifdef FEAT_COMMENTS
11197 buf->b_p_com = vim_strsave(p_com);
11198#endif
11199#ifdef FEAT_FOLDING
11200 buf->b_p_cms = vim_strsave(p_cms);
11201#endif
11202 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011203 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011204 buf->b_p_nf = vim_strsave(p_nf);
11205 buf->b_p_mps = vim_strsave(p_mps);
11206#ifdef FEAT_SMARTINDENT
11207 buf->b_p_si = p_si;
11208#endif
11209 buf->b_p_ci = p_ci;
11210#ifdef FEAT_CINDENT
11211 buf->b_p_cin = p_cin;
11212 buf->b_p_cink = vim_strsave(p_cink);
11213 buf->b_p_cino = vim_strsave(p_cino);
11214#endif
11215#ifdef FEAT_AUTOCMD
11216 /* Don't copy 'filetype', it must be detected */
11217 buf->b_p_ft = empty_option;
11218#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011219 buf->b_p_pi = p_pi;
11220#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11221 buf->b_p_cinw = vim_strsave(p_cinw);
11222#endif
11223#ifdef FEAT_LISP
11224 buf->b_p_lisp = p_lisp;
11225#endif
11226#ifdef FEAT_SYN_HL
11227 /* Don't copy 'syntax', it must be set */
11228 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011229 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011230 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011231#endif
11232#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011233 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011234 (void)compile_cap_prog(&buf->b_s);
11235 buf->b_s.b_p_spf = vim_strsave(p_spf);
11236 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237#endif
11238#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11239 buf->b_p_inde = vim_strsave(p_inde);
11240 buf->b_p_indk = vim_strsave(p_indk);
11241#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011242 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011243#if defined(FEAT_EVAL)
11244 buf->b_p_fex = vim_strsave(p_fex);
11245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011246#ifdef FEAT_CRYPT
11247 buf->b_p_key = vim_strsave(p_key);
11248#endif
11249#ifdef FEAT_SEARCHPATH
11250 buf->b_p_sua = vim_strsave(p_sua);
11251#endif
11252#ifdef FEAT_KEYMAP
11253 buf->b_p_keymap = vim_strsave(p_keymap);
11254 buf->b_kmap_state |= KEYMAP_INIT;
11255#endif
11256 /* This isn't really an option, but copying the langmap and IME
11257 * state from the current buffer is better than resetting it. */
11258 buf->b_p_iminsert = p_iminsert;
11259 buf->b_p_imsearch = p_imsearch;
11260
11261 /* options that are normally global but also have a local value
11262 * are not copied, start using the global value */
11263 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011264 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011265 buf->b_p_bkc = empty_option;
11266 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267#ifdef FEAT_QUICKFIX
11268 buf->b_p_gp = empty_option;
11269 buf->b_p_mp = empty_option;
11270 buf->b_p_efm = empty_option;
11271#endif
11272 buf->b_p_ep = empty_option;
11273 buf->b_p_kp = empty_option;
11274 buf->b_p_path = empty_option;
11275 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011276 buf->b_p_tc = empty_option;
11277 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278#ifdef FEAT_FIND_ID
11279 buf->b_p_def = empty_option;
11280 buf->b_p_inc = empty_option;
11281# ifdef FEAT_EVAL
11282 buf->b_p_inex = vim_strsave(p_inex);
11283# endif
11284#endif
11285#ifdef FEAT_INS_EXPAND
11286 buf->b_p_dict = empty_option;
11287 buf->b_p_tsr = empty_option;
11288#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011289#ifdef FEAT_TEXTOBJ
11290 buf->b_p_qe = vim_strsave(p_qe);
11291#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011292#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11293 buf->b_p_bexpr = empty_option;
11294#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011295#if defined(FEAT_CRYPT)
11296 buf->b_p_cm = empty_option;
11297#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011298#ifdef FEAT_PERSISTENT_UNDO
11299 buf->b_p_udf = p_udf;
11300#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011301#ifdef FEAT_LISP
11302 buf->b_p_lw = empty_option;
11303#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011304#ifdef FEAT_MBYTE
11305 buf->b_p_menc = empty_option;
11306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011307
11308 /*
11309 * Don't copy the options set by ex_help(), use the saved values,
11310 * when going from a help buffer to a non-help buffer.
11311 * Don't touch these at all when BCO_NOHELP is used and going from
11312 * or to a help buffer.
11313 */
11314 if (dont_do_help)
11315 buf->b_p_isk = save_p_isk;
11316 else
11317 {
11318 buf->b_p_isk = vim_strsave(p_isk);
11319 did_isk = TRUE;
11320 buf->b_p_ts = p_ts;
11321 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322 if (buf->b_p_bt[0] == 'h')
11323 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011324 buf->b_p_ma = p_ma;
11325 }
11326 }
11327
11328 /*
11329 * When the options should be copied (ignoring BCO_ALWAYS), set the
11330 * flag that indicates that the options have been initialized.
11331 */
11332 if (should_copy)
11333 buf->b_p_initialized = TRUE;
11334 }
11335
11336 check_buf_options(buf); /* make sure we don't have NULLs */
11337 if (did_isk)
11338 (void)buf_init_chartab(buf, FALSE);
11339}
11340
11341/*
11342 * Reset the 'modifiable' option and its default value.
11343 */
11344 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011345reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011346{
11347 int opt_idx;
11348
11349 curbuf->b_p_ma = FALSE;
11350 p_ma = FALSE;
11351 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011352 if (opt_idx >= 0)
11353 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011354}
11355
11356/*
11357 * Set the global value for 'iminsert' to the local value.
11358 */
11359 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011360set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011361{
11362 p_iminsert = curbuf->b_p_iminsert;
11363}
11364
11365/*
11366 * Set the global value for 'imsearch' to the local value.
11367 */
11368 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011369set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011370{
11371 p_imsearch = curbuf->b_p_imsearch;
11372}
11373
11374#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11375static int expand_option_idx = -1;
11376static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11377static int expand_option_flags = 0;
11378
11379 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011380set_context_in_set_cmd(
11381 expand_T *xp,
11382 char_u *arg,
11383 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011384{
11385 int nextchar;
11386 long_u flags = 0; /* init for GCC */
11387 int opt_idx = 0; /* init for GCC */
11388 char_u *p;
11389 char_u *s;
11390 int is_term_option = FALSE;
11391 int key;
11392
11393 expand_option_flags = opt_flags;
11394
11395 xp->xp_context = EXPAND_SETTINGS;
11396 if (*arg == NUL)
11397 {
11398 xp->xp_pattern = arg;
11399 return;
11400 }
11401 p = arg + STRLEN(arg) - 1;
11402 if (*p == ' ' && *(p - 1) != '\\')
11403 {
11404 xp->xp_pattern = p + 1;
11405 return;
11406 }
11407 while (p > arg)
11408 {
11409 s = p;
11410 /* count number of backslashes before ' ' or ',' */
11411 if (*p == ' ' || *p == ',')
11412 {
11413 while (s > arg && *(s - 1) == '\\')
11414 --s;
11415 }
11416 /* break at a space with an even number of backslashes */
11417 if (*p == ' ' && ((p - s) & 1) == 0)
11418 {
11419 ++p;
11420 break;
11421 }
11422 --p;
11423 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011424 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011425 {
11426 xp->xp_context = EXPAND_BOOL_SETTINGS;
11427 p += 2;
11428 }
11429 if (STRNCMP(p, "inv", 3) == 0)
11430 {
11431 xp->xp_context = EXPAND_BOOL_SETTINGS;
11432 p += 3;
11433 }
11434 xp->xp_pattern = arg = p;
11435 if (*arg == '<')
11436 {
11437 while (*p != '>')
11438 if (*p++ == NUL) /* expand terminal option name */
11439 return;
11440 key = get_special_key_code(arg + 1);
11441 if (key == 0) /* unknown name */
11442 {
11443 xp->xp_context = EXPAND_NOTHING;
11444 return;
11445 }
11446 nextchar = *++p;
11447 is_term_option = TRUE;
11448 expand_option_name[2] = KEY2TERMCAP0(key);
11449 expand_option_name[3] = KEY2TERMCAP1(key);
11450 }
11451 else
11452 {
11453 if (p[0] == 't' && p[1] == '_')
11454 {
11455 p += 2;
11456 if (*p != NUL)
11457 ++p;
11458 if (*p == NUL)
11459 return; /* expand option name */
11460 nextchar = *++p;
11461 is_term_option = TRUE;
11462 expand_option_name[2] = p[-2];
11463 expand_option_name[3] = p[-1];
11464 }
11465 else
11466 {
11467 /* Allow * wildcard */
11468 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11469 p++;
11470 if (*p == NUL)
11471 return;
11472 nextchar = *p;
11473 *p = NUL;
11474 opt_idx = findoption(arg);
11475 *p = nextchar;
11476 if (opt_idx == -1 || options[opt_idx].var == NULL)
11477 {
11478 xp->xp_context = EXPAND_NOTHING;
11479 return;
11480 }
11481 flags = options[opt_idx].flags;
11482 if (flags & P_BOOL)
11483 {
11484 xp->xp_context = EXPAND_NOTHING;
11485 return;
11486 }
11487 }
11488 }
11489 /* handle "-=" and "+=" */
11490 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11491 {
11492 ++p;
11493 nextchar = '=';
11494 }
11495 if ((nextchar != '=' && nextchar != ':')
11496 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11497 {
11498 xp->xp_context = EXPAND_UNSUCCESSFUL;
11499 return;
11500 }
11501 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11502 {
11503 xp->xp_context = EXPAND_OLD_SETTING;
11504 if (is_term_option)
11505 expand_option_idx = -1;
11506 else
11507 expand_option_idx = opt_idx;
11508 xp->xp_pattern = p + 1;
11509 return;
11510 }
11511 xp->xp_context = EXPAND_NOTHING;
11512 if (is_term_option || (flags & P_NUM))
11513 return;
11514
11515 xp->xp_pattern = p + 1;
11516
11517 if (flags & P_EXPAND)
11518 {
11519 p = options[opt_idx].var;
11520 if (p == (char_u *)&p_bdir
11521 || p == (char_u *)&p_dir
11522 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011523 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524 || p == (char_u *)&p_rtp
11525#ifdef FEAT_SEARCHPATH
11526 || p == (char_u *)&p_cdpath
11527#endif
11528#ifdef FEAT_SESSION
11529 || p == (char_u *)&p_vdir
11530#endif
11531 )
11532 {
11533 xp->xp_context = EXPAND_DIRECTORIES;
11534 if (p == (char_u *)&p_path
11535#ifdef FEAT_SEARCHPATH
11536 || p == (char_u *)&p_cdpath
11537#endif
11538 )
11539 xp->xp_backslash = XP_BS_THREE;
11540 else
11541 xp->xp_backslash = XP_BS_ONE;
11542 }
11543 else
11544 {
11545 xp->xp_context = EXPAND_FILES;
11546 /* for 'tags' need three backslashes for a space */
11547 if (p == (char_u *)&p_tags)
11548 xp->xp_backslash = XP_BS_THREE;
11549 else
11550 xp->xp_backslash = XP_BS_ONE;
11551 }
11552 }
11553
11554 /* For an option that is a list of file names, find the start of the
11555 * last file name. */
11556 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11557 {
11558 /* count number of backslashes before ' ' or ',' */
11559 if (*p == ' ' || *p == ',')
11560 {
11561 s = p;
11562 while (s > xp->xp_pattern && *(s - 1) == '\\')
11563 --s;
11564 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11565 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11566 {
11567 xp->xp_pattern = p + 1;
11568 break;
11569 }
11570 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011571
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011572#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011573 /* for 'spellsuggest' start at "file:" */
11574 if (options[opt_idx].var == (char_u *)&p_sps
11575 && STRNCMP(p, "file:", 5) == 0)
11576 {
11577 xp->xp_pattern = p + 5;
11578 break;
11579 }
11580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011581 }
11582
11583 return;
11584}
11585
11586 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011587ExpandSettings(
11588 expand_T *xp,
11589 regmatch_T *regmatch,
11590 int *num_file,
11591 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592{
11593 int num_normal = 0; /* Nr of matching non-term-code settings */
11594 int num_term = 0; /* Nr of matching terminal code settings */
11595 int opt_idx;
11596 int match;
11597 int count = 0;
11598 char_u *str;
11599 int loop;
11600 int is_term_opt;
11601 char_u name_buf[MAX_KEY_NAME_LEN];
11602 static char *(names[]) = {"all", "termcap"};
11603 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11604
11605 /* do this loop twice:
11606 * loop == 0: count the number of matching options
11607 * loop == 1: copy the matching options into allocated memory
11608 */
11609 for (loop = 0; loop <= 1; ++loop)
11610 {
11611 regmatch->rm_ic = ic;
11612 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11613 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011614 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11615 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11617 {
11618 if (loop == 0)
11619 num_normal++;
11620 else
11621 (*file)[count++] = vim_strsave((char_u *)names[match]);
11622 }
11623 }
11624 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11625 opt_idx++)
11626 {
11627 if (options[opt_idx].var == NULL)
11628 continue;
11629 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11630 && !(options[opt_idx].flags & P_BOOL))
11631 continue;
11632 is_term_opt = istermoption(&options[opt_idx]);
11633 if (is_term_opt && num_normal > 0)
11634 continue;
11635 match = FALSE;
11636 if (vim_regexec(regmatch, str, (colnr_T)0)
11637 || (options[opt_idx].shortname != NULL
11638 && vim_regexec(regmatch,
11639 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11640 match = TRUE;
11641 else if (is_term_opt)
11642 {
11643 name_buf[0] = '<';
11644 name_buf[1] = 't';
11645 name_buf[2] = '_';
11646 name_buf[3] = str[2];
11647 name_buf[4] = str[3];
11648 name_buf[5] = '>';
11649 name_buf[6] = NUL;
11650 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11651 {
11652 match = TRUE;
11653 str = name_buf;
11654 }
11655 }
11656 if (match)
11657 {
11658 if (loop == 0)
11659 {
11660 if (is_term_opt)
11661 num_term++;
11662 else
11663 num_normal++;
11664 }
11665 else
11666 (*file)[count++] = vim_strsave(str);
11667 }
11668 }
11669 /*
11670 * Check terminal key codes, these are not in the option table
11671 */
11672 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11673 {
11674 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11675 {
11676 if (!isprint(str[0]) || !isprint(str[1]))
11677 continue;
11678
11679 name_buf[0] = 't';
11680 name_buf[1] = '_';
11681 name_buf[2] = str[0];
11682 name_buf[3] = str[1];
11683 name_buf[4] = NUL;
11684
11685 match = FALSE;
11686 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11687 match = TRUE;
11688 else
11689 {
11690 name_buf[0] = '<';
11691 name_buf[1] = 't';
11692 name_buf[2] = '_';
11693 name_buf[3] = str[0];
11694 name_buf[4] = str[1];
11695 name_buf[5] = '>';
11696 name_buf[6] = NUL;
11697
11698 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11699 match = TRUE;
11700 }
11701 if (match)
11702 {
11703 if (loop == 0)
11704 num_term++;
11705 else
11706 (*file)[count++] = vim_strsave(name_buf);
11707 }
11708 }
11709
11710 /*
11711 * Check special key names.
11712 */
11713 regmatch->rm_ic = TRUE; /* ignore case here */
11714 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11715 {
11716 name_buf[0] = '<';
11717 STRCPY(name_buf + 1, str);
11718 STRCAT(name_buf, ">");
11719
11720 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11721 {
11722 if (loop == 0)
11723 num_term++;
11724 else
11725 (*file)[count++] = vim_strsave(name_buf);
11726 }
11727 }
11728 }
11729 if (loop == 0)
11730 {
11731 if (num_normal > 0)
11732 *num_file = num_normal;
11733 else if (num_term > 0)
11734 *num_file = num_term;
11735 else
11736 return OK;
11737 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11738 if (*file == NULL)
11739 {
11740 *file = (char_u **)"";
11741 return FAIL;
11742 }
11743 }
11744 }
11745 return OK;
11746}
11747
11748 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011749ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011750{
11751 char_u *var = NULL; /* init for GCC */
11752 char_u *buf;
11753
11754 *num_file = 0;
11755 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11756 if (*file == NULL)
11757 return FAIL;
11758
11759 /*
11760 * For a terminal key code expand_option_idx is < 0.
11761 */
11762 if (expand_option_idx < 0)
11763 {
11764 var = find_termcode(expand_option_name + 2);
11765 if (var == NULL)
11766 expand_option_idx = findoption(expand_option_name);
11767 }
11768
11769 if (expand_option_idx >= 0)
11770 {
11771 /* put string of option value in NameBuff */
11772 option_value2string(&options[expand_option_idx], expand_option_flags);
11773 var = NameBuff;
11774 }
11775 else if (var == NULL)
11776 var = (char_u *)"";
11777
11778 /* A backslash is required before some characters. This is the reverse of
11779 * what happens in do_set(). */
11780 buf = vim_strsave_escaped(var, escape_chars);
11781
11782 if (buf == NULL)
11783 {
11784 vim_free(*file);
11785 *file = NULL;
11786 return FAIL;
11787 }
11788
11789#ifdef BACKSLASH_IN_FILENAME
11790 /* For MS-Windows et al. we don't double backslashes at the start and
11791 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011792 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011793 if (var[0] == '\\' && var[1] == '\\'
11794 && expand_option_idx >= 0
11795 && (options[expand_option_idx].flags & P_EXPAND)
11796 && vim_isfilec(var[2])
11797 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011798 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799#endif
11800
11801 *file[0] = buf;
11802 *num_file = 1;
11803 return OK;
11804}
11805#endif
11806
11807/*
11808 * Get the value for the numeric or string option *opp in a nice format into
11809 * NameBuff[]. Must not be called with a hidden option!
11810 */
11811 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011812option_value2string(
11813 struct vimoption *opp,
11814 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011815{
11816 char_u *varp;
11817
11818 varp = get_varp_scope(opp, opt_flags);
11819
11820 if (opp->flags & P_NUM)
11821 {
11822 long wc = 0;
11823
11824 if (wc_use_keyname(varp, &wc))
11825 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11826 else if (wc != 0)
11827 STRCPY(NameBuff, transchar((int)wc));
11828 else
11829 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11830 }
11831 else /* P_STRING */
11832 {
11833 varp = *(char_u **)(varp);
11834 if (varp == NULL) /* just in case */
11835 NameBuff[0] = NUL;
11836#ifdef FEAT_CRYPT
11837 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011838 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011839 STRCPY(NameBuff, "*****");
11840#endif
11841 else if (opp->flags & P_EXPAND)
11842 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11843 /* Translate 'pastetoggle' into special key names */
11844 else if ((char_u **)opp->var == &p_pt)
11845 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11846 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011847 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011848 }
11849}
11850
11851/*
11852 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11853 * printed as a keyname.
11854 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11855 */
11856 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011857wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011858{
11859 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11860 {
11861 *wcp = *(long *)varp;
11862 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11863 return TRUE;
11864 }
11865 return FALSE;
11866}
11867
Bram Moolenaar01615492015-02-03 13:00:38 +010011868#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011870 * Any character has an equivalent 'langmap' character. This is used for
11871 * keyboards that have a special language mode that sends characters above
11872 * 128 (although other characters can be translated too). The "to" field is a
11873 * Vim command character. This avoids having to switch the keyboard back to
11874 * ASCII mode when leaving Insert mode.
11875 *
11876 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11877 * commands.
11878 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11879 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11880 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011882# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011883/*
11884 * With multi-byte support use growarray for 'langmap' chars >= 256
11885 */
11886typedef struct
11887{
11888 int from;
11889 int to;
11890} langmap_entry_T;
11891
11892static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011893static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011894
11895/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011896 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11897 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011898 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011899 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011900langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011901{
11902 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011903 int a = 0;
11904 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011905
11906 /* Do a binary search for an existing entry. */
11907 while (a != b)
11908 {
11909 int i = (a + b) / 2;
11910 int d = entries[i].from - from;
11911
11912 if (d == 0)
11913 {
11914 entries[i].to = to;
11915 return;
11916 }
11917 if (d < 0)
11918 a = i + 1;
11919 else
11920 b = i;
11921 }
11922
11923 if (ga_grow(&langmap_mapga, 1) != OK)
11924 return; /* out of memory */
11925
11926 /* insert new entry at position "a" */
11927 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11928 mch_memmove(entries + 1, entries,
11929 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11930 ++langmap_mapga.ga_len;
11931 entries[0].from = from;
11932 entries[0].to = to;
11933}
11934
11935/*
11936 * Apply 'langmap' to multi-byte character "c" and return the result.
11937 */
11938 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011939langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011940{
11941 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11942 int a = 0;
11943 int b = langmap_mapga.ga_len;
11944
11945 while (a != b)
11946 {
11947 int i = (a + b) / 2;
11948 int d = entries[i].from - c;
11949
11950 if (d == 0)
11951 return entries[i].to; /* found matching entry */
11952 if (d < 0)
11953 a = i + 1;
11954 else
11955 b = i;
11956 }
11957 return c; /* no entry found, return "c" unmodified */
11958}
11959# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011960
11961 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011962langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963{
11964 int i;
11965
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011966 for (i = 0; i < 256; i++)
11967 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11968# ifdef FEAT_MBYTE
11969 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11970# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011971}
11972
11973/*
11974 * Called when langmap option is set; the language map can be
11975 * changed at any time!
11976 */
11977 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011978langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979{
11980 char_u *p;
11981 char_u *p2;
11982 int from, to;
11983
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011984#ifdef FEAT_MBYTE
11985 ga_clear(&langmap_mapga); /* clear the previous map first */
11986#endif
11987 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011988
11989 for (p = p_langmap; p[0] != NUL; )
11990 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011991 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011992 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993 {
11994 if (p2[0] == '\\' && p2[1] != NUL)
11995 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996 }
11997 if (p2[0] == ';')
11998 ++p2; /* abcd;ABCD form, p2 points to A */
11999 else
12000 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12001 while (p[0])
12002 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012003 if (p[0] == ',')
12004 {
12005 ++p;
12006 break;
12007 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012008 if (p[0] == '\\' && p[1] != NUL)
12009 ++p;
12010#ifdef FEAT_MBYTE
12011 from = (*mb_ptr2char)(p);
12012#else
12013 from = p[0];
12014#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012015 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012016 if (p2 == NULL)
12017 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012018 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012019 if (p[0] != ',')
12020 {
12021 if (p[0] == '\\')
12022 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012024 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012026 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012027#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012028 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029 }
12030 else
12031 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012032 if (p2[0] != ',')
12033 {
12034 if (p2[0] == '\\')
12035 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012037 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012038#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012039 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012040#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012041 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012042 }
12043 if (to == NUL)
12044 {
12045 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12046 transchar(from));
12047 return;
12048 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012049
12050#ifdef FEAT_MBYTE
12051 if (from >= 256)
12052 langmap_set_entry(from, to);
12053 else
12054#endif
12055 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056
12057 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012058 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012059 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012060 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012061 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012062 if (*p == ';')
12063 {
12064 p = p2;
12065 if (p[0] != NUL)
12066 {
12067 if (p[0] != ',')
12068 {
12069 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12070 return;
12071 }
12072 ++p;
12073 }
12074 break;
12075 }
12076 }
12077 }
12078 }
12079}
12080#endif
12081
12082/*
12083 * Return TRUE if format option 'x' is in effect.
12084 * Take care of no formatting when 'paste' is set.
12085 */
12086 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012087has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012088{
12089 if (p_paste)
12090 return FALSE;
12091 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12092}
12093
12094/*
12095 * Return TRUE if "x" is present in 'shortmess' option, or
12096 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12097 */
12098 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012099shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012101 return p_shm != NULL &&
12102 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 || (vim_strchr(p_shm, 'a') != NULL
12104 && vim_strchr((char_u *)SHM_A, x) != NULL));
12105}
12106
12107/*
12108 * paste_option_changed() - Called after p_paste was set or reset.
12109 */
12110 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012111paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012112{
12113 static int old_p_paste = FALSE;
12114 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012115 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012116#ifdef FEAT_CMDL_INFO
12117 static int save_ru = 0;
12118#endif
12119#ifdef FEAT_RIGHTLEFT
12120 static int save_ri = 0;
12121 static int save_hkmap = 0;
12122#endif
12123 buf_T *buf;
12124
12125 if (p_paste)
12126 {
12127 /*
12128 * Paste switched from off to on.
12129 * Save the current values, so they can be restored later.
12130 */
12131 if (!old_p_paste)
12132 {
12133 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012134 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012135 {
12136 buf->b_p_tw_nopaste = buf->b_p_tw;
12137 buf->b_p_wm_nopaste = buf->b_p_wm;
12138 buf->b_p_sts_nopaste = buf->b_p_sts;
12139 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012140 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141 }
12142
12143 /* save global options */
12144 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012145 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146#ifdef FEAT_CMDL_INFO
12147 save_ru = p_ru;
12148#endif
12149#ifdef FEAT_RIGHTLEFT
12150 save_ri = p_ri;
12151 save_hkmap = p_hkmap;
12152#endif
12153 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012154 p_ai_nopaste = p_ai;
12155 p_et_nopaste = p_et;
12156 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012157 p_tw_nopaste = p_tw;
12158 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012159 }
12160
12161 /*
12162 * Always set the option values, also when 'paste' is set when it is
12163 * already on.
12164 */
12165 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012166 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167 {
12168 buf->b_p_tw = 0; /* textwidth is 0 */
12169 buf->b_p_wm = 0; /* wrapmargin is 0 */
12170 buf->b_p_sts = 0; /* softtabstop is 0 */
12171 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012172 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173 }
12174
12175 /* set global options */
12176 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012177 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012178#ifdef FEAT_CMDL_INFO
12179# ifdef FEAT_WINDOWS
12180 if (p_ru)
12181 status_redraw_all(); /* redraw to remove the ruler */
12182# endif
12183 p_ru = 0; /* no ruler */
12184#endif
12185#ifdef FEAT_RIGHTLEFT
12186 p_ri = 0; /* no reverse insert */
12187 p_hkmap = 0; /* no Hebrew keyboard */
12188#endif
12189 /* set global values for local buffer options */
12190 p_tw = 0;
12191 p_wm = 0;
12192 p_sts = 0;
12193 p_ai = 0;
12194 }
12195
12196 /*
12197 * Paste switched from on to off: Restore saved values.
12198 */
12199 else if (old_p_paste)
12200 {
12201 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012202 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012203 {
12204 buf->b_p_tw = buf->b_p_tw_nopaste;
12205 buf->b_p_wm = buf->b_p_wm_nopaste;
12206 buf->b_p_sts = buf->b_p_sts_nopaste;
12207 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012208 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 }
12210
12211 /* restore global options */
12212 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012213 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012214#ifdef FEAT_CMDL_INFO
12215# ifdef FEAT_WINDOWS
12216 if (p_ru != save_ru)
12217 status_redraw_all(); /* redraw to draw the ruler */
12218# endif
12219 p_ru = save_ru;
12220#endif
12221#ifdef FEAT_RIGHTLEFT
12222 p_ri = save_ri;
12223 p_hkmap = save_hkmap;
12224#endif
12225 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012226 p_ai = p_ai_nopaste;
12227 p_et = p_et_nopaste;
12228 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012229 p_tw = p_tw_nopaste;
12230 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012231 }
12232
12233 old_p_paste = p_paste;
12234}
12235
12236/*
12237 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12238 *
12239 * Reset 'compatible' and set the values for options that didn't get set yet
12240 * to the Vim defaults.
12241 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012242 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012243 */
12244 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012245vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012247 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012248 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012249 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012250
12251 if (!option_was_set((char_u *)"cp"))
12252 {
12253 p_cp = FALSE;
12254 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12255 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12256 set_option_default(opt_idx, OPT_FREE, FALSE);
12257 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012258 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012260
12261 if (fname != NULL)
12262 {
12263 p = vim_getenv(envname, &dofree);
12264 if (p == NULL)
12265 {
12266 /* Set $MYVIMRC to the first vimrc file found. */
12267 p = FullName_save(fname, FALSE);
12268 if (p != NULL)
12269 {
12270 vim_setenv(envname, p);
12271 vim_free(p);
12272 }
12273 }
12274 else if (dofree)
12275 vim_free(p);
12276 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277}
12278
12279/*
12280 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12281 */
12282 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012283change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012284{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012285 int opt_idx;
12286
Bram Moolenaar071d4272004-06-13 20:20:40 +000012287 if (p_cp != on)
12288 {
12289 p_cp = on;
12290 compatible_set();
12291 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012292 opt_idx = findoption((char_u *)"cp");
12293 if (opt_idx >= 0)
12294 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295}
12296
12297/*
12298 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012299 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012300 */
12301 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012302option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012303{
12304 int idx;
12305
12306 idx = findoption(name);
12307 if (idx < 0) /* unknown option */
12308 return FALSE;
12309 if (options[idx].flags & P_WAS_SET)
12310 return TRUE;
12311 return FALSE;
12312}
12313
12314/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012315 * Reset the flag indicating option "name" was set.
12316 */
12317 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012318reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012319{
12320 int idx = findoption(name);
12321
12322 if (idx >= 0)
12323 options[idx].flags &= ~P_WAS_SET;
12324}
12325
12326/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012327 * compatible_set() - Called when 'compatible' has been set or unset.
12328 *
12329 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12330 * flag) to a Vi compatible value.
12331 * When 'compatible' is unset: Set all options that have a different default
12332 * for Vim (without the P_VI_DEF flag) to that default.
12333 */
12334 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012335compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012336{
12337 int opt_idx;
12338
12339 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12340 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12341 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12342 set_option_default(opt_idx, OPT_FREE, p_cp);
12343 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012344 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012345}
12346
12347#ifdef FEAT_LINEBREAK
12348
12349# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12350 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012351 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012352# endif
12353
12354/*
12355 * fill_breakat_flags() -- called when 'breakat' changes value.
12356 */
12357 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012358fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012359{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012360 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012361 int i;
12362
12363 for (i = 0; i < 256; i++)
12364 breakat_flags[i] = FALSE;
12365
12366 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012367 for (p = p_breakat; *p; p++)
12368 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012369}
12370
12371# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012372 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012373# endif
12374
12375#endif
12376
12377/*
12378 * Check an option that can be a range of string values.
12379 *
12380 * Return OK for correct value, FAIL otherwise.
12381 * Empty is always OK.
12382 */
12383 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012384check_opt_strings(
12385 char_u *val,
12386 char **values,
12387 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012388{
12389 return opt_strings_flags(val, values, NULL, list);
12390}
12391
12392/*
12393 * Handle an option that can be a range of string values.
12394 * Set a flag in "*flagp" for each string present.
12395 *
12396 * Return OK for correct value, FAIL otherwise.
12397 * Empty is always OK.
12398 */
12399 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012400opt_strings_flags(
12401 char_u *val, /* new value */
12402 char **values, /* array of valid string values */
12403 unsigned *flagp,
12404 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012405{
12406 int i;
12407 int len;
12408 unsigned new_flags = 0;
12409
12410 while (*val)
12411 {
12412 for (i = 0; ; ++i)
12413 {
12414 if (values[i] == NULL) /* val not found in values[] */
12415 return FAIL;
12416
12417 len = (int)STRLEN(values[i]);
12418 if (STRNCMP(values[i], val, len) == 0
12419 && ((list && val[len] == ',') || val[len] == NUL))
12420 {
12421 val += len + (val[len] == ',');
12422 new_flags |= (1 << i);
12423 break; /* check next item in val list */
12424 }
12425 }
12426 }
12427 if (flagp != NULL)
12428 *flagp = new_flags;
12429
12430 return OK;
12431}
12432
12433/*
12434 * Read the 'wildmode' option, fill wim_flags[].
12435 */
12436 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012437check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012438{
12439 char_u new_wim_flags[4];
12440 char_u *p;
12441 int i;
12442 int idx = 0;
12443
12444 for (i = 0; i < 4; ++i)
12445 new_wim_flags[i] = 0;
12446
12447 for (p = p_wim; *p; ++p)
12448 {
12449 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12450 ;
12451 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12452 return FAIL;
12453 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12454 new_wim_flags[idx] |= WIM_LONGEST;
12455 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12456 new_wim_flags[idx] |= WIM_FULL;
12457 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12458 new_wim_flags[idx] |= WIM_LIST;
12459 else
12460 return FAIL;
12461 p += i;
12462 if (*p == NUL)
12463 break;
12464 if (*p == ',')
12465 {
12466 if (idx == 3)
12467 return FAIL;
12468 ++idx;
12469 }
12470 }
12471
12472 /* fill remaining entries with last flag */
12473 while (idx < 3)
12474 {
12475 new_wim_flags[idx + 1] = new_wim_flags[idx];
12476 ++idx;
12477 }
12478
12479 /* only when there are no errors, wim_flags[] is changed */
12480 for (i = 0; i < 4; ++i)
12481 wim_flags[i] = new_wim_flags[i];
12482 return OK;
12483}
12484
12485/*
12486 * Check if backspacing over something is allowed.
12487 */
12488 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012489can_bs(
12490 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012491{
12492 switch (*p_bs)
12493 {
12494 case '2': return TRUE;
12495 case '1': return (what != BS_START);
12496 case '0': return FALSE;
12497 }
12498 return vim_strchr(p_bs, what) != NULL;
12499}
12500
12501/*
12502 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12503 * the file must be considered changed when the value is different.
12504 */
12505 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012506save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507{
12508 buf->b_start_ffc = *buf->b_p_ff;
12509 buf->b_start_eol = buf->b_p_eol;
12510#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012511 buf->b_start_bomb = buf->b_p_bomb;
12512
Bram Moolenaar071d4272004-06-13 20:20:40 +000012513 /* Only use free/alloc when necessary, they take time. */
12514 if (buf->b_start_fenc == NULL
12515 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12516 {
12517 vim_free(buf->b_start_fenc);
12518 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12519 }
12520#endif
12521}
12522
12523/*
12524 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12525 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012526 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12527 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012528 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012529 * When "ignore_empty" is true don't consider a new, empty buffer to be
12530 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012531 */
12532 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012533file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012534{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012535 /* In a buffer that was never loaded the options are not valid. */
12536 if (buf->b_flags & BF_NEVERLOADED)
12537 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012538 if (ignore_empty
12539 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012540 && buf->b_ml.ml_line_count == 1
12541 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12542 return FALSE;
12543 if (buf->b_start_ffc != *buf->b_p_ff)
12544 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012545 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012546 return TRUE;
12547#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012548 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12549 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012550 if (buf->b_start_fenc == NULL)
12551 return (*buf->b_p_fenc != NUL);
12552 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12553#else
12554 return FALSE;
12555#endif
12556}
12557
12558/*
12559 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12560 */
12561 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012562check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012563{
12564 return check_opt_strings(p, p_ff_values, FALSE);
12565}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012566
12567/*
12568 * Return the effective shiftwidth value for current buffer, using the
12569 * 'tabstop' value when 'shiftwidth' is zero.
12570 */
12571 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012572get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012573{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012574 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012575}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012576
12577/*
12578 * Return the effective softtabstop value for the current buffer, using the
12579 * 'tabstop' value when 'softtabstop' is negative.
12580 */
12581 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012582get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012583{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012584 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012585}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012586
12587/*
12588 * Check matchpairs option for "*initc".
12589 * If there is a match set "*initc" to the matching character and "*findc" to
12590 * the opposite character. Set "*backwards" to the direction.
12591 * When "switchit" is TRUE swap the direction.
12592 */
12593 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012594find_mps_values(
12595 int *initc,
12596 int *findc,
12597 int *backwards,
12598 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012599{
12600 char_u *ptr;
12601
12602 ptr = curbuf->b_p_mps;
12603 while (*ptr != NUL)
12604 {
12605#ifdef FEAT_MBYTE
12606 if (has_mbyte)
12607 {
12608 char_u *prev;
12609
12610 if (mb_ptr2char(ptr) == *initc)
12611 {
12612 if (switchit)
12613 {
12614 *findc = *initc;
12615 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12616 *backwards = TRUE;
12617 }
12618 else
12619 {
12620 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12621 *backwards = FALSE;
12622 }
12623 return;
12624 }
12625 prev = ptr;
12626 ptr += mb_ptr2len(ptr) + 1;
12627 if (mb_ptr2char(ptr) == *initc)
12628 {
12629 if (switchit)
12630 {
12631 *findc = *initc;
12632 *initc = mb_ptr2char(prev);
12633 *backwards = FALSE;
12634 }
12635 else
12636 {
12637 *findc = mb_ptr2char(prev);
12638 *backwards = TRUE;
12639 }
12640 return;
12641 }
12642 ptr += mb_ptr2len(ptr);
12643 }
12644 else
12645#endif
12646 {
12647 if (*ptr == *initc)
12648 {
12649 if (switchit)
12650 {
12651 *backwards = TRUE;
12652 *findc = *initc;
12653 *initc = ptr[2];
12654 }
12655 else
12656 {
12657 *backwards = FALSE;
12658 *findc = ptr[2];
12659 }
12660 return;
12661 }
12662 ptr += 2;
12663 if (*ptr == *initc)
12664 {
12665 if (switchit)
12666 {
12667 *backwards = FALSE;
12668 *findc = *initc;
12669 *initc = ptr[-2];
12670 }
12671 else
12672 {
12673 *backwards = TRUE;
12674 *findc = ptr[-2];
12675 }
12676 return;
12677 }
12678 ++ptr;
12679 }
12680 if (*ptr == ',')
12681 ++ptr;
12682 }
12683}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012684
12685#if defined(FEAT_LINEBREAK) || defined(PROTO)
12686/*
12687 * This is called when 'breakindentopt' is changed and when a window is
12688 * initialized.
12689 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012690 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012691briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012692{
12693 char_u *p;
12694 int bri_shift = 0;
12695 long bri_min = 20;
12696 int bri_sbr = FALSE;
12697
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012698 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012699 while (*p != NUL)
12700 {
12701 if (STRNCMP(p, "shift:", 6) == 0
12702 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12703 {
12704 p += 6;
12705 bri_shift = getdigits(&p);
12706 }
12707 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12708 {
12709 p += 4;
12710 bri_min = getdigits(&p);
12711 }
12712 else if (STRNCMP(p, "sbr", 3) == 0)
12713 {
12714 p += 3;
12715 bri_sbr = TRUE;
12716 }
12717 if (*p != ',' && *p != NUL)
12718 return FAIL;
12719 if (*p == ',')
12720 ++p;
12721 }
12722
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012723 wp->w_p_brishift = bri_shift;
12724 wp->w_p_brimin = bri_min;
12725 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012726
12727 return OK;
12728}
12729#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012730
12731/*
12732 * Get the local or global value of 'backupcopy'.
12733 */
12734 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012735get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012736{
12737 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12738}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012739
12740#if defined(FEAT_SIGNS) || defined(PROTO)
12741/*
12742 * Return TRUE when window "wp" has a column to draw signs in.
12743 */
12744 int
12745signcolumn_on(win_T *wp)
12746{
12747 if (*wp->w_p_scl == 'n')
12748 return FALSE;
12749 if (*wp->w_p_scl == 'y')
12750 return TRUE;
12751 return (wp->w_buffer->b_signlist != NULL
12752# ifdef FEAT_NETBEANS_INTG
12753 || wp->w_buffer->b_has_sign_column
12754# endif
12755 );
12756}
12757#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012758
12759#if defined(FEAT_EVAL) || defined(PROTO)
12760/*
12761 * Get window or buffer local options.
12762 */
12763 dict_T *
12764get_winbuf_options(int bufopt)
12765{
12766 dict_T *d;
12767 int opt_idx;
12768
12769 d = dict_alloc();
12770 if (d == NULL)
12771 return NULL;
12772
12773 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12774 {
12775 struct vimoption *opt = &options[opt_idx];
12776
12777 if ((bufopt && (opt->indir & PV_BUF))
12778 || (!bufopt && (opt->indir & PV_WIN)))
12779 {
12780 char_u *varp = get_varp(opt);
12781
12782 if (varp != NULL)
12783 {
12784 if (opt->flags & P_STRING)
12785 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012786 else if (opt->flags & P_NUM)
12787 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012788 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012789 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012790 }
12791 }
12792 }
12793
12794 return d;
12795}
12796#endif