blob: ceafea389ed4b9ec7f6ef5126c2b5536440c8229 [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
Bram Moolenaar4033c552017-09-16 20:54:51 +0200225#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000226# 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# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CURSORBIND
252# define PV_CRBIND OPT_WIN(WV_CRBIND)
253#endif
254#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200255# define PV_COCU OPT_WIN(WV_COCU)
256# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200257#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200258#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200259# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260# define PV_TMS OPT_WIN(WV_TMS)
261#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200262#ifdef FEAT_SIGNS
263# define PV_SCL OPT_WIN(WV_SCL)
264#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000265
266/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267typedef enum
268{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000269 PV_NONE = 0,
270 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271} idopt_T;
272
273/*
274 * Options local to a window have a value local to a buffer and global to all
275 * buffers. Indicate this by setting "var" to VAR_WIN.
276 */
277#define VAR_WIN ((char_u *)-1)
278
279/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000280 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281 * Only to be used in option.c!
282 */
283static int p_ai;
284static int p_bin;
285#ifdef FEAT_MBYTE
286static int p_bomb;
287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288static char_u *p_bh;
289static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static int p_bl;
291static int p_ci;
292#ifdef FEAT_CINDENT
293static int p_cin;
294static char_u *p_cink;
295static char_u *p_cino;
296#endif
297#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298static char_u *p_cinw;
299#endif
300#ifdef FEAT_COMMENTS
301static char_u *p_com;
302#endif
303#ifdef FEAT_FOLDING
304static char_u *p_cms;
305#endif
306#ifdef FEAT_INS_EXPAND
307static char_u *p_cpt;
308#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#ifdef FEAT_COMPL_FUNC
310static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000311static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
316#ifdef FEAT_MBYTE
317static char_u *p_fenc;
318#endif
319static char_u *p_ff;
320static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000321static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322#ifdef FEAT_AUTOCMD
323static char_u *p_ft;
324#endif
325static long p_iminsert;
326static long p_imsearch;
327#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328static char_u *p_inex;
329#endif
330#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331static char_u *p_inde;
332static char_u *p_indk;
333#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000334#if defined(FEAT_EVAL)
335static char_u *p_fex;
336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_inf;
338static char_u *p_isk;
339#ifdef FEAT_CRYPT
340static char_u *p_key;
341#endif
342#ifdef FEAT_LISP
343static int p_lisp;
344#endif
345static int p_ml;
346static int p_ma;
347static int p_mod;
348static char_u *p_mps;
349static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000351#ifdef FEAT_TEXTOBJ
352static char_u *p_qe;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_ro;
355#ifdef FEAT_SMARTINDENT
356static int p_si;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static long p_sts;
360#if defined(FEAT_SEARCHPATH)
361static char_u *p_sua;
362#endif
363static long p_sw;
364static int p_swf;
365#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000366static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000368#endif
369#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000370static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000371static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000372static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#endif
374static long p_ts;
375static long p_tw;
376static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200377#ifdef FEAT_PERSISTENT_UNDO
378static int p_udf;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380static long p_wm;
381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
400 char *fullname; /* full option name */
401 char *shortname; /* permissible abbreviation */
402 long_u flags; /* see below */
403 char_u *var; /* global option: pointer to variable;
404 * window-local option: VAR_WIN;
405 * buffer-local option: global value */
406 idopt_T indir; /* global option: PV_NONE;
407 * local option: indirect option index */
408 char_u *def_val[2]; /* default values for variable (vi and vim) */
409#ifdef FEAT_EVAL
410 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411# define SCRIPTID_INIT , 0
412#else
413# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200476# 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 +0000477
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100478/* Default python version for pyx* commands */
479#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
480# define DEFAULT_PYTHON_VER 0
481#elif defined(FEAT_PYTHON3)
482# define DEFAULT_PYTHON_VER 3
483#elif defined(FEAT_PYTHON)
484# define DEFAULT_PYTHON_VER 2
485#else
486# define DEFAULT_PYTHON_VER 0
487#endif
488
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489/*
490 * options[] is initialized here.
491 * The order of the options MUST be alphabetic for ":set all" and findoption().
492 * All option names MUST start with a lowercase letter (for findoption()).
493 * Exception: "t_" options are at the end.
494 * The options with a NULL variable are 'hidden': a set command for them is
495 * ignored and they are not printed.
496 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100497static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200499 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500#ifdef FEAT_RIGHTLEFT
501 (char_u *)&p_aleph, PV_NONE,
502#else
503 (char_u *)NULL, PV_NONE,
504#endif
505 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100506#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507 (char_u *)128L,
508#else
509 (char_u *)224L,
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200513#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)&p_antialias, PV_NONE,
515 {(char_u *)FALSE, (char_u *)FALSE}
516#else
517 (char_u *)NULL, PV_NONE,
518 {(char_u *)FALSE, (char_u *)FALSE}
519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000520 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200521 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522#ifdef FEAT_ARABIC
523 (char_u *)VAR_WIN, PV_ARAB,
524#else
525 (char_u *)NULL, PV_NONE,
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
529#ifdef FEAT_ARABIC
530 (char_u *)&p_arshape, PV_NONE,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
536#ifdef FEAT_RIGHTLEFT
537 (char_u *)&p_ari, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
543#ifdef FEAT_FKMAP
544 (char_u *)&p_altkeymap, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
550#if defined(FEAT_MBYTE)
551 (char_u *)&p_ambw, PV_NONE,
552 {(char_u *)"single", (char_u *)0L}
553#else
554 (char_u *)NULL, PV_NONE,
555 {(char_u *)0L, (char_u *)0L}
556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100559#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100561 {(char_u *)FALSE, (char_u *)0L}
562#else
563 (char_u *)NULL, PV_NONE,
564 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoindent", "ai", P_BOOL|P_VI_DEF,
568 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoprint", "ap", P_BOOL|P_VI_DEF,
571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000574 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowrite", "aw", P_BOOL|P_VI_DEF,
577 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autowriteall","awa", P_BOOL|P_VI_DEF,
580 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
583 (char_u *)&p_bg, PV_NONE,
584 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100585#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)"dark",
587#else
588 (char_u *)"light",
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
595 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200598 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599#ifdef UNIX
600 {(char_u *)"yes", (char_u *)"auto"}
601#else
602 {(char_u *)"auto", (char_u *)"auto"}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000609 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 (char_u *)&p_bex, PV_NONE,
611 {
612#ifdef VMS
613 (char_u *)"_",
614#else
615 (char_u *)"~",
616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200618 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_WILDIGN
620 (char_u *)&p_bsk, PV_NONE,
621 {(char_u *)"", (char_u *)0L}
622#else
623 (char_u *)NULL, PV_NONE,
624 {(char_u *)0L, (char_u *)0L}
625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 {(char_u *)600L, (char_u *)0L}
631#else
632 (char_u *)NULL, PV_NONE,
633 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 SCRIPTID_INIT},
636 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
637#ifdef FEAT_BEVAL
638 (char_u *)&p_beval, PV_NONE,
639 {(char_u *)FALSE, (char_u *)0L}
640#else
641 (char_u *)NULL, PV_NONE,
642 {(char_u *)0L, (char_u *)0L}
643#endif
644 SCRIPTID_INIT},
645 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
646#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
647 (char_u *)&p_bexpr, PV_BEXPR,
648 {(char_u *)"", (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654 {"beautify", "bf", P_BOOL|P_VI_DEF,
655 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200657 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
658 (char_u *)&p_bo, PV_NONE,
659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
661 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000662 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
667#ifdef FEAT_MBYTE
668 (char_u *)&p_bomb, PV_BOMB,
669#else
670 (char_u *)NULL, PV_NONE,
671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
674#ifdef FEAT_LINEBREAK
675 (char_u *)&p_breakat, PV_NONE,
676 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200682 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
683#ifdef FEAT_LINEBREAK
684 (char_u *)VAR_WIN, PV_BRI,
685 {(char_u *)FALSE, (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
690 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200691 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
692 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693#ifdef FEAT_LINEBREAK
694 (char_u *)VAR_WIN, PV_BRIOPT,
695 {(char_u *)"", (char_u *)NULL}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)"", (char_u *)NULL}
699#endif
700 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
702#ifdef FEAT_BROWSE
703 (char_u *)&p_bsdir, PV_NONE,
704 {(char_u *)"last", (char_u *)0L}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 (char_u *)&p_bh, PV_BH,
712 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
715 (char_u *)&p_bl, PV_BL,
716 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 (char_u *)&p_bt, PV_BT,
720 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200722 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000723#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 (char_u *)&p_cmp, PV_NONE,
725 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
732#ifdef FEAT_SEARCHPATH
733 (char_u *)&p_cdpath, PV_NONE,
734 {(char_u *)",,", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cedit", NULL, P_STRING,
741#ifdef FEAT_CMDWIN
742 (char_u *)&p_cedit, PV_NONE,
743 {(char_u *)"", (char_u *)CTRL_F_STR}
744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
750#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
751 (char_u *)&p_ccv, PV_NONE,
752 {(char_u *)"", (char_u *)0L}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000757 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
759#ifdef FEAT_CINDENT
760 (char_u *)&p_cin, PV_CIN,
761#else
762 (char_u *)NULL, PV_NONE,
763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200765 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766#ifdef FEAT_CINDENT
767 (char_u *)&p_cink, PV_CINK,
768 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
769#else
770 (char_u *)NULL, PV_NONE,
771 {(char_u *)0L, (char_u *)0L}
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#ifdef FEAT_CINDENT
776 (char_u *)&p_cino, PV_CINO,
777#else
778 (char_u *)NULL, PV_NONE,
779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000780 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200781 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
783 (char_u *)&p_cinw, PV_CINW,
784 {(char_u *)"if,else,while,do,for,switch",
785 (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#ifdef FEAT_CLIPBOARD
793 (char_u *)&p_cb, PV_NONE,
794# ifdef FEAT_XCLIPBOARD
795 {(char_u *)"autoselect,exclude:cons\\|linux",
796 (char_u *)0L}
797# else
798 {(char_u *)"", (char_u *)0L}
799# endif
800#else
801 (char_u *)NULL, PV_NONE,
802 {(char_u *)"", (char_u *)0L}
803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
806 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
809#ifdef FEAT_CMDWIN
810 (char_u *)&p_cwh, PV_NONE,
811#else
812 (char_u *)NULL, PV_NONE,
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200815 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200816#ifdef FEAT_SYN_HL
817 (char_u *)VAR_WIN, PV_CC,
818#else
819 (char_u *)NULL, PV_NONE,
820#endif
821 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
823 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200825 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
826 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827#ifdef FEAT_COMMENTS
828 (char_u *)&p_com, PV_COM,
829 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
830 (char_u *)0L}
831#else
832 (char_u *)NULL, PV_NONE,
833 {(char_u *)0L, (char_u *)0L}
834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200836 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837#ifdef FEAT_FOLDING
838 (char_u *)&p_cms, PV_CMS,
839 {(char_u *)"/*%s*/", (char_u *)0L}
840#else
841 (char_u *)NULL, PV_NONE,
842 {(char_u *)0L, (char_u *)0L}
843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000844 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000845 /* P_PRI_MKRC isn't needed here, optval_default()
846 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 {"compatible", "cp", P_BOOL|P_RALL,
848 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000849 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200850 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851#ifdef FEAT_INS_EXPAND
852 (char_u *)&p_cpt, PV_CPT,
853 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
854#else
855 (char_u *)NULL, PV_NONE,
856 {(char_u *)0L, (char_u *)0L}
857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200859 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200860#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 (char_u *)VAR_WIN, PV_COCU,
862 {(char_u *)"", (char_u *)NULL}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)NULL, (char_u *)0L}
866#endif
867 SCRIPTID_INIT},
868 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
869#ifdef FEAT_CONCEAL
870 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#else
872 (char_u *)NULL, PV_NONE,
873#endif
874 {(char_u *)0L, (char_u *)0L}
875 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000876 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
877#ifdef FEAT_COMPL_FUNC
878 (char_u *)&p_cfu, PV_CFU,
879 {(char_u *)"", (char_u *)0L}
880#else
881 (char_u *)NULL, PV_NONE,
882 {(char_u *)0L, (char_u *)0L}
883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000884 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200885 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000886#ifdef FEAT_INS_EXPAND
887 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000888 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000889#else
890 (char_u *)NULL, PV_NONE,
891 {(char_u *)0L, (char_u *)0L}
892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000893 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 {"confirm", "cf", P_BOOL|P_VI_DEF,
895#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
896 (char_u *)&p_confirm, PV_NONE,
897#else
898 (char_u *)NULL, PV_NONE,
899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
905 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
908 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
910 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200911 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200913 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200914 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200915#else
916 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200918#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
921#ifdef FEAT_CSCOPE
922 (char_u *)&p_cspc, PV_NONE,
923#else
924 (char_u *)NULL, PV_NONE,
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_csprg, PV_NONE,
930 {(char_u *)"cscope", (char_u *)0L}
931#else
932 (char_u *)NULL, PV_NONE,
933 {(char_u *)0L, (char_u *)0L}
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200936 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
938 (char_u *)&p_csqf, PV_NONE,
939 {(char_u *)"", (char_u *)0L}
940#else
941 (char_u *)NULL, PV_NONE,
942 {(char_u *)0L, (char_u *)0L}
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200945 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csre, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_cst, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_csto, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
967#ifdef FEAT_CSCOPE
968 (char_u *)&p_csverbose, PV_NONE,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200973 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
974#ifdef FEAT_CURSORBIND
975 (char_u *)VAR_WIN, PV_CRBIND,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000980 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
981#ifdef FEAT_SYN_HL
982 (char_u *)VAR_WIN, PV_CUC,
983#else
984 (char_u *)NULL, PV_NONE,
985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100987 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000988#ifdef FEAT_SYN_HL
989 (char_u *)VAR_WIN, PV_CUL,
990#else
991 (char_u *)NULL, PV_NONE,
992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {"debug", NULL, P_STRING|P_VI_DEF,
995 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200997 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000999 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001000 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003 {(char_u *)NULL, (char_u *)0L}
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1007#ifdef FEAT_MBYTE
1008 (char_u *)&p_deco, PV_NONE,
1009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001013 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001015 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016#else
1017 (char_u *)NULL, PV_NONE,
1018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001019 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1021#ifdef FEAT_DIFF
1022 (char_u *)VAR_WIN, PV_DIFF,
1023#else
1024 (char_u *)NULL, PV_NONE,
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001027 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1029 (char_u *)&p_dex, PV_NONE,
1030 {(char_u *)"", (char_u *)0L}
1031#else
1032 (char_u *)NULL, PV_NONE,
1033 {(char_u *)0L, (char_u *)0L}
1034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001036 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1037 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038#ifdef FEAT_DIFF
1039 (char_u *)&p_dip, PV_NONE,
1040 {(char_u *)"filler", (char_u *)NULL}
1041#else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)"", (char_u *)NULL}
1044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1047#ifdef FEAT_DIGRAPHS
1048 (char_u *)&p_dg, PV_NONE,
1049#else
1050 (char_u *)NULL, PV_NONE,
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1054 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001057 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 (char_u *)&p_ead, PV_NONE,
1062 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1065 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001067 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1068#if defined(FEAT_MBYTE)
1069 (char_u *)&p_emoji, PV_NONE,
1070 {(char_u *)TRUE, (char_u *)0L}
1071#else
1072 (char_u *)NULL, PV_NONE,
1073 {(char_u *)0L, (char_u *)0L}
1074#endif
1075 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001076 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077#ifdef FEAT_MBYTE
1078 (char_u *)&p_enc, PV_NONE,
1079 {(char_u *)ENC_DFLT, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)0L, (char_u *)0L}
1083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1086 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1089 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001092 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1095 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1098#ifdef FEAT_QUICKFIX
1099 (char_u *)&p_ef, PV_NONE,
1100 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1101#else
1102 (char_u *)NULL, PV_NONE,
1103 {(char_u *)NULL, (char_u *)0L}
1104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001106 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001108 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110#else
1111 (char_u *)NULL, PV_NONE,
1112 {(char_u *)NULL, (char_u *)0L}
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"esckeys", "ek", P_BOOL|P_VIM,
1116 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#ifdef FEAT_AUTOCMD
1120 (char_u *)&p_ei, PV_NONE,
1121#else
1122 (char_u *)NULL, PV_NONE,
1123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1126 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1129 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001131 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1132 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133#ifdef FEAT_MBYTE
1134 (char_u *)&p_fenc, PV_FENC,
1135 {(char_u *)"", (char_u *)0L}
1136#else
1137 (char_u *)NULL, PV_NONE,
1138 {(char_u *)0L, (char_u *)0L}
1139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_MBYTE
1143 (char_u *)&p_fencs, PV_NONE,
1144 {(char_u *)"ucs-bom", (char_u *)0L}
1145#else
1146 (char_u *)NULL, PV_NONE,
1147 {(char_u *)0L, (char_u *)0L}
1148#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001150 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1151 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001154 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1157 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001158 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1159 (char_u *)&p_fic, PV_NONE,
1160 {
1161#ifdef CASE_INSENSITIVE_FILENAME
1162 (char_u *)TRUE,
1163#else
1164 (char_u *)FALSE,
1165#endif
1166 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001167 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168#ifdef FEAT_AUTOCMD
1169 (char_u *)&p_ft, PV_FT,
1170 {(char_u *)"", (char_u *)0L}
1171#else
1172 (char_u *)NULL, PV_NONE,
1173 {(char_u *)0L, (char_u *)0L}
1174#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001176 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)&p_fcs, PV_NONE,
1178 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001180 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1181 (char_u *)&p_fixeol, PV_FIXEOL,
1182 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1184#ifdef FEAT_FKMAP
1185 (char_u *)&p_fkmap, PV_NONE,
1186#else
1187 (char_u *)NULL, PV_NONE,
1188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001189 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 {"flash", "fl", P_BOOL|P_VI_DEF,
1191 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001193 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001194#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001196 {(char_u *)"", (char_u *)0L}
1197#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)NULL, PV_NONE,
1199 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#endif
1201 SCRIPTID_INIT},
1202 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1203#ifdef FEAT_FOLDING
1204 (char_u *)VAR_WIN, PV_FDC,
1205 {(char_u *)FALSE, (char_u *)0L}
1206#else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209#endif
1210 SCRIPTID_INIT},
1211 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1212#ifdef FEAT_FOLDING
1213 (char_u *)VAR_WIN, PV_FEN,
1214 {(char_u *)TRUE, (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 SCRIPTID_INIT},
1220 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1221#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1222 (char_u *)VAR_WIN, PV_FDE,
1223 {(char_u *)"0", (char_u *)NULL}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001228 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001230#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001232 {(char_u *)"#", (char_u *)NULL}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
1237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001239#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001241 {(char_u *)0L, (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001247 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250 {(char_u *)-1L, (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
1255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001257 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001258#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001261#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 (char_u *)NULL, PV_NONE,
1263 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001265 SCRIPTID_INIT},
1266 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1267#ifdef FEAT_FOLDING
1268 (char_u *)VAR_WIN, PV_FDM,
1269 {(char_u *)"manual", (char_u *)NULL}
1270#else
1271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
1273#endif
1274 SCRIPTID_INIT},
1275 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1276#ifdef FEAT_FOLDING
1277 (char_u *)VAR_WIN, PV_FML,
1278 {(char_u *)1L, (char_u *)0L}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
1284 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1285#ifdef FEAT_FOLDING
1286 (char_u *)VAR_WIN, PV_FDN,
1287 {(char_u *)20L, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291#endif
1292 SCRIPTID_INIT},
1293 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1294#ifdef FEAT_FOLDING
1295 (char_u *)&p_fdo, PV_NONE,
1296 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1297 (char_u *)0L}
1298#else
1299 (char_u *)NULL, PV_NONE,
1300 {(char_u *)NULL, (char_u *)0L}
1301#endif
1302 SCRIPTID_INIT},
1303 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1304#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1305 (char_u *)VAR_WIN, PV_FDT,
1306 {(char_u *)"foldtext()", (char_u *)NULL}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001312 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001313#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001314 (char_u *)&p_fex, PV_FEX,
1315 {(char_u *)"", (char_u *)0L}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)0L, (char_u *)0L}
1319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001320 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1322 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001323 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1324 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001325 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1326 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001327 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1328 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001330 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001332 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1333#ifdef HAVE_FSYNC
1334 (char_u *)&p_fs, PV_NONE,
1335 {(char_u *)TRUE, (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)FALSE, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1342 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"graphic", "gr", P_BOOL|P_VI_DEF,
1345 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001347 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348#ifdef FEAT_QUICKFIX
1349 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351#else
1352 (char_u *)NULL, PV_NONE,
1353 {(char_u *)NULL, (char_u *)0L}
1354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1357#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001358 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 {
1360# ifdef WIN3264
1361 /* may be changed to "grep -n" in os_win32.c */
1362 (char_u *)"findstr /n",
1363# else
1364# ifdef UNIX
1365 /* Add an extra file name so that grep will always
1366 * insert a file name in the match line. */
1367 (char_u *)"grep -n $* /dev/null",
1368# else
1369# ifdef VMS
1370 (char_u *)"SEARCH/NUMBERS ",
1371# else
1372 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373# endif
1374# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377#else
1378 (char_u *)NULL, PV_NONE,
1379 {(char_u *)NULL, (char_u *)0L}
1380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001381 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001382 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383#ifdef CURSOR_SHAPE
1384 (char_u *)&p_guicursor, PV_NONE,
1385 {
1386# ifdef FEAT_GUI
1387 (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 +01001388# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1390# endif
1391 (char_u *)0L}
1392#else
1393 (char_u *)NULL, PV_NONE,
1394 {(char_u *)NULL, (char_u *)0L}
1395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001396 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001397 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398#ifdef FEAT_GUI
1399 (char_u *)&p_guifont, PV_NONE,
1400 {(char_u *)"", (char_u *)0L}
1401#else
1402 (char_u *)NULL, PV_NONE,
1403 {(char_u *)NULL, (char_u *)0L}
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001406 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1408 (char_u *)&p_guifontset, PV_NONE,
1409 {(char_u *)"", (char_u *)0L}
1410#else
1411 (char_u *)NULL, PV_NONE,
1412 {(char_u *)NULL, (char_u *)0L}
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1417 (char_u *)&p_guifontwide, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001425#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 (char_u *)&p_ghr, PV_NONE,
1427#else
1428 (char_u *)NULL, PV_NONE,
1429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001430 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001432#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001434# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001435 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001437 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438# endif
1439#else
1440 (char_u *)NULL, PV_NONE,
1441 {(char_u *)NULL, (char_u *)0L}
1442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 {"guipty", NULL, P_BOOL|P_VI_DEF,
1445#if defined(FEAT_GUI)
1446 (char_u *)&p_guipty, PV_NONE,
1447#else
1448 (char_u *)NULL, PV_NONE,
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001451 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001452#if defined(FEAT_GUI_TABLINE)
1453 (char_u *)&p_gtl, PV_NONE,
1454 {(char_u *)"", (char_u *)0L}
1455#else
1456 (char_u *)NULL, PV_NONE,
1457 {(char_u *)NULL, (char_u *)0L}
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001460 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001461#if defined(FEAT_GUI_TABLINE)
1462 (char_u *)&p_gtt, PV_NONE,
1463 {(char_u *)"", (char_u *)0L}
1464#else
1465 (char_u *)NULL, PV_NONE,
1466 {(char_u *)NULL, (char_u *)0L}
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1470 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1473 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001479 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480#ifdef FEAT_MULTI_LANG
1481 (char_u *)&p_hlg, PV_NONE,
1482 {(char_u *)"", (char_u *)0L}
1483#else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)0L, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"hidden", "hid", P_BOOL|P_VI_DEF,
1489 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001491 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001492 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001493 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1494 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"history", "hi", P_NUM|P_VIM,
1496 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001497 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1499#ifdef FEAT_RIGHTLEFT
1500 (char_u *)&p_hkmap, PV_NONE,
1501#else
1502 (char_u *)NULL, PV_NONE,
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1506#ifdef FEAT_RIGHTLEFT
1507 (char_u *)&p_hkmapp, PV_NONE,
1508#else
1509 (char_u *)NULL, PV_NONE,
1510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1513 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"icon", NULL, P_BOOL|P_VI_DEF,
1516#ifdef FEAT_TITLE
1517 (char_u *)&p_icon, PV_NONE,
1518#else
1519 (char_u *)NULL, PV_NONE,
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"iconstring", NULL, P_STRING|P_VI_DEF,
1523#ifdef FEAT_TITLE
1524 (char_u *)&p_iconstring, PV_NONE,
1525#else
1526 (char_u *)NULL, PV_NONE,
1527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001528 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1530 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001532 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1533# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1534 (char_u *)&p_imaf, PV_NONE,
1535 {(char_u *)"", (char_u *)NULL}
1536# else
1537 (char_u *)NULL, PV_NONE,
1538 {(char_u *)NULL, (char_u *)0L}
1539# endif
1540 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001542#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 (char_u *)&p_imak, PV_NONE,
1544#else
1545 (char_u *)NULL, PV_NONE,
1546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1549#ifdef USE_IM_CONTROL
1550 (char_u *)&p_imcmdline, PV_NONE,
1551#else
1552 (char_u *)NULL, PV_NONE,
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1556#ifdef USE_IM_CONTROL
1557 (char_u *)&p_imdisable, PV_NONE,
1558#else
1559 (char_u *)NULL, PV_NONE,
1560#endif
1561#ifdef __sgi
1562 {(char_u *)TRUE, (char_u *)0L}
1563#else
1564 {(char_u *)FALSE, (char_u *)0L}
1565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"iminsert", "imi", P_NUM|P_VI_DEF,
1568 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"imsearch", "ims", P_NUM|P_VI_DEF,
1572 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001573 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001574 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001575 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001576#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001577 (char_u *)&p_imsf, PV_NONE,
1578 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001579#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001580 (char_u *)NULL, PV_NONE,
1581 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001582#endif
1583 SCRIPTID_INIT},
1584 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1585#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1586 (char_u *)&p_imst, PV_NONE,
1587 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1588#else
1589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)0L, (char_u *)0L}
1591#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001592 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1594#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001595 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1603#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1604 (char_u *)&p_inex, PV_INEX,
1605 {(char_u *)"", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)0L, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1612 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001613 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1615#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1616 (char_u *)&p_inde, PV_INDE,
1617 {(char_u *)"", (char_u *)0L}
1618#else
1619 (char_u *)NULL, PV_NONE,
1620 {(char_u *)0L, (char_u *)0L}
1621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001623 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 (char_u *)&p_indk, PV_INDK,
1626 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"infercase", "inf", P_BOOL|P_VI_DEF,
1633 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1636 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1639 (char_u *)&p_isf, PV_NONE,
1640 {
1641#ifdef BACKSLASH_IN_FILENAME
1642 /* Excluded are: & and ^ are special in cmd.exe
1643 * ( and ) are used in text separating fnames */
1644 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1645#else
1646# ifdef AMIGA
1647 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1648# else
1649# ifdef VMS
1650 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1651# else /* UNIX et al. */
1652# ifdef EBCDIC
1653 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1654# else
1655 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1656# endif
1657# endif
1658# endif
1659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001660 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1662 (char_u *)&p_isi, PV_NONE,
1663 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001664#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 (char_u *)"@,48-57,_,128-167,224-235",
1666#else
1667# ifdef EBCDIC
1668 /* TODO: EBCDIC Check this! @ == isalpha()*/
1669 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1670 "112-120,128,140-142,156,158,172,"
1671 "174,186,191,203-207,219-225,235-239,"
1672 "251-254",
1673# else
1674 (char_u *)"@,48-57,_,192-255",
1675# endif
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1679 (char_u *)&p_isk, PV_ISK,
1680 {
1681#ifdef EBCDIC
1682 (char_u *)"@,240-249,_",
1683 /* TODO: EBCDIC Check this! @ == isalpha()*/
1684 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1685 "112-120,128,140-142,156,158,172,"
1686 "174,186,191,203-207,219-225,235-239,"
1687 "251-254",
1688#else
1689 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001690# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 (char_u *)"@,48-57,_,128-167,224-235"
1692# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001693 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694# endif
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1698 (char_u *)&p_isp, PV_NONE,
1699 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001700#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 (char_u *)"@,~-255",
1702#else
1703# ifdef EBCDIC
1704 /* all chars above 63 are printable */
1705 (char_u *)"63-255",
1706# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001707 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708# endif
1709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1712 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001713 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1715#ifdef FEAT_CRYPT
1716 (char_u *)&p_key, PV_KEY,
1717 {(char_u *)"", (char_u *)0L}
1718#else
1719 (char_u *)NULL, PV_NONE,
1720 {(char_u *)0L, (char_u *)0L}
1721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001723 {"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 +00001724#ifdef FEAT_KEYMAP
1725 (char_u *)&p_keymap, PV_KMAP,
1726 {(char_u *)"", (char_u *)0L}
1727#else
1728 (char_u *)NULL, PV_NONE,
1729 {(char_u *)"", (char_u *)0L}
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001732 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001734 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001736 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001738#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 (char_u *)":help",
1740#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001741# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001743# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001744# ifdef USEMAN_S
1745 (char_u *)"man -s",
1746# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001748# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749# endif
1750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001751 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001752 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753#ifdef FEAT_LANGMAP
1754 (char_u *)&p_langmap, PV_NONE,
1755 {(char_u *)"", /* unmatched } */
1756#else
1757 (char_u *)NULL, PV_NONE,
1758 {(char_u *)NULL,
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001761 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1763 (char_u *)&p_lm, PV_NONE,
1764#else
1765 (char_u *)NULL, PV_NONE,
1766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001768 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1769#ifdef FEAT_LANGMAP
1770 (char_u *)&p_lnr, PV_NONE,
1771#else
1772 (char_u *)NULL, PV_NONE,
1773#endif
1774 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001775 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1776#ifdef FEAT_LANGMAP
1777 (char_u *)&p_lrm, PV_NONE,
1778#else
1779 (char_u *)NULL, PV_NONE,
1780#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001781 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1786 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001787 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1789#ifdef FEAT_LINEBREAK
1790 (char_u *)VAR_WIN, PV_LBR,
1791#else
1792 (char_u *)NULL, PV_NONE,
1793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1796 (char_u *)&Rows, PV_NONE,
1797 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001798#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 (char_u *)25L,
1800#else
1801 (char_u *)24L,
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1805#ifdef FEAT_GUI
1806 (char_u *)&p_linespace, PV_NONE,
1807#else
1808 (char_u *)NULL, PV_NONE,
1809#endif
1810#ifdef FEAT_GUI_W32
1811 {(char_u *)1L, (char_u *)0L}
1812#else
1813 {(char_u *)0L, (char_u *)0L}
1814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001815 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 {"lisp", NULL, P_BOOL|P_VI_DEF,
1817#ifdef FEAT_LISP
1818 (char_u *)&p_lisp, PV_LISP,
1819#else
1820 (char_u *)NULL, PV_NONE,
1821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001823 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001825 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1827#else
1828 (char_u *)NULL, PV_NONE,
1829 {(char_u *)"", (char_u *)0L}
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1833 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001835 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1839 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001841 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001842#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001843 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001844 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001845#else
1846 (char_u *)NULL, PV_NONE,
1847 {(char_u *)"", (char_u *)0L}
1848#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001849 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001850 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001851#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001852 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001853 {(char_u *)TRUE, (char_u *)0L}
1854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001857#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001858 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"magic", NULL, P_BOOL|P_VI_DEF,
1860 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001862 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863#ifdef FEAT_QUICKFIX
1864 (char_u *)&p_mef, PV_NONE,
1865 {(char_u *)"", (char_u *)0L}
1866#else
1867 (char_u *)NULL, PV_NONE,
1868 {(char_u *)NULL, (char_u *)0L}
1869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001871 {"makeencoding","menc", P_STRING|P_VI_DEF,
1872#ifdef FEAT_MBYTE
1873 (char_u *)&p_menc, PV_MENC,
1874 {(char_u *)"", (char_u *)0L}
1875#else
1876 (char_u *)NULL, PV_NONE,
1877 {(char_u *)0L, (char_u *)0L}
1878#endif
1879 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1881#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001882 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883# ifdef VMS
1884 {(char_u *)"MMS", (char_u *)0L}
1885# else
1886 {(char_u *)"make", (char_u *)0L}
1887# endif
1888#else
1889 (char_u *)NULL, PV_NONE,
1890 {(char_u *)NULL, (char_u *)0L}
1891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001892 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001893 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1896 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"matchtime", "mat", P_NUM|P_VI_DEF,
1898 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001900 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001901#ifdef FEAT_MBYTE
1902 (char_u *)&p_mco, PV_NONE,
1903#else
1904 (char_u *)NULL, PV_NONE,
1905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001906 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1908#ifdef FEAT_EVAL
1909 (char_u *)&p_mfd, PV_NONE,
1910#else
1911 (char_u *)NULL, PV_NONE,
1912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001913 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1915 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001916 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"maxmem", "mm", P_NUM|P_VI_DEF,
1918 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1920 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001921 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1922 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1925 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1927 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"menuitems", "mis", P_NUM|P_VI_DEF,
1929#ifdef FEAT_MENU
1930 (char_u *)&p_mis, PV_NONE,
1931#else
1932 (char_u *)NULL, PV_NONE,
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"mesg", NULL, P_BOOL|P_VI_DEF,
1936 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001938 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001939#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001940 (char_u *)&p_msm, PV_NONE,
1941 {(char_u *)"460000,2000,500", (char_u *)0L}
1942#else
1943 (char_u *)NULL, PV_NONE,
1944 {(char_u *)0L, (char_u *)0L}
1945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"modeline", "ml", P_BOOL|P_VIM,
1948 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"modelines", "mls", P_NUM|P_VI_DEF,
1951 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1954 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1957 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"more", NULL, P_BOOL|P_VIM,
1960 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1963 (char_u *)&p_mouse, PV_NONE,
1964 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001965#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 (char_u *)"a",
1967#else
1968 (char_u *)"",
1969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1972#ifdef FEAT_GUI
1973 (char_u *)&p_mousef, PV_NONE,
1974#else
1975 (char_u *)NULL, PV_NONE,
1976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1979#ifdef FEAT_GUI
1980 (char_u *)&p_mh, PV_NONE,
1981#else
1982 (char_u *)NULL, PV_NONE,
1983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1986 (char_u *)&p_mousem, PV_NONE,
1987 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001988#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 (char_u *)"popup",
1990#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001991# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 (char_u *)"popup_setpos",
1993# else
1994 (char_u *)"extend",
1995# endif
1996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001998 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999#ifdef FEAT_MOUSESHAPE
2000 (char_u *)&p_mouseshape, PV_NONE,
2001 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2002#else
2003 (char_u *)NULL, PV_NONE,
2004 {(char_u *)NULL, (char_u *)0L}
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2008 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002009 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002010 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2011#if defined(DYNAMIC_MZSCHEME)
2012 (char_u *)&p_mzschemedll, PV_NONE,
2013 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2014#else
2015 (char_u *)NULL, PV_NONE,
2016 {(char_u *)"", (char_u *)0L}
2017#endif
2018 SCRIPTID_INIT},
2019 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2020#if defined(DYNAMIC_MZSCHEME)
2021 (char_u *)&p_mzschemegcdll, PV_NONE,
2022 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)"", (char_u *)0L}
2026#endif
2027 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002028 {"mzquantum", "mzq", P_NUM,
2029#ifdef FEAT_MZSCHEME
2030 (char_u *)&p_mzq, PV_NONE,
2031#else
2032 (char_u *)NULL, PV_NONE,
2033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 {"novice", NULL, P_BOOL|P_VI_DEF,
2036 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002038 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002040 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2043 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002045 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2046#ifdef FEAT_LINEBREAK
2047 (char_u *)VAR_WIN, PV_NUW,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002052 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002053#ifdef FEAT_COMPL_FUNC
2054 (char_u *)&p_ofu, PV_OFU,
2055 {(char_u *)"", (char_u *)0L}
2056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)0L, (char_u *)0L}
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"open", NULL, P_BOOL|P_VI_DEF,
2062 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002064 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002065#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002066 (char_u *)&p_odev, PV_NONE,
2067#else
2068 (char_u *)NULL, PV_NONE,
2069#endif
2070 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002072 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2073 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {"optimize", "opt", P_BOOL|P_VI_DEF,
2076 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002080 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002081 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2082 |P_SECURE,
2083 (char_u *)&p_pp, PV_NONE,
2084 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"paragraphs", "para", P_STRING|P_VI_DEF,
2087 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002088 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002090 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2094 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2097#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2098 (char_u *)&p_pex, PV_NONE,
2099 {(char_u *)"", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)0L, (char_u *)0L}
2103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002105 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 (char_u *)&p_pm, 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 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002109 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002111#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002112 (char_u *)".,,",
2113#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002117 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002118#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002119 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002120 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002121#else
2122 (char_u *)NULL, PV_NONE,
2123 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002124#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002125 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2127 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002129 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002130#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 (char_u *)&p_pvh, PV_NONE,
2132#else
2133 (char_u *)NULL, PV_NONE,
2134#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002135 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002137#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 (char_u *)VAR_WIN, PV_PVW,
2139#else
2140 (char_u *)NULL, PV_NONE,
2141#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002142 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002143 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144#ifdef FEAT_PRINTER
2145 (char_u *)&p_pdev, PV_NONE,
2146 {(char_u *)"", (char_u *)0L}
2147#else
2148 (char_u *)NULL, PV_NONE,
2149 {(char_u *)NULL, (char_u *)0L}
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 {"printencoding", "penc", P_STRING|P_VI_DEF,
2153#ifdef FEAT_POSTSCRIPT
2154 (char_u *)&p_penc, PV_NONE,
2155 {(char_u *)"", (char_u *)0L}
2156#else
2157 (char_u *)NULL, PV_NONE,
2158 {(char_u *)NULL, (char_u *)0L}
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002161 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162#ifdef FEAT_POSTSCRIPT
2163 (char_u *)&p_pexpr, PV_NONE,
2164 {(char_u *)"", (char_u *)0L}
2165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 {"printfont", "pfn", P_STRING|P_VI_DEF,
2171#ifdef FEAT_PRINTER
2172 (char_u *)&p_pfn, PV_NONE,
2173 {
2174# ifdef MSWIN
2175 (char_u *)"Courier_New:h10",
2176# else
2177 (char_u *)"courier",
2178# endif
2179 (char_u *)0L}
2180#else
2181 (char_u *)NULL, PV_NONE,
2182 {(char_u *)NULL, (char_u *)0L}
2183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002184 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2186#ifdef FEAT_PRINTER
2187 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002188 /* untranslated to avoid problems when 'encoding'
2189 * is changed */
2190 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191#else
2192 (char_u *)NULL, PV_NONE,
2193 {(char_u *)NULL, (char_u *)0L}
2194#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002195 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002196 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2197#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2198 (char_u *)&p_pmcs, PV_NONE,
2199 {(char_u *)"", (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002205 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2206#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2207 (char_u *)&p_pmfn, PV_NONE,
2208 {(char_u *)"", (char_u *)0L}
2209#else
2210 (char_u *)NULL, PV_NONE,
2211 {(char_u *)NULL, (char_u *)0L}
2212#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002213 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002214 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215#ifdef FEAT_PRINTER
2216 (char_u *)&p_popt, PV_NONE,
2217 {(char_u *)"", (char_u *)0L}
2218#else
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)NULL, (char_u *)0L}
2221#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002224 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002226 {"pumheight", "ph", P_NUM|P_VI_DEF,
2227#ifdef FEAT_INS_EXPAND
2228 (char_u *)&p_ph, PV_NONE,
2229#else
2230 (char_u *)NULL, PV_NONE,
2231#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002232 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002233 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002234#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002235 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002236 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002237#else
2238 (char_u *)NULL, PV_NONE,
2239 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002240#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002241 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002242 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002243#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002244 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002245 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002246#else
2247 (char_u *)NULL, PV_NONE,
2248 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002249#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002251 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2252#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2253 (char_u *)&p_pyx, PV_NONE,
2254#else
2255 (char_u *)NULL, PV_NONE,
2256#endif
2257 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2258 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002259 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2260#ifdef FEAT_TEXTOBJ
2261 (char_u *)&p_qe, PV_QE,
2262 {(char_u *)"\\", (char_u *)0L}
2263#else
2264 (char_u *)NULL, PV_NONE,
2265 {(char_u *)NULL, (char_u *)0L}
2266#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002267 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2269 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"redraw", NULL, P_BOOL|P_VI_DEF,
2272 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002274 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2275#ifdef FEAT_RELTIME
2276 (char_u *)&p_rdt, PV_NONE,
2277#else
2278 (char_u *)NULL, PV_NONE,
2279#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002281 {"regexpengine", "re", P_NUM|P_VI_DEF,
2282 (char_u *)&p_re, PV_NONE,
2283 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002284 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2285 (char_u *)VAR_WIN, PV_RNU,
2286 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"remap", NULL, P_BOOL|P_VI_DEF,
2288 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002290 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002291#ifdef FEAT_RENDER_OPTIONS
2292 (char_u *)&p_rop, PV_NONE,
2293 {(char_u *)"", (char_u *)0L}
2294#else
2295 (char_u *)NULL, PV_NONE,
2296 {(char_u *)NULL, (char_u *)0L}
2297#endif
2298 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"report", NULL, P_NUM|P_VI_DEF,
2300 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2303#ifdef WIN3264
2304 (char_u *)&p_rs, PV_NONE,
2305#else
2306 (char_u *)NULL, PV_NONE,
2307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2310#ifdef FEAT_RIGHTLEFT
2311 (char_u *)&p_ri, PV_NONE,
2312#else
2313 (char_u *)NULL, PV_NONE,
2314#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2317#ifdef FEAT_RIGHTLEFT
2318 (char_u *)VAR_WIN, PV_RL,
2319#else
2320 (char_u *)NULL, PV_NONE,
2321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2324#ifdef FEAT_RIGHTLEFT
2325 (char_u *)VAR_WIN, PV_RLC,
2326 {(char_u *)"search", (char_u *)NULL}
2327#else
2328 (char_u *)NULL, PV_NONE,
2329 {(char_u *)NULL, (char_u *)0L}
2330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002332 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002333#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002334 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002335 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002336#else
2337 (char_u *)NULL, PV_NONE,
2338 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002339#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2342#ifdef FEAT_CMDL_INFO
2343 (char_u *)&p_ru, PV_NONE,
2344#else
2345 (char_u *)NULL, PV_NONE,
2346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2349#ifdef FEAT_STL_OPT
2350 (char_u *)&p_ruf, PV_NONE,
2351#else
2352 (char_u *)NULL, PV_NONE,
2353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002355 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2356 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2359 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2361 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002362 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2364#ifdef FEAT_SCROLLBIND
2365 (char_u *)VAR_WIN, PV_SCBIND,
2366#else
2367 (char_u *)NULL, PV_NONE,
2368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2371 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002372 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2374 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002376 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377#ifdef FEAT_SCROLLBIND
2378 (char_u *)&p_sbo, PV_NONE,
2379 {(char_u *)"ver,jump", (char_u *)0L}
2380#else
2381 (char_u *)NULL, PV_NONE,
2382 {(char_u *)0L, (char_u *)0L}
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"sections", "sect", P_STRING|P_VI_DEF,
2386 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2388 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2390 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)"inclusive", (char_u *)0L}
2395 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002396 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002399 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400#ifdef FEAT_SESSION
2401 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002402 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 (char_u *)0L}
2404#else
2405 (char_u *)NULL, PV_NONE,
2406 {(char_u *)0L, (char_u *)0L}
2407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002408 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2410 (char_u *)&p_sh, PV_NONE,
2411 {
2412#ifdef VMS
2413 (char_u *)"-",
2414#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002415# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002417# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419# endif
2420#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2423 (char_u *)&p_shcf, PV_NONE,
2424 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002425#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 (char_u *)"/c",
2427#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2432#ifdef FEAT_QUICKFIX
2433 (char_u *)&p_sp, PV_NONE,
2434 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002435#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437#else
2438 (char_u *)">",
2439#endif
2440 (char_u *)0L}
2441#else
2442 (char_u *)NULL, PV_NONE,
2443 {(char_u *)0L, (char_u *)0L}
2444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2447 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2450 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2453#ifdef BACKSLASH_IN_FILENAME
2454 (char_u *)&p_ssl, PV_NONE,
2455#else
2456 (char_u *)NULL, PV_NONE,
2457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002459 {"shelltemp", "stmp", P_BOOL,
2460 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"shelltype", "st", P_NUM|P_VI_DEF,
2463#ifdef AMIGA
2464 (char_u *)&p_st, PV_NONE,
2465#else
2466 (char_u *)NULL, PV_NONE,
2467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2470 (char_u *)&p_sxq, PV_NONE,
2471 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002472#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 (char_u *)"\"",
2474#else
2475 (char_u *)"",
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002478 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2479 (char_u *)&p_sxe, PV_NONE,
2480 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002481#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002482 (char_u *)"\"&|<>()@^",
2483#else
2484 (char_u *)"",
2485#endif
2486 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2488 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2491 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2494 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 {(char_u *)"", (char_u *)"filnxtToO"}
2496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2501#ifdef FEAT_LINEBREAK
2502 (char_u *)&p_sbr, PV_NONE,
2503#else
2504 (char_u *)NULL, PV_NONE,
2505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"showcmd", "sc", P_BOOL|P_VIM,
2508#ifdef FEAT_CMDL_INFO
2509 (char_u *)&p_sc, PV_NONE,
2510#else
2511 (char_u *)NULL, PV_NONE,
2512#endif
2513 {(char_u *)FALSE,
2514#ifdef UNIX
2515 (char_u *)FALSE
2516#else
2517 (char_u *)TRUE
2518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2521 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2524 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"showmode", "smd", P_BOOL|P_VIM,
2527 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002529 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002530 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2533 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2536 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002538 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2539#ifdef FEAT_SIGNS
2540 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002541 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002542#else
2543 (char_u *)NULL, PV_NONE,
2544 {(char_u *)NULL, (char_u *)0L}
2545#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002546 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2548 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2551 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2554#ifdef FEAT_SMARTINDENT
2555 (char_u *)&p_si, PV_SI,
2556#else
2557 (char_u *)NULL, PV_NONE,
2558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2561 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2564 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2567 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002569 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002570#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002571 (char_u *)VAR_WIN, PV_SPELL,
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 Moolenaar488c6512005-08-11 20:09:58 +00002576 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002577#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002578 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002579 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002580#else
2581 (char_u *)NULL, PV_NONE,
2582 {(char_u *)0L, (char_u *)0L}
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002585 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2586 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002587#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002588 (char_u *)&p_spf, PV_SPF,
2589 {(char_u *)"", (char_u *)0L}
2590#else
2591 (char_u *)NULL, PV_NONE,
2592 {(char_u *)0L, (char_u *)0L}
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002595 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2596 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002597#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002598 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002599 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002600#else
2601 (char_u *)NULL, PV_NONE,
2602 {(char_u *)0L, (char_u *)0L}
2603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002605 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002606#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002607 (char_u *)&p_sps, PV_NONE,
2608 {(char_u *)"best", (char_u *)0L}
2609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2621 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2624#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002625 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626#else
2627 (char_u *)NULL, PV_NONE,
2628#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002630 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 (char_u *)&p_su, PV_NONE,
2632 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002634 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002635#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 (char_u *)&p_sua, PV_SUA,
2637 {(char_u *)"", (char_u *)0L}
2638#else
2639 (char_u *)NULL, PV_NONE,
2640 {(char_u *)0L, (char_u *)0L}
2641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2644 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"swapsync", "sws", P_STRING|P_VI_DEF,
2647 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002649 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002652 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2653#ifdef FEAT_SYN_HL
2654 (char_u *)&p_smc, PV_SMC,
2655 {(char_u *)3000L, (char_u *)0L}
2656#else
2657 (char_u *)NULL, PV_NONE,
2658 {(char_u *)0L, (char_u *)0L}
2659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002661 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662#ifdef FEAT_SYN_HL
2663 (char_u *)&p_syn, PV_SYN,
2664 {(char_u *)"", (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002670 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2671#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002672 (char_u *)&p_tal, PV_NONE,
2673#else
2674 (char_u *)NULL, PV_NONE,
2675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002677 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002678 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002679 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2681 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2684 (char_u *)&p_tbs, PV_NONE,
2685#ifdef VMS /* binary searching doesn't appear to work on VMS */
2686 {(char_u *)0L, (char_u *)0L}
2687#else
2688 {(char_u *)TRUE, (char_u *)0L}
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002691 {"tagcase", "tc", P_STRING|P_VIM,
2692 (char_u *)&p_tc, PV_TC,
2693 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 {"taglength", "tl", P_NUM|P_VI_DEF,
2695 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"tagrelative", "tr", P_BOOL|P_VIM,
2698 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002700 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002701 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {
2703#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2704 (char_u *)"./tags,./TAGS,tags,TAGS",
2705#else
2706 (char_u *)"./tags,tags",
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2710 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002712 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002713#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002714 (char_u *)&p_tcldll, PV_NONE,
2715 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002716#else
2717 (char_u *)NULL, PV_NONE,
2718 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002719#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2722 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2725#ifdef FEAT_ARABIC
2726 (char_u *)&p_tbidi, PV_NONE,
2727#else
2728 (char_u *)NULL, PV_NONE,
2729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2732#ifdef FEAT_MBYTE
2733 (char_u *)&p_tenc, PV_NONE,
2734 {(char_u *)"", (char_u *)0L}
2735#else
2736 (char_u *)NULL, PV_NONE,
2737 {(char_u *)0L, (char_u *)0L}
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002740 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2741#ifdef FEAT_TERMGUICOLORS
2742 (char_u *)&p_tgc, PV_NONE,
2743 {(char_u *)FALSE, (char_u *)FALSE}
2744#else
2745 (char_u*)NULL, PV_NONE,
2746 {(char_u *)FALSE, (char_u *)FALSE}
2747#endif
2748 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002749 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2750#ifdef FEAT_TERMINAL
2751 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002752 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002753#else
2754 (char_u *)NULL, PV_NONE,
2755 {(char_u *)NULL, (char_u *)0L}
2756#endif
2757 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002758 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2759#ifdef FEAT_TERMINAL
2760 (char_u *)VAR_WIN, PV_TMS,
2761 {(char_u *)"", (char_u *)NULL}
2762#else
2763 (char_u *)NULL, PV_NONE,
2764 {(char_u *)NULL, (char_u *)0L}
2765#endif
2766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"terse", NULL, P_BOOL|P_VI_DEF,
2768 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002769 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 {"textauto", "ta", P_BOOL|P_VIM,
2771 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002772 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2773 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2775 (char_u *)&p_tx, PV_TX,
2776 {
2777#ifdef USE_CRNL
2778 (char_u *)TRUE,
2779#else
2780 (char_u *)FALSE,
2781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002783 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002786 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002788 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789#else
2790 (char_u *)NULL, PV_NONE,
2791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2794 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"timeout", "to", P_BOOL|P_VI_DEF,
2797 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2800 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"title", NULL, P_BOOL|P_VI_DEF,
2803#ifdef FEAT_TITLE
2804 (char_u *)&p_title, PV_NONE,
2805#else
2806 (char_u *)NULL, PV_NONE,
2807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"titlelen", NULL, P_NUM|P_VI_DEF,
2810#ifdef FEAT_TITLE
2811 (char_u *)&p_titlelen, PV_NONE,
2812#else
2813 (char_u *)NULL, PV_NONE,
2814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002816 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817#ifdef FEAT_TITLE
2818 (char_u *)&p_titleold, PV_NONE,
2819 {(char_u *)N_("Thanks for flying Vim"),
2820 (char_u *)0L}
2821#else
2822 (char_u *)NULL, PV_NONE,
2823 {(char_u *)0L, (char_u *)0L}
2824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"titlestring", NULL, P_STRING|P_VI_DEF,
2827#ifdef FEAT_TITLE
2828 (char_u *)&p_titlestring, PV_NONE,
2829#else
2830 (char_u *)NULL, PV_NONE,
2831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002833 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002834#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002837#else
2838 (char_u *)NULL, PV_NONE,
2839 {(char_u *)0L, (char_u *)0L}
2840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002843#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002845 {(char_u *)"small", (char_u *)0L}
2846#else
2847 (char_u *)NULL, PV_NONE,
2848 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2852 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2855 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002856 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2858 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2861 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2864#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2865 (char_u *)&p_ttym, PV_NONE,
2866#else
2867 (char_u *)NULL, PV_NONE,
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2871 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2874 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002876 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2877 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002878#ifdef FEAT_PERSISTENT_UNDO
2879 (char_u *)&p_udir, PV_NONE,
2880 {(char_u *)".", (char_u *)0L}
2881#else
2882 (char_u *)NULL, PV_NONE,
2883 {(char_u *)0L, (char_u *)0L}
2884#endif
2885 SCRIPTID_INIT},
2886 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2887#ifdef FEAT_PERSISTENT_UNDO
2888 (char_u *)&p_udf, PV_UDF,
2889#else
2890 (char_u *)NULL, PV_NONE,
2891#endif
2892 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002894 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002896#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 (char_u *)1000L,
2898#else
2899 (char_u *)100L,
2900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002901 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002902 {"undoreload", "ur", P_NUM|P_VI_DEF,
2903 (char_u *)&p_ur, PV_NONE,
2904 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905 {"updatecount", "uc", P_NUM|P_VI_DEF,
2906 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002907 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"updatetime", "ut", P_NUM|P_VI_DEF,
2909 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"verbose", "vbs", P_NUM|P_VI_DEF,
2912 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002913 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002914 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2915 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2918#ifdef FEAT_SESSION
2919 (char_u *)&p_vdir, PV_NONE,
2920 {(char_u *)DFLT_VDIR, (char_u *)0L}
2921#else
2922 (char_u *)NULL, PV_NONE,
2923 {(char_u *)0L, (char_u *)0L}
2924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002926 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927#ifdef FEAT_SESSION
2928 (char_u *)&p_vop, PV_NONE,
2929 {(char_u *)"folds,options,cursor", (char_u *)0L}
2930#else
2931 (char_u *)NULL, PV_NONE,
2932 {(char_u *)0L, (char_u *)0L}
2933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002935 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936#ifdef FEAT_VIMINFO
2937 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002938#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002939 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940#else
2941# ifdef AMIGA
2942 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002943 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002945 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946# endif
2947#endif
2948#else
2949 (char_u *)NULL, PV_NONE,
2950 {(char_u *)0L, (char_u *)0L}
2951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002952 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002953 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2954#ifdef FEAT_VIMINFO
2955 (char_u *)&p_viminfofile, PV_NONE,
2956 {(char_u *)"", (char_u *)0L}
2957#else
2958 (char_u *)NULL, PV_NONE,
2959 {(char_u *)0L, (char_u *)0L}
2960#endif
2961 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002962 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2963 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964#ifdef FEAT_VIRTUALEDIT
2965 (char_u *)&p_ve, PV_NONE,
2966 {(char_u *)"", (char_u *)""}
2967#else
2968 (char_u *)NULL, PV_NONE,
2969 {(char_u *)0L, (char_u *)0L}
2970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002971 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2973 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002974 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975 {"w300", NULL, P_NUM|P_VI_DEF,
2976 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002977 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 {"w1200", NULL, P_NUM|P_VI_DEF,
2979 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002980 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 {"w9600", NULL, P_NUM|P_VI_DEF,
2982 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 {"warn", NULL, P_BOOL|P_VI_DEF,
2985 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002986 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2988 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002990 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002992 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 {"wildchar", "wc", P_NUM|P_VIM,
2994 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002995 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2996 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002997 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003000 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001#ifdef FEAT_WILDIGN
3002 (char_u *)&p_wig, PV_NONE,
3003#else
3004 (char_u *)NULL, PV_NONE,
3005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003006 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003007 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3008 (char_u *)&p_wic, PV_NONE,
3009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3011#ifdef FEAT_WILDMENU
3012 (char_u *)&p_wmnu, PV_NONE,
3013#else
3014 (char_u *)NULL, PV_NONE,
3015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003016 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003017 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003019 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003020 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3021#ifdef FEAT_CMDL_COMPL
3022 (char_u *)&p_wop, PV_NONE,
3023 {(char_u *)"", (char_u *)0L}
3024#else
3025 (char_u *)NULL, PV_NONE,
3026 {(char_u *)NULL, (char_u *)0L}
3027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3030#ifdef FEAT_WAK
3031 (char_u *)&p_wak, PV_NONE,
3032 {(char_u *)"menu", (char_u *)0L}
3033#else
3034 (char_u *)NULL, PV_NONE,
3035 {(char_u *)NULL, (char_u *)0L}
3036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003037 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003039 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003040 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003043 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003047 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003048 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003049 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003052 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003055 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003056 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003057#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003058 (char_u *)&p_winptydll, PV_NONE, {
3059# ifdef _WIN64
3060 (char_u *)"winpty64.dll",
3061# else
3062 (char_u *)"winpty32.dll",
3063# endif
3064 (char_u *)0L}
3065#else
3066 (char_u *)NULL, PV_NONE,
3067 {(char_u *)0L, (char_u *)0L}
3068#endif
3069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003072 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3074 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003075 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3077 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003078 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3080 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003081 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 {"write", NULL, P_BOOL|P_VI_DEF,
3083 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003084 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 {"writeany", "wa", P_BOOL|P_VI_DEF,
3086 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003087 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3089 (char_u *)&p_wb, PV_NONE,
3090 {
3091#ifdef FEAT_WRITEBACKUP
3092 (char_u *)TRUE,
3093#else
3094 (char_u *)FALSE,
3095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003096 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 {"writedelay", "wd", P_NUM|P_VI_DEF,
3098 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003099 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100
3101/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003102#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003104 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105
3106 p_term("t_AB", T_CAB)
3107 p_term("t_AF", T_CAF)
3108 p_term("t_AL", T_CAL)
3109 p_term("t_al", T_AL)
3110 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003111 p_term("t_BE", T_BE)
3112 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 p_term("t_cd", T_CD)
3114 p_term("t_ce", T_CE)
3115 p_term("t_cl", T_CL)
3116 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003117 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 p_term("t_Co", T_CCO)
3119 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003120 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_da", T_DA)
3124 p_term("t_db", T_DB)
3125 p_term("t_DL", T_CDL)
3126 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003127 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003128 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003130 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_IE", T_CIE)
3132 p_term("t_IS", T_CIS)
3133 p_term("t_ke", T_KE)
3134 p_term("t_ks", T_KS)
3135 p_term("t_le", T_LE)
3136 p_term("t_mb", T_MB)
3137 p_term("t_md", T_MD)
3138 p_term("t_me", T_ME)
3139 p_term("t_mr", T_MR)
3140 p_term("t_ms", T_MS)
3141 p_term("t_nd", T_ND)
3142 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003143 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003144 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003145 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003147 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 p_term("t_RV", T_CRV)
3149 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003150 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003152 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003153 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003154 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003156 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003158 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 p_term("t_te", T_TE)
3160 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003161 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_ts", T_TS)
3163 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_ue", T_UE)
3165 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_vb", T_VB)
3168 p_term("t_ve", T_VE)
3169 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003170 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_vs", T_VS)
3172 p_term("t_WP", T_CWP)
3173 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003174 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 p_term("t_xs", T_XS)
3176 p_term("t_ZH", T_CZH)
3177 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003178 p_term("t_8f", T_8F)
3179 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180
3181/* terminal key codes are not in here */
3182
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003183 /* end marker */
3184 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185};
3186
3187#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3188
3189#ifdef FEAT_MBYTE
3190static char *(p_ambw_values[]) = {"single", "double", NULL};
3191#endif
3192static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003193static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003195#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003196static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003197#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003198#ifdef FEAT_CMDL_COMPL
3199static char *(p_wop_values[]) = {"tagfile", NULL};
3200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201#ifdef FEAT_WAK
3202static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3203#endif
3204static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3206static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208#ifdef FEAT_BROWSE
3209static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3210#endif
3211#ifdef FEAT_SCROLLBIND
3212static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3213#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003214static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003216#ifdef FEAT_AUTOCMD
3217static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3218#else
3219static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003221static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3223#ifdef FEAT_FOLDING
3224static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003225# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003227# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 NULL};
3229static char *(p_fcl_values[]) = {"all", NULL};
3230#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003231#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003232static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003233#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003234#ifdef FEAT_SIGNS
3235static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3236#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003238static void set_option_default(int, int opt_flags, int compatible);
3239static void set_options_default(int opt_flags);
3240static char_u *term_bg_default(void);
3241static void did_set_option(int opt_idx, int opt_flags, int new_value);
3242static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003244static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245#endif
3246#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003247static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003249static char_u *option_expand(int opt_idx, char_u *val);
3250static void didset_options(void);
3251static void didset_options2(void);
3252static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003253#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003254static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003255#else
3256# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3257#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static void set_string_option_global(int opt_idx, char_u **varp);
3259static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3260static 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);
3261static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003262#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003268#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static char_u *did_set_spell_option(int is_spellfile);
3270static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003271#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003272#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003274#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3276static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3277static void check_redraw(long_u flags);
3278static int findoption(char_u *);
3279static int find_key_option(char_u *);
3280static void showoptions(int all, int opt_flags);
3281static int optval_default(struct vimoption *, char_u *varp);
3282static void showoneopt(struct vimoption *, int opt_flags);
3283static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3284static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3285static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3286static int istermoption(struct vimoption *);
3287static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3288static char_u *get_varp(struct vimoption *);
3289static void option_value2string(struct vimoption *, int opt_flags);
3290static void check_winopt(winopt_T *wop);
3291static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static void langmap_init(void);
3294static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static void paste_option_changed(void);
3297static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3302static int check_opt_strings(char_u *val, char **values, int);
3303static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003304#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307
3308/*
3309 * Initialize the options, first part.
3310 *
3311 * Called only once from main(), just after creating the first buffer.
3312 */
3313 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003314set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315{
3316 char_u *p;
3317 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003318 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319
3320#ifdef FEAT_LANGMAP
3321 langmap_init();
3322#endif
3323
3324 /* Be Vi compatible by default */
3325 p_cp = TRUE;
3326
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003327 /* Use POSIX compatibility when $VIM_POSIX is set. */
3328 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003329 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003330 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003331 set_string_default("shm", (char_u *)"A");
3332 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003333
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334 /*
3335 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003336 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003338 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003339#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003340 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003342 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343# endif
3344#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003345 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346 set_string_default("sh", p);
3347
3348#ifdef FEAT_WILDIGN
3349 /*
3350 * Set the default for 'backupskip' to include environment variables for
3351 * temp files.
3352 */
3353 {
3354# ifdef UNIX
3355 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3356# else
3357 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3358# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003359 int len;
3360 garray_T ga;
3361 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362
3363 ga_init2(&ga, 1, 100);
3364 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3365 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003366 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367# ifdef UNIX
3368 if (*names[n] == NUL)
3369 p = (char_u *)"/tmp";
3370 else
3371# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003372 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373 if (p != NULL && *p != NUL)
3374 {
3375 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003376 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377 if (ga_grow(&ga, len) == OK)
3378 {
3379 if (ga.ga_len > 0)
3380 STRCAT(ga.ga_data, ",");
3381 STRCAT(ga.ga_data, p);
3382 add_pathsep(ga.ga_data);
3383 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 ga.ga_len += len;
3385 }
3386 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003387 if (mustfree)
3388 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 }
3390 if (ga.ga_data != NULL)
3391 {
3392 set_string_default("bsk", ga.ga_data);
3393 vim_free(ga.ga_data);
3394 }
3395 }
3396#endif
3397
3398 /*
3399 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3400 */
3401 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003402 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003404#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3405 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3406#endif
3407 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003409 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003410 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411#else
3412# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003413 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003414 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003416 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417# endif
3418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 opt_idx = findoption((char_u *)"maxmem");
3421 if (opt_idx >= 0)
3422 {
3423#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003424 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3425 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003426#endif
3427 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3428 }
3429 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 }
3431
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432#ifdef FEAT_SEARCHPATH
3433 {
3434 char_u *cdpath;
3435 char_u *buf;
3436 int i;
3437 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003438 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439
3440 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003441 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442 if (cdpath != NULL)
3443 {
3444 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3445 if (buf != NULL)
3446 {
3447 buf[0] = ','; /* start with ",", current dir first */
3448 j = 1;
3449 for (i = 0; cdpath[i] != NUL; ++i)
3450 {
3451 if (vim_ispathlistsep(cdpath[i]))
3452 buf[j++] = ',';
3453 else
3454 {
3455 if (cdpath[i] == ' ' || cdpath[i] == ',')
3456 buf[j++] = '\\';
3457 buf[j++] = cdpath[i];
3458 }
3459 }
3460 buf[j] = NUL;
3461 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003462 if (opt_idx >= 0)
3463 {
3464 options[opt_idx].def_val[VI_DEFAULT] = buf;
3465 options[opt_idx].flags |= P_DEF_ALLOCED;
3466 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003467 else
3468 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003470 if (mustfree)
3471 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 }
3473 }
3474#endif
3475
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003476#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477 /* Set print encoding on platforms that don't default to latin1 */
3478 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003479# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 (char_u *)"cp1252"
3481# else
3482# ifdef VMS
3483 (char_u *)"dec-mcs"
3484# else
3485# ifdef EBCDIC
3486 (char_u *)"ebcdic-uk"
3487# else
3488# ifdef MAC
3489 (char_u *)"mac-roman"
3490# else /* HPUX */
3491 (char_u *)"hp-roman8"
3492# endif
3493# endif
3494# endif
3495# endif
3496 );
3497#endif
3498
3499#ifdef FEAT_POSTSCRIPT
3500 /* 'printexpr' must be allocated to be able to evaluate it. */
3501 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003502# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003503 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504# else
3505# ifdef VMS
3506 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3507
3508# else
3509 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3510# endif
3511# endif
3512 );
3513#endif
3514
3515 /*
3516 * Set all the options (except the terminal options) to their default
3517 * value. Also set the global value for local options.
3518 */
3519 set_options_default(0);
3520
3521#ifdef FEAT_GUI
3522 if (found_reverse_arg)
3523 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3524#endif
3525
3526 curbuf->b_p_initialized = TRUE;
3527 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003528 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 check_buf_options(curbuf);
3530 check_win_options(curwin);
3531 check_options();
3532
3533 /* Must be before option_expand(), because that one needs vim_isIDc() */
3534 didset_options();
3535
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003536#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003537 /* Use the current chartab for the generic chartab. This is not in
3538 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003539 init_spell_chartab();
3540#endif
3541
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 /*
3543 * Expand environment variables and things like "~" for the defaults.
3544 * If option_expand() returns non-NULL the variable is expanded. This can
3545 * only happen for non-indirect options.
3546 * Also set the default to the expanded value, so ":set" does not list
3547 * them.
3548 * Don't set the P_ALLOCED flag, because we don't want to free the
3549 * default.
3550 */
3551 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3552 {
3553 if ((options[opt_idx].flags & P_GETTEXT)
3554 && options[opt_idx].var != NULL)
3555 p = (char_u *)_(*(char **)options[opt_idx].var);
3556 else
3557 p = option_expand(opt_idx, NULL);
3558 if (p != NULL && (p = vim_strsave(p)) != NULL)
3559 {
3560 *(char_u **)options[opt_idx].var = p;
3561 /* VIMEXP
3562 * Defaults for all expanded options are currently the same for Vi
3563 * and Vim. When this changes, add some code here! Also need to
3564 * split P_DEF_ALLOCED in two.
3565 */
3566 if (options[opt_idx].flags & P_DEF_ALLOCED)
3567 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3568 options[opt_idx].def_val[VI_DEFAULT] = p;
3569 options[opt_idx].flags |= P_DEF_ALLOCED;
3570 }
3571 }
3572
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 save_file_ff(curbuf); /* Buffer is unchanged */
3574
Bram Moolenaar071d4272004-06-13 20:20:40 +00003575#if defined(FEAT_ARABIC)
3576 /* Detect use of mlterm.
3577 * Mlterm is a terminal emulator akin to xterm that has some special
3578 * abilities (bidi namely).
3579 * NOTE: mlterm's author is being asked to 'set' a variable
3580 * instead of an environment variable due to inheritance.
3581 */
3582 if (mch_getenv((char_u *)"MLTERM") != NULL)
3583 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3584#endif
3585
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003586 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587
3588#ifdef FEAT_MBYTE
3589# if defined(WIN3264) && defined(FEAT_GETTEXT)
3590 /*
3591 * If $LANG isn't set, try to get a good value for it. This makes the
3592 * right language be used automatically. Don't do this for English.
3593 */
3594 if (mch_getenv((char_u *)"LANG") == NULL)
3595 {
3596 char buf[20];
3597
3598 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3599 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3600 * only the first two. */
3601 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3602 (LPTSTR)buf, 20);
3603 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3604 {
3605 /* There are a few exceptions (probably more) */
3606 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3607 STRCPY(buf, "zh_TW");
3608 else if (STRNICMP(buf, "chs", 3) == 0
3609 || STRNICMP(buf, "zhc", 3) == 0)
3610 STRCPY(buf, "zh_CN");
3611 else if (STRNICMP(buf, "jp", 2) == 0)
3612 STRCPY(buf, "ja");
3613 else
3614 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003615 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616 }
3617 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003618# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003619# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003620 /* Moved to os_mac_conv.c to avoid dependency problems. */
3621 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003622# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623# endif
3624
3625 /* enc_locale() will try to find the encoding of the current locale. */
3626 p = enc_locale();
3627 if (p != NULL)
3628 {
3629 char_u *save_enc;
3630
3631 /* Try setting 'encoding' and check if the value is valid.
3632 * If not, go back to the default "latin1". */
3633 save_enc = p_enc;
3634 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003635 if (STRCMP(p_enc, "gb18030") == 0)
3636 {
3637 /* We don't support "gb18030", but "cp936" is a good substitute
3638 * for practical purposes, thus use that. It's not an alias to
3639 * still support conversion between gb18030 and utf-8. */
3640 p_enc = vim_strsave((char_u *)"cp936");
3641 vim_free(p);
3642 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643 if (mb_init() == NULL)
3644 {
3645 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003646 if (opt_idx >= 0)
3647 {
3648 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3649 options[opt_idx].flags |= P_DEF_ALLOCED;
3650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651
Bram Moolenaard0573012017-10-28 21:11:06 +02003652#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003653 if (STRCMP(p_enc, "latin1") == 0
3654# ifdef FEAT_MBYTE
3655 || enc_utf8
3656# endif
3657 )
3658 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003659 /* Adjust the default for 'isprint' and 'iskeyword' to match
3660 * latin1. Also set the defaults for when 'nocompatible' is
3661 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003662 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003663 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003664 set_string_option_direct((char_u *)"isk", -1,
3665 ISK_LATIN1, OPT_FREE, SID_NONE);
3666 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003667 if (opt_idx >= 0)
3668 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003669 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003670 if (opt_idx >= 0)
3671 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003672 (void)init_chartab();
3673 }
3674#endif
3675
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676# if defined(WIN3264) && !defined(FEAT_GUI)
3677 /* Win32 console: When GetACP() returns a different value from
3678 * GetConsoleCP() set 'termencoding'. */
3679 if (GetACP() != GetConsoleCP())
3680 {
3681 char buf[50];
3682
3683 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3684 p_tenc = vim_strsave((char_u *)buf);
3685 if (p_tenc != NULL)
3686 {
3687 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003688 if (opt_idx >= 0)
3689 {
3690 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3691 options[opt_idx].flags |= P_DEF_ALLOCED;
3692 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693 convert_setup(&input_conv, p_tenc, p_enc);
3694 convert_setup(&output_conv, p_enc, p_tenc);
3695 }
3696 else
3697 p_tenc = empty_option;
3698 }
3699# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003700# if defined(WIN3264) && defined(FEAT_MBYTE)
3701 /* $HOME may have characters in active code page. */
3702 init_homedir();
3703# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704 }
3705 else
3706 {
3707 vim_free(p_enc);
3708 p_enc = save_enc;
3709 }
3710 }
3711#endif
3712
3713#ifdef FEAT_MULTI_LANG
3714 /* Set the default for 'helplang'. */
3715 set_helplang_default(get_mess_lang());
3716#endif
3717}
3718
3719/*
3720 * Set an option to its default value.
3721 * This does not take care of side effects!
3722 */
3723 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003724set_option_default(
3725 int opt_idx,
3726 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3727 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728{
3729 char_u *varp; /* pointer to variable for current option */
3730 int dvi; /* index in def_val[] */
3731 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003732 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3734
3735 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3736 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003737 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738 {
3739 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3740 if (flags & P_STRING)
3741 {
3742 /* Use set_string_option_direct() for local options to handle
3743 * freeing and allocating the value. */
3744 if (options[opt_idx].indir != PV_NONE)
3745 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003746 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747 else
3748 {
3749 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3750 free_string_option(*(char_u **)(varp));
3751 *(char_u **)varp = options[opt_idx].def_val[dvi];
3752 options[opt_idx].flags &= ~P_ALLOCED;
3753 }
3754 }
3755 else if (flags & P_NUM)
3756 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003757 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 win_comp_scroll(curwin);
3759 else
3760 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003761 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 /* May also set global value for local option. */
3763 if (both)
3764 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3765 *(long *)varp;
3766 }
3767 }
3768 else /* P_BOOL */
3769 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003770 /* the cast to long is required for Manx C, long_i is needed for
3771 * MSVC */
3772 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003773#ifdef UNIX
3774 /* 'modeline' defaults to off for root */
3775 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3776 *(int *)varp = FALSE;
3777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778 /* May also set global value for local option. */
3779 if (both)
3780 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3781 *(int *)varp;
3782 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003783
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003784 /* The default value is not insecure. */
3785 flagsp = insecure_flag(opt_idx, opt_flags);
3786 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 }
3788
3789#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003790 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791#endif
3792}
3793
3794/*
3795 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003796 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 */
3798 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003799set_options_default(
3800 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801{
3802 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003804 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805
3806 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003807 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003808#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003809 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003810 || (TRUE
3811# if defined(FEAT_MBYTE)
3812 && options[i].var != (char_u *)&p_enc
3813# endif
3814# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003815 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003816 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003817# endif
3818 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003819#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003820 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 set_option_default(i, opt_flags, p_cp);
3822
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003826#ifdef FEAT_CINDENT
3827 parse_cino(curbuf);
3828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829}
3830
3831/*
3832 * Set the Vi-default value of a string option.
3833 * Used for 'sh', 'backupskip' and 'term'.
3834 */
3835 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003836set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837{
3838 char_u *p;
3839 int opt_idx;
3840
3841 p = vim_strsave(val);
3842 if (p != NULL) /* we don't want a NULL */
3843 {
3844 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003845 if (opt_idx >= 0)
3846 {
3847 if (options[opt_idx].flags & P_DEF_ALLOCED)
3848 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3849 options[opt_idx].def_val[VI_DEFAULT] = p;
3850 options[opt_idx].flags |= P_DEF_ALLOCED;
3851 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 }
3853}
3854
3855/*
3856 * Set the Vi-default value of a number option.
3857 * Used for 'lines' and 'columns'.
3858 */
3859 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003860set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003862 int opt_idx;
3863
3864 opt_idx = findoption((char_u *)name);
3865 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003866 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867}
3868
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003869#if defined(EXITFREE) || defined(PROTO)
3870/*
3871 * Free all options.
3872 */
3873 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003874free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003875{
3876 int i;
3877
3878 for (i = 0; !istermoption(&options[i]); i++)
3879 {
3880 if (options[i].indir == PV_NONE)
3881 {
3882 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003883 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003884 free_string_option(*(char_u **)options[i].var);
3885 if (options[i].flags & P_DEF_ALLOCED)
3886 free_string_option(options[i].def_val[VI_DEFAULT]);
3887 }
3888 else if (options[i].var != VAR_WIN
3889 && (options[i].flags & P_STRING))
3890 /* buffer-local option: free global value */
3891 free_string_option(*(char_u **)options[i].var);
3892 }
3893}
3894#endif
3895
3896
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897/*
3898 * Initialize the options, part two: After getting Rows and Columns and
3899 * setting 'term'.
3900 */
3901 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003902set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003904 int idx;
3905
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003907 * 'scroll' defaults to half the window height. The stored default is zero,
3908 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003910 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003911 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003912 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 comp_col();
3914
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003915 /*
3916 * 'window' is only for backwards compatibility with Vi.
3917 * Default is Rows - 1.
3918 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003919 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003920 p_window = Rows - 1;
3921 set_number_default("window", Rows - 1);
3922
Bram Moolenaarf740b292006-02-16 22:11:02 +00003923 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003924#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003925 /*
3926 * If 'background' wasn't set by the user, try guessing the value,
3927 * depending on the terminal name. Only need to check for terminals
3928 * with a dark background, that can handle color.
3929 */
3930 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003931 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3932 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003934 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003935 /* don't mark it as set, when starting the GUI it may be
3936 * changed again */
3937 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 }
3939#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003940
3941#ifdef CURSOR_SHAPE
3942 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3943#endif
3944#ifdef FEAT_MOUSESHAPE
3945 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3946#endif
3947#ifdef FEAT_PRINTER
3948 (void)parse_printoptions(); /* parse 'printoptions' default value */
3949#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950}
3951
3952/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003953 * Return "dark" or "light" depending on the kind of terminal.
3954 * This is just guessing! Recognized are:
3955 * "linux" Linux console
3956 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003957 * "cygwin.*" Cygwin shell
3958 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003959 * We also check the COLORFGBG environment variable, which is set by
3960 * rxvt and derivatives. This variable contains either two or three
3961 * values separated by semicolons; we want the last value in either
3962 * case. If this value is 0-6 or 8, our background is dark.
3963 */
3964 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003965term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003966{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003967#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003968 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003969 return (char_u *)"dark";
3970#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003971 char_u *p;
3972
Bram Moolenaarf740b292006-02-16 22:11:02 +00003973 if (STRCMP(T_NAME, "linux") == 0
3974 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003975 || STRNCMP(T_NAME, "cygwin", 6) == 0
3976 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003977 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3978 && (p = vim_strrchr(p, ';')) != NULL
3979 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3980 && p[2] == NUL))
3981 return (char_u *)"dark";
3982 return (char_u *)"light";
3983#endif
3984}
3985
3986/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987 * Initialize the options, part three: After reading the .vimrc
3988 */
3989 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003990set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003992#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993/*
3994 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3995 * This is done after other initializations, where 'shell' might have been
3996 * set, but only if they have not been set before.
3997 */
3998 char_u *p;
3999 int idx_srr;
4000 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004001# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004002 int idx_sp;
4003 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004004# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005
4006 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004007 if (idx_srr < 0)
4008 do_srr = FALSE;
4009 else
4010 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004011# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004013 if (idx_sp < 0)
4014 do_sp = FALSE;
4015 else
4016 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004017# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004018 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 if (p != NULL)
4020 {
4021 /*
4022 * Default for p_sp is "| tee", for p_srr is ">".
4023 * For known shells it is changed here to include stderr.
4024 */
4025 if ( fnamecmp(p, "csh") == 0
4026 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004027# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 || fnamecmp(p, "csh.exe") == 0
4029 || fnamecmp(p, "tcsh.exe") == 0
4030# endif
4031 )
4032 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004033# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034 if (do_sp)
4035 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004036# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004038# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004040# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4042 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 if (do_srr)
4045 {
4046 p_srr = (char_u *)">&";
4047 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4048 }
4049 }
4050 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004051 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 if ( fnamecmp(p, "sh") == 0
4053 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004054 || fnamecmp(p, "mksh") == 0
4055 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004057 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004059 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 || fnamecmp(p, "cmd") == 0
4062 || fnamecmp(p, "sh.exe") == 0
4063 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004064 || fnamecmp(p, "mksh.exe") == 0
4065 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004067 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 || fnamecmp(p, "bash.exe") == 0
4069 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004071 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 if (do_sp)
4075 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004076# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4082 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 if (do_srr)
4085 {
4086 p_srr = (char_u *)">%s 2>&1";
4087 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4088 }
4089 }
4090 vim_free(p);
4091 }
4092#endif
4093
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004094#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004096 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4097 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 * This is done after other initializations, where 'shell' might have been
4099 * set, but only if they have not been set before. Default for p_shcf is
4100 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004101 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004103 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 {
4105 int idx3;
4106
4107 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004108 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 {
4110 p_shcf = (char_u *)"-c";
4111 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4112 }
4113
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 /* Somehow Win32 requires the quotes around the redirection too */
4115 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004116 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 {
4118 p_sxq = (char_u *)"\"";
4119 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004122 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4123 {
4124 int idx3;
4125
4126 /*
4127 * cmd.exe on Windows will strip the first and last double quote given
4128 * on the command line, e.g. most of the time things like:
4129 * cmd /c "my path/to/echo" "my args to echo"
4130 * become:
4131 * my path/to/echo" "my args to echo
4132 * when executed.
4133 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004134 * To avoid this, set shellxquote to surround the command in
4135 * parenthesis. This appears to make most commands work, without
4136 * breaking commands that worked previously, such as
4137 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004138 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004139 idx3 = findoption((char_u *)"sxq");
4140 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4141 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004142 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004143 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4144 }
4145
Bram Moolenaara64ba222012-02-12 23:23:31 +01004146 idx3 = findoption((char_u *)"shcf");
4147 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4148 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004149 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004150 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4151 }
4152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153#endif
4154
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004155 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004156 {
4157 int idx_ffs = findoption((char_u *)"ffs");
4158
4159 /* Apply the first entry of 'fileformats' to the initial buffer. */
4160 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4161 set_fileformat(default_fileformat(), OPT_LOCAL);
4162 }
4163
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164#ifdef FEAT_TITLE
4165 set_title_defaults();
4166#endif
4167}
4168
4169#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4170/*
4171 * When 'helplang' is still at its default value, set it to "lang".
4172 * Only the first two characters of "lang" are used.
4173 */
4174 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004175set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176{
4177 int idx;
4178
4179 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4180 return;
4181 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004182 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 {
4184 if (options[idx].flags & P_ALLOCED)
4185 free_string_option(p_hlg);
4186 p_hlg = vim_strsave(lang);
4187 if (p_hlg == NULL)
4188 p_hlg = empty_option;
4189 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004190 {
4191 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4192 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4193 {
4194 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4195 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4196 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004198 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199 options[idx].flags |= P_ALLOCED;
4200 }
4201}
4202#endif
4203
4204#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004205static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206
4207 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004208gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004209{
4210 if (gui_get_lightness(gui.back_pixel) < 127)
4211 return (char_u *)"dark";
4212 return (char_u *)"light";
4213}
4214
4215/*
4216 * Option initializations that can only be done after opening the GUI window.
4217 */
4218 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004219init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220{
4221 /* Set the 'background' option according to the lightness of the
4222 * background color, unless the user has set it already. */
4223 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4224 {
4225 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4226 highlight_changed();
4227 }
4228}
4229#endif
4230
4231#ifdef FEAT_TITLE
4232/*
4233 * 'title' and 'icon' only default to true if they have not been set or reset
4234 * in .vimrc and we can read the old value.
4235 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4236 * they can be reset. This reduces startup time when using X on a remote
4237 * machine.
4238 */
4239 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004240set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241{
4242 int idx1;
4243 long val;
4244
4245 /*
4246 * If GUI is (going to be) used, we can always set the window title and
4247 * icon name. Saves a bit of time, because the X11 display server does
4248 * not need to be contacted.
4249 */
4250 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004251 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004252 {
4253#ifdef FEAT_GUI
4254 if (gui.starting || gui.in_use)
4255 val = TRUE;
4256 else
4257#endif
4258 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004259 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260 p_title = val;
4261 }
4262 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004263 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004264 {
4265#ifdef FEAT_GUI
4266 if (gui.starting || gui.in_use)
4267 val = TRUE;
4268 else
4269#endif
4270 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004271 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272 p_icon = val;
4273 }
4274}
4275#endif
4276
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004277#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4278 static void
4279trigger_optionsset_string(
4280 int opt_idx,
4281 int opt_flags,
4282 char_u *oldval,
4283 char_u *newval)
4284{
4285 if (oldval != NULL && newval != NULL)
4286 {
4287 char_u buf_type[7];
4288
4289 sprintf((char *)buf_type, "%s",
4290 (opt_flags & OPT_LOCAL) ? "local" : "global");
4291 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4292 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4293 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4294 apply_autocmds(EVENT_OPTIONSET,
4295 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4296 reset_v_option_vars();
4297 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004298}
4299#endif
4300
Bram Moolenaar071d4272004-06-13 20:20:40 +00004301/*
4302 * Parse 'arg' for option settings.
4303 *
4304 * 'arg' may be IObuff, but only when no errors can be present and option
4305 * does not need to be expanded with option_expand().
4306 * "opt_flags":
4307 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004308 * OPT_GLOBAL for ":setglobal"
4309 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004310 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004311 * OPT_WINONLY to only set window-local options
4312 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004313 *
4314 * returns FAIL if an error is detected, OK otherwise
4315 */
4316 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004317do_set(
4318 char_u *arg, /* option string (may be written to!) */
4319 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320{
4321 int opt_idx;
4322 char_u *errmsg;
4323 char_u errbuf[80];
4324 char_u *startarg;
4325 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4326 int nextchar; /* next non-white char after option name */
4327 int afterchar; /* character just after option name */
4328 int len;
4329 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004330 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004331 int key;
4332 long_u flags; /* flags for current option */
4333 char_u *varp = NULL; /* pointer to variable for current option */
4334 int did_show = FALSE; /* already showed one value */
4335 int adding; /* "opt+=arg" */
4336 int prepending; /* "opt^=arg" */
4337 int removing; /* "opt-=arg" */
4338 int cp_val = 0;
4339 char_u key_name[2];
4340
4341 if (*arg == NUL)
4342 {
4343 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004344 did_show = TRUE;
4345 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 }
4347
4348 while (*arg != NUL) /* loop to process all options */
4349 {
4350 errmsg = NULL;
4351 startarg = arg; /* remember for error message */
4352
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004353 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4354 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004355 {
4356 /*
4357 * ":set all" show all options.
4358 * ":set all&" set all options to their default value.
4359 */
4360 arg += 3;
4361 if (*arg == '&')
4362 {
4363 ++arg;
4364 /* Only for :set command set global value of local options. */
4365 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004366 didset_options();
4367 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004368 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004369 }
4370 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004371 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004372 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004373 did_show = TRUE;
4374 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004376 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377 {
4378 showoptions(2, opt_flags);
4379 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004380 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004381 arg += 7;
4382 }
4383 else
4384 {
4385 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004386 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387 {
4388 prefix = 0;
4389 arg += 2;
4390 }
4391 else if (STRNCMP(arg, "inv", 3) == 0)
4392 {
4393 prefix = 2;
4394 arg += 3;
4395 }
4396
4397 /* find end of name */
4398 key = 0;
4399 if (*arg == '<')
4400 {
4401 nextchar = 0;
4402 opt_idx = -1;
4403 /* look out for <t_>;> */
4404 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4405 len = 5;
4406 else
4407 {
4408 len = 1;
4409 while (arg[len] != NUL && arg[len] != '>')
4410 ++len;
4411 }
4412 if (arg[len] != '>')
4413 {
4414 errmsg = e_invarg;
4415 goto skip;
4416 }
4417 arg[len] = NUL; /* put NUL after name */
4418 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4419 opt_idx = findoption(arg + 1);
4420 arg[len++] = '>'; /* restore '>' */
4421 if (opt_idx == -1)
4422 key = find_key_option(arg + 1);
4423 }
4424 else
4425 {
4426 len = 0;
4427 /*
4428 * The two characters after "t_" may not be alphanumeric.
4429 */
4430 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4431 len = 4;
4432 else
4433 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4434 ++len;
4435 nextchar = arg[len];
4436 arg[len] = NUL; /* put NUL after name */
4437 opt_idx = findoption(arg);
4438 arg[len] = nextchar; /* restore nextchar */
4439 if (opt_idx == -1)
4440 key = find_key_option(arg);
4441 }
4442
4443 /* remember character after option name */
4444 afterchar = arg[len];
4445
4446 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004447 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004448 ++len;
4449
4450 adding = FALSE;
4451 prepending = FALSE;
4452 removing = FALSE;
4453 if (arg[len] != NUL && arg[len + 1] == '=')
4454 {
4455 if (arg[len] == '+')
4456 {
4457 adding = TRUE; /* "+=" */
4458 ++len;
4459 }
4460 else if (arg[len] == '^')
4461 {
4462 prepending = TRUE; /* "^=" */
4463 ++len;
4464 }
4465 else if (arg[len] == '-')
4466 {
4467 removing = TRUE; /* "-=" */
4468 ++len;
4469 }
4470 }
4471 nextchar = arg[len];
4472
4473 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4474 {
4475 errmsg = (char_u *)N_("E518: Unknown option");
4476 goto skip;
4477 }
4478
4479 if (opt_idx >= 0)
4480 {
4481 if (options[opt_idx].var == NULL) /* hidden option: skip */
4482 {
4483 /* Only give an error message when requesting the value of
4484 * a hidden option, ignore setting it. */
4485 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4486 && (!(options[opt_idx].flags & P_BOOL)
4487 || nextchar == '?'))
4488 errmsg = (char_u *)N_("E519: Option not supported");
4489 goto skip;
4490 }
4491
4492 flags = options[opt_idx].flags;
4493 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4494 }
4495 else
4496 {
4497 flags = P_STRING;
4498 if (key < 0)
4499 {
4500 key_name[0] = KEY2TERMCAP0(key);
4501 key_name[1] = KEY2TERMCAP1(key);
4502 }
4503 else
4504 {
4505 key_name[0] = KS_KEY;
4506 key_name[1] = (key & 0xff);
4507 }
4508 }
4509
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004510 /* Skip all options that are not window-local (used when showing
4511 * an already loaded buffer in a window). */
4512 if ((opt_flags & OPT_WINONLY)
4513 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4514 goto skip;
4515
Bram Moolenaara3227e22006-03-08 21:32:40 +00004516 /* Skip all options that are window-local (used for :vimgrep). */
4517 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4518 && options[opt_idx].var == VAR_WIN)
4519 goto skip;
4520
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004521 /* Disallow changing some options from modelines. */
4522 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004523 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004524 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004525 {
4526 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4527 goto skip;
4528 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004529#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004530 /* In diff mode some options are overruled. This avoids that
4531 * 'foldmethod' becomes "marker" instead of "diff" and that
4532 * "wrap" gets set. */
4533 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004534 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004535 && (
4536#ifdef FEAT_FOLDING
4537 options[opt_idx].indir == PV_FDM ||
4538#endif
4539 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004540 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004541#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004542 }
4543
4544#ifdef HAVE_SANDBOX
4545 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004546 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004547 {
4548 errmsg = (char_u *)_(e_sandbox);
4549 goto skip;
4550 }
4551#endif
4552
4553 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4554 {
4555 arg += len;
4556 cp_val = p_cp;
4557 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4558 {
4559 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4560 {
4561 cp_val = FALSE;
4562 arg += 3;
4563 }
4564 else /* "opt&vi": set to Vi default */
4565 {
4566 cp_val = TRUE;
4567 arg += 2;
4568 }
4569 }
4570 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004571 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004572 {
4573 errmsg = e_trailing;
4574 goto skip;
4575 }
4576 }
4577
4578 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004579 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4580 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 */
4582 if (nextchar == '?'
4583 || (prefix == 1
4584 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4585 && !(flags & P_BOOL)))
4586 {
4587 /*
4588 * print value
4589 */
4590 if (did_show)
4591 msg_putchar('\n'); /* cursor below last one */
4592 else
4593 {
4594 gotocmdline(TRUE); /* cursor at status line */
4595 did_show = TRUE; /* remember that we did a line */
4596 }
4597 if (opt_idx >= 0)
4598 {
4599 showoneopt(&options[opt_idx], opt_flags);
4600#ifdef FEAT_EVAL
4601 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004602 {
4603 /* Mention where the option was last set. */
4604 if (varp == options[opt_idx].var)
4605 last_set_msg(options[opt_idx].scriptID);
4606 else if ((int)options[opt_idx].indir & PV_WIN)
4607 last_set_msg(curwin->w_p_scriptID[
4608 (int)options[opt_idx].indir & PV_MASK]);
4609 else if ((int)options[opt_idx].indir & PV_BUF)
4610 last_set_msg(curbuf->b_p_scriptID[
4611 (int)options[opt_idx].indir & PV_MASK]);
4612 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613#endif
4614 }
4615 else
4616 {
4617 char_u *p;
4618
4619 p = find_termcode(key_name);
4620 if (p == NULL)
4621 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004622 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 goto skip;
4624 }
4625 else
4626 (void)show_one_termcode(key_name, p, TRUE);
4627 }
4628 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004629 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004630 errmsg = e_trailing;
4631 }
4632 else
4633 {
4634 if (flags & P_BOOL) /* boolean */
4635 {
4636 if (nextchar == '=' || nextchar == ':')
4637 {
4638 errmsg = e_invarg;
4639 goto skip;
4640 }
4641
4642 /*
4643 * ":set opt!": invert
4644 * ":set opt&": reset to default value
4645 * ":set opt<": reset to global value
4646 */
4647 if (nextchar == '!')
4648 value = *(int *)(varp) ^ 1;
4649 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004650 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 ((flags & P_VI_DEF) || cp_val)
4652 ? VI_DEFAULT : VIM_DEFAULT];
4653 else if (nextchar == '<')
4654 {
4655 /* For 'autoread' -1 means to use global value. */
4656 if ((int *)varp == &curbuf->b_p_ar
4657 && opt_flags == OPT_LOCAL)
4658 value = -1;
4659 else
4660 value = *(int *)get_varp_scope(&(options[opt_idx]),
4661 OPT_GLOBAL);
4662 }
4663 else
4664 {
4665 /*
4666 * ":set invopt": invert
4667 * ":set opt" or ":set noopt": set or reset
4668 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004669 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004670 {
4671 errmsg = e_trailing;
4672 goto skip;
4673 }
4674 if (prefix == 2) /* inv */
4675 value = *(int *)(varp) ^ 1;
4676 else
4677 value = prefix;
4678 }
4679
4680 errmsg = set_bool_option(opt_idx, varp, (int)value,
4681 opt_flags);
4682 }
4683 else /* numeric or string */
4684 {
4685 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4686 || prefix != 1)
4687 {
4688 errmsg = e_invarg;
4689 goto skip;
4690 }
4691
4692 if (flags & P_NUM) /* numeric */
4693 {
4694 /*
4695 * Different ways to set a number option:
4696 * & set to default value
4697 * < set to global value
4698 * <xx> accept special key codes for 'wildchar'
4699 * c accept any non-digit for 'wildchar'
4700 * [-]0-9 set number
4701 * other error
4702 */
4703 ++arg;
4704 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004705 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004706 ((flags & P_VI_DEF) || cp_val)
4707 ? VI_DEFAULT : VIM_DEFAULT];
4708 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004709 {
4710 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4711 * use the global value. */
4712 if ((long *)varp == &curbuf->b_p_ul
4713 && opt_flags == OPT_LOCAL)
4714 value = NO_LOCAL_UNDOLEVEL;
4715 else
4716 value = *(long *)get_varp_scope(
4717 &(options[opt_idx]), OPT_GLOBAL);
4718 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 else if (((long *)varp == &p_wc
4720 || (long *)varp == &p_wcm)
4721 && (*arg == '<'
4722 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004723 || (*arg != NUL
4724 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004725 && !VIM_ISDIGIT(*arg))))
4726 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004727 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004728 if (value == 0 && (long *)varp != &p_wcm)
4729 {
4730 errmsg = e_invarg;
4731 goto skip;
4732 }
4733 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004734 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4735 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004736 /* Allow negative (for 'undolevels'), octal and
4737 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004738 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4739 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004740 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004741 {
4742 errmsg = e_invarg;
4743 goto skip;
4744 }
4745 }
4746 else
4747 {
4748 errmsg = (char_u *)N_("E521: Number required after =");
4749 goto skip;
4750 }
4751
4752 if (adding)
4753 value = *(long *)varp + value;
4754 if (prepending)
4755 value = *(long *)varp * value;
4756 if (removing)
4757 value = *(long *)varp - value;
4758 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004759 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 }
4761 else if (opt_idx >= 0) /* string */
4762 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004763 char_u *save_arg = NULL;
4764 char_u *s = NULL;
4765 char_u *oldval = NULL; /* previous value if *varp */
4766 char_u *newval;
4767 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004768#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004769 char_u *saved_origval = NULL;
4770 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004771#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004772 unsigned newlen;
4773 int comma;
4774 int bs;
4775 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004776 was allocated */
4777
4778 /* When using ":set opt=val" for a global option
4779 * with a local value the local value will be
4780 * reset, use the global value here. */
4781 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004782 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004783 varp = options[opt_idx].var;
4784
4785 /* The old value is kept until we are sure that the
4786 * new value is valid. */
4787 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004788
4789 /* When setting the local value of a global
4790 * option, the old value may be the global value. */
4791 if (((int)options[opt_idx].indir & PV_BOTH)
4792 && (opt_flags & OPT_LOCAL))
4793 origval = *(char_u **)get_varp(
4794 &options[opt_idx]);
4795 else
4796 origval = oldval;
4797
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 if (nextchar == '&') /* set to default val */
4799 {
4800 newval = options[opt_idx].def_val[
4801 ((flags & P_VI_DEF) || cp_val)
4802 ? VI_DEFAULT : VIM_DEFAULT];
4803 if ((char_u **)varp == &p_bg)
4804 {
4805 /* guess the value of 'background' */
4806#ifdef FEAT_GUI
4807 if (gui.in_use)
4808 newval = gui_bg_default();
4809 else
4810#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004811 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004812 }
4813
4814 /* expand environment variables and ~ (since the
4815 * default value was already expanded, only
4816 * required when an environment variable was set
4817 * later */
4818 if (newval == NULL)
4819 newval = empty_option;
4820 else
4821 {
4822 s = option_expand(opt_idx, newval);
4823 if (s == NULL)
4824 s = newval;
4825 newval = vim_strsave(s);
4826 }
4827 new_value_alloced = TRUE;
4828 }
4829 else if (nextchar == '<') /* set to global val */
4830 {
4831 newval = vim_strsave(*(char_u **)get_varp_scope(
4832 &(options[opt_idx]), OPT_GLOBAL));
4833 new_value_alloced = TRUE;
4834 }
4835 else
4836 {
4837 ++arg; /* jump to after the '=' or ':' */
4838
4839 /*
4840 * Set 'keywordprg' to ":help" if an empty
4841 * value was passed to :set by the user.
4842 * Misuse errbuf[] for the resulting string.
4843 */
4844 if (varp == (char_u *)&p_kp
4845 && (*arg == NUL || *arg == ' '))
4846 {
4847 STRCPY(errbuf, ":help");
4848 save_arg = arg;
4849 arg = errbuf;
4850 }
4851 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004852 * Convert 'backspace' number to string, for
4853 * adding, prepending and removing string.
4854 */
4855 else if (varp == (char_u *)&p_bs
4856 && VIM_ISDIGIT(**(char_u **)varp))
4857 {
4858 i = getdigits((char_u **)varp);
4859 switch (i)
4860 {
4861 case 0:
4862 *(char_u **)varp = empty_option;
4863 break;
4864 case 1:
4865 *(char_u **)varp = vim_strsave(
4866 (char_u *)"indent,eol");
4867 break;
4868 case 2:
4869 *(char_u **)varp = vim_strsave(
4870 (char_u *)"indent,eol,start");
4871 break;
4872 }
4873 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004874 if (origval == oldval)
4875 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004876 oldval = *(char_u **)varp;
4877 }
4878 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004879 * Convert 'whichwrap' number to string, for
4880 * backwards compatibility with Vim 3.0.
4881 * Misuse errbuf[] for the resulting string.
4882 */
4883 else if (varp == (char_u *)&p_ww
4884 && VIM_ISDIGIT(*arg))
4885 {
4886 *errbuf = NUL;
4887 i = getdigits(&arg);
4888 if (i & 1)
4889 STRCAT(errbuf, "b,");
4890 if (i & 2)
4891 STRCAT(errbuf, "s,");
4892 if (i & 4)
4893 STRCAT(errbuf, "h,l,");
4894 if (i & 8)
4895 STRCAT(errbuf, "<,>,");
4896 if (i & 16)
4897 STRCAT(errbuf, "[,],");
4898 if (*errbuf != NUL) /* remove trailing , */
4899 errbuf[STRLEN(errbuf) - 1] = NUL;
4900 save_arg = arg;
4901 arg = errbuf;
4902 }
4903 /*
4904 * Remove '>' before 'dir' and 'bdir', for
4905 * backwards compatibility with version 3.0
4906 */
4907 else if ( *arg == '>'
4908 && (varp == (char_u *)&p_dir
4909 || varp == (char_u *)&p_bdir))
4910 {
4911 ++arg;
4912 }
4913
Bram Moolenaar071d4272004-06-13 20:20:40 +00004914 /*
4915 * Copy the new string into allocated memory.
4916 * Can't use set_string_option_direct(), because
4917 * we need to remove the backslashes.
4918 */
4919 /* get a bit too much */
4920 newlen = (unsigned)STRLEN(arg) + 1;
4921 if (adding || prepending || removing)
4922 newlen += (unsigned)STRLEN(origval) + 1;
4923 newval = alloc(newlen);
4924 if (newval == NULL) /* out of mem, don't change */
4925 break;
4926 s = newval;
4927
4928 /*
4929 * Copy the string, skip over escaped chars.
4930 * For MS-DOS and WIN32 backslashes before normal
4931 * file name characters are not removed, and keep
4932 * backslash at start, for "\\machine\path", but
4933 * do remove it for "\\\\machine\\path".
4934 * The reverse is found in ExpandOldSetting().
4935 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004936 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004937 {
4938 if (*arg == '\\' && arg[1] != NUL
4939#ifdef BACKSLASH_IN_FILENAME
4940 && !((flags & P_EXPAND)
4941 && vim_isfilec(arg[1])
4942 && (arg[1] != '\\'
4943 || (s == newval
4944 && arg[2] != '\\')))
4945#endif
4946 )
4947 ++arg; /* remove backslash */
4948#ifdef FEAT_MBYTE
4949 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004950 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004951 {
4952 /* copy multibyte char */
4953 mch_memmove(s, arg, (size_t)i);
4954 arg += i;
4955 s += i;
4956 }
4957 else
4958#endif
4959 *s++ = *arg++;
4960 }
4961 *s = NUL;
4962
4963 /*
4964 * Expand environment variables and ~.
4965 * Don't do it when adding without inserting a
4966 * comma.
4967 */
4968 if (!(adding || prepending || removing)
4969 || (flags & P_COMMA))
4970 {
4971 s = option_expand(opt_idx, newval);
4972 if (s != NULL)
4973 {
4974 vim_free(newval);
4975 newlen = (unsigned)STRLEN(s) + 1;
4976 if (adding || prepending || removing)
4977 newlen += (unsigned)STRLEN(origval) + 1;
4978 newval = alloc(newlen);
4979 if (newval == NULL)
4980 break;
4981 STRCPY(newval, s);
4982 }
4983 }
4984
4985 /* locate newval[] in origval[] when removing it
4986 * and when adding to avoid duplicates */
4987 i = 0; /* init for GCC */
4988 if (removing || (flags & P_NODUP))
4989 {
4990 i = (int)STRLEN(newval);
4991 bs = 0;
4992 for (s = origval; *s; ++s)
4993 {
4994 if ((!(flags & P_COMMA)
4995 || s == origval
4996 || (s[-1] == ',' && !(bs & 1)))
4997 && STRNCMP(s, newval, i) == 0
4998 && (!(flags & P_COMMA)
4999 || s[i] == ','
5000 || s[i] == NUL))
5001 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005002 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005003 * even number of backslashes or a single
5004 * backslash preceded by a comma before it
5005 * is recognized as a separator */
5006 if ((s > origval + 1
5007 && s[-1] == '\\'
5008 && s[-2] != ',')
5009 || (s == origval + 1
5010 && s[-1] == '\\'))
5011
Bram Moolenaar071d4272004-06-13 20:20:40 +00005012 ++bs;
5013 else
5014 bs = 0;
5015 }
5016
5017 /* do not add if already there */
5018 if ((adding || prepending) && *s)
5019 {
5020 prepending = FALSE;
5021 adding = FALSE;
5022 STRCPY(newval, origval);
5023 }
5024 }
5025
5026 /* concatenate the two strings; add a ',' if
5027 * needed */
5028 if (adding || prepending)
5029 {
5030 comma = ((flags & P_COMMA) && *origval != NUL
5031 && *newval != NUL);
5032 if (adding)
5033 {
5034 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005035 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005036 if (comma && i > 1
5037 && (flags & P_ONECOMMA) == P_ONECOMMA
5038 && origval[i - 1] == ','
5039 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005040 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005041 mch_memmove(newval + i + comma, newval,
5042 STRLEN(newval) + 1);
5043 mch_memmove(newval, origval, (size_t)i);
5044 }
5045 else
5046 {
5047 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005048 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005049 }
5050 if (comma)
5051 newval[i] = ',';
5052 }
5053
5054 /* Remove newval[] from origval[]. (Note: "i" has
5055 * been set above and is used here). */
5056 if (removing)
5057 {
5058 STRCPY(newval, origval);
5059 if (*s)
5060 {
5061 /* may need to remove a comma */
5062 if (flags & P_COMMA)
5063 {
5064 if (s == origval)
5065 {
5066 /* include comma after string */
5067 if (s[i] == ',')
5068 ++i;
5069 }
5070 else
5071 {
5072 /* include comma before string */
5073 --s;
5074 ++i;
5075 }
5076 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005077 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005078 }
5079 }
5080
5081 if (flags & P_FLAGLIST)
5082 {
5083 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005084 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005085 {
5086 /* if options have P_FLAGLIST and
5087 * P_ONECOMMA such as 'whichwrap' */
5088 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005089 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005090 if (*s != ',' && *(s + 1) == ','
5091 && vim_strchr(s + 2, *s) != NULL)
5092 {
5093 /* Remove the duplicated value and
5094 * the next comma. */
5095 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005096 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005097 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005098 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005099 else
5100 {
5101 if ((!(flags & P_COMMA) || *s != ',')
5102 && vim_strchr(s + 1, *s) != NULL)
5103 {
5104 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005105 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005106 }
5107 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005108 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005109 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005110 }
5111
5112 if (save_arg != NULL) /* number for 'whichwrap' */
5113 arg = save_arg;
5114 new_value_alloced = TRUE;
5115 }
5116
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005117 /*
5118 * Set the new value.
5119 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 *(char_u **)(varp) = newval;
5121
Bram Moolenaar53744302015-07-17 17:38:22 +02005122#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005123 if (!starting
5124# ifdef FEAT_CRYPT
5125 && options[opt_idx].indir != PV_KEY
5126# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005127 && origval != NULL && newval != NULL)
5128 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005129 /* origval may be freed by
5130 * did_set_string_option(), make a copy. */
5131 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005132 /* newval (and varp) may become invalid if the
5133 * buffer is closed by autocommands. */
5134 saved_newval = vim_strsave(newval);
5135 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005136#endif
5137
Bram Moolenaar071d4272004-06-13 20:20:40 +00005138 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005139 * ":set" on local options. Note: when setting 'syntax'
5140 * or 'filetype' autocommands may be triggered that can
5141 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005142 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5143 new_value_alloced, oldval, errbuf, opt_flags);
5144
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005145#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5146 if (errmsg == NULL)
5147 trigger_optionsset_string(opt_idx, opt_flags,
5148 saved_origval, saved_newval);
5149 vim_free(saved_origval);
5150 vim_free(saved_newval);
5151#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152 /* If error detected, print the error message. */
5153 if (errmsg != NULL)
5154 goto skip;
5155 }
5156 else /* key code option */
5157 {
5158 char_u *p;
5159
5160 if (nextchar == '&')
5161 {
5162 if (add_termcap_entry(key_name, TRUE) == FAIL)
5163 errmsg = (char_u *)N_("E522: Not found in termcap");
5164 }
5165 else
5166 {
5167 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005168 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005169 if (*p == '\\' && p[1] != NUL)
5170 ++p;
5171 nextchar = *p;
5172 *p = NUL;
5173 add_termcode(key_name, arg, FALSE);
5174 *p = nextchar;
5175 }
5176 if (full_screen)
5177 ttest(FALSE);
5178 redraw_all_later(CLEAR);
5179 }
5180 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005181
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005183 did_set_option(opt_idx, opt_flags,
5184 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 }
5186
5187skip:
5188 /*
5189 * Advance to next argument.
5190 * - skip until a blank found, taking care of backslashes
5191 * - skip blanks
5192 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5193 */
5194 for (i = 0; i < 2 ; ++i)
5195 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005196 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005197 if (*arg++ == '\\' && *arg != NUL)
5198 ++arg;
5199 arg = skipwhite(arg);
5200 if (*arg != '=')
5201 break;
5202 }
5203 }
5204
5205 if (errmsg != NULL)
5206 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005207 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005208 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005209 if (i + (arg - startarg) < IOSIZE)
5210 {
5211 /* append the argument with the error */
5212 STRCAT(IObuff, ": ");
5213 mch_memmove(IObuff + i, startarg, (arg - startarg));
5214 IObuff[i + (arg - startarg)] = NUL;
5215 }
5216 /* make sure all characters are printable */
5217 trans_characters(IObuff, IOSIZE);
5218
5219 ++no_wait_return; /* wait_return done later */
5220 emsg(IObuff); /* show error highlighted */
5221 --no_wait_return;
5222
5223 return FAIL;
5224 }
5225
5226 arg = skipwhite(arg);
5227 }
5228
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005229theend:
5230 if (silent_mode && did_show)
5231 {
5232 /* After displaying option values in silent mode. */
5233 silent_mode = FALSE;
5234 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5235 msg_putchar('\n');
5236 cursor_on(); /* msg_start() switches it off */
5237 out_flush();
5238 silent_mode = TRUE;
5239 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5240 }
5241
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 return OK;
5243}
5244
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005245/*
5246 * Call this when an option has been given a new value through a user command.
5247 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5248 */
5249 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005250did_set_option(
5251 int opt_idx,
5252 int opt_flags, /* possibly with OPT_MODELINE */
5253 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005254{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005255 long_u *p;
5256
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005257 options[opt_idx].flags |= P_WAS_SET;
5258
5259 /* When an option is set in the sandbox, from a modeline or in secure mode
5260 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005261 * flag. */
5262 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005263 if (secure
5264#ifdef HAVE_SANDBOX
5265 || sandbox != 0
5266#endif
5267 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005268 *p = *p | P_INSECURE;
5269 else if (new_value)
5270 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005271}
5272
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005274illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275{
5276 if (errbuf == NULL)
5277 return (char_u *)"";
5278 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005279 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005280 return errbuf;
5281}
5282
5283/*
5284 * Convert a key name or string into a key value.
5285 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005286 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005287 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005288 int
5289string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290{
5291 if (*arg == '<')
5292 return find_key_option(arg + 1);
5293 if (*arg == '^')
5294 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005295 if (multi_byte)
5296 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005297 return *arg;
5298}
5299
5300#ifdef FEAT_CMDWIN
5301/*
5302 * Check value of 'cedit' and set cedit_key.
5303 * Returns NULL if value is OK, error message otherwise.
5304 */
5305 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005306check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307{
5308 int n;
5309
5310 if (*p_cedit == NUL)
5311 cedit_key = -1;
5312 else
5313 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005314 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315 if (vim_isprintc(n))
5316 return e_invarg;
5317 cedit_key = n;
5318 }
5319 return NULL;
5320}
5321#endif
5322
5323#ifdef FEAT_TITLE
5324/*
5325 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5326 * maketitle() to create and display it.
5327 * When switching the title or icon off, call mch_restore_title() to get
5328 * the old value back.
5329 */
5330 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005331did_set_title(
5332 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333{
5334 if (starting != NO_SCREEN
5335#ifdef FEAT_GUI
5336 && !gui.starting
5337#endif
5338 )
5339 {
5340 maketitle();
5341 if (icon)
5342 {
5343 if (!p_icon)
5344 mch_restore_title(2);
5345 }
5346 else
5347 {
5348 if (!p_title)
5349 mch_restore_title(1);
5350 }
5351 }
5352}
5353#endif
5354
5355/*
5356 * set_options_bin - called when 'bin' changes value.
5357 */
5358 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005359set_options_bin(
5360 int oldval,
5361 int newval,
5362 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363{
5364 /*
5365 * The option values that are changed when 'bin' changes are
5366 * copied when 'bin is set and restored when 'bin' is reset.
5367 */
5368 if (newval)
5369 {
5370 if (!oldval) /* switched on */
5371 {
5372 if (!(opt_flags & OPT_GLOBAL))
5373 {
5374 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5375 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5376 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5377 curbuf->b_p_et_nobin = curbuf->b_p_et;
5378 }
5379 if (!(opt_flags & OPT_LOCAL))
5380 {
5381 p_tw_nobin = p_tw;
5382 p_wm_nobin = p_wm;
5383 p_ml_nobin = p_ml;
5384 p_et_nobin = p_et;
5385 }
5386 }
5387
5388 if (!(opt_flags & OPT_GLOBAL))
5389 {
5390 curbuf->b_p_tw = 0; /* no automatic line wrap */
5391 curbuf->b_p_wm = 0; /* no automatic line wrap */
5392 curbuf->b_p_ml = 0; /* no modelines */
5393 curbuf->b_p_et = 0; /* no expandtab */
5394 }
5395 if (!(opt_flags & OPT_LOCAL))
5396 {
5397 p_tw = 0;
5398 p_wm = 0;
5399 p_ml = FALSE;
5400 p_et = FALSE;
5401 p_bin = TRUE; /* needed when called for the "-b" argument */
5402 }
5403 }
5404 else if (oldval) /* switched off */
5405 {
5406 if (!(opt_flags & OPT_GLOBAL))
5407 {
5408 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5409 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5410 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5411 curbuf->b_p_et = curbuf->b_p_et_nobin;
5412 }
5413 if (!(opt_flags & OPT_LOCAL))
5414 {
5415 p_tw = p_tw_nobin;
5416 p_wm = p_wm_nobin;
5417 p_ml = p_ml_nobin;
5418 p_et = p_et_nobin;
5419 }
5420 }
5421}
5422
5423#ifdef FEAT_VIMINFO
5424/*
5425 * Find the parameter represented by the given character (eg ', :, ", or /),
5426 * and return its associated value in the 'viminfo' string.
5427 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005428 * If the parameter is not specified in the string or there is no following
5429 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005430 */
5431 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005432get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433{
5434 char_u *p;
5435
5436 p = find_viminfo_parameter(type);
5437 if (p != NULL && VIM_ISDIGIT(*p))
5438 return atoi((char *)p);
5439 return -1;
5440}
5441
5442/*
5443 * Find the parameter represented by the given character (eg ''', ':', '"', or
5444 * '/') in the 'viminfo' option and return a pointer to the string after it.
5445 * Return NULL if the parameter is not specified in the string.
5446 */
5447 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005448find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005449{
5450 char_u *p;
5451
5452 for (p = p_viminfo; *p; ++p)
5453 {
5454 if (*p == type)
5455 return p + 1;
5456 if (*p == 'n') /* 'n' is always the last one */
5457 break;
5458 p = vim_strchr(p, ','); /* skip until next ',' */
5459 if (p == NULL) /* hit the end without finding parameter */
5460 break;
5461 }
5462 return NULL;
5463}
5464#endif
5465
5466/*
5467 * Expand environment variables for some string options.
5468 * These string options cannot be indirect!
5469 * If "val" is NULL expand the current value of the option.
5470 * Return pointer to NameBuff, or NULL when not expanded.
5471 */
5472 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005473option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474{
5475 /* if option doesn't need expansion nothing to do */
5476 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5477 return NULL;
5478
5479 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5480 * expand_env() would truncate the string. */
5481 if (val != NULL && STRLEN(val) > MAXPATHL)
5482 return NULL;
5483
5484 if (val == NULL)
5485 val = *(char_u **)options[opt_idx].var;
5486
5487 /*
5488 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5489 * Escape spaces when expanding 'tags', they are used to separate file
5490 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005491 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492 */
5493 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005494 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005495#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005496 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5497#endif
5498 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5500 return NULL;
5501
5502 return NameBuff;
5503}
5504
5505/*
5506 * After setting various option values: recompute variables that depend on
5507 * option values.
5508 */
5509 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005510didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511{
5512 /* initialize the table for 'iskeyword' et.al. */
5513 (void)init_chartab();
5514
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005515#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005517#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005519 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520#ifdef FEAT_SESSION
5521 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5522 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5523#endif
5524#ifdef FEAT_FOLDING
5525 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5526#endif
5527 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005528 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529#ifdef FEAT_VIRTUALEDIT
5530 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5531#endif
5532#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5533 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5534#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005535#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005536 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005537 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005538 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005539 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5542 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5543#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005544#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5546#endif
5547#ifdef FEAT_CMDWIN
5548 /* set cedit_key */
5549 (void)check_cedit();
5550#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005551#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005552 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005553#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005554#ifdef FEAT_LINEBREAK
5555 /* initialize the table for 'breakat'. */
5556 fill_breakat_flags();
5557#endif
5558
5559}
5560
5561/*
5562 * More side effects of setting options.
5563 */
5564 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005565didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005566{
5567 /* Initialize the highlight_attr[] table. */
5568 (void)highlight_changed();
5569
5570 /* Parse default for 'wildmode' */
5571 check_opt_wim();
5572
5573 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005574 /* Parse default for 'fillchars'. */
5575 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005576
5577#ifdef FEAT_CLIPBOARD
5578 /* Parse default for 'clipboard' */
5579 (void)check_clipboard_option();
5580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581}
5582
5583/*
5584 * Check for string options that are NULL (normally only termcap options).
5585 */
5586 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005587check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588{
5589 int opt_idx;
5590
5591 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5592 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5593 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5594}
5595
5596/*
5597 * Check string options in a buffer for NULL value.
5598 */
5599 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005600check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005601{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005602 check_string_option(&buf->b_p_bh);
5603 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604#ifdef FEAT_MBYTE
5605 check_string_option(&buf->b_p_fenc);
5606#endif
5607 check_string_option(&buf->b_p_ff);
5608#ifdef FEAT_FIND_ID
5609 check_string_option(&buf->b_p_def);
5610 check_string_option(&buf->b_p_inc);
5611# ifdef FEAT_EVAL
5612 check_string_option(&buf->b_p_inex);
5613# endif
5614#endif
5615#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5616 check_string_option(&buf->b_p_inde);
5617 check_string_option(&buf->b_p_indk);
5618#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005619#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5620 check_string_option(&buf->b_p_bexpr);
5621#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005622#if defined(FEAT_CRYPT)
5623 check_string_option(&buf->b_p_cm);
5624#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005625 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005626#if defined(FEAT_EVAL)
5627 check_string_option(&buf->b_p_fex);
5628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005629#ifdef FEAT_CRYPT
5630 check_string_option(&buf->b_p_key);
5631#endif
5632 check_string_option(&buf->b_p_kp);
5633 check_string_option(&buf->b_p_mps);
5634 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005635 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636 check_string_option(&buf->b_p_isk);
5637#ifdef FEAT_COMMENTS
5638 check_string_option(&buf->b_p_com);
5639#endif
5640#ifdef FEAT_FOLDING
5641 check_string_option(&buf->b_p_cms);
5642#endif
5643 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005644#ifdef FEAT_TEXTOBJ
5645 check_string_option(&buf->b_p_qe);
5646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005647#ifdef FEAT_SYN_HL
5648 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005649 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005650#endif
5651#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005652 check_string_option(&buf->b_s.b_p_spc);
5653 check_string_option(&buf->b_s.b_p_spf);
5654 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655#endif
5656#ifdef FEAT_SEARCHPATH
5657 check_string_option(&buf->b_p_sua);
5658#endif
5659#ifdef FEAT_CINDENT
5660 check_string_option(&buf->b_p_cink);
5661 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005662 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663#endif
5664#ifdef FEAT_AUTOCMD
5665 check_string_option(&buf->b_p_ft);
5666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5668 check_string_option(&buf->b_p_cinw);
5669#endif
5670#ifdef FEAT_INS_EXPAND
5671 check_string_option(&buf->b_p_cpt);
5672#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005673#ifdef FEAT_COMPL_FUNC
5674 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005675 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677#ifdef FEAT_KEYMAP
5678 check_string_option(&buf->b_p_keymap);
5679#endif
5680#ifdef FEAT_QUICKFIX
5681 check_string_option(&buf->b_p_gp);
5682 check_string_option(&buf->b_p_mp);
5683 check_string_option(&buf->b_p_efm);
5684#endif
5685 check_string_option(&buf->b_p_ep);
5686 check_string_option(&buf->b_p_path);
5687 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005688 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689#ifdef FEAT_INS_EXPAND
5690 check_string_option(&buf->b_p_dict);
5691 check_string_option(&buf->b_p_tsr);
5692#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005693#ifdef FEAT_LISP
5694 check_string_option(&buf->b_p_lw);
5695#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005696 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005697#ifdef FEAT_MBYTE
5698 check_string_option(&buf->b_p_menc);
5699#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700}
5701
5702/*
5703 * Free the string allocated for an option.
5704 * Checks for the string being empty_option. This may happen if we're out of
5705 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5706 * check_options().
5707 * Does NOT check for P_ALLOCED flag!
5708 */
5709 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005710free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711{
5712 if (p != empty_option)
5713 vim_free(p);
5714}
5715
5716 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005717clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005718{
5719 if (*pp != empty_option)
5720 vim_free(*pp);
5721 *pp = empty_option;
5722}
5723
5724 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005725check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726{
5727 if (*pp == NULL)
5728 *pp = empty_option;
5729}
5730
5731/*
5732 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5733 */
5734 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005735set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736{
5737 int opt_idx;
5738
5739 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5740 if (options[opt_idx].var == (char_u *)p)
5741 {
5742 options[opt_idx].flags |= P_ALLOCED;
5743 return;
5744 }
5745 return; /* cannot happen: didn't find it! */
5746}
5747
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005748#if defined(FEAT_EVAL) || defined(PROTO)
5749/*
5750 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5751 * Return FALSE when it wasn't.
5752 * Return -1 for an unknown option.
5753 */
5754 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005755was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005756{
5757 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005758 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005759
5760 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005761 {
5762 flagp = insecure_flag(idx, opt_flags);
5763 return (*flagp & P_INSECURE) != 0;
5764 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005765 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005766 return -1;
5767}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005768
5769/*
5770 * Get a pointer to the flags used for the P_INSECURE flag of option
5771 * "opt_idx". For some local options a local flags field is used.
5772 */
5773 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005774insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005775{
5776 if (opt_flags & OPT_LOCAL)
5777 switch ((int)options[opt_idx].indir)
5778 {
5779#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005780 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005781#endif
5782#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005783# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005784 case PV_FDE: return &curwin->w_p_fde_flags;
5785 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005786# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005787# ifdef FEAT_BEVAL
5788 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5789# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005790# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005791 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005792# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005793 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005794# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005795 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005796# endif
5797#endif
5798 }
5799
5800 /* Nothing special, return global flags field. */
5801 return &options[opt_idx].flags;
5802}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005803#endif
5804
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005805#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005806static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005807
5808/*
5809 * Redraw the window title and/or tab page text later.
5810 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005811static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005812{
5813 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005814 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005815}
5816#endif
5817
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818/*
5819 * Set a string option to a new value (without checking the effect).
5820 * The string is copied into allocated memory.
5821 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005822 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005823 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005824 */
5825 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005826set_string_option_direct(
5827 char_u *name,
5828 int opt_idx,
5829 char_u *val,
5830 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5831 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005832{
5833 char_u *s;
5834 char_u **varp;
5835 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005836 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837
Bram Moolenaar89d40322006-08-29 15:30:07 +00005838 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005839 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005840 idx = findoption(name);
5841 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005842 {
5843 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005844 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 }
5848
Bram Moolenaar89d40322006-08-29 15:30:07 +00005849 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005850 return;
5851
5852 s = vim_strsave(val);
5853 if (s != NULL)
5854 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005855 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005857 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858 free_string_option(*varp);
5859 *varp = s;
5860
5861 /* For buffer/window local option may also set the global value. */
5862 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005863 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864
Bram Moolenaar89d40322006-08-29 15:30:07 +00005865 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866
5867 /* When setting both values of a global option with a local value,
5868 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005869 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870 {
5871 free_string_option(*varp);
5872 *varp = empty_option;
5873 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005874# ifdef FEAT_EVAL
5875 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005877 set_sid == 0 ? current_SID : set_sid);
5878# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 }
5880}
5881
5882/*
5883 * Set global value for string option when it's a local option.
5884 */
5885 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005886set_string_option_global(
5887 int opt_idx, /* option index */
5888 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889{
5890 char_u **p, *s;
5891
5892 /* the global value is always allocated */
5893 if (options[opt_idx].var == VAR_WIN)
5894 p = (char_u **)GLOBAL_WO(varp);
5895 else
5896 p = (char_u **)options[opt_idx].var;
5897 if (options[opt_idx].indir != PV_NONE
5898 && p != varp
5899 && (s = vim_strsave(*varp)) != NULL)
5900 {
5901 free_string_option(*p);
5902 *p = s;
5903 }
5904}
5905
5906/*
5907 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005908 *
5909 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005911 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005912set_string_option(
5913 int opt_idx,
5914 char_u *value,
5915 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916{
5917 char_u *s;
5918 char_u **varp;
5919 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005920#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5921 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005922 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005923#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005924 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925
5926 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005927 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005928
5929 s = vim_strsave(value);
5930 if (s != NULL)
5931 {
5932 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5933 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005934 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935 ? OPT_GLOBAL : OPT_LOCAL)
5936 : opt_flags);
5937 oldval = *varp;
5938 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005939
5940#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005941 if (!starting
5942# ifdef FEAT_CRYPT
5943 && options[opt_idx].indir != PV_KEY
5944# endif
5945 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005946 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005947 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005948 saved_newval = vim_strsave(s);
5949 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005950#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005951 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5952 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005953 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005954
Bram Moolenaar53744302015-07-17 17:38:22 +02005955#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005956 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005957 if (r == NULL)
5958 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005959 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005960 vim_free(saved_oldval);
5961 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005964 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965}
5966
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005967#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005968/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005969 * Return TRUE if "val" is a valid 'filetype' name.
5970 * Also used for 'syntax' and 'keymap'.
5971 */
5972 static int
5973valid_filetype(char_u *val)
5974{
5975 char_u *s;
5976
5977 for (s = val; *s != NUL; ++s)
5978 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5979 return FALSE;
5980 return TRUE;
5981}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005982#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005983
5984/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005985 * Handle string options that need some action to perform when changed.
5986 * Returns NULL for success, or an error message for an error.
5987 */
5988 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005989did_set_string_option(
5990 int opt_idx, /* index in options[] table */
5991 char_u **varp, /* pointer to the option variable */
5992 int new_value_alloced, /* new value was allocated */
5993 char_u *oldval, /* previous value of the option */
5994 char_u *errbuf, /* buffer for errors, or NULL */
5995 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005996{
5997 char_u *errmsg = NULL;
5998 char_u *s, *p;
5999 int did_chartab = FALSE;
6000 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006001 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006002#ifdef FEAT_GUI
6003 /* set when changing an option that only requires a redraw in the GUI */
6004 int redraw_gui_only = FALSE;
6005#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006006#ifdef FEAT_AUTOCMD
6007 int ft_changed = FALSE;
6008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009
6010 /* Get the global option to compare with, otherwise we would have to check
6011 * two values for all local options. */
6012 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6013
6014 /* Disallow changing some options from secure mode */
6015 if ((secure
6016#ifdef HAVE_SANDBOX
6017 || sandbox != 0
6018#endif
6019 ) && (options[opt_idx].flags & P_SECURE))
6020 {
6021 errmsg = e_secure;
6022 }
6023
Bram Moolenaar7554da42016-11-25 22:04:13 +01006024 /* Check for a "normal" directory or file name in some options. Disallow a
6025 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006026 * are often illegal in a file name. Be more permissive if "secure" is off.
6027 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006028 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006029 && vim_strpbrk(*varp, (char_u *)(secure
6030 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006031 || ((options[opt_idx].flags & P_NDNAME)
6032 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006033 {
6034 errmsg = e_invarg;
6035 }
6036
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 /* 'term' */
6038 else if (varp == &T_NAME)
6039 {
6040 if (T_NAME[0] == NUL)
6041 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6042#ifdef FEAT_GUI
6043 if (gui.in_use)
6044 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6045 else if (term_is_gui(T_NAME))
6046 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6047#endif
6048 else if (set_termname(T_NAME) == FAIL)
6049 errmsg = (char_u *)N_("E522: Not found in termcap");
6050 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006051 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006052 /* Screen colors may have changed. */
6053 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006054
6055 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6056 * P_ALLOCED flag on 'term'. */
6057 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006058 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006059 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060 }
6061
6062 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006063 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006064 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006065 char_u *bkc = p_bkc;
6066 unsigned int *flags = &bkc_flags;
6067
6068 if (opt_flags & OPT_LOCAL)
6069 {
6070 bkc = curbuf->b_p_bkc;
6071 flags = &curbuf->b_bkc_flags;
6072 }
6073
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006074 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6075 /* make the local value empty: use the global value */
6076 *flags = 0;
6077 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006078 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006079 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6080 errmsg = e_invarg;
6081 if ((((int)*flags & BKC_AUTO) != 0)
6082 + (((int)*flags & BKC_YES) != 0)
6083 + (((int)*flags & BKC_NO) != 0) != 1)
6084 {
6085 /* Must have exactly one of "auto", "yes" and "no". */
6086 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6087 errmsg = e_invarg;
6088 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006089 }
6090 }
6091
6092 /* 'backupext' and 'patchmode' */
6093 else if (varp == &p_bex || varp == &p_pm)
6094 {
6095 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6096 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6097 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6098 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006099#ifdef FEAT_LINEBREAK
6100 /* 'breakindentopt' */
6101 else if (varp == &curwin->w_p_briopt)
6102 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006103 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006104 errmsg = e_invarg;
6105 }
6106#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107
6108 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006109 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006111 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 */
6113 else if ( varp == &p_isi
6114 || varp == &(curbuf->b_p_isk)
6115 || varp == &p_isp
6116 || varp == &p_isf)
6117 {
6118 if (init_chartab() == FAIL)
6119 {
6120 did_chartab = TRUE; /* need to restore it below */
6121 errmsg = e_invarg; /* error in value */
6122 }
6123 }
6124
6125 /* 'helpfile' */
6126 else if (varp == &p_hf)
6127 {
6128 /* May compute new values for $VIM and $VIMRUNTIME */
6129 if (didset_vim)
6130 {
6131 vim_setenv((char_u *)"VIM", (char_u *)"");
6132 didset_vim = FALSE;
6133 }
6134 if (didset_vimruntime)
6135 {
6136 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6137 didset_vimruntime = FALSE;
6138 }
6139 }
6140
Bram Moolenaar1a384422010-07-14 19:53:30 +02006141#ifdef FEAT_SYN_HL
6142 /* 'colorcolumn' */
6143 else if (varp == &curwin->w_p_cc)
6144 errmsg = check_colorcolumn(curwin);
6145#endif
6146
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147#ifdef FEAT_MULTI_LANG
6148 /* 'helplang' */
6149 else if (varp == &p_hlg)
6150 {
6151 /* Check for "", "ab", "ab,cd", etc. */
6152 for (s = p_hlg; *s != NUL; s += 3)
6153 {
6154 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6155 {
6156 errmsg = e_invarg;
6157 break;
6158 }
6159 if (s[2] == NUL)
6160 break;
6161 }
6162 }
6163#endif
6164
6165 /* 'highlight' */
6166 else if (varp == &p_hl)
6167 {
6168 if (highlight_changed() == FAIL)
6169 errmsg = e_invarg; /* invalid flags */
6170 }
6171
6172 /* 'nrformats' */
6173 else if (gvarp == &p_nf)
6174 {
6175 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6176 errmsg = e_invarg;
6177 }
6178
6179#ifdef FEAT_SESSION
6180 /* 'sessionoptions' */
6181 else if (varp == &p_ssop)
6182 {
6183 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6184 errmsg = e_invarg;
6185 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6186 {
6187 /* Don't allow both "sesdir" and "curdir". */
6188 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6189 errmsg = e_invarg;
6190 }
6191 }
6192 /* 'viewoptions' */
6193 else if (varp == &p_vop)
6194 {
6195 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6196 errmsg = e_invarg;
6197 }
6198#endif
6199
6200 /* 'scrollopt' */
6201#ifdef FEAT_SCROLLBIND
6202 else if (varp == &p_sbo)
6203 {
6204 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6205 errmsg = e_invarg;
6206 }
6207#endif
6208
6209 /* 'ambiwidth' */
6210#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006211 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212 {
6213 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6214 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006215 else if (set_chars_option(&p_lcs) != NULL)
6216 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006217 else if (set_chars_option(&p_fcs) != NULL)
6218 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219 }
6220#endif
6221
6222 /* 'background' */
6223 else if (varp == &p_bg)
6224 {
6225 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6226 {
6227#ifdef FEAT_EVAL
6228 int dark = (*p_bg == 'd');
6229#endif
6230
6231 init_highlight(FALSE, FALSE);
6232
6233#ifdef FEAT_EVAL
6234 if (dark != (*p_bg == 'd')
6235 && get_var_value((char_u *)"g:colors_name") != NULL)
6236 {
6237 /* The color scheme must have set 'background' back to another
6238 * value, that's not what we want here. Disable the color
6239 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006240 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006241 free_string_option(p_bg);
6242 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6243 check_string_option(&p_bg);
6244 init_highlight(FALSE, FALSE);
6245 }
6246#endif
6247 }
6248 else
6249 errmsg = e_invarg;
6250 }
6251
6252 /* 'wildmode' */
6253 else if (varp == &p_wim)
6254 {
6255 if (check_opt_wim() == FAIL)
6256 errmsg = e_invarg;
6257 }
6258
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006259#ifdef FEAT_CMDL_COMPL
6260 /* 'wildoptions' */
6261 else if (varp == &p_wop)
6262 {
6263 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6264 errmsg = e_invarg;
6265 }
6266#endif
6267
Bram Moolenaar071d4272004-06-13 20:20:40 +00006268#ifdef FEAT_WAK
6269 /* 'winaltkeys' */
6270 else if (varp == &p_wak)
6271 {
6272 if (*p_wak == NUL
6273 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6274 errmsg = e_invarg;
6275# ifdef FEAT_MENU
6276# ifdef FEAT_GUI_MOTIF
6277 else if (gui.in_use)
6278 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6279# else
6280# ifdef FEAT_GUI_GTK
6281 else if (gui.in_use)
6282 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6283# endif
6284# endif
6285# endif
6286 }
6287#endif
6288
6289#ifdef FEAT_AUTOCMD
6290 /* 'eventignore' */
6291 else if (varp == &p_ei)
6292 {
6293 if (check_ei() == FAIL)
6294 errmsg = e_invarg;
6295 }
6296#endif
6297
6298#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006299 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6300 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6301 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006302 {
6303 if (gvarp == &p_fenc)
6304 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006305 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006306 errmsg = e_modifiable;
6307 else if (vim_strchr(*varp, ',') != NULL)
6308 /* No comma allowed in 'fileencoding'; catches confusing it
6309 * with 'fileencodings'. */
6310 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006311 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006312 {
6313# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006315 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006317 /* Add 'fileencoding' to the swap file. */
6318 ml_setflags(curbuf);
6319 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006320 }
6321 if (errmsg == NULL)
6322 {
6323 /* canonize the value, so that STRCMP() can be used on it */
6324 p = enc_canonize(*varp);
6325 if (p != NULL)
6326 {
6327 vim_free(*varp);
6328 *varp = p;
6329 }
6330 if (varp == &p_enc)
6331 {
6332 errmsg = mb_init();
6333# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006334 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006335# endif
6336 }
6337 }
6338
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006339# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006340 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6341 {
6342 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6343 if (STRCMP(p_tenc, "utf-8") != 0)
6344 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6345 }
6346# endif
6347
6348 if (errmsg == NULL)
6349 {
6350# ifdef FEAT_KEYMAP
6351 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6352 * (with another encoding). */
6353 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6354 (void)keymap_init();
6355# endif
6356
6357 /* When 'termencoding' is not empty and 'encoding' changes or when
6358 * 'termencoding' changes, need to setup for keyboard input and
6359 * display output conversion. */
6360 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6361 {
6362 convert_setup(&input_conv, p_tenc, p_enc);
6363 convert_setup(&output_conv, p_enc, p_tenc);
6364 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006365
6366# if defined(WIN3264) && defined(FEAT_MBYTE)
6367 /* $HOME may have characters in active code page. */
6368 if (varp == &p_enc)
6369 init_homedir();
6370# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371 }
6372 }
6373#endif
6374
6375#if defined(FEAT_POSTSCRIPT)
6376 else if (varp == &p_penc)
6377 {
6378 /* Canonize printencoding if VIM standard one */
6379 p = enc_canonize(p_penc);
6380 if (p != NULL)
6381 {
6382 vim_free(p_penc);
6383 p_penc = p;
6384 }
6385 else
6386 {
6387 /* Ensure lower case and '-' for '_' */
6388 for (s = p_penc; *s != NUL; s++)
6389 {
6390 if (*s == '_')
6391 *s = '-';
6392 else
6393 *s = TOLOWER_ASC(*s);
6394 }
6395 }
6396 }
6397#endif
6398
Bram Moolenaar9372a112005-12-06 19:59:18 +00006399#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400 else if (varp == &p_imak)
6401 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006402 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403 errmsg = e_invarg;
6404 }
6405#endif
6406
6407#ifdef FEAT_KEYMAP
6408 else if (varp == &curbuf->b_p_keymap)
6409 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006410 if (!valid_filetype(*varp))
6411 errmsg = e_invarg;
6412 else
6413 /* load or unload key mapping tables */
6414 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415
Bram Moolenaarfab06232009-03-04 03:13:35 +00006416 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006417 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006418 if (*curbuf->b_p_keymap != NUL)
6419 {
6420 /* Installed a new keymap, switch on using it. */
6421 curbuf->b_p_iminsert = B_IMODE_LMAP;
6422 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6423 curbuf->b_p_imsearch = B_IMODE_LMAP;
6424 }
6425 else
6426 {
6427 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6428 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6429 curbuf->b_p_iminsert = B_IMODE_NONE;
6430 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6431 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6432 }
6433 if ((opt_flags & OPT_LOCAL) == 0)
6434 {
6435 set_iminsert_global();
6436 set_imsearch_global();
6437 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006438 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 }
6440 }
6441#endif
6442
6443 /* 'fileformat' */
6444 else if (gvarp == &p_ff)
6445 {
6446 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6447 errmsg = e_modifiable;
6448 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6449 errmsg = e_invarg;
6450 else
6451 {
6452 /* may also change 'textmode' */
6453 if (get_fileformat(curbuf) == EOL_DOS)
6454 curbuf->b_p_tx = TRUE;
6455 else
6456 curbuf->b_p_tx = FALSE;
6457#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006458 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006460 /* update flag in swap file */
6461 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006462 /* Redraw needed when switching to/from "mac": a CR in the text
6463 * will be displayed differently. */
6464 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6465 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466 }
6467 }
6468
6469 /* 'fileformats' */
6470 else if (varp == &p_ffs)
6471 {
6472 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6473 errmsg = e_invarg;
6474 else
6475 {
6476 /* also change 'textauto' */
6477 if (*p_ffs == NUL)
6478 p_ta = FALSE;
6479 else
6480 p_ta = TRUE;
6481 }
6482 }
6483
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006484#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006485 /* 'cryptkey' */
6486 else if (gvarp == &p_key)
6487 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006488# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489 /* Make sure the ":set" command doesn't show the new value in the
6490 * history. */
6491 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006492# endif
6493 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6494 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006495 ml_set_crypt_key(curbuf, oldval,
6496 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006497 }
6498
6499 else if (gvarp == &p_cm)
6500 {
6501 if (opt_flags & OPT_LOCAL)
6502 p = curbuf->b_p_cm;
6503 else
6504 p = p_cm;
6505 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6506 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006507 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006508 errmsg = e_invarg;
6509 else
6510 {
6511 /* When setting the global value to empty, make it "zip". */
6512 if (*p_cm == NUL)
6513 {
6514 if (new_value_alloced)
6515 free_string_option(p_cm);
6516 p_cm = vim_strsave((char_u *)"zip");
6517 new_value_alloced = TRUE;
6518 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006519 /* When using ":set cm=name" the local value is going to be empty.
6520 * Do that here, otherwise the crypt functions will still use the
6521 * local value. */
6522 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6523 {
6524 free_string_option(curbuf->b_p_cm);
6525 curbuf->b_p_cm = empty_option;
6526 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006527
6528 /* Need to update the swapfile when the effective method changed.
6529 * Set "s" to the effective old value, "p" to the effective new
6530 * method and compare. */
6531 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6532 s = p_cm; /* was previously using the global value */
6533 else
6534 s = oldval;
6535 if (*curbuf->b_p_cm == NUL)
6536 p = p_cm; /* is now using the global value */
6537 else
6538 p = curbuf->b_p_cm;
6539 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006540 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006541
6542 /* If the global value changes need to update the swapfile for all
6543 * buffers using that value. */
6544 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6545 {
6546 buf_T *buf;
6547
Bram Moolenaar29323592016-07-24 22:04:11 +02006548 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006549 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006550 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006551 }
6552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006553 }
6554#endif
6555
6556 /* 'matchpairs' */
6557 else if (gvarp == &p_mps)
6558 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006559#ifdef FEAT_MBYTE
6560 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006561 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006562 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006564 int x2 = -1;
6565 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006566
6567 if (*p != NUL)
6568 p += mb_ptr2len(p);
6569 if (*p != NUL)
6570 x2 = *p++;
6571 if (*p != NUL)
6572 {
6573 x3 = mb_ptr2char(p);
6574 p += mb_ptr2len(p);
6575 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006576 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006577 {
6578 errmsg = e_invarg;
6579 break;
6580 }
6581 if (*p == NUL)
6582 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006583 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006584 }
6585 else
6586#endif
6587 {
6588 /* Check for "x:y,x:y" */
6589 for (p = *varp; *p != NUL; p += 4)
6590 {
6591 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6592 {
6593 errmsg = e_invarg;
6594 break;
6595 }
6596 if (p[3] == NUL)
6597 break;
6598 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006599 }
6600 }
6601
6602#ifdef FEAT_COMMENTS
6603 /* 'comments' */
6604 else if (gvarp == &p_com)
6605 {
6606 for (s = *varp; *s; )
6607 {
6608 while (*s && *s != ':')
6609 {
6610 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6611 && !VIM_ISDIGIT(*s) && *s != '-')
6612 {
6613 errmsg = illegal_char(errbuf, *s);
6614 break;
6615 }
6616 ++s;
6617 }
6618 if (*s++ == NUL)
6619 errmsg = (char_u *)N_("E524: Missing colon");
6620 else if (*s == ',' || *s == NUL)
6621 errmsg = (char_u *)N_("E525: Zero length string");
6622 if (errmsg != NULL)
6623 break;
6624 while (*s && *s != ',')
6625 {
6626 if (*s == '\\' && s[1] != NUL)
6627 ++s;
6628 ++s;
6629 }
6630 s = skip_to_option_part(s);
6631 }
6632 }
6633#endif
6634
6635 /* 'listchars' */
6636 else if (varp == &p_lcs)
6637 {
6638 errmsg = set_chars_option(varp);
6639 }
6640
Bram Moolenaar071d4272004-06-13 20:20:40 +00006641 /* 'fillchars' */
6642 else if (varp == &p_fcs)
6643 {
6644 errmsg = set_chars_option(varp);
6645 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006646
6647#ifdef FEAT_CMDWIN
6648 /* 'cedit' */
6649 else if (varp == &p_cedit)
6650 {
6651 errmsg = check_cedit();
6652 }
6653#endif
6654
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006655 /* 'verbosefile' */
6656 else if (varp == &p_vfile)
6657 {
6658 verbose_stop();
6659 if (*p_vfile != NUL && verbose_open() == FAIL)
6660 errmsg = e_invarg;
6661 }
6662
Bram Moolenaar071d4272004-06-13 20:20:40 +00006663#ifdef FEAT_VIMINFO
6664 /* 'viminfo' */
6665 else if (varp == &p_viminfo)
6666 {
6667 for (s = p_viminfo; *s;)
6668 {
6669 /* Check it's a valid character */
6670 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6671 {
6672 errmsg = illegal_char(errbuf, *s);
6673 break;
6674 }
6675 if (*s == 'n') /* name is always last one */
6676 {
6677 break;
6678 }
6679 else if (*s == 'r') /* skip until next ',' */
6680 {
6681 while (*++s && *s != ',')
6682 ;
6683 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006684 else if (*s == '%')
6685 {
6686 /* optional number */
6687 while (vim_isdigit(*++s))
6688 ;
6689 }
6690 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006691 ++s; /* no extra chars */
6692 else /* must have a number */
6693 {
6694 while (vim_isdigit(*++s))
6695 ;
6696
6697 if (!VIM_ISDIGIT(*(s - 1)))
6698 {
6699 if (errbuf != NULL)
6700 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006701 sprintf((char *)errbuf,
6702 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006703 transchar_byte(*(s - 1)));
6704 errmsg = errbuf;
6705 }
6706 else
6707 errmsg = (char_u *)"";
6708 break;
6709 }
6710 }
6711 if (*s == ',')
6712 ++s;
6713 else if (*s)
6714 {
6715 if (errbuf != NULL)
6716 errmsg = (char_u *)N_("E527: Missing comma");
6717 else
6718 errmsg = (char_u *)"";
6719 break;
6720 }
6721 }
6722 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6723 errmsg = (char_u *)N_("E528: Must specify a ' value");
6724 }
6725#endif /* FEAT_VIMINFO */
6726
6727 /* terminal options */
6728 else if (istermoption(&options[opt_idx]) && full_screen)
6729 {
6730 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6731 if (varp == &T_CCO)
6732 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006733 int colors = atoi((char *)T_CCO);
6734
6735 /* Only reinitialize colors if t_Co value has really changed to
6736 * avoid expensive reload of colorscheme if t_Co is set to the
6737 * same value multiple times. */
6738 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006739 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006740 t_colors = colors;
6741 if (t_colors <= 1)
6742 {
6743 if (new_value_alloced)
6744 vim_free(T_CCO);
6745 T_CCO = empty_option;
6746 }
6747 /* We now have a different color setup, initialize it again. */
6748 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750 }
6751 ttest(FALSE);
6752 if (varp == &T_ME)
6753 {
6754 out_str(T_ME);
6755 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006756#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 /* Since t_me has been set, this probably means that the user
6758 * wants to use this as default colors. Need to reset default
6759 * background/foreground colors. */
6760 mch_set_normal_colors();
6761#endif
6762 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006763 if (varp == &T_BE && termcap_active)
6764 {
6765 if (*T_BE == NUL)
6766 /* When clearing t_BE we assume the user no longer wants
6767 * bracketed paste, thus disable it by writing t_BD. */
6768 out_str(T_BD);
6769 else
6770 out_str(T_BE);
6771 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772 }
6773
6774#ifdef FEAT_LINEBREAK
6775 /* 'showbreak' */
6776 else if (varp == &p_sbr)
6777 {
6778 for (s = p_sbr; *s; )
6779 {
6780 if (ptr2cells(s) != 1)
6781 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006782 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 }
6784 }
6785#endif
6786
6787#ifdef FEAT_GUI
6788 /* 'guifont' */
6789 else if (varp == &p_guifont)
6790 {
6791 if (gui.in_use)
6792 {
6793 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006794# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 /*
6796 * Put up a font dialog and let the user select a new value.
6797 * If this is cancelled go back to the old value but don't
6798 * give an error message.
6799 */
6800 if (STRCMP(p, "*") == 0)
6801 {
6802 p = gui_mch_font_dialog(oldval);
6803
6804 if (new_value_alloced)
6805 free_string_option(p_guifont);
6806
6807 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6808 new_value_alloced = TRUE;
6809 }
6810# endif
6811 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6812 {
6813# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6814 if (STRCMP(p_guifont, "*") == 0)
6815 {
6816 /* Dialog was cancelled: Keep the old value without giving
6817 * an error message. */
6818 if (new_value_alloced)
6819 free_string_option(p_guifont);
6820 p_guifont = vim_strsave(oldval);
6821 new_value_alloced = TRUE;
6822 }
6823 else
6824# endif
6825 errmsg = (char_u *)N_("E596: Invalid font(s)");
6826 }
6827 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006828 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 }
6830# ifdef FEAT_XFONTSET
6831 else if (varp == &p_guifontset)
6832 {
6833 if (STRCMP(p_guifontset, "*") == 0)
6834 errmsg = (char_u *)N_("E597: can't select fontset");
6835 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6836 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006837 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006838 }
6839# endif
6840# ifdef FEAT_MBYTE
6841 else if (varp == &p_guifontwide)
6842 {
6843 if (STRCMP(p_guifontwide, "*") == 0)
6844 errmsg = (char_u *)N_("E533: can't select wide font");
6845 else if (gui_get_wide_font() == FAIL)
6846 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006847 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006848 }
6849# endif
6850#endif
6851
6852#ifdef CURSOR_SHAPE
6853 /* 'guicursor' */
6854 else if (varp == &p_guicursor)
6855 errmsg = parse_shape_opt(SHAPE_CURSOR);
6856#endif
6857
6858#ifdef FEAT_MOUSESHAPE
6859 /* 'mouseshape' */
6860 else if (varp == &p_mouseshape)
6861 {
6862 errmsg = parse_shape_opt(SHAPE_MOUSE);
6863 update_mouseshape(-1);
6864 }
6865#endif
6866
6867#ifdef FEAT_PRINTER
6868 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006869 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006870# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006871 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006872 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006873# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006874#endif
6875
6876#ifdef FEAT_LANGMAP
6877 /* 'langmap' */
6878 else if (varp == &p_langmap)
6879 langmap_set();
6880#endif
6881
6882#ifdef FEAT_LINEBREAK
6883 /* 'breakat' */
6884 else if (varp == &p_breakat)
6885 fill_breakat_flags();
6886#endif
6887
6888#ifdef FEAT_TITLE
6889 /* 'titlestring' and 'iconstring' */
6890 else if (varp == &p_titlestring || varp == &p_iconstring)
6891 {
6892# ifdef FEAT_STL_OPT
6893 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6894
6895 /* NULL => statusline syntax */
6896 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6897 stl_syntax |= flagval;
6898 else
6899 stl_syntax &= ~flagval;
6900# endif
6901 did_set_title(varp == &p_iconstring);
6902
6903 }
6904#endif
6905
6906#ifdef FEAT_GUI
6907 /* 'guioptions' */
6908 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006909 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006911 redraw_gui_only = TRUE;
6912 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006913#endif
6914
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006915#if defined(FEAT_GUI_TABLINE)
6916 /* 'guitablabel' */
6917 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006918 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006919 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006920 redraw_gui_only = TRUE;
6921 }
6922 /* 'guitabtooltip' */
6923 else if (varp == &p_gtt)
6924 {
6925 redraw_gui_only = TRUE;
6926 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006927#endif
6928
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6930 /* 'ttymouse' */
6931 else if (varp == &p_ttym)
6932 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006933 /* Switch the mouse off before changing the escape sequences used for
6934 * that. */
6935 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6937 errmsg = e_invarg;
6938 else
6939 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006940 if (termcap_active)
6941 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006942 }
6943#endif
6944
Bram Moolenaar071d4272004-06-13 20:20:40 +00006945 /* 'selection' */
6946 else if (varp == &p_sel)
6947 {
6948 if (*p_sel == NUL
6949 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6950 errmsg = e_invarg;
6951 }
6952
6953 /* 'selectmode' */
6954 else if (varp == &p_slm)
6955 {
6956 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6957 errmsg = e_invarg;
6958 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006959
6960#ifdef FEAT_BROWSE
6961 /* 'browsedir' */
6962 else if (varp == &p_bsdir)
6963 {
6964 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6965 && !mch_isdir(p_bsdir))
6966 errmsg = e_invarg;
6967 }
6968#endif
6969
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970 /* 'keymodel' */
6971 else if (varp == &p_km)
6972 {
6973 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6974 errmsg = e_invarg;
6975 else
6976 {
6977 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6978 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6979 }
6980 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006981
6982 /* 'mousemodel' */
6983 else if (varp == &p_mousem)
6984 {
6985 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6986 errmsg = e_invarg;
6987#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6988 else if (*p_mousem != *oldval)
6989 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6990 * to create or delete the popup menus. */
6991 gui_motif_update_mousemodel(root_menu);
6992#endif
6993 }
6994
6995 /* 'switchbuf' */
6996 else if (varp == &p_swb)
6997 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006998 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999 errmsg = e_invarg;
7000 }
7001
7002 /* 'debug' */
7003 else if (varp == &p_debug)
7004 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007005 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007006 errmsg = e_invarg;
7007 }
7008
7009 /* 'display' */
7010 else if (varp == &p_dy)
7011 {
7012 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7013 errmsg = e_invarg;
7014 else
7015 (void)init_chartab();
7016
7017 }
7018
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019 /* 'eadirection' */
7020 else if (varp == &p_ead)
7021 {
7022 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7023 errmsg = e_invarg;
7024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007025
7026#ifdef FEAT_CLIPBOARD
7027 /* 'clipboard' */
7028 else if (varp == &p_cb)
7029 errmsg = check_clipboard_option();
7030#endif
7031
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007032#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007033 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7034 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007035 else if (varp == &(curwin->w_s->b_p_spl)
7036 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007037 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007038 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007039 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007040 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007041 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007042 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007043 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007044 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007045 /* 'spellsuggest' */
7046 else if (varp == &p_sps)
7047 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007048 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007049 errmsg = e_invarg;
7050 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007051 /* 'mkspellmem' */
7052 else if (varp == &p_msm)
7053 {
7054 if (spell_check_msm() != OK)
7055 errmsg = e_invarg;
7056 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007057#endif
7058
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059 /* When 'bufhidden' is set, check for valid value. */
7060 else if (gvarp == &p_bh)
7061 {
7062 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7063 errmsg = e_invarg;
7064 }
7065
7066 /* When 'buftype' is set, check for valid value. */
7067 else if (gvarp == &p_bt)
7068 {
7069 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7070 errmsg = e_invarg;
7071 else
7072 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007073 if (curwin->w_status_height)
7074 {
7075 curwin->w_redr_status = TRUE;
7076 redraw_later(VALID);
7077 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007079#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007080 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007081#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007082 }
7083 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007084
7085#ifdef FEAT_STL_OPT
7086 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007087 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007088 {
7089 int wid;
7090
7091 if (varp == &p_ruf) /* reset ru_wid first */
7092 ru_wid = 0;
7093 s = *varp;
7094 if (varp == &p_ruf && *s == '%')
7095 {
7096 /* set ru_wid if 'ruf' starts with "%99(" */
7097 if (*++s == '-') /* ignore a '-' */
7098 s++;
7099 wid = getdigits(&s);
7100 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7101 ru_wid = wid;
7102 else
7103 errmsg = check_stl_option(p_ruf);
7104 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007105 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007106 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007107 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007108 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007109 comp_col();
7110 }
7111#endif
7112
7113#ifdef FEAT_INS_EXPAND
7114 /* check if it is a valid value for 'complete' -- Acevedo */
7115 else if (gvarp == &p_cpt)
7116 {
7117 for (s = *varp; *s;)
7118 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007119 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 s++;
7121 if (!*s)
7122 break;
7123 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7124 {
7125 errmsg = illegal_char(errbuf, *s);
7126 break;
7127 }
7128 if (*++s != NUL && *s != ',' && *s != ' ')
7129 {
7130 if (s[-1] == 'k' || s[-1] == 's')
7131 {
7132 /* skip optional filename after 'k' and 's' */
7133 while (*s && *s != ',' && *s != ' ')
7134 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007135 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007136 ++s;
7137 ++s;
7138 }
7139 }
7140 else
7141 {
7142 if (errbuf != NULL)
7143 {
7144 sprintf((char *)errbuf,
7145 _("E535: Illegal character after <%c>"),
7146 *--s);
7147 errmsg = errbuf;
7148 }
7149 else
7150 errmsg = (char_u *)"";
7151 break;
7152 }
7153 }
7154 }
7155 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007156
7157 /* 'completeopt' */
7158 else if (varp == &p_cot)
7159 {
7160 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7161 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007162 else
7163 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165#endif /* FEAT_INS_EXPAND */
7166
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007167#ifdef FEAT_SIGNS
7168 /* 'signcolumn' */
7169 else if (varp == &curwin->w_p_scl)
7170 {
7171 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7172 errmsg = e_invarg;
7173 }
7174#endif
7175
Bram Moolenaar071d4272004-06-13 20:20:40 +00007176
7177#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007178 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179 else if (varp == &p_toolbar)
7180 {
7181 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7182 &toolbar_flags, TRUE) != OK)
7183 errmsg = e_invarg;
7184 else
7185 {
7186 out_flush();
7187 gui_mch_show_toolbar((toolbar_flags &
7188 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7189 }
7190 }
7191#endif
7192
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007193#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007194 /* 'toolbariconsize': GTK+ 2 only */
7195 else if (varp == &p_tbis)
7196 {
7197 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7198 errmsg = e_invarg;
7199 else
7200 {
7201 out_flush();
7202 gui_mch_show_toolbar((toolbar_flags &
7203 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7204 }
7205 }
7206#endif
7207
7208 /* 'pastetoggle': translate key codes like in a mapping */
7209 else if (varp == &p_pt)
7210 {
7211 if (*p_pt)
7212 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007213 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007214 if (p != NULL)
7215 {
7216 if (new_value_alloced)
7217 free_string_option(p_pt);
7218 p_pt = p;
7219 new_value_alloced = TRUE;
7220 }
7221 }
7222 }
7223
7224 /* 'backspace' */
7225 else if (varp == &p_bs)
7226 {
7227 if (VIM_ISDIGIT(*p_bs))
7228 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007229 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007230 errmsg = e_invarg;
7231 }
7232 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7233 errmsg = e_invarg;
7234 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007235 else if (varp == &p_bo)
7236 {
7237 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7238 errmsg = e_invarg;
7239 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007240
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007241 /* 'tagcase' */
7242 else if (gvarp == &p_tc)
7243 {
7244 unsigned int *flags;
7245
7246 if (opt_flags & OPT_LOCAL)
7247 {
7248 p = curbuf->b_p_tc;
7249 flags = &curbuf->b_tc_flags;
7250 }
7251 else
7252 {
7253 p = p_tc;
7254 flags = &tc_flags;
7255 }
7256
7257 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7258 /* make the local value empty: use the global value */
7259 *flags = 0;
7260 else if (*p == NUL
7261 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7262 errmsg = e_invarg;
7263 }
7264
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007265#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007266 /* 'casemap' */
7267 else if (varp == &p_cmp)
7268 {
7269 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7270 errmsg = e_invarg;
7271 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007273
7274#ifdef FEAT_DIFF
7275 /* 'diffopt' */
7276 else if (varp == &p_dip)
7277 {
7278 if (diffopt_changed() == FAIL)
7279 errmsg = e_invarg;
7280 }
7281#endif
7282
7283#ifdef FEAT_FOLDING
7284 /* 'foldmethod' */
7285 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7286 {
7287 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7288 || *curwin->w_p_fdm == NUL)
7289 errmsg = e_invarg;
7290 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007291 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007292 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007293 if (foldmethodIsDiff(curwin))
7294 newFoldLevel();
7295 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296 }
7297# ifdef FEAT_EVAL
7298 /* 'foldexpr' */
7299 else if (varp == &curwin->w_p_fde)
7300 {
7301 if (foldmethodIsExpr(curwin))
7302 foldUpdateAll(curwin);
7303 }
7304# endif
7305 /* 'foldmarker' */
7306 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7307 {
7308 p = vim_strchr(*varp, ',');
7309 if (p == NULL)
7310 errmsg = (char_u *)N_("E536: comma required");
7311 else if (p == *varp || p[1] == NUL)
7312 errmsg = e_invarg;
7313 else if (foldmethodIsMarker(curwin))
7314 foldUpdateAll(curwin);
7315 }
7316 /* 'commentstring' */
7317 else if (gvarp == &p_cms)
7318 {
7319 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7320 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7321 }
7322 /* 'foldopen' */
7323 else if (varp == &p_fdo)
7324 {
7325 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7326 errmsg = e_invarg;
7327 }
7328 /* 'foldclose' */
7329 else if (varp == &p_fcl)
7330 {
7331 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7332 errmsg = e_invarg;
7333 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007334 /* 'foldignore' */
7335 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7336 {
7337 if (foldmethodIsIndent(curwin))
7338 foldUpdateAll(curwin);
7339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007340#endif
7341
7342#ifdef FEAT_VIRTUALEDIT
7343 /* 'virtualedit' */
7344 else if (varp == &p_ve)
7345 {
7346 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7347 errmsg = e_invarg;
7348 else if (STRCMP(p_ve, oldval) != 0)
7349 {
7350 /* Recompute cursor position in case the new 've' setting
7351 * changes something. */
7352 validate_virtcol();
7353 coladvance(curwin->w_virtcol);
7354 }
7355 }
7356#endif
7357
7358#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7359 else if (varp == &p_csqf)
7360 {
7361 if (p_csqf != NULL)
7362 {
7363 p = p_csqf;
7364 while (*p != NUL)
7365 {
7366 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7367 || p[1] == NUL
7368 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7369 || (p[2] != NUL && p[2] != ','))
7370 {
7371 errmsg = e_invarg;
7372 break;
7373 }
7374 else if (p[2] == NUL)
7375 break;
7376 else
7377 p += 3;
7378 }
7379 }
7380 }
7381#endif
7382
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007383#ifdef FEAT_CINDENT
7384 /* 'cinoptions' */
7385 else if (gvarp == &p_cino)
7386 {
7387 /* TODO: recognize errors */
7388 parse_cino(curbuf);
7389 }
7390#endif
7391
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007392#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007393 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007394 else if (varp == &p_rop && gui.in_use)
7395 {
7396 if (!gui_mch_set_rendering_options(p_rop))
7397 errmsg = e_invarg;
7398 }
7399#endif
7400
Bram Moolenaard0b51382016-11-04 15:23:45 +01007401#ifdef FEAT_AUTOCMD
7402 else if (gvarp == &p_ft)
7403 {
7404 if (!valid_filetype(*varp))
7405 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007406 else
7407 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007408 }
7409#endif
7410
7411#ifdef FEAT_SYN_HL
7412 else if (gvarp == &p_syn)
7413 {
7414 if (!valid_filetype(*varp))
7415 errmsg = e_invarg;
7416 }
7417#endif
7418
Bram Moolenaar825680f2017-07-22 17:04:02 +02007419#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007420 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007421 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007422 {
7423 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7424 errmsg = e_invarg;
7425 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007426 /* 'termsize' */
7427 else if (varp == &curwin->w_p_tms)
7428 {
7429 if (*curwin->w_p_tms != NUL)
7430 {
7431 p = skipdigits(curwin->w_p_tms);
7432 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7433 errmsg = e_invarg;
7434 }
7435 }
7436#endif
7437
Bram Moolenaar071d4272004-06-13 20:20:40 +00007438 /* Options that are a list of flags. */
7439 else
7440 {
7441 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007442 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007444 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007446 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007447 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007448 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007450#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007451 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007452 p = (char_u *)COCU_ALL;
7453#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007454 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007455 {
7456#ifdef FEAT_MOUSE
7457 p = (char_u *)MOUSE_ALL;
7458#else
7459 if (*p_mouse != NUL)
7460 errmsg = (char_u *)N_("E538: No mouse support");
7461#endif
7462 }
7463#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007464 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007465 p = (char_u *)GO_ALL;
7466#endif
7467 if (p != NULL)
7468 {
7469 for (s = *varp; *s; ++s)
7470 if (vim_strchr(p, *s) == NULL)
7471 {
7472 errmsg = illegal_char(errbuf, *s);
7473 break;
7474 }
7475 }
7476 }
7477
7478 /*
7479 * If error detected, restore the previous value.
7480 */
7481 if (errmsg != NULL)
7482 {
7483 if (new_value_alloced)
7484 free_string_option(*varp);
7485 *varp = oldval;
7486 /*
7487 * When resetting some values, need to act on it.
7488 */
7489 if (did_chartab)
7490 (void)init_chartab();
7491 if (varp == &p_hl)
7492 (void)highlight_changed();
7493 }
7494 else
7495 {
7496#ifdef FEAT_EVAL
7497 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007498 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499#endif
7500 /*
7501 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007502 * Use "free_oldval", because recursiveness may change the flags under
7503 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007505 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 free_string_option(oldval);
7507 if (new_value_alloced)
7508 options[opt_idx].flags |= P_ALLOCED;
7509 else
7510 options[opt_idx].flags &= ~P_ALLOCED;
7511
7512 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007513 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 {
7515 /* global option with local value set to use global value; free
7516 * the local value and make it empty */
7517 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7518 free_string_option(*(char_u **)p);
7519 *(char_u **)p = empty_option;
7520 }
7521
7522 /* May set global value for local option. */
7523 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7524 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007525
7526#ifdef FEAT_AUTOCMD
7527 /*
7528 * Trigger the autocommand only after setting the flags.
7529 */
7530# ifdef FEAT_SYN_HL
7531 /* When 'syntax' is set, load the syntax of that name */
7532 if (varp == &(curbuf->b_p_syn))
7533 {
7534 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7535 curbuf->b_fname, TRUE, curbuf);
7536 }
7537# endif
7538 else if (varp == &(curbuf->b_p_ft))
7539 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007540 /* 'filetype' is set, trigger the FileType autocommand.
7541 * Skip this when called from a modeline and the filetype was
7542 * already set to this value. */
7543 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7544 {
7545 did_filetype = TRUE;
7546 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007547 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007548 /* Just in case the old "curbuf" is now invalid. */
7549 if (varp != &(curbuf->b_p_ft))
7550 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007551 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007552 }
7553#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007554#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007555 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007556 {
7557 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007558 char_u *q = curwin->w_s->b_p_spl;
7559
7560 /* Skip the first name if it is "cjk". */
7561 if (STRNCMP(q, "cjk,", 4) == 0)
7562 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007563
7564 /*
7565 * Source the spell/LANG.vim in 'runtimepath'.
7566 * They could set 'spellcapcheck' depending on the language.
7567 * Use the first name in 'spelllang' up to '_region' or
7568 * '.encoding'.
7569 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007570 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007571 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7572 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007573 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007574 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007575 }
7576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 }
7578
7579#ifdef FEAT_MOUSE
7580 if (varp == &p_mouse)
7581 {
7582# ifdef FEAT_MOUSE_TTY
7583 if (*p_mouse == NUL)
7584 mch_setmouse(FALSE); /* switch mouse off */
7585 else
7586# endif
7587 setmouse(); /* in case 'mouse' changed */
7588 }
7589#endif
7590
Bram Moolenaar913077c2012-03-28 19:59:04 +02007591 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007592 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007593 curwin->w_set_curswant = TRUE;
7594
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007595#ifdef FEAT_GUI
7596 /* check redraw when it's not a GUI option or the GUI is active. */
7597 if (!redraw_gui_only || gui.in_use)
7598#endif
7599 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007600
7601 return errmsg;
7602}
7603
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007604#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007605/*
7606 * Simple int comparison function for use with qsort()
7607 */
7608 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007609int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007610{
7611 return *(const int *)a - *(const int *)b;
7612}
7613
7614/*
7615 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7616 * Returns error message, NULL if it's OK.
7617 */
7618 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007619check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007620{
7621 char_u *s;
7622 int col;
7623 int count = 0;
7624 int color_cols[256];
7625 int i;
7626 int j = 0;
7627
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007628 if (wp->w_buffer == NULL)
7629 return NULL; /* buffer was closed */
7630
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007631 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007632 {
7633 if (*s == '-' || *s == '+')
7634 {
7635 /* -N and +N: add to 'textwidth' */
7636 col = (*s == '-') ? -1 : 1;
7637 ++s;
7638 if (!VIM_ISDIGIT(*s))
7639 return e_invarg;
7640 col = col * getdigits(&s);
7641 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007642 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007643 col += wp->w_buffer->b_p_tw;
7644 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007645 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007646 }
7647 else if (VIM_ISDIGIT(*s))
7648 col = getdigits(&s);
7649 else
7650 return e_invarg;
7651 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007652skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007653 if (*s == NUL)
7654 break;
7655 if (*s != ',')
7656 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007657 if (*++s == NUL)
7658 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007659 }
7660
7661 vim_free(wp->w_p_cc_cols);
7662 if (count == 0)
7663 wp->w_p_cc_cols = NULL;
7664 else
7665 {
7666 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7667 if (wp->w_p_cc_cols != NULL)
7668 {
7669 /* sort the columns for faster usage on screen redraw inside
7670 * win_line() */
7671 qsort(color_cols, count, sizeof(int), int_cmp);
7672
7673 for (i = 0; i < count; ++i)
7674 /* skip duplicates */
7675 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7676 wp->w_p_cc_cols[j++] = color_cols[i];
7677 wp->w_p_cc_cols[j] = -1; /* end marker */
7678 }
7679 }
7680
7681 return NULL; /* no error */
7682}
7683#endif
7684
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685/*
7686 * Handle setting 'listchars' or 'fillchars'.
7687 * Returns error message, NULL if it's OK.
7688 */
7689 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007690set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691{
7692 int round, i, len, entries;
7693 char_u *p, *s;
7694 int c1, c2 = 0;
7695 struct charstab
7696 {
7697 int *cp;
7698 char *name;
7699 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007700 static struct charstab filltab[] =
7701 {
7702 {&fill_stl, "stl"},
7703 {&fill_stlnc, "stlnc"},
7704 {&fill_vert, "vert"},
7705 {&fill_fold, "fold"},
7706 {&fill_diff, "diff"},
7707 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708 static struct charstab lcstab[] =
7709 {
7710 {&lcs_eol, "eol"},
7711 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007712 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007714 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715 {&lcs_tab2, "tab"},
7716 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007717#ifdef FEAT_CONCEAL
7718 {&lcs_conceal, "conceal"},
7719#else
7720 {NULL, "conceal"},
7721#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007722 };
7723 struct charstab *tab;
7724
Bram Moolenaar071d4272004-06-13 20:20:40 +00007725 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007726 {
7727 tab = lcstab;
7728 entries = sizeof(lcstab) / sizeof(struct charstab);
7729 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007730 else
7731 {
7732 tab = filltab;
7733 entries = sizeof(filltab) / sizeof(struct charstab);
7734 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735
7736 /* first round: check for valid value, second round: assign values */
7737 for (round = 0; round <= 1; ++round)
7738 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007739 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007740 {
7741 /* After checking that the value is valid: set defaults: space for
7742 * 'fillchars', NUL for 'listchars' */
7743 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007744 if (tab[i].cp != NULL)
7745 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746 if (varp == &p_lcs)
7747 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 else
7749 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 }
7751 p = *varp;
7752 while (*p)
7753 {
7754 for (i = 0; i < entries; ++i)
7755 {
7756 len = (int)STRLEN(tab[i].name);
7757 if (STRNCMP(p, tab[i].name, len) == 0
7758 && p[len] == ':'
7759 && p[len + 1] != NUL)
7760 {
7761 s = p + len + 1;
7762#ifdef FEAT_MBYTE
7763 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007764 if (mb_char2cells(c1) > 1)
7765 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766#else
7767 c1 = *s++;
7768#endif
7769 if (tab[i].cp == &lcs_tab2)
7770 {
7771 if (*s == NUL)
7772 continue;
7773#ifdef FEAT_MBYTE
7774 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007775 if (mb_char2cells(c2) > 1)
7776 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777#else
7778 c2 = *s++;
7779#endif
7780 }
7781 if (*s == ',' || *s == NUL)
7782 {
7783 if (round)
7784 {
7785 if (tab[i].cp == &lcs_tab2)
7786 {
7787 lcs_tab1 = c1;
7788 lcs_tab2 = c2;
7789 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007790 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 *(tab[i].cp) = c1;
7792
7793 }
7794 p = s;
7795 break;
7796 }
7797 }
7798 }
7799
7800 if (i == entries)
7801 return e_invarg;
7802 if (*p == ',')
7803 ++p;
7804 }
7805 }
7806
7807 return NULL; /* no error */
7808}
7809
7810#ifdef FEAT_STL_OPT
7811/*
7812 * Check validity of options with the 'statusline' format.
7813 * Return error message or NULL.
7814 */
7815 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007816check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007817{
7818 int itemcnt = 0;
7819 int groupdepth = 0;
7820 static char_u errbuf[80];
7821
7822 while (*s && itemcnt < STL_MAX_ITEM)
7823 {
7824 /* Check for valid keys after % sequences */
7825 while (*s && *s != '%')
7826 s++;
7827 if (!*s)
7828 break;
7829 s++;
7830 if (*s != '%' && *s != ')')
7831 ++itemcnt;
7832 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7833 {
7834 s++;
7835 continue;
7836 }
7837 if (*s == ')')
7838 {
7839 s++;
7840 if (--groupdepth < 0)
7841 break;
7842 continue;
7843 }
7844 if (*s == '-')
7845 s++;
7846 while (VIM_ISDIGIT(*s))
7847 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007848 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 continue;
7850 if (*s == '.')
7851 {
7852 s++;
7853 while (*s && VIM_ISDIGIT(*s))
7854 s++;
7855 }
7856 if (*s == '(')
7857 {
7858 groupdepth++;
7859 continue;
7860 }
7861 if (vim_strchr(STL_ALL, *s) == NULL)
7862 {
7863 return illegal_char(errbuf, *s);
7864 }
7865 if (*s == '{')
7866 {
7867 s++;
7868 while (*s != '}' && *s)
7869 s++;
7870 if (*s != '}')
7871 return (char_u *)N_("E540: Unclosed expression sequence");
7872 }
7873 }
7874 if (itemcnt >= STL_MAX_ITEM)
7875 return (char_u *)N_("E541: too many items");
7876 if (groupdepth != 0)
7877 return (char_u *)N_("E542: unbalanced groups");
7878 return NULL;
7879}
7880#endif
7881
7882#ifdef FEAT_CLIPBOARD
7883/*
7884 * Extract the items in the 'clipboard' option and set global values.
7885 */
7886 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007887check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007888{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007889 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007890 int new_autoselect_star = FALSE;
7891 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007893 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 regprog_T *new_exclude_prog = NULL;
7895 char_u *errmsg = NULL;
7896 char_u *p;
7897
7898 for (p = p_cb; *p != NUL; )
7899 {
7900 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7901 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007902 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 p += 7;
7904 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007905 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007906 && (p[11] == ',' || p[11] == NUL))
7907 {
7908 new_unnamed |= CLIP_UNNAMED_PLUS;
7909 p += 11;
7910 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007912 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007914 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 p += 10;
7916 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007917 else if (STRNCMP(p, "autoselectplus", 14) == 0
7918 && (p[14] == ',' || p[14] == NUL))
7919 {
7920 new_autoselect_plus = TRUE;
7921 p += 14;
7922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007924 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 {
7926 new_autoselectml = TRUE;
7927 p += 12;
7928 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007929 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7930 {
7931 new_html = TRUE;
7932 p += 4;
7933 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7935 {
7936 p += 8;
7937 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7938 if (new_exclude_prog == NULL)
7939 errmsg = e_invarg;
7940 break;
7941 }
7942 else
7943 {
7944 errmsg = e_invarg;
7945 break;
7946 }
7947 if (*p == ',')
7948 ++p;
7949 }
7950 if (errmsg == NULL)
7951 {
7952 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007953 clip_autoselect_star = new_autoselect_star;
7954 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007956 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007957 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007959#ifdef FEAT_GUI_GTK
7960 if (gui.in_use)
7961 {
7962 gui_gtk_set_selection_targets();
7963 gui_gtk_set_dnd_targets();
7964 }
7965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 }
7967 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007968 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969
7970 return errmsg;
7971}
7972#endif
7973
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007974#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007975 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007976did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007977{
7978 char_u *errmsg = NULL;
7979 win_T *wp;
7980 int l;
7981
7982 if (is_spellfile)
7983 {
7984 l = (int)STRLEN(curwin->w_s->b_p_spf);
7985 if (l > 0 && (l < 4
7986 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7987 errmsg = e_invarg;
7988 }
7989
7990 if (errmsg == NULL)
7991 {
7992 FOR_ALL_WINDOWS(wp)
7993 if (wp->w_buffer == curbuf && wp->w_p_spell)
7994 {
7995 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007996 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007997 }
7998 }
7999 return errmsg;
8000}
8001
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008002/*
8003 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8004 * Return error message when failed, NULL when OK.
8005 */
8006 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008007compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008008{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008009 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008010 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008011
Bram Moolenaar860cae12010-06-05 23:22:07 +02008012 if (*synblock->b_p_spc == NUL)
8013 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008014 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008015 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008016 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008017 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008018 if (re != NULL)
8019 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008020 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008021 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008022 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008023 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008024 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008025 return e_invarg;
8026 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008027 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008028 }
8029
Bram Moolenaar473de612013-06-08 18:19:48 +02008030 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008031 return NULL;
8032}
8033#endif
8034
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008035#if defined(FEAT_EVAL) || defined(PROTO)
8036/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008037 * Set the scriptID for an option, taking care of setting the buffer- or
8038 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008039 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008040 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008041set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008042{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008043 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8044 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008045
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008046 /* Remember where the option was set. For local options need to do that
8047 * in the buffer or window structure. */
8048 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008049 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008050 if (both || (opt_flags & OPT_LOCAL))
8051 {
8052 if (indir & PV_BUF)
8053 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8054 else if (indir & PV_WIN)
8055 curwin->w_p_scriptID[indir & PV_MASK] = id;
8056 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008057}
8058#endif
8059
Bram Moolenaar071d4272004-06-13 20:20:40 +00008060/*
8061 * Set the value of a boolean option, and take care of side effects.
8062 * Returns NULL for success, or an error message for an error.
8063 */
8064 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008065set_bool_option(
8066 int opt_idx, /* index in options[] table */
8067 char_u *varp, /* pointer to the option variable */
8068 int value, /* new value */
8069 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070{
8071 int old_value = *(int *)varp;
8072
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073 /* Disallow changing some options from secure mode */
8074 if ((secure
8075#ifdef HAVE_SANDBOX
8076 || sandbox != 0
8077#endif
8078 ) && (options[opt_idx].flags & P_SECURE))
8079 return e_secure;
8080
8081 *(int *)varp = value; /* set the new value */
8082#ifdef FEAT_EVAL
8083 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008084 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085#endif
8086
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008087#ifdef FEAT_GUI
8088 need_mouse_correct = TRUE;
8089#endif
8090
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 /* May set global value for local option. */
8092 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8093 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8094
8095 /*
8096 * Handle side effects of changing a bool option.
8097 */
8098
8099 /* 'compatible' */
8100 if ((int *)varp == &p_cp)
8101 {
8102 compatible_set();
8103 }
8104
Bram Moolenaar920694c2016-08-21 17:45:02 +02008105#ifdef FEAT_LANGMAP
8106 if ((int *)varp == &p_lrm)
8107 /* 'langremap' -> !'langnoremap' */
8108 p_lnr = !p_lrm;
8109 else if ((int *)varp == &p_lnr)
8110 /* 'langnoremap' -> !'langremap' */
8111 p_lrm = !p_lnr;
8112#endif
8113
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008114#ifdef FEAT_PERSISTENT_UNDO
8115 /* 'undofile' */
8116 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8117 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008118 /* Only take action when the option was set. When reset we do not
8119 * delete the undo file, the option may be set again without making
8120 * any changes in between. */
8121 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008122 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008123 char_u hash[UNDO_HASH_SIZE];
8124 buf_T *save_curbuf = curbuf;
8125
Bram Moolenaar29323592016-07-24 22:04:11 +02008126 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008127 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008128 /* When 'undofile' is set globally: for every buffer, otherwise
8129 * only for the current buffer: Try to read in the undofile,
8130 * if one exists, the buffer wasn't changed and the buffer was
8131 * loaded */
8132 if ((curbuf == save_curbuf
8133 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8134 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8135 {
8136 u_compute_hash(hash);
8137 u_read_undo(NULL, hash, curbuf->b_fname);
8138 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008139 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008140 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008141 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008142 }
8143#endif
8144
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 else if ((int *)varp == &curbuf->b_p_ro)
8146 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008147 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8149 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008150
8151 /* when 'readonly' is set may give W10 again */
8152 if (curbuf->b_p_ro)
8153 curbuf->b_did_warn = FALSE;
8154
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008156 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157#endif
8158 }
8159
Bram Moolenaar9c449722010-07-20 18:44:27 +02008160#ifdef FEAT_GUI
8161 else if ((int *)varp == &p_mh)
8162 {
8163 if (!p_mh)
8164 gui_mch_mousehide(FALSE);
8165 }
8166#endif
8167
Bram Moolenaara539df02010-08-01 14:35:05 +02008168 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008170 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008171# ifdef FEAT_TERMINAL
8172 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008173 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008174 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008175 {
8176 curbuf->b_p_ma = FALSE;
8177 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8178 }
8179# endif
8180# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008181 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008182# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008183 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008184#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185 /* when 'endofline' is changed, redraw the window title */
8186 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008187 {
8188 redraw_titles();
8189 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008190 /* when 'fixeol' is changed, redraw the window title */
8191 else if ((int *)varp == &curbuf->b_p_fixeol)
8192 {
8193 redraw_titles();
8194 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008195# ifdef FEAT_MBYTE
8196 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008197 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008198 {
8199 redraw_titles();
8200 }
8201# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202#endif
8203
8204 /* when 'bin' is set also set some other options */
8205 else if ((int *)varp == &curbuf->b_p_bin)
8206 {
8207 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8208#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008209 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008210#endif
8211 }
8212
8213#ifdef FEAT_AUTOCMD
8214 /* when 'buflisted' changes, trigger autocommands */
8215 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8216 {
8217 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8218 NULL, NULL, TRUE, curbuf);
8219 }
8220#endif
8221
8222 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8223 else if ((int *)varp == &curbuf->b_p_swf)
8224 {
8225 if (curbuf->b_p_swf && p_uc)
8226 ml_open_file(curbuf); /* create the swap file */
8227 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008228 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8229 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008230 mf_close_file(curbuf, TRUE); /* remove the swap file */
8231 }
8232
8233 /* when 'terse' is set change 'shortmess' */
8234 else if ((int *)varp == &p_terse)
8235 {
8236 char_u *p;
8237
8238 p = vim_strchr(p_shm, SHM_SEARCH);
8239
8240 /* insert 's' in p_shm */
8241 if (p_terse && p == NULL)
8242 {
8243 STRCPY(IObuff, p_shm);
8244 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008245 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246 }
8247 /* remove 's' from p_shm */
8248 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008249 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008250 }
8251
8252 /* when 'paste' is set or reset also change other options */
8253 else if ((int *)varp == &p_paste)
8254 {
8255 paste_option_changed();
8256 }
8257
8258 /* when 'insertmode' is set from an autocommand need to do work here */
8259 else if ((int *)varp == &p_im)
8260 {
8261 if (p_im)
8262 {
8263 if ((State & INSERT) == 0)
8264 need_start_insertmode = TRUE;
8265 stop_insert_mode = FALSE;
8266 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008267 /* only reset if it was set previously */
8268 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008269 {
8270 need_start_insertmode = FALSE;
8271 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008272 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008273 clear_cmdline = TRUE; /* remove "(insert)" */
8274 restart_edit = 0;
8275 }
8276 }
8277
8278 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8279 else if ((int *)varp == &p_ic && p_hls)
8280 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008281 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008282 }
8283
8284#ifdef FEAT_SEARCH_EXTRA
8285 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8286 else if ((int *)varp == &p_hls)
8287 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008288 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 }
8290#endif
8291
8292#ifdef FEAT_SCROLLBIND
8293 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8294 * at the end of normal_cmd() */
8295 else if ((int *)varp == &curwin->w_p_scb)
8296 {
8297 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008298 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008299 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008300 curwin->w_scbind_pos = curwin->w_topline;
8301 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008302 }
8303#endif
8304
Bram Moolenaar4033c552017-09-16 20:54:51 +02008305#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 /* There can be only one window with 'previewwindow' set. */
8307 else if ((int *)varp == &curwin->w_p_pvw)
8308 {
8309 if (curwin->w_p_pvw)
8310 {
8311 win_T *win;
8312
Bram Moolenaar29323592016-07-24 22:04:11 +02008313 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 if (win->w_p_pvw && win != curwin)
8315 {
8316 curwin->w_p_pvw = FALSE;
8317 return (char_u *)N_("E590: A preview window already exists");
8318 }
8319 }
8320 }
8321#endif
8322
8323 /* when 'textmode' is set or reset also change 'fileformat' */
8324 else if ((int *)varp == &curbuf->b_p_tx)
8325 {
8326 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8327 }
8328
8329 /* when 'textauto' is set or reset also change 'fileformats' */
8330 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008331 set_string_option_direct((char_u *)"ffs", -1,
8332 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008333 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008334
8335 /*
8336 * When 'lisp' option changes include/exclude '-' in
8337 * keyword characters.
8338 */
8339#ifdef FEAT_LISP
8340 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8341 {
8342 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8343 }
8344#endif
8345
8346#ifdef FEAT_TITLE
8347 /* when 'title' changed, may need to change the title; same for 'icon' */
8348 else if ((int *)varp == &p_title)
8349 {
8350 did_set_title(FALSE);
8351 }
8352
8353 else if ((int *)varp == &p_icon)
8354 {
8355 did_set_title(TRUE);
8356 }
8357#endif
8358
8359 else if ((int *)varp == &curbuf->b_changed)
8360 {
8361 if (!value)
8362 save_file_ff(curbuf); /* Buffer is unchanged */
8363#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008364 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365#endif
8366#ifdef FEAT_AUTOCMD
8367 modified_was_set = value;
8368#endif
8369 }
8370
8371#ifdef BACKSLASH_IN_FILENAME
8372 else if ((int *)varp == &p_ssl)
8373 {
8374 if (p_ssl)
8375 {
8376 psepc = '/';
8377 psepcN = '\\';
8378 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008379 }
8380 else
8381 {
8382 psepc = '\\';
8383 psepcN = '/';
8384 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385 }
8386
8387 /* need to adjust the file name arguments and buffer names. */
8388 buflist_slash_adjust();
8389 alist_slash_adjust();
8390# ifdef FEAT_EVAL
8391 scriptnames_slash_adjust();
8392# endif
8393 }
8394#endif
8395
8396 /* If 'wrap' is set, set w_leftcol to zero. */
8397 else if ((int *)varp == &curwin->w_p_wrap)
8398 {
8399 if (curwin->w_p_wrap)
8400 curwin->w_leftcol = 0;
8401 }
8402
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 else if ((int *)varp == &p_ea)
8404 {
8405 if (p_ea && !old_value)
8406 win_equal(curwin, FALSE, 0);
8407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408
8409 else if ((int *)varp == &p_wiv)
8410 {
8411 /*
8412 * When 'weirdinvert' changed, set/reset 't_xs'.
8413 * Then set 'weirdinvert' according to value of 't_xs'.
8414 */
8415 if (p_wiv && !old_value)
8416 T_XS = (char_u *)"y";
8417 else if (!p_wiv && old_value)
8418 T_XS = empty_option;
8419 p_wiv = (*T_XS != NUL);
8420 }
8421
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008422#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 else if ((int *)varp == &p_beval)
8424 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008425 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008427 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428 gui_mch_disable_beval_area(balloonEval);
8429 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008432#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433 else if ((int *)varp == &p_acd)
8434 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008435 /* Change directories when the 'acd' option is set now. */
8436 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 }
8438#endif
8439
8440#ifdef FEAT_DIFF
8441 /* 'diff' */
8442 else if ((int *)varp == &curwin->w_p_diff)
8443 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008444 /* May add or remove the buffer from the list of diff buffers. */
8445 diff_buf_adjust(curwin);
8446# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 if (foldmethodIsDiff(curwin))
8448 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008449# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450 }
8451#endif
8452
8453#ifdef USE_IM_CONTROL
8454 /* 'imdisable' */
8455 else if ((int *)varp == &p_imdisable)
8456 {
8457 /* Only de-activate it here, it will be enabled when changing mode. */
8458 if (p_imdisable)
8459 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008460 else if (State & INSERT)
8461 /* When the option is set from an autocommand, it may need to take
8462 * effect right away. */
8463 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 }
8465#endif
8466
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008467#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008468 /* 'spell' */
8469 else if ((int *)varp == &curwin->w_p_spell)
8470 {
8471 if (curwin->w_p_spell)
8472 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008473 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008474 if (errmsg != NULL)
8475 EMSG(_(errmsg));
8476 }
8477 }
8478#endif
8479
Bram Moolenaar071d4272004-06-13 20:20:40 +00008480#ifdef FEAT_FKMAP
8481 else if ((int *)varp == &p_altkeymap)
8482 {
8483 if (old_value != p_altkeymap)
8484 {
8485 if (!p_altkeymap)
8486 {
8487 p_hkmap = p_fkmap;
8488 p_fkmap = 0;
8489 }
8490 else
8491 {
8492 p_fkmap = p_hkmap;
8493 p_hkmap = 0;
8494 }
8495 (void)init_chartab();
8496 }
8497 }
8498
8499 /*
8500 * In case some second language keymapping options have changed, check
8501 * and correct the setting in a consistent way.
8502 */
8503
8504 /*
8505 * If hkmap or fkmap are set, reset Arabic keymapping.
8506 */
8507 if ((p_hkmap || p_fkmap) && p_altkeymap)
8508 {
8509 p_altkeymap = p_fkmap;
8510# ifdef FEAT_ARABIC
8511 curwin->w_p_arab = FALSE;
8512# endif
8513 (void)init_chartab();
8514 }
8515
8516 /*
8517 * If hkmap set, reset Farsi keymapping.
8518 */
8519 if (p_hkmap && p_altkeymap)
8520 {
8521 p_altkeymap = 0;
8522 p_fkmap = 0;
8523# ifdef FEAT_ARABIC
8524 curwin->w_p_arab = FALSE;
8525# endif
8526 (void)init_chartab();
8527 }
8528
8529 /*
8530 * If fkmap set, reset Hebrew keymapping.
8531 */
8532 if (p_fkmap && !p_altkeymap)
8533 {
8534 p_altkeymap = 1;
8535 p_hkmap = 0;
8536# ifdef FEAT_ARABIC
8537 curwin->w_p_arab = FALSE;
8538# endif
8539 (void)init_chartab();
8540 }
8541#endif
8542
8543#ifdef FEAT_ARABIC
8544 if ((int *)varp == &curwin->w_p_arab)
8545 {
8546 if (curwin->w_p_arab)
8547 {
8548 /*
8549 * 'arabic' is set, handle various sub-settings.
8550 */
8551 if (!p_tbidi)
8552 {
8553 /* set rightleft mode */
8554 if (!curwin->w_p_rl)
8555 {
8556 curwin->w_p_rl = TRUE;
8557 changed_window_setting();
8558 }
8559
8560 /* Enable Arabic shaping (major part of what Arabic requires) */
8561 if (!p_arshape)
8562 {
8563 p_arshape = TRUE;
8564 redraw_later_clear();
8565 }
8566 }
8567
8568 /* Arabic requires a utf-8 encoding, inform the user if its not
8569 * set. */
8570 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008571 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008572 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8573
Bram Moolenaar8820b482017-03-16 17:23:31 +01008574 msg_source(HL_ATTR(HLF_W));
8575 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008576#ifdef FEAT_EVAL
8577 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8578#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008579 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008580
8581# ifdef FEAT_MBYTE
8582 /* set 'delcombine' */
8583 p_deco = TRUE;
8584# endif
8585
8586# ifdef FEAT_KEYMAP
8587 /* Force-set the necessary keymap for arabic */
8588 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8589 OPT_LOCAL);
8590# endif
8591# ifdef FEAT_FKMAP
8592 p_altkeymap = 0;
8593 p_hkmap = 0;
8594 p_fkmap = 0;
8595 (void)init_chartab();
8596# endif
8597 }
8598 else
8599 {
8600 /*
8601 * 'arabic' is reset, handle various sub-settings.
8602 */
8603 if (!p_tbidi)
8604 {
8605 /* reset rightleft mode */
8606 if (curwin->w_p_rl)
8607 {
8608 curwin->w_p_rl = FALSE;
8609 changed_window_setting();
8610 }
8611
8612 /* 'arabicshape' isn't reset, it is a global option and
8613 * another window may still need it "on". */
8614 }
8615
8616 /* 'delcombine' isn't reset, it is a global option and another
8617 * window may still want it "on". */
8618
8619# ifdef FEAT_KEYMAP
8620 /* Revert to the default keymap */
8621 curbuf->b_p_iminsert = B_IMODE_NONE;
8622 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8623# endif
8624 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008625 }
8626
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008627#endif
8628
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008629#ifdef FEAT_TERMGUICOLORS
8630 /* 'termguicolors' */
8631 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008632 {
8633# ifdef FEAT_GUI
8634 if (!gui.in_use && !gui.starting)
8635# endif
8636 highlight_gui_started();
8637 }
8638#endif
8639
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640 /*
8641 * End of handling side effects for bool options.
8642 */
8643
Bram Moolenaar53744302015-07-17 17:38:22 +02008644 /* after handling side effects, call autocommand */
8645
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646 options[opt_idx].flags |= P_WAS_SET;
8647
Bram Moolenaar53744302015-07-17 17:38:22 +02008648#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8649 if (!starting)
8650 {
8651 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008652 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8653 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8654 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008655 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8656 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8657 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8658 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8659 reset_v_option_vars();
8660 }
8661#endif
8662
Bram Moolenaar071d4272004-06-13 20:20:40 +00008663 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008664 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008665 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008666 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008667 check_redraw(options[opt_idx].flags);
8668
8669 return NULL;
8670}
8671
8672/*
8673 * Set the value of a number option, and take care of side effects.
8674 * Returns NULL for success, or an error message for an error.
8675 */
8676 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008677set_num_option(
8678 int opt_idx, /* index in options[] table */
8679 char_u *varp, /* pointer to the option variable */
8680 long value, /* new value */
8681 char_u *errbuf, /* buffer for error messages */
8682 size_t errbuflen, /* length of "errbuf" */
8683 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684 OPT_MODELINE */
8685{
8686 char_u *errmsg = NULL;
8687 long old_value = *(long *)varp;
8688 long old_Rows = Rows; /* remember old Rows */
8689 long old_Columns = Columns; /* remember old Columns */
8690 long *pp = (long *)varp;
8691
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008692 /* Disallow changing some options from secure mode. */
8693 if ((secure
8694#ifdef HAVE_SANDBOX
8695 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008696#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008697 ) && (options[opt_idx].flags & P_SECURE))
8698 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699
8700 *pp = value;
8701#ifdef FEAT_EVAL
8702 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008703 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008705#ifdef FEAT_GUI
8706 need_mouse_correct = TRUE;
8707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008708
Bram Moolenaar14f24742012-08-08 18:01:05 +02008709 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008710 {
8711 errmsg = e_positive;
8712 curbuf->b_p_sw = curbuf->b_p_ts;
8713 }
8714
8715 /*
8716 * Number options that need some action when changed
8717 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718 if (pp == &p_wh || pp == &p_hh)
8719 {
8720 if (p_wh < 1)
8721 {
8722 errmsg = e_positive;
8723 p_wh = 1;
8724 }
8725 if (p_wmh > p_wh)
8726 {
8727 errmsg = e_winheight;
8728 p_wh = p_wmh;
8729 }
8730 if (p_hh < 0)
8731 {
8732 errmsg = e_positive;
8733 p_hh = 0;
8734 }
8735
8736 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008737 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008738 {
8739 if (pp == &p_wh && curwin->w_height < p_wh)
8740 win_setheight((int)p_wh);
8741 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8742 win_setheight((int)p_hh);
8743 }
8744 }
8745
8746 /* 'winminheight' */
8747 else if (pp == &p_wmh)
8748 {
8749 if (p_wmh < 0)
8750 {
8751 errmsg = e_positive;
8752 p_wmh = 0;
8753 }
8754 if (p_wmh > p_wh)
8755 {
8756 errmsg = e_winheight;
8757 p_wmh = p_wh;
8758 }
8759 win_setminheight();
8760 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008761 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762 {
8763 if (p_wiw < 1)
8764 {
8765 errmsg = e_positive;
8766 p_wiw = 1;
8767 }
8768 if (p_wmw > p_wiw)
8769 {
8770 errmsg = e_winwidth;
8771 p_wiw = p_wmw;
8772 }
8773
8774 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008775 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 win_setwidth((int)p_wiw);
8777 }
8778
8779 /* 'winminwidth' */
8780 else if (pp == &p_wmw)
8781 {
8782 if (p_wmw < 0)
8783 {
8784 errmsg = e_positive;
8785 p_wmw = 0;
8786 }
8787 if (p_wmw > p_wiw)
8788 {
8789 errmsg = e_winwidth;
8790 p_wmw = p_wiw;
8791 }
8792 win_setminheight();
8793 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008794
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 /* (re)set last window status line */
8796 else if (pp == &p_ls)
8797 {
8798 last_status(FALSE);
8799 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008800
8801 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008802 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008803 {
8804 shell_new_rows(); /* recompute window positions and heights */
8805 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806
8807#ifdef FEAT_GUI
8808 else if (pp == &p_linespace)
8809 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008810 /* Recompute gui.char_height and resize the Vim window to keep the
8811 * same number of lines. */
8812 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008813 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814 }
8815#endif
8816
8817#ifdef FEAT_FOLDING
8818 /* 'foldlevel' */
8819 else if (pp == &curwin->w_p_fdl)
8820 {
8821 if (curwin->w_p_fdl < 0)
8822 curwin->w_p_fdl = 0;
8823 newFoldLevel();
8824 }
8825
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008826 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 else if (pp == &curwin->w_p_fml)
8828 {
8829 foldUpdateAll(curwin);
8830 }
8831
8832 /* 'foldnestmax' */
8833 else if (pp == &curwin->w_p_fdn)
8834 {
8835 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8836 foldUpdateAll(curwin);
8837 }
8838
8839 /* 'foldcolumn' */
8840 else if (pp == &curwin->w_p_fdc)
8841 {
8842 if (curwin->w_p_fdc < 0)
8843 {
8844 errmsg = e_positive;
8845 curwin->w_p_fdc = 0;
8846 }
8847 else if (curwin->w_p_fdc > 12)
8848 {
8849 errmsg = e_invarg;
8850 curwin->w_p_fdc = 12;
8851 }
8852 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008853#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008855#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 /* 'shiftwidth' or 'tabstop' */
8857 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8858 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008859# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008860 if (foldmethodIsIndent(curwin))
8861 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008862# endif
8863# ifdef FEAT_CINDENT
8864 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8865 * parse 'cinoptions'. */
8866 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8867 parse_cino(curbuf);
8868# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008870#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008871
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008872#ifdef FEAT_MBYTE
8873 /* 'maxcombine' */
8874 else if (pp == &p_mco)
8875 {
8876 if (p_mco > MAX_MCO)
8877 p_mco = MAX_MCO;
8878 else if (p_mco < 0)
8879 p_mco = 0;
8880 screenclear(); /* will re-allocate the screen */
8881 }
8882#endif
8883
Bram Moolenaar071d4272004-06-13 20:20:40 +00008884 else if (pp == &curbuf->b_p_iminsert)
8885 {
8886 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8887 {
8888 errmsg = e_invarg;
8889 curbuf->b_p_iminsert = B_IMODE_NONE;
8890 }
8891 p_iminsert = curbuf->b_p_iminsert;
8892 if (termcap_active) /* don't do this in the alternate screen */
8893 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008894#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008895 /* Show/unshow value of 'keymap' in status lines. */
8896 status_redraw_curbuf();
8897#endif
8898 }
8899
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008900#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8901 /* 'imstyle' */
8902 else if (pp == &p_imst)
8903 {
8904 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8905 errmsg = e_invarg;
8906 }
8907#endif
8908
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008909 else if (pp == &p_window)
8910 {
8911 if (p_window < 1)
8912 p_window = 1;
8913 else if (p_window >= Rows)
8914 p_window = Rows - 1;
8915 }
8916
Bram Moolenaar071d4272004-06-13 20:20:40 +00008917 else if (pp == &curbuf->b_p_imsearch)
8918 {
8919 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8920 {
8921 errmsg = e_invarg;
8922 curbuf->b_p_imsearch = B_IMODE_NONE;
8923 }
8924 p_imsearch = curbuf->b_p_imsearch;
8925 }
8926
8927#ifdef FEAT_TITLE
8928 /* if 'titlelen' has changed, redraw the title */
8929 else if (pp == &p_titlelen)
8930 {
8931 if (p_titlelen < 0)
8932 {
8933 errmsg = e_positive;
8934 p_titlelen = 85;
8935 }
8936 if (starting != NO_SCREEN && old_value != p_titlelen)
8937 need_maketitle = TRUE;
8938 }
8939#endif
8940
8941 /* if p_ch changed value, change the command line height */
8942 else if (pp == &p_ch)
8943 {
8944 if (p_ch < 1)
8945 {
8946 errmsg = e_positive;
8947 p_ch = 1;
8948 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008949 if (p_ch > Rows - min_rows() + 1)
8950 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008951
8952 /* Only compute the new window layout when startup has been
8953 * completed. Otherwise the frame sizes may be wrong. */
8954 if (p_ch != old_value && full_screen
8955#ifdef FEAT_GUI
8956 && !gui.starting
8957#endif
8958 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008959 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008960 }
8961
8962 /* when 'updatecount' changes from zero to non-zero, open swap files */
8963 else if (pp == &p_uc)
8964 {
8965 if (p_uc < 0)
8966 {
8967 errmsg = e_positive;
8968 p_uc = 100;
8969 }
8970 if (p_uc && !old_value)
8971 ml_open_files();
8972 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008973#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008974 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008975 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008976 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008977 {
8978 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008979 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008980 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008981 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008982 {
8983 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008984 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008985 }
8986 }
8987#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008988#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008989 else if (pp == &p_mzq)
8990 mzvim_reset_timer();
8991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008992
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008993#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8994 /* 'pyxversion' */
8995 else if (pp == &p_pyx)
8996 {
8997 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8998 errmsg = e_invarg;
8999 }
9000#endif
9001
Bram Moolenaar071d4272004-06-13 20:20:40 +00009002 /* sync undo before 'undolevels' changes */
9003 else if (pp == &p_ul)
9004 {
9005 /* use the old value, otherwise u_sync() may not work properly */
9006 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009007 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009008 p_ul = value;
9009 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009010 else if (pp == &curbuf->b_p_ul)
9011 {
9012 /* use the old value, otherwise u_sync() may not work properly */
9013 curbuf->b_p_ul = old_value;
9014 u_sync(TRUE);
9015 curbuf->b_p_ul = value;
9016 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009017
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009018#ifdef FEAT_LINEBREAK
9019 /* 'numberwidth' must be positive */
9020 else if (pp == &curwin->w_p_nuw)
9021 {
9022 if (curwin->w_p_nuw < 1)
9023 {
9024 errmsg = e_positive;
9025 curwin->w_p_nuw = 1;
9026 }
9027 if (curwin->w_p_nuw > 10)
9028 {
9029 errmsg = e_invarg;
9030 curwin->w_p_nuw = 10;
9031 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009032 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009033 }
9034#endif
9035
Bram Moolenaar1a384422010-07-14 19:53:30 +02009036 else if (pp == &curbuf->b_p_tw)
9037 {
9038 if (curbuf->b_p_tw < 0)
9039 {
9040 errmsg = e_positive;
9041 curbuf->b_p_tw = 0;
9042 }
9043#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009044 {
9045 win_T *wp;
9046 tabpage_T *tp;
9047
9048 FOR_ALL_TAB_WINDOWS(tp, wp)
9049 check_colorcolumn(wp);
9050 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009051#endif
9052 }
9053
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 /*
9055 * Check the bounds for numeric options here
9056 */
9057 if (Rows < min_rows() && full_screen)
9058 {
9059 if (errbuf != NULL)
9060 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009061 vim_snprintf((char *)errbuf, errbuflen,
9062 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009063 errmsg = errbuf;
9064 }
9065 Rows = min_rows();
9066 }
9067 if (Columns < MIN_COLUMNS && full_screen)
9068 {
9069 if (errbuf != NULL)
9070 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009071 vim_snprintf((char *)errbuf, errbuflen,
9072 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009073 errmsg = errbuf;
9074 }
9075 Columns = MIN_COLUMNS;
9076 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009077 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078
Bram Moolenaar071d4272004-06-13 20:20:40 +00009079 /*
9080 * If the screen (shell) height has been changed, assume it is the
9081 * physical screenheight.
9082 */
9083 if (old_Rows != Rows || old_Columns != Columns)
9084 {
9085 /* Changing the screen size is not allowed while updating the screen. */
9086 if (updating_screen)
9087 *pp = old_value;
9088 else if (full_screen
9089#ifdef FEAT_GUI
9090 && !gui.starting
9091#endif
9092 )
9093 set_shellsize((int)Columns, (int)Rows, TRUE);
9094 else
9095 {
9096 /* Postpone the resizing; check the size and cmdline position for
9097 * messages. */
9098 check_shellsize();
9099 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9100 cmdline_row = Rows - p_ch;
9101 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009102 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009103 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009104 }
9105
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106 if (curbuf->b_p_ts <= 0)
9107 {
9108 errmsg = e_positive;
9109 curbuf->b_p_ts = 8;
9110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 if (p_tm < 0)
9112 {
9113 errmsg = e_positive;
9114 p_tm = 0;
9115 }
9116 if ((curwin->w_p_scr <= 0
9117 || (curwin->w_p_scr > curwin->w_height
9118 && curwin->w_height > 0))
9119 && full_screen)
9120 {
9121 if (pp == &(curwin->w_p_scr))
9122 {
9123 if (curwin->w_p_scr != 0)
9124 errmsg = e_scroll;
9125 win_comp_scroll(curwin);
9126 }
9127 /* If 'scroll' became invalid because of a side effect silently adjust
9128 * it. */
9129 else if (curwin->w_p_scr <= 0)
9130 curwin->w_p_scr = 1;
9131 else /* curwin->w_p_scr > curwin->w_height */
9132 curwin->w_p_scr = curwin->w_height;
9133 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009134 if (p_hi < 0)
9135 {
9136 errmsg = e_positive;
9137 p_hi = 0;
9138 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009139 else if (p_hi > 10000)
9140 {
9141 errmsg = e_invarg;
9142 p_hi = 10000;
9143 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009144 if (p_re < 0 || p_re > 2)
9145 {
9146 errmsg = e_invarg;
9147 p_re = 0;
9148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149 if (p_report < 0)
9150 {
9151 errmsg = e_positive;
9152 p_report = 1;
9153 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009154 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155 {
9156 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9157 p_sj = Rows / 2;
9158 else
9159 {
9160 errmsg = e_scroll;
9161 p_sj = 1;
9162 }
9163 }
9164 if (p_so < 0 && full_screen)
9165 {
9166 errmsg = e_scroll;
9167 p_so = 0;
9168 }
9169 if (p_siso < 0 && full_screen)
9170 {
9171 errmsg = e_positive;
9172 p_siso = 0;
9173 }
9174#ifdef FEAT_CMDWIN
9175 if (p_cwh < 1)
9176 {
9177 errmsg = e_positive;
9178 p_cwh = 1;
9179 }
9180#endif
9181 if (p_ut < 0)
9182 {
9183 errmsg = e_positive;
9184 p_ut = 2000;
9185 }
9186 if (p_ss < 0)
9187 {
9188 errmsg = e_positive;
9189 p_ss = 0;
9190 }
9191
9192 /* May set global value for local option. */
9193 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9194 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9195
9196 options[opt_idx].flags |= P_WAS_SET;
9197
Bram Moolenaar53744302015-07-17 17:38:22 +02009198#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9199 if (!starting && errmsg == NULL)
9200 {
9201 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009202 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9203 vim_snprintf((char *)buf_new, 10, "%ld", value);
9204 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009205 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9206 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9207 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9208 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9209 reset_v_option_vars();
9210 }
9211#endif
9212
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009214 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009215 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009216 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217 check_redraw(options[opt_idx].flags);
9218
9219 return errmsg;
9220}
9221
9222/*
9223 * Called after an option changed: check if something needs to be redrawn.
9224 */
9225 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009226check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227{
9228 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009229 int doclear = (flags & P_RCLR) == P_RCLR;
9230 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231
Bram Moolenaar071d4272004-06-13 20:20:40 +00009232 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9233 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009234
9235 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9236 changed_window_setting();
9237 if (flags & P_RBUF)
9238 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009239 if (flags & P_RWINONLY)
9240 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009241 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009242 redraw_all_later(CLEAR);
9243 else if (all)
9244 redraw_all_later(NOT_VALID);
9245}
9246
9247/*
9248 * Find index for option 'arg'.
9249 * Return -1 if not found.
9250 */
9251 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009252findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009253{
9254 int opt_idx;
9255 char *s, *p;
9256 static short quick_tab[27] = {0, 0}; /* quick access table */
9257 int is_term_opt;
9258
9259 /*
9260 * For first call: Initialize the quick-access table.
9261 * It contains the index for the first option that starts with a certain
9262 * letter. There are 26 letters, plus the first "t_" option.
9263 */
9264 if (quick_tab[1] == 0)
9265 {
9266 p = options[0].fullname;
9267 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9268 {
9269 if (s[0] != p[0])
9270 {
9271 if (s[0] == 't' && s[1] == '_')
9272 quick_tab[26] = opt_idx;
9273 else
9274 quick_tab[CharOrdLow(s[0])] = opt_idx;
9275 }
9276 p = s;
9277 }
9278 }
9279
9280 /*
9281 * Check for name starting with an illegal character.
9282 */
9283#ifdef EBCDIC
9284 if (!islower(arg[0]))
9285#else
9286 if (arg[0] < 'a' || arg[0] > 'z')
9287#endif
9288 return -1;
9289
9290 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9291 if (is_term_opt)
9292 opt_idx = quick_tab[26];
9293 else
9294 opt_idx = quick_tab[CharOrdLow(arg[0])];
9295 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9296 {
9297 if (STRCMP(arg, s) == 0) /* match full name */
9298 break;
9299 }
9300 if (s == NULL && !is_term_opt)
9301 {
9302 opt_idx = quick_tab[CharOrdLow(arg[0])];
9303 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9304 {
9305 s = options[opt_idx].shortname;
9306 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9307 break;
9308 s = NULL;
9309 }
9310 }
9311 if (s == NULL)
9312 opt_idx = -1;
9313 return opt_idx;
9314}
9315
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009316#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009317/*
9318 * Get the value for an option.
9319 *
9320 * Returns:
9321 * Number or Toggle option: 1, *numval gets value.
9322 * String option: 0, *stringval gets allocated string.
9323 * Hidden Number or Toggle option: -1.
9324 * hidden String option: -2.
9325 * unknown option: -3.
9326 */
9327 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009328get_option_value(
9329 char_u *name,
9330 long *numval,
9331 char_u **stringval, /* NULL when only checking existence */
9332 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009333{
9334 int opt_idx;
9335 char_u *varp;
9336
9337 opt_idx = findoption(name);
9338 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009339 {
9340 int key;
9341
9342 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9343 && (key = find_key_option(name)) != 0)
9344 {
9345 char_u key_name[2];
9346 char_u *p;
9347
9348 if (key < 0)
9349 {
9350 key_name[0] = KEY2TERMCAP0(key);
9351 key_name[1] = KEY2TERMCAP1(key);
9352 }
9353 else
9354 {
9355 key_name[0] = KS_KEY;
9356 key_name[1] = (key & 0xff);
9357 }
9358 p = find_termcode(key_name);
9359 if (p != NULL)
9360 {
9361 if (stringval != NULL)
9362 *stringval = vim_strsave(p);
9363 return 0;
9364 }
9365 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009366 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368
9369 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9370
9371 if (options[opt_idx].flags & P_STRING)
9372 {
9373 if (varp == NULL) /* hidden option */
9374 return -2;
9375 if (stringval != NULL)
9376 {
9377#ifdef FEAT_CRYPT
9378 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009379 if ((char_u **)varp == &curbuf->b_p_key
9380 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009381 *stringval = vim_strsave((char_u *)"*****");
9382 else
9383#endif
9384 *stringval = vim_strsave(*(char_u **)(varp));
9385 }
9386 return 0;
9387 }
9388
9389 if (varp == NULL) /* hidden option */
9390 return -1;
9391 if (options[opt_idx].flags & P_NUM)
9392 *numval = *(long *)varp;
9393 else
9394 {
9395 /* Special case: 'modified' is b_changed, but we also want to consider
9396 * it set when 'ff' or 'fenc' changed. */
9397 if ((int *)varp == &curbuf->b_changed)
9398 *numval = curbufIsChanged();
9399 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009400 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009401 }
9402 return 1;
9403}
9404#endif
9405
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009406#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009407/*
9408 * Returns the option attributes and its value. Unlike the above function it
9409 * will return either global value or local value of the option depending on
9410 * what was requested, but it will never return global value if it was
9411 * requested to return local one and vice versa. Neither it will return
9412 * buffer-local value if it was requested to return window-local one.
9413 *
9414 * Pretends that option is absent if it is not present in the requested scope
9415 * (i.e. has no global, window-local or buffer-local value depending on
9416 * opt_type). Uses
9417 *
9418 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009419 * 0 hidden or unknown option, also option that does not have requested
9420 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009421 * see SOPT_* in vim.h for other flags
9422 *
9423 * Possible opt_type values: see SREQ_* in vim.h
9424 */
9425 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009426get_option_value_strict(
9427 char_u *name,
9428 long *numval,
9429 char_u **stringval, /* NULL when only obtaining attributes */
9430 int opt_type,
9431 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009432{
9433 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009434 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009435 struct vimoption *p;
9436 int r = 0;
9437
9438 opt_idx = findoption(name);
9439 if (opt_idx < 0)
9440 return 0;
9441
9442 p = &(options[opt_idx]);
9443
9444 /* Hidden option */
9445 if (p->var == NULL)
9446 return 0;
9447
9448 if (p->flags & P_BOOL)
9449 r |= SOPT_BOOL;
9450 else if (p->flags & P_NUM)
9451 r |= SOPT_NUM;
9452 else if (p->flags & P_STRING)
9453 r |= SOPT_STRING;
9454
9455 if (p->indir == PV_NONE)
9456 {
9457 if (opt_type == SREQ_GLOBAL)
9458 r |= SOPT_GLOBAL;
9459 else
9460 return 0; /* Did not request global-only option */
9461 }
9462 else
9463 {
9464 if (p->indir & PV_BOTH)
9465 r |= SOPT_GLOBAL;
9466 else if (opt_type == SREQ_GLOBAL)
9467 return 0; /* Requested global option */
9468
9469 if (p->indir & PV_WIN)
9470 {
9471 if (opt_type == SREQ_BUF)
9472 return 0; /* Did not request window-local option */
9473 else
9474 r |= SOPT_WIN;
9475 }
9476 else if (p->indir & PV_BUF)
9477 {
9478 if (opt_type == SREQ_WIN)
9479 return 0; /* Did not request buffer-local option */
9480 else
9481 r |= SOPT_BUF;
9482 }
9483 }
9484
9485 if (stringval == NULL)
9486 return r;
9487
9488 if (opt_type == SREQ_GLOBAL)
9489 varp = p->var;
9490 else
9491 {
9492 if (opt_type == SREQ_BUF)
9493 {
9494 /* Special case: 'modified' is b_changed, but we also want to
9495 * consider it set when 'ff' or 'fenc' changed. */
9496 if (p->indir == PV_MOD)
9497 {
9498 *numval = bufIsChanged((buf_T *) from);
9499 varp = NULL;
9500 }
9501#ifdef FEAT_CRYPT
9502 else if (p->indir == PV_KEY)
9503 {
9504 /* never return the value of the crypt key */
9505 *stringval = NULL;
9506 varp = NULL;
9507 }
9508#endif
9509 else
9510 {
9511 aco_save_T aco;
9512 aucmd_prepbuf(&aco, (buf_T *) from);
9513 varp = get_varp(p);
9514 aucmd_restbuf(&aco);
9515 }
9516 }
9517 else if (opt_type == SREQ_WIN)
9518 {
9519 win_T *save_curwin;
9520 save_curwin = curwin;
9521 curwin = (win_T *) from;
9522 curbuf = curwin->w_buffer;
9523 varp = get_varp(p);
9524 curwin = save_curwin;
9525 curbuf = curwin->w_buffer;
9526 }
9527 if (varp == p->var)
9528 return (r | SOPT_UNSET);
9529 }
9530
9531 if (varp != NULL)
9532 {
9533 if (p->flags & P_STRING)
9534 *stringval = vim_strsave(*(char_u **)(varp));
9535 else if (p->flags & P_NUM)
9536 *numval = *(long *) varp;
9537 else
9538 *numval = *(int *)varp;
9539 }
9540
9541 return r;
9542}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009543
9544/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009545 * Iterate over options. First argument is a pointer to a pointer to a
9546 * structure inside options[] array, second is option type like in the above
9547 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009548 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009549 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009550 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009551 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009552 * first argument to NULL.
9553 *
9554 * Returns full option name for current option on each call.
9555 */
9556 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009557option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009558{
9559 struct vimoption *ret = NULL;
9560 do
9561 {
9562 if (*option == NULL)
9563 *option = (void *) options;
9564 else if (((struct vimoption *) (*option))->fullname == NULL)
9565 {
9566 *option = NULL;
9567 return NULL;
9568 }
9569 else
9570 *option = (void *) (((struct vimoption *) (*option)) + 1);
9571
9572 ret = ((struct vimoption *) (*option));
9573
9574 /* Hidden option */
9575 if (ret->var == NULL)
9576 {
9577 ret = NULL;
9578 continue;
9579 }
9580
9581 switch (opt_type)
9582 {
9583 case SREQ_GLOBAL:
9584 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9585 ret = NULL;
9586 break;
9587 case SREQ_BUF:
9588 if (!(ret->indir & PV_BUF))
9589 ret = NULL;
9590 break;
9591 case SREQ_WIN:
9592 if (!(ret->indir & PV_WIN))
9593 ret = NULL;
9594 break;
9595 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009596 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009597 return NULL;
9598 }
9599 }
9600 while (ret == NULL);
9601
9602 return (char_u *)ret->fullname;
9603}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009604#endif
9605
Bram Moolenaar071d4272004-06-13 20:20:40 +00009606/*
9607 * Set the value of option "name".
9608 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009609 *
9610 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009612 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009613set_option_value(
9614 char_u *name,
9615 long number,
9616 char_u *string,
9617 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009618{
9619 int opt_idx;
9620 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009621 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009622
9623 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009624 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009625 {
9626 int key;
9627
9628 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9629 && (key = find_key_option(name)) != 0)
9630 {
9631 char_u key_name[2];
9632
9633 if (key < 0)
9634 {
9635 key_name[0] = KEY2TERMCAP0(key);
9636 key_name[1] = KEY2TERMCAP1(key);
9637 }
9638 else
9639 {
9640 key_name[0] = KS_KEY;
9641 key_name[1] = (key & 0xff);
9642 }
9643 add_termcode(key_name, string, FALSE);
9644 if (full_screen)
9645 ttest(FALSE);
9646 redraw_all_later(CLEAR);
9647 return NULL;
9648 }
9649
Bram Moolenaar071d4272004-06-13 20:20:40 +00009650 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652 else
9653 {
9654 flags = options[opt_idx].flags;
9655#ifdef HAVE_SANDBOX
9656 /* Disallow changing some options in the sandbox */
9657 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009658 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009659 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009660 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009662#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009663 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009664 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009665 else
9666 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009667 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009668 if (varp != NULL) /* hidden option is not changed */
9669 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009670 if (number == 0 && string != NULL)
9671 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009672 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009673
9674 /* Either we are given a string or we are setting option
9675 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009676 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009677 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009678 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009679 {
9680 /* There's another character after zeros or the string
9681 * is empty. In both cases, we are trying to set a
9682 * num option using a string. */
9683 EMSG3(_("E521: Number required: &%s = '%s'"),
9684 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009685 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009686
9687 }
9688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009689 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009690 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009691 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009692 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009693 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009694 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009695 }
9696 }
9697 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009698 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009699}
9700
9701/*
9702 * Get the terminal code for a terminal option.
9703 * Returns NULL when not found.
9704 */
9705 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009706get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009707{
9708 int opt_idx;
9709 char_u *varp;
9710
9711 if (tname[0] != 't' || tname[1] != '_' ||
9712 tname[2] == NUL || tname[3] == NUL)
9713 return NULL;
9714 if ((opt_idx = findoption(tname)) >= 0)
9715 {
9716 varp = get_varp(&(options[opt_idx]));
9717 if (varp != NULL)
9718 varp = *(char_u **)(varp);
9719 return varp;
9720 }
9721 return find_termcode(tname + 2);
9722}
9723
9724 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009725get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726{
9727 int i;
9728
9729 i = findoption((char_u *)"hl");
9730 if (i >= 0)
9731 return options[i].def_val[VI_DEFAULT];
9732 return (char_u *)NULL;
9733}
9734
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009735#if defined(FEAT_MBYTE) || defined(PROTO)
9736 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009737get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009738{
9739 int i;
9740
9741 i = findoption((char_u *)"enc");
9742 if (i >= 0)
9743 return options[i].def_val[VI_DEFAULT];
9744 return (char_u *)NULL;
9745}
9746#endif
9747
Bram Moolenaar071d4272004-06-13 20:20:40 +00009748/*
9749 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9750 */
9751 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009752find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009753{
9754 int key;
9755 int modifiers;
9756
9757 /*
9758 * Don't use get_special_key_code() for t_xx, we don't want it to call
9759 * add_termcap_entry().
9760 */
9761 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9762 key = TERMCAP2KEY(arg[2], arg[3]);
9763 else
9764 {
9765 --arg; /* put arg at the '<' */
9766 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009767 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768 if (modifiers) /* can't handle modifiers here */
9769 key = 0;
9770 }
9771 return key;
9772}
9773
9774/*
9775 * if 'all' == 0: show changed options
9776 * if 'all' == 1: show all normal options
9777 * if 'all' == 2: show all terminal options
9778 */
9779 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009780showoptions(
9781 int all,
9782 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783{
9784 struct vimoption *p;
9785 int col;
9786 int isterm;
9787 char_u *varp;
9788 struct vimoption **items;
9789 int item_count;
9790 int run;
9791 int row, rows;
9792 int cols;
9793 int i;
9794 int len;
9795
9796#define INC 20
9797#define GAP 3
9798
9799 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9800 PARAM_COUNT));
9801 if (items == NULL)
9802 return;
9803
9804 /* Highlight title */
9805 if (all == 2)
9806 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9807 else if (opt_flags & OPT_GLOBAL)
9808 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9809 else if (opt_flags & OPT_LOCAL)
9810 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9811 else
9812 MSG_PUTS_TITLE(_("\n--- Options ---"));
9813
9814 /*
9815 * do the loop two times:
9816 * 1. display the short items
9817 * 2. display the long items (only strings and numbers)
9818 */
9819 for (run = 1; run <= 2 && !got_int; ++run)
9820 {
9821 /*
9822 * collect the items in items[]
9823 */
9824 item_count = 0;
9825 for (p = &options[0]; p->fullname != NULL; p++)
9826 {
9827 varp = NULL;
9828 isterm = istermoption(p);
9829 if (opt_flags != 0)
9830 {
9831 if (p->indir != PV_NONE && !isterm)
9832 varp = get_varp_scope(p, opt_flags);
9833 }
9834 else
9835 varp = get_varp(p);
9836 if (varp != NULL
9837 && ((all == 2 && isterm)
9838 || (all == 1 && !isterm)
9839 || (all == 0 && !optval_default(p, varp))))
9840 {
9841 if (p->flags & P_BOOL)
9842 len = 1; /* a toggle option fits always */
9843 else
9844 {
9845 option_value2string(p, opt_flags);
9846 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9847 }
9848 if ((len <= INC - GAP && run == 1) ||
9849 (len > INC - GAP && run == 2))
9850 items[item_count++] = p;
9851 }
9852 }
9853
9854 /*
9855 * display the items
9856 */
9857 if (run == 1)
9858 {
9859 cols = (Columns + GAP - 3) / INC;
9860 if (cols == 0)
9861 cols = 1;
9862 rows = (item_count + cols - 1) / cols;
9863 }
9864 else /* run == 2 */
9865 rows = item_count;
9866 for (row = 0; row < rows && !got_int; ++row)
9867 {
9868 msg_putchar('\n'); /* go to next line */
9869 if (got_int) /* 'q' typed in more */
9870 break;
9871 col = 0;
9872 for (i = row; i < item_count; i += rows)
9873 {
9874 msg_col = col; /* make columns */
9875 showoneopt(items[i], opt_flags);
9876 col += INC;
9877 }
9878 out_flush();
9879 ui_breakcheck();
9880 }
9881 }
9882 vim_free(items);
9883}
9884
9885/*
9886 * Return TRUE if option "p" has its default value.
9887 */
9888 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009889optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009890{
9891 int dvi;
9892
9893 if (varp == NULL)
9894 return TRUE; /* hidden option is always at default */
9895 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9896 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009897 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009898 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009899 /* the cast to long is required for Manx C, long_i is
9900 * needed for MSVC */
9901 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009902 /* P_STRING */
9903 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9904}
9905
9906/*
9907 * showoneopt: show the value of one option
9908 * must not be called with a hidden option!
9909 */
9910 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009911showoneopt(
9912 struct vimoption *p,
9913 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009914{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009915 char_u *varp;
9916 int save_silent = silent_mode;
9917
9918 silent_mode = FALSE;
9919 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009920
9921 varp = get_varp_scope(p, opt_flags);
9922
9923 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9924 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9925 ? !curbufIsChanged() : !*(int *)varp))
9926 MSG_PUTS("no");
9927 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9928 MSG_PUTS("--");
9929 else
9930 MSG_PUTS(" ");
9931 MSG_PUTS(p->fullname);
9932 if (!(p->flags & P_BOOL))
9933 {
9934 msg_putchar('=');
9935 /* put value string in NameBuff */
9936 option_value2string(p, opt_flags);
9937 msg_outtrans(NameBuff);
9938 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009939
9940 silent_mode = save_silent;
9941 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009942}
9943
9944/*
9945 * Write modified options as ":set" commands to a file.
9946 *
9947 * There are three values for "opt_flags":
9948 * OPT_GLOBAL: Write global option values and fresh values of
9949 * buffer-local options (used for start of a session
9950 * file).
9951 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9952 * curwin (used for a vimrc file).
9953 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9954 * and local values for window-local options of
9955 * curwin. Local values are also written when at the
9956 * default value, because a modeline or autocommand
9957 * may have set them when doing ":edit file" and the
9958 * user has set them back at the default or fresh
9959 * value.
9960 * When "local_only" is TRUE, don't write fresh
9961 * values, only local values (for ":mkview").
9962 * (fresh value = value used for a new buffer or window for a local option).
9963 *
9964 * Return FAIL on error, OK otherwise.
9965 */
9966 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009967makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009968{
9969 struct vimoption *p;
9970 char_u *varp; /* currently used value */
9971 char_u *varp_fresh; /* local value */
9972 char_u *varp_local = NULL; /* fresh value */
9973 char *cmd;
9974 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009975 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009976
9977 /*
9978 * The options that don't have a default (terminal name, columns, lines)
9979 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009980 * Do the loop over "options[]" twice: once for options with the
9981 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009982 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009983 for (pri = 1; pri >= 0; --pri)
9984 {
9985 for (p = &options[0]; !istermoption(p); p++)
9986 if (!(p->flags & P_NO_MKRC)
9987 && !istermoption(p)
9988 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989 {
9990 /* skip global option when only doing locals */
9991 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9992 continue;
9993
9994 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9995 * file, they are always buffer-specific. */
9996 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9997 continue;
9998
9999 /* Global values are only written when not at the default value. */
10000 varp = get_varp_scope(p, opt_flags);
10001 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10002 continue;
10003
10004 round = 2;
10005 if (p->indir != PV_NONE)
10006 {
10007 if (p->var == VAR_WIN)
10008 {
10009 /* skip window-local option when only doing globals */
10010 if (!(opt_flags & OPT_LOCAL))
10011 continue;
10012 /* When fresh value of window-local option is not at the
10013 * default, need to write it too. */
10014 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10015 {
10016 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10017 if (!optval_default(p, varp_fresh))
10018 {
10019 round = 1;
10020 varp_local = varp;
10021 varp = varp_fresh;
10022 }
10023 }
10024 }
10025 }
10026
10027 /* Round 1: fresh value for window-local options.
10028 * Round 2: other values */
10029 for ( ; round <= 2; varp = varp_local, ++round)
10030 {
10031 if (round == 1 || (opt_flags & OPT_GLOBAL))
10032 cmd = "set";
10033 else
10034 cmd = "setlocal";
10035
10036 if (p->flags & P_BOOL)
10037 {
10038 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10039 return FAIL;
10040 }
10041 else if (p->flags & P_NUM)
10042 {
10043 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10044 return FAIL;
10045 }
10046 else /* P_STRING */
10047 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010048#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10049 int do_endif = FALSE;
10050
Bram Moolenaar071d4272004-06-13 20:20:40 +000010051 /* Don't set 'syntax' and 'filetype' again if the value is
10052 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010053 if (
10054# if defined(FEAT_SYN_HL)
10055 p->indir == PV_SYN
10056# if defined(FEAT_AUTOCMD)
10057 ||
10058# endif
10059# endif
10060# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010061 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010062# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010063 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010064 {
10065 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10066 *(char_u **)(varp)) < 0
10067 || put_eol(fd) < 0)
10068 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010069 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10073 (p->flags & P_EXPAND) != 0) == FAIL)
10074 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010075#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10076 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010077 {
10078 if (put_line(fd, "endif") == FAIL)
10079 return FAIL;
10080 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010081#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010082 }
10083 }
10084 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010086 return OK;
10087}
10088
10089#if defined(FEAT_FOLDING) || defined(PROTO)
10090/*
10091 * Generate set commands for the local fold options only. Used when
10092 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10093 */
10094 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010095makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010096{
10097 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10098# ifdef FEAT_EVAL
10099 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10100 == FAIL
10101# endif
10102 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10103 == FAIL
10104 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10105 == FAIL
10106 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10107 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10108 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10109 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10110 )
10111 return FAIL;
10112
10113 return OK;
10114}
10115#endif
10116
10117 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010118put_setstring(
10119 FILE *fd,
10120 char *cmd,
10121 char *name,
10122 char_u **valuep,
10123 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124{
10125 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010126 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127
10128 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10129 return FAIL;
10130 if (*valuep != NULL)
10131 {
10132 /* Output 'pastetoggle' as key names. For other
10133 * options some characters have to be escaped with
10134 * CTRL-V or backslash */
10135 if (valuep == &p_pt)
10136 {
10137 s = *valuep;
10138 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010139 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140 return FAIL;
10141 }
10142 else if (expand)
10143 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010144 buf = alloc(MAXPATHL);
10145 if (buf == NULL)
10146 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10148 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010149 {
10150 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010152 }
10153 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154 }
10155 else if (put_escstr(fd, *valuep, 2) == FAIL)
10156 return FAIL;
10157 }
10158 if (put_eol(fd) < 0)
10159 return FAIL;
10160 return OK;
10161}
10162
10163 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010164put_setnum(
10165 FILE *fd,
10166 char *cmd,
10167 char *name,
10168 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169{
10170 long wc;
10171
10172 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10173 return FAIL;
10174 if (wc_use_keyname((char_u *)valuep, &wc))
10175 {
10176 /* print 'wildchar' and 'wildcharm' as a key name */
10177 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10178 return FAIL;
10179 }
10180 else if (fprintf(fd, "%ld", *valuep) < 0)
10181 return FAIL;
10182 if (put_eol(fd) < 0)
10183 return FAIL;
10184 return OK;
10185}
10186
10187 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010188put_setbool(
10189 FILE *fd,
10190 char *cmd,
10191 char *name,
10192 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193{
Bram Moolenaar893de922007-10-02 18:40:57 +000010194 if (value < 0) /* global/local option using global value */
10195 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10197 || put_eol(fd) < 0)
10198 return FAIL;
10199 return OK;
10200}
10201
10202/*
10203 * Clear all the terminal options.
10204 * If the option has been allocated, free the memory.
10205 * Terminal options are never hidden or indirect.
10206 */
10207 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010208clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010209{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210 /*
10211 * Reset a few things before clearing the old options. This may cause
10212 * outputting a few things that the terminal doesn't understand, but the
10213 * screen will be cleared later, so this is OK.
10214 */
10215#ifdef FEAT_MOUSE_TTY
10216 mch_setmouse(FALSE); /* switch mouse off */
10217#endif
10218#ifdef FEAT_TITLE
10219 mch_restore_title(3); /* restore window titles */
10220#endif
10221#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10222 /* When starting the GUI close the display opened for the clipboard.
10223 * After restoring the title, because that will need the display. */
10224 if (gui.starting)
10225 clear_xterm_clip();
10226#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010227 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010229 free_termoptions();
10230}
10231
10232 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010233free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010234{
10235 struct vimoption *p;
10236
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237 for (p = &options[0]; p->fullname != NULL; p++)
10238 if (istermoption(p))
10239 {
10240 if (p->flags & P_ALLOCED)
10241 free_string_option(*(char_u **)(p->var));
10242 if (p->flags & P_DEF_ALLOCED)
10243 free_string_option(p->def_val[VI_DEFAULT]);
10244 *(char_u **)(p->var) = empty_option;
10245 p->def_val[VI_DEFAULT] = empty_option;
10246 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10247 }
10248 clear_termcodes();
10249}
10250
10251/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010252 * Free the string for one term option, if it was allocated.
10253 * Set the string to empty_option and clear allocated flag.
10254 * "var" points to the option value.
10255 */
10256 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010257free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010258{
10259 struct vimoption *p;
10260
10261 for (p = &options[0]; p->fullname != NULL; p++)
10262 if (p->var == var)
10263 {
10264 if (p->flags & P_ALLOCED)
10265 free_string_option(*(char_u **)(p->var));
10266 *(char_u **)(p->var) = empty_option;
10267 p->flags &= ~P_ALLOCED;
10268 break;
10269 }
10270}
10271
10272/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273 * Set the terminal option defaults to the current value.
10274 * Used after setting the terminal name.
10275 */
10276 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010277set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010278{
10279 struct vimoption *p;
10280
10281 for (p = &options[0]; p->fullname != NULL; p++)
10282 {
10283 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10284 {
10285 if (p->flags & P_DEF_ALLOCED)
10286 {
10287 free_string_option(p->def_val[VI_DEFAULT]);
10288 p->flags &= ~P_DEF_ALLOCED;
10289 }
10290 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10291 if (p->flags & P_ALLOCED)
10292 {
10293 p->flags |= P_DEF_ALLOCED;
10294 p->flags &= ~P_ALLOCED; /* don't free the value now */
10295 }
10296 }
10297 }
10298}
10299
10300/*
10301 * return TRUE if 'p' starts with 't_'
10302 */
10303 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010304istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305{
10306 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10307}
10308
10309/*
10310 * Compute columns for ruler and shown command. 'sc_col' is also used to
10311 * decide what the maximum length of a message on the status line can be.
10312 * If there is a status line for the last window, 'sc_col' is independent
10313 * of 'ru_col'.
10314 */
10315
10316#define COL_RULER 17 /* columns needed by standard ruler */
10317
10318 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010319comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010321#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010322 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323
10324 sc_col = 0;
10325 ru_col = 0;
10326 if (p_ru)
10327 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010328# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010330# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010332# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333 /* no last status line, adjust sc_col */
10334 if (!last_has_status)
10335 sc_col = ru_col;
10336 }
10337 if (p_sc)
10338 {
10339 sc_col += SHOWCMD_COLS;
10340 if (!p_ru || last_has_status) /* no need for separating space */
10341 ++sc_col;
10342 }
10343 sc_col = Columns - sc_col;
10344 ru_col = Columns - ru_col;
10345 if (sc_col <= 0) /* screen too narrow, will become a mess */
10346 sc_col = 1;
10347 if (ru_col <= 0)
10348 ru_col = 1;
10349#else
10350 sc_col = Columns;
10351 ru_col = Columns;
10352#endif
10353}
10354
10355/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010356 * Unset local option value, similar to ":set opt<".
10357 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010358 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010359unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010360{
10361 struct vimoption *p;
10362 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010363 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010364
10365 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010366 if (opt_idx < 0)
10367 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010368 p = &(options[opt_idx]);
10369
10370 switch ((int)p->indir)
10371 {
10372 /* global option with local value: use local value if it's been set */
10373 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010374 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010375 break;
10376 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010377 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010378 break;
10379 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010380 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010381 break;
10382 case PV_AR:
10383 buf->b_p_ar = -1;
10384 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010385 case PV_BKC:
10386 clear_string_option(&buf->b_p_bkc);
10387 buf->b_bkc_flags = 0;
10388 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010389 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010390 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010391 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010392 case PV_TC:
10393 clear_string_option(&buf->b_p_tc);
10394 buf->b_tc_flags = 0;
10395 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010396#ifdef FEAT_FIND_ID
10397 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010398 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010399 break;
10400 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010401 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010402 break;
10403#endif
10404#ifdef FEAT_INS_EXPAND
10405 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010406 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010407 break;
10408 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010409 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010410 break;
10411#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010412 case PV_FP:
10413 clear_string_option(&buf->b_p_fp);
10414 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010415#ifdef FEAT_QUICKFIX
10416 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010417 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010418 break;
10419 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010420 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010421 break;
10422 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010423 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010424 break;
10425#endif
10426#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10427 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010428 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010429 break;
10430#endif
10431#if defined(FEAT_CRYPT)
10432 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010433 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434 break;
10435#endif
10436#ifdef FEAT_STL_OPT
10437 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010438 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010439 break;
10440#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010441 case PV_UL:
10442 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10443 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010444#ifdef FEAT_LISP
10445 case PV_LW:
10446 clear_string_option(&buf->b_p_lw);
10447 break;
10448#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010449#ifdef FEAT_MBYTE
10450 case PV_MENC:
10451 clear_string_option(&buf->b_p_menc);
10452 break;
10453#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010454 }
10455}
10456
10457/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010458 * Get pointer to option variable, depending on local or global scope.
10459 */
10460 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010461get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462{
10463 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10464 {
10465 if (p->var == VAR_WIN)
10466 return (char_u *)GLOBAL_WO(get_varp(p));
10467 return p->var;
10468 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010469 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010470 {
10471 switch ((int)p->indir)
10472 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010473 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010475 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10476 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10477 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010478#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010479 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10480 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10481 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010482 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010483 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010484 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010485#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010486 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10487 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488#endif
10489#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010490 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10491 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010492#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010493#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10494 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10495#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010496#if defined(FEAT_CRYPT)
10497 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10498#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010499#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010500 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010501#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010502 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010503#ifdef FEAT_LISP
10504 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10505#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010506 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010507#ifdef FEAT_MBYTE
10508 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510 }
10511 return NULL; /* "cannot happen" */
10512 }
10513 return get_varp(p);
10514}
10515
10516/*
10517 * Get pointer to option variable.
10518 */
10519 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010520get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521{
10522 /* hidden option, always return NULL */
10523 if (p->var == NULL)
10524 return NULL;
10525
10526 switch ((int)p->indir)
10527 {
10528 case PV_NONE: return p->var;
10529
10530 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010531 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010533 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010535 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010537 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010539 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010541 case PV_TC: return *curbuf->b_p_tc != NUL
10542 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010543 case PV_BKC: return *curbuf->b_p_bkc != NUL
10544 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010546 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010548 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10550#endif
10551#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010552 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010554 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10556#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010557 case PV_FP: return *curbuf->b_p_fp != NUL
10558 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010560 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010562 case PV_GP: return *curbuf->b_p_gp != NUL
10563 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10564 case PV_MP: return *curbuf->b_p_mp != NUL
10565 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010567#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10568 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10569 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10570#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010571#if defined(FEAT_CRYPT)
10572 case PV_CM: return *curbuf->b_p_cm != NUL
10573 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10574#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010575#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010576 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010577 ? (char_u *)&(curwin->w_p_stl) : p->var;
10578#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010579 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10580 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010581#ifdef FEAT_LISP
10582 case PV_LW: return *curbuf->b_p_lw != NUL
10583 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10584#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010585#ifdef FEAT_MBYTE
10586 case PV_MENC: return *curbuf->b_p_menc != NUL
10587 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589
10590#ifdef FEAT_ARABIC
10591 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10592#endif
10593 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010594#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010595 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10596#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010597#ifdef FEAT_SYN_HL
10598 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10599 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010600 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010601#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602#ifdef FEAT_DIFF
10603 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10604#endif
10605#ifdef FEAT_FOLDING
10606 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10607 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10608 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10609 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10610 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10611 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10612 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10613# ifdef FEAT_EVAL
10614 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10615 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10616# endif
10617 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10618#endif
10619 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010620 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010621#ifdef FEAT_LINEBREAK
10622 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10623#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010624 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010625 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010626#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010627 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10628#endif
10629#ifdef FEAT_RIGHTLEFT
10630 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10631 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10632#endif
10633 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10634 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10635#ifdef FEAT_LINEBREAK
10636 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010637 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10638 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639#endif
10640#ifdef FEAT_SCROLLBIND
10641 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10642#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010643#ifdef FEAT_CURSORBIND
10644 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10645#endif
10646#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010647 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10648 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10649#endif
10650#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010651 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010652 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010653#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010654
10655 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10656 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10657#ifdef FEAT_MBYTE
10658 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10659#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010660 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10661 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010662 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10663 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10664#ifdef FEAT_CINDENT
10665 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10666 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10667 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10668#endif
10669#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10670 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10671#endif
10672#ifdef FEAT_COMMENTS
10673 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10674#endif
10675#ifdef FEAT_FOLDING
10676 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10677#endif
10678#ifdef FEAT_INS_EXPAND
10679 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10680#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010681#ifdef FEAT_COMPL_FUNC
10682 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010683 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010684#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010686 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010687 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10688#ifdef FEAT_MBYTE
10689 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10690#endif
10691 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10692#ifdef FEAT_AUTOCMD
10693 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10694#endif
10695 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010696 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10698 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10699 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10700 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10701#ifdef FEAT_FIND_ID
10702# ifdef FEAT_EVAL
10703 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10704# endif
10705#endif
10706#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10707 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10708 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10709#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010710#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010711 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10712#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713#ifdef FEAT_CRYPT
10714 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10715#endif
10716#ifdef FEAT_LISP
10717 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10718#endif
10719 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10720 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10721 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10722 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10723 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010724 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010725#ifdef FEAT_TEXTOBJ
10726 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10727#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010728 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10729#ifdef FEAT_SMARTINDENT
10730 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10731#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010733 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10734#ifdef FEAT_SEARCHPATH
10735 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10736#endif
10737 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10738#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010739 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010740 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10741#endif
10742#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010743 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10744 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10745 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746#endif
10747 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10748 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10749 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10750 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010751#ifdef FEAT_PERSISTENT_UNDO
10752 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10755#ifdef FEAT_KEYMAP
10756 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10757#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010758#ifdef FEAT_SIGNS
10759 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10760#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010761 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762 }
10763 /* always return a valid pointer to avoid a crash! */
10764 return (char_u *)&(curbuf->b_p_wm);
10765}
10766
10767/*
10768 * Get the value of 'equalprg', either the buffer-local one or the global one.
10769 */
10770 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010771get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772{
10773 if (*curbuf->b_p_ep == NUL)
10774 return p_ep;
10775 return curbuf->b_p_ep;
10776}
10777
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778/*
10779 * Copy options from one window to another.
10780 * Used when splitting a window.
10781 */
10782 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010783win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010784{
10785 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10786 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10787# ifdef FEAT_RIGHTLEFT
10788# ifdef FEAT_FKMAP
10789 /* Is this right? */
10790 wp_to->w_farsi = wp_from->w_farsi;
10791# endif
10792# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010793#if defined(FEAT_LINEBREAK)
10794 briopt_check(wp_to);
10795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797
10798/*
10799 * Copy the options from one winopt_T to another.
10800 * Doesn't free the old option values in "to", use clear_winopt() for that.
10801 * The 'scroll' option is not copied, because it depends on the window height.
10802 * The 'previewwindow' option is reset, there can be only one preview window.
10803 */
10804 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010805copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806{
10807#ifdef FEAT_ARABIC
10808 to->wo_arab = from->wo_arab;
10809#endif
10810 to->wo_list = from->wo_list;
10811 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010812 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010813#ifdef FEAT_LINEBREAK
10814 to->wo_nuw = from->wo_nuw;
10815#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816#ifdef FEAT_RIGHTLEFT
10817 to->wo_rl = from->wo_rl;
10818 to->wo_rlc = vim_strsave(from->wo_rlc);
10819#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010820#ifdef FEAT_STL_OPT
10821 to->wo_stl = vim_strsave(from->wo_stl);
10822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010824#ifdef FEAT_DIFF
10825 to->wo_wrap_save = from->wo_wrap_save;
10826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827#ifdef FEAT_LINEBREAK
10828 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010829 to->wo_bri = from->wo_bri;
10830 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010831#endif
10832#ifdef FEAT_SCROLLBIND
10833 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010834 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010836#ifdef FEAT_CURSORBIND
10837 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010838 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010839#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010840#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010841 to->wo_spell = from->wo_spell;
10842#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010843#ifdef FEAT_SYN_HL
10844 to->wo_cuc = from->wo_cuc;
10845 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010846 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848#ifdef FEAT_DIFF
10849 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010850 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010852#ifdef FEAT_CONCEAL
10853 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010854 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010855#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010856#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010857 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010858 to->wo_tms = vim_strsave(from->wo_tms);
10859#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860#ifdef FEAT_FOLDING
10861 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010862 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010864 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 to->wo_fdi = vim_strsave(from->wo_fdi);
10866 to->wo_fml = from->wo_fml;
10867 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010868 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010870 to->wo_fdm_save = from->wo_diff_saved
10871 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872 to->wo_fdn = from->wo_fdn;
10873# ifdef FEAT_EVAL
10874 to->wo_fde = vim_strsave(from->wo_fde);
10875 to->wo_fdt = vim_strsave(from->wo_fdt);
10876# endif
10877 to->wo_fmr = vim_strsave(from->wo_fmr);
10878#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010879#ifdef FEAT_SIGNS
10880 to->wo_scl = vim_strsave(from->wo_scl);
10881#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882 check_winopt(to); /* don't want NULL pointers */
10883}
10884
10885/*
10886 * Check string options in a window for a NULL value.
10887 */
10888 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010889check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890{
10891 check_winopt(&win->w_onebuf_opt);
10892 check_winopt(&win->w_allbuf_opt);
10893}
10894
10895/*
10896 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10897 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010898 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010899check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900{
10901#ifdef FEAT_FOLDING
10902 check_string_option(&wop->wo_fdi);
10903 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010904 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905# ifdef FEAT_EVAL
10906 check_string_option(&wop->wo_fde);
10907 check_string_option(&wop->wo_fdt);
10908# endif
10909 check_string_option(&wop->wo_fmr);
10910#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010911#ifdef FEAT_SIGNS
10912 check_string_option(&wop->wo_scl);
10913#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914#ifdef FEAT_RIGHTLEFT
10915 check_string_option(&wop->wo_rlc);
10916#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010917#ifdef FEAT_STL_OPT
10918 check_string_option(&wop->wo_stl);
10919#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010920#ifdef FEAT_SYN_HL
10921 check_string_option(&wop->wo_cc);
10922#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010923#ifdef FEAT_CONCEAL
10924 check_string_option(&wop->wo_cocu);
10925#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010926#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010927 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010928 check_string_option(&wop->wo_tms);
10929#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010930#ifdef FEAT_LINEBREAK
10931 check_string_option(&wop->wo_briopt);
10932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933}
10934
10935/*
10936 * Free the allocated memory inside a winopt_T.
10937 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010939clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940{
10941#ifdef FEAT_FOLDING
10942 clear_string_option(&wop->wo_fdi);
10943 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010944 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945# ifdef FEAT_EVAL
10946 clear_string_option(&wop->wo_fde);
10947 clear_string_option(&wop->wo_fdt);
10948# endif
10949 clear_string_option(&wop->wo_fmr);
10950#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010951#ifdef FEAT_SIGNS
10952 clear_string_option(&wop->wo_scl);
10953#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010954#ifdef FEAT_LINEBREAK
10955 clear_string_option(&wop->wo_briopt);
10956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957#ifdef FEAT_RIGHTLEFT
10958 clear_string_option(&wop->wo_rlc);
10959#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010960#ifdef FEAT_STL_OPT
10961 clear_string_option(&wop->wo_stl);
10962#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010963#ifdef FEAT_SYN_HL
10964 clear_string_option(&wop->wo_cc);
10965#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010966#ifdef FEAT_CONCEAL
10967 clear_string_option(&wop->wo_cocu);
10968#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010969#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010970 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010971 clear_string_option(&wop->wo_tms);
10972#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010973}
10974
10975/*
10976 * Copy global option values to local options for one buffer.
10977 * Used when creating a new buffer and sometimes when entering a buffer.
10978 * flags:
10979 * BCO_ENTER We will enter the buf buffer.
10980 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10981 * appropriate.
10982 * BCO_NOHELP Don't copy the values to a help buffer.
10983 */
10984 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010985buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010986{
10987 int should_copy = TRUE;
10988 char_u *save_p_isk = NULL; /* init for GCC */
10989 int dont_do_help;
10990 int did_isk = FALSE;
10991
10992 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010993 * Skip this when the option defaults have not been set yet. Happens when
10994 * main() allocates the first buffer.
10995 */
10996 if (p_cpo != NULL)
10997 {
10998 /*
10999 * Always copy when entering and 'cpo' contains 'S'.
11000 * Don't copy when already initialized.
11001 * Don't copy when 'cpo' contains 's' and not entering.
11002 * 'S' BCO_ENTER initialized 's' should_copy
11003 * yes yes X X TRUE
11004 * yes no yes X FALSE
11005 * no X yes X FALSE
11006 * X no no yes FALSE
11007 * X no no no TRUE
11008 * no yes no X TRUE
11009 */
11010 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11011 && (buf->b_p_initialized
11012 || (!(flags & BCO_ENTER)
11013 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11014 should_copy = FALSE;
11015
11016 if (should_copy || (flags & BCO_ALWAYS))
11017 {
11018 /* Don't copy the options specific to a help buffer when
11019 * BCO_NOHELP is given or the options were initialized already
11020 * (jumping back to a help file with CTRL-T or CTRL-O) */
11021 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11022 || buf->b_p_initialized;
11023 if (dont_do_help) /* don't free b_p_isk */
11024 {
11025 save_p_isk = buf->b_p_isk;
11026 buf->b_p_isk = NULL;
11027 }
11028 /*
11029 * Always free the allocated strings.
11030 * If not already initialized, set 'readonly' and copy 'fileformat'.
11031 */
11032 if (!buf->b_p_initialized)
11033 {
11034 free_buf_options(buf, TRUE);
11035 buf->b_p_ro = FALSE; /* don't copy readonly */
11036 buf->b_p_tx = p_tx;
11037#ifdef FEAT_MBYTE
11038 buf->b_p_fenc = vim_strsave(p_fenc);
11039#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011040 switch (*p_ffs)
11041 {
11042 case 'm':
11043 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11044 case 'd':
11045 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11046 case 'u':
11047 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11048 default:
11049 buf->b_p_ff = vim_strsave(p_ff);
11050 }
11051 if (buf->b_p_ff != NULL)
11052 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011053 buf->b_p_bh = empty_option;
11054 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055 }
11056 else
11057 free_buf_options(buf, FALSE);
11058
11059 buf->b_p_ai = p_ai;
11060 buf->b_p_ai_nopaste = p_ai_nopaste;
11061 buf->b_p_sw = p_sw;
11062 buf->b_p_tw = p_tw;
11063 buf->b_p_tw_nopaste = p_tw_nopaste;
11064 buf->b_p_tw_nobin = p_tw_nobin;
11065 buf->b_p_wm = p_wm;
11066 buf->b_p_wm_nopaste = p_wm_nopaste;
11067 buf->b_p_wm_nobin = p_wm_nobin;
11068 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011069#ifdef FEAT_MBYTE
11070 buf->b_p_bomb = p_bomb;
11071#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011072 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073 buf->b_p_et = p_et;
11074 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011075 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076 buf->b_p_ml = p_ml;
11077 buf->b_p_ml_nobin = p_ml_nobin;
11078 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011079 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080#ifdef FEAT_INS_EXPAND
11081 buf->b_p_cpt = vim_strsave(p_cpt);
11082#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011083#ifdef FEAT_COMPL_FUNC
11084 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011085 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087 buf->b_p_sts = p_sts;
11088 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011090#ifdef FEAT_COMMENTS
11091 buf->b_p_com = vim_strsave(p_com);
11092#endif
11093#ifdef FEAT_FOLDING
11094 buf->b_p_cms = vim_strsave(p_cms);
11095#endif
11096 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011097 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098 buf->b_p_nf = vim_strsave(p_nf);
11099 buf->b_p_mps = vim_strsave(p_mps);
11100#ifdef FEAT_SMARTINDENT
11101 buf->b_p_si = p_si;
11102#endif
11103 buf->b_p_ci = p_ci;
11104#ifdef FEAT_CINDENT
11105 buf->b_p_cin = p_cin;
11106 buf->b_p_cink = vim_strsave(p_cink);
11107 buf->b_p_cino = vim_strsave(p_cino);
11108#endif
11109#ifdef FEAT_AUTOCMD
11110 /* Don't copy 'filetype', it must be detected */
11111 buf->b_p_ft = empty_option;
11112#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113 buf->b_p_pi = p_pi;
11114#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11115 buf->b_p_cinw = vim_strsave(p_cinw);
11116#endif
11117#ifdef FEAT_LISP
11118 buf->b_p_lisp = p_lisp;
11119#endif
11120#ifdef FEAT_SYN_HL
11121 /* Don't copy 'syntax', it must be set */
11122 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011123 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011124 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011125#endif
11126#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011127 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011128 (void)compile_cap_prog(&buf->b_s);
11129 buf->b_s.b_p_spf = vim_strsave(p_spf);
11130 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011131#endif
11132#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11133 buf->b_p_inde = vim_strsave(p_inde);
11134 buf->b_p_indk = vim_strsave(p_indk);
11135#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011136 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011137#if defined(FEAT_EVAL)
11138 buf->b_p_fex = vim_strsave(p_fex);
11139#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140#ifdef FEAT_CRYPT
11141 buf->b_p_key = vim_strsave(p_key);
11142#endif
11143#ifdef FEAT_SEARCHPATH
11144 buf->b_p_sua = vim_strsave(p_sua);
11145#endif
11146#ifdef FEAT_KEYMAP
11147 buf->b_p_keymap = vim_strsave(p_keymap);
11148 buf->b_kmap_state |= KEYMAP_INIT;
11149#endif
11150 /* This isn't really an option, but copying the langmap and IME
11151 * state from the current buffer is better than resetting it. */
11152 buf->b_p_iminsert = p_iminsert;
11153 buf->b_p_imsearch = p_imsearch;
11154
11155 /* options that are normally global but also have a local value
11156 * are not copied, start using the global value */
11157 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011158 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011159 buf->b_p_bkc = empty_option;
11160 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011161#ifdef FEAT_QUICKFIX
11162 buf->b_p_gp = empty_option;
11163 buf->b_p_mp = empty_option;
11164 buf->b_p_efm = empty_option;
11165#endif
11166 buf->b_p_ep = empty_option;
11167 buf->b_p_kp = empty_option;
11168 buf->b_p_path = empty_option;
11169 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011170 buf->b_p_tc = empty_option;
11171 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011172#ifdef FEAT_FIND_ID
11173 buf->b_p_def = empty_option;
11174 buf->b_p_inc = empty_option;
11175# ifdef FEAT_EVAL
11176 buf->b_p_inex = vim_strsave(p_inex);
11177# endif
11178#endif
11179#ifdef FEAT_INS_EXPAND
11180 buf->b_p_dict = empty_option;
11181 buf->b_p_tsr = empty_option;
11182#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011183#ifdef FEAT_TEXTOBJ
11184 buf->b_p_qe = vim_strsave(p_qe);
11185#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011186#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11187 buf->b_p_bexpr = empty_option;
11188#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011189#if defined(FEAT_CRYPT)
11190 buf->b_p_cm = empty_option;
11191#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011192#ifdef FEAT_PERSISTENT_UNDO
11193 buf->b_p_udf = p_udf;
11194#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011195#ifdef FEAT_LISP
11196 buf->b_p_lw = empty_option;
11197#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011198#ifdef FEAT_MBYTE
11199 buf->b_p_menc = empty_option;
11200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201
11202 /*
11203 * Don't copy the options set by ex_help(), use the saved values,
11204 * when going from a help buffer to a non-help buffer.
11205 * Don't touch these at all when BCO_NOHELP is used and going from
11206 * or to a help buffer.
11207 */
11208 if (dont_do_help)
11209 buf->b_p_isk = save_p_isk;
11210 else
11211 {
11212 buf->b_p_isk = vim_strsave(p_isk);
11213 did_isk = TRUE;
11214 buf->b_p_ts = p_ts;
11215 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011216 if (buf->b_p_bt[0] == 'h')
11217 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011218 buf->b_p_ma = p_ma;
11219 }
11220 }
11221
11222 /*
11223 * When the options should be copied (ignoring BCO_ALWAYS), set the
11224 * flag that indicates that the options have been initialized.
11225 */
11226 if (should_copy)
11227 buf->b_p_initialized = TRUE;
11228 }
11229
11230 check_buf_options(buf); /* make sure we don't have NULLs */
11231 if (did_isk)
11232 (void)buf_init_chartab(buf, FALSE);
11233}
11234
11235/*
11236 * Reset the 'modifiable' option and its default value.
11237 */
11238 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011239reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240{
11241 int opt_idx;
11242
11243 curbuf->b_p_ma = FALSE;
11244 p_ma = FALSE;
11245 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011246 if (opt_idx >= 0)
11247 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248}
11249
11250/*
11251 * Set the global value for 'iminsert' to the local value.
11252 */
11253 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011254set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011255{
11256 p_iminsert = curbuf->b_p_iminsert;
11257}
11258
11259/*
11260 * Set the global value for 'imsearch' to the local value.
11261 */
11262 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011263set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011264{
11265 p_imsearch = curbuf->b_p_imsearch;
11266}
11267
11268#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11269static int expand_option_idx = -1;
11270static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11271static int expand_option_flags = 0;
11272
11273 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011274set_context_in_set_cmd(
11275 expand_T *xp,
11276 char_u *arg,
11277 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278{
11279 int nextchar;
11280 long_u flags = 0; /* init for GCC */
11281 int opt_idx = 0; /* init for GCC */
11282 char_u *p;
11283 char_u *s;
11284 int is_term_option = FALSE;
11285 int key;
11286
11287 expand_option_flags = opt_flags;
11288
11289 xp->xp_context = EXPAND_SETTINGS;
11290 if (*arg == NUL)
11291 {
11292 xp->xp_pattern = arg;
11293 return;
11294 }
11295 p = arg + STRLEN(arg) - 1;
11296 if (*p == ' ' && *(p - 1) != '\\')
11297 {
11298 xp->xp_pattern = p + 1;
11299 return;
11300 }
11301 while (p > arg)
11302 {
11303 s = p;
11304 /* count number of backslashes before ' ' or ',' */
11305 if (*p == ' ' || *p == ',')
11306 {
11307 while (s > arg && *(s - 1) == '\\')
11308 --s;
11309 }
11310 /* break at a space with an even number of backslashes */
11311 if (*p == ' ' && ((p - s) & 1) == 0)
11312 {
11313 ++p;
11314 break;
11315 }
11316 --p;
11317 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011318 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319 {
11320 xp->xp_context = EXPAND_BOOL_SETTINGS;
11321 p += 2;
11322 }
11323 if (STRNCMP(p, "inv", 3) == 0)
11324 {
11325 xp->xp_context = EXPAND_BOOL_SETTINGS;
11326 p += 3;
11327 }
11328 xp->xp_pattern = arg = p;
11329 if (*arg == '<')
11330 {
11331 while (*p != '>')
11332 if (*p++ == NUL) /* expand terminal option name */
11333 return;
11334 key = get_special_key_code(arg + 1);
11335 if (key == 0) /* unknown name */
11336 {
11337 xp->xp_context = EXPAND_NOTHING;
11338 return;
11339 }
11340 nextchar = *++p;
11341 is_term_option = TRUE;
11342 expand_option_name[2] = KEY2TERMCAP0(key);
11343 expand_option_name[3] = KEY2TERMCAP1(key);
11344 }
11345 else
11346 {
11347 if (p[0] == 't' && p[1] == '_')
11348 {
11349 p += 2;
11350 if (*p != NUL)
11351 ++p;
11352 if (*p == NUL)
11353 return; /* expand option name */
11354 nextchar = *++p;
11355 is_term_option = TRUE;
11356 expand_option_name[2] = p[-2];
11357 expand_option_name[3] = p[-1];
11358 }
11359 else
11360 {
11361 /* Allow * wildcard */
11362 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11363 p++;
11364 if (*p == NUL)
11365 return;
11366 nextchar = *p;
11367 *p = NUL;
11368 opt_idx = findoption(arg);
11369 *p = nextchar;
11370 if (opt_idx == -1 || options[opt_idx].var == NULL)
11371 {
11372 xp->xp_context = EXPAND_NOTHING;
11373 return;
11374 }
11375 flags = options[opt_idx].flags;
11376 if (flags & P_BOOL)
11377 {
11378 xp->xp_context = EXPAND_NOTHING;
11379 return;
11380 }
11381 }
11382 }
11383 /* handle "-=" and "+=" */
11384 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11385 {
11386 ++p;
11387 nextchar = '=';
11388 }
11389 if ((nextchar != '=' && nextchar != ':')
11390 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11391 {
11392 xp->xp_context = EXPAND_UNSUCCESSFUL;
11393 return;
11394 }
11395 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11396 {
11397 xp->xp_context = EXPAND_OLD_SETTING;
11398 if (is_term_option)
11399 expand_option_idx = -1;
11400 else
11401 expand_option_idx = opt_idx;
11402 xp->xp_pattern = p + 1;
11403 return;
11404 }
11405 xp->xp_context = EXPAND_NOTHING;
11406 if (is_term_option || (flags & P_NUM))
11407 return;
11408
11409 xp->xp_pattern = p + 1;
11410
11411 if (flags & P_EXPAND)
11412 {
11413 p = options[opt_idx].var;
11414 if (p == (char_u *)&p_bdir
11415 || p == (char_u *)&p_dir
11416 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011417 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011418 || p == (char_u *)&p_rtp
11419#ifdef FEAT_SEARCHPATH
11420 || p == (char_u *)&p_cdpath
11421#endif
11422#ifdef FEAT_SESSION
11423 || p == (char_u *)&p_vdir
11424#endif
11425 )
11426 {
11427 xp->xp_context = EXPAND_DIRECTORIES;
11428 if (p == (char_u *)&p_path
11429#ifdef FEAT_SEARCHPATH
11430 || p == (char_u *)&p_cdpath
11431#endif
11432 )
11433 xp->xp_backslash = XP_BS_THREE;
11434 else
11435 xp->xp_backslash = XP_BS_ONE;
11436 }
11437 else
11438 {
11439 xp->xp_context = EXPAND_FILES;
11440 /* for 'tags' need three backslashes for a space */
11441 if (p == (char_u *)&p_tags)
11442 xp->xp_backslash = XP_BS_THREE;
11443 else
11444 xp->xp_backslash = XP_BS_ONE;
11445 }
11446 }
11447
11448 /* For an option that is a list of file names, find the start of the
11449 * last file name. */
11450 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11451 {
11452 /* count number of backslashes before ' ' or ',' */
11453 if (*p == ' ' || *p == ',')
11454 {
11455 s = p;
11456 while (s > xp->xp_pattern && *(s - 1) == '\\')
11457 --s;
11458 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11459 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11460 {
11461 xp->xp_pattern = p + 1;
11462 break;
11463 }
11464 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011465
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011466#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011467 /* for 'spellsuggest' start at "file:" */
11468 if (options[opt_idx].var == (char_u *)&p_sps
11469 && STRNCMP(p, "file:", 5) == 0)
11470 {
11471 xp->xp_pattern = p + 5;
11472 break;
11473 }
11474#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011475 }
11476
11477 return;
11478}
11479
11480 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011481ExpandSettings(
11482 expand_T *xp,
11483 regmatch_T *regmatch,
11484 int *num_file,
11485 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486{
11487 int num_normal = 0; /* Nr of matching non-term-code settings */
11488 int num_term = 0; /* Nr of matching terminal code settings */
11489 int opt_idx;
11490 int match;
11491 int count = 0;
11492 char_u *str;
11493 int loop;
11494 int is_term_opt;
11495 char_u name_buf[MAX_KEY_NAME_LEN];
11496 static char *(names[]) = {"all", "termcap"};
11497 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11498
11499 /* do this loop twice:
11500 * loop == 0: count the number of matching options
11501 * loop == 1: copy the matching options into allocated memory
11502 */
11503 for (loop = 0; loop <= 1; ++loop)
11504 {
11505 regmatch->rm_ic = ic;
11506 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11507 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011508 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11509 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011510 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11511 {
11512 if (loop == 0)
11513 num_normal++;
11514 else
11515 (*file)[count++] = vim_strsave((char_u *)names[match]);
11516 }
11517 }
11518 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11519 opt_idx++)
11520 {
11521 if (options[opt_idx].var == NULL)
11522 continue;
11523 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11524 && !(options[opt_idx].flags & P_BOOL))
11525 continue;
11526 is_term_opt = istermoption(&options[opt_idx]);
11527 if (is_term_opt && num_normal > 0)
11528 continue;
11529 match = FALSE;
11530 if (vim_regexec(regmatch, str, (colnr_T)0)
11531 || (options[opt_idx].shortname != NULL
11532 && vim_regexec(regmatch,
11533 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11534 match = TRUE;
11535 else if (is_term_opt)
11536 {
11537 name_buf[0] = '<';
11538 name_buf[1] = 't';
11539 name_buf[2] = '_';
11540 name_buf[3] = str[2];
11541 name_buf[4] = str[3];
11542 name_buf[5] = '>';
11543 name_buf[6] = NUL;
11544 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11545 {
11546 match = TRUE;
11547 str = name_buf;
11548 }
11549 }
11550 if (match)
11551 {
11552 if (loop == 0)
11553 {
11554 if (is_term_opt)
11555 num_term++;
11556 else
11557 num_normal++;
11558 }
11559 else
11560 (*file)[count++] = vim_strsave(str);
11561 }
11562 }
11563 /*
11564 * Check terminal key codes, these are not in the option table
11565 */
11566 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11567 {
11568 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11569 {
11570 if (!isprint(str[0]) || !isprint(str[1]))
11571 continue;
11572
11573 name_buf[0] = 't';
11574 name_buf[1] = '_';
11575 name_buf[2] = str[0];
11576 name_buf[3] = str[1];
11577 name_buf[4] = NUL;
11578
11579 match = FALSE;
11580 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11581 match = TRUE;
11582 else
11583 {
11584 name_buf[0] = '<';
11585 name_buf[1] = 't';
11586 name_buf[2] = '_';
11587 name_buf[3] = str[0];
11588 name_buf[4] = str[1];
11589 name_buf[5] = '>';
11590 name_buf[6] = NUL;
11591
11592 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11593 match = TRUE;
11594 }
11595 if (match)
11596 {
11597 if (loop == 0)
11598 num_term++;
11599 else
11600 (*file)[count++] = vim_strsave(name_buf);
11601 }
11602 }
11603
11604 /*
11605 * Check special key names.
11606 */
11607 regmatch->rm_ic = TRUE; /* ignore case here */
11608 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11609 {
11610 name_buf[0] = '<';
11611 STRCPY(name_buf + 1, str);
11612 STRCAT(name_buf, ">");
11613
11614 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11615 {
11616 if (loop == 0)
11617 num_term++;
11618 else
11619 (*file)[count++] = vim_strsave(name_buf);
11620 }
11621 }
11622 }
11623 if (loop == 0)
11624 {
11625 if (num_normal > 0)
11626 *num_file = num_normal;
11627 else if (num_term > 0)
11628 *num_file = num_term;
11629 else
11630 return OK;
11631 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11632 if (*file == NULL)
11633 {
11634 *file = (char_u **)"";
11635 return FAIL;
11636 }
11637 }
11638 }
11639 return OK;
11640}
11641
11642 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011643ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011644{
11645 char_u *var = NULL; /* init for GCC */
11646 char_u *buf;
11647
11648 *num_file = 0;
11649 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11650 if (*file == NULL)
11651 return FAIL;
11652
11653 /*
11654 * For a terminal key code expand_option_idx is < 0.
11655 */
11656 if (expand_option_idx < 0)
11657 {
11658 var = find_termcode(expand_option_name + 2);
11659 if (var == NULL)
11660 expand_option_idx = findoption(expand_option_name);
11661 }
11662
11663 if (expand_option_idx >= 0)
11664 {
11665 /* put string of option value in NameBuff */
11666 option_value2string(&options[expand_option_idx], expand_option_flags);
11667 var = NameBuff;
11668 }
11669 else if (var == NULL)
11670 var = (char_u *)"";
11671
11672 /* A backslash is required before some characters. This is the reverse of
11673 * what happens in do_set(). */
11674 buf = vim_strsave_escaped(var, escape_chars);
11675
11676 if (buf == NULL)
11677 {
11678 vim_free(*file);
11679 *file = NULL;
11680 return FAIL;
11681 }
11682
11683#ifdef BACKSLASH_IN_FILENAME
11684 /* For MS-Windows et al. we don't double backslashes at the start and
11685 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011686 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011687 if (var[0] == '\\' && var[1] == '\\'
11688 && expand_option_idx >= 0
11689 && (options[expand_option_idx].flags & P_EXPAND)
11690 && vim_isfilec(var[2])
11691 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011692 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011693#endif
11694
11695 *file[0] = buf;
11696 *num_file = 1;
11697 return OK;
11698}
11699#endif
11700
11701/*
11702 * Get the value for the numeric or string option *opp in a nice format into
11703 * NameBuff[]. Must not be called with a hidden option!
11704 */
11705 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011706option_value2string(
11707 struct vimoption *opp,
11708 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011709{
11710 char_u *varp;
11711
11712 varp = get_varp_scope(opp, opt_flags);
11713
11714 if (opp->flags & P_NUM)
11715 {
11716 long wc = 0;
11717
11718 if (wc_use_keyname(varp, &wc))
11719 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11720 else if (wc != 0)
11721 STRCPY(NameBuff, transchar((int)wc));
11722 else
11723 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11724 }
11725 else /* P_STRING */
11726 {
11727 varp = *(char_u **)(varp);
11728 if (varp == NULL) /* just in case */
11729 NameBuff[0] = NUL;
11730#ifdef FEAT_CRYPT
11731 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011732 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011733 STRCPY(NameBuff, "*****");
11734#endif
11735 else if (opp->flags & P_EXPAND)
11736 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11737 /* Translate 'pastetoggle' into special key names */
11738 else if ((char_u **)opp->var == &p_pt)
11739 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11740 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011741 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011742 }
11743}
11744
11745/*
11746 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11747 * printed as a keyname.
11748 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11749 */
11750 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011751wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752{
11753 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11754 {
11755 *wcp = *(long *)varp;
11756 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11757 return TRUE;
11758 }
11759 return FALSE;
11760}
11761
Bram Moolenaar01615492015-02-03 13:00:38 +010011762#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011763/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011764 * Any character has an equivalent 'langmap' character. This is used for
11765 * keyboards that have a special language mode that sends characters above
11766 * 128 (although other characters can be translated too). The "to" field is a
11767 * Vim command character. This avoids having to switch the keyboard back to
11768 * ASCII mode when leaving Insert mode.
11769 *
11770 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11771 * commands.
11772 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11773 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11774 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011776# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011777/*
11778 * With multi-byte support use growarray for 'langmap' chars >= 256
11779 */
11780typedef struct
11781{
11782 int from;
11783 int to;
11784} langmap_entry_T;
11785
11786static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011787static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788
11789/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011790 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11791 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011792 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011793 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011794langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011795{
11796 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011797 int a = 0;
11798 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011799
11800 /* Do a binary search for an existing entry. */
11801 while (a != b)
11802 {
11803 int i = (a + b) / 2;
11804 int d = entries[i].from - from;
11805
11806 if (d == 0)
11807 {
11808 entries[i].to = to;
11809 return;
11810 }
11811 if (d < 0)
11812 a = i + 1;
11813 else
11814 b = i;
11815 }
11816
11817 if (ga_grow(&langmap_mapga, 1) != OK)
11818 return; /* out of memory */
11819
11820 /* insert new entry at position "a" */
11821 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11822 mch_memmove(entries + 1, entries,
11823 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11824 ++langmap_mapga.ga_len;
11825 entries[0].from = from;
11826 entries[0].to = to;
11827}
11828
11829/*
11830 * Apply 'langmap' to multi-byte character "c" and return the result.
11831 */
11832 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011833langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011834{
11835 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11836 int a = 0;
11837 int b = langmap_mapga.ga_len;
11838
11839 while (a != b)
11840 {
11841 int i = (a + b) / 2;
11842 int d = entries[i].from - c;
11843
11844 if (d == 0)
11845 return entries[i].to; /* found matching entry */
11846 if (d < 0)
11847 a = i + 1;
11848 else
11849 b = i;
11850 }
11851 return c; /* no entry found, return "c" unmodified */
11852}
11853# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011854
11855 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011856langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011857{
11858 int i;
11859
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011860 for (i = 0; i < 256; i++)
11861 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11862# ifdef FEAT_MBYTE
11863 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11864# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011865}
11866
11867/*
11868 * Called when langmap option is set; the language map can be
11869 * changed at any time!
11870 */
11871 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011872langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873{
11874 char_u *p;
11875 char_u *p2;
11876 int from, to;
11877
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011878#ifdef FEAT_MBYTE
11879 ga_clear(&langmap_mapga); /* clear the previous map first */
11880#endif
11881 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011882
11883 for (p = p_langmap; p[0] != NUL; )
11884 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011885 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011886 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887 {
11888 if (p2[0] == '\\' && p2[1] != NUL)
11889 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890 }
11891 if (p2[0] == ';')
11892 ++p2; /* abcd;ABCD form, p2 points to A */
11893 else
11894 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11895 while (p[0])
11896 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011897 if (p[0] == ',')
11898 {
11899 ++p;
11900 break;
11901 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902 if (p[0] == '\\' && p[1] != NUL)
11903 ++p;
11904#ifdef FEAT_MBYTE
11905 from = (*mb_ptr2char)(p);
11906#else
11907 from = p[0];
11908#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011909 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011910 if (p2 == NULL)
11911 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011912 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011913 if (p[0] != ',')
11914 {
11915 if (p[0] == '\\')
11916 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011917#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011918 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011920 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011923 }
11924 else
11925 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011926 if (p2[0] != ',')
11927 {
11928 if (p2[0] == '\\')
11929 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011930#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011931 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011933 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011935 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936 }
11937 if (to == NUL)
11938 {
11939 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11940 transchar(from));
11941 return;
11942 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011943
11944#ifdef FEAT_MBYTE
11945 if (from >= 256)
11946 langmap_set_entry(from, to);
11947 else
11948#endif
11949 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011950
11951 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011952 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011953 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011954 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011955 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956 if (*p == ';')
11957 {
11958 p = p2;
11959 if (p[0] != NUL)
11960 {
11961 if (p[0] != ',')
11962 {
11963 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11964 return;
11965 }
11966 ++p;
11967 }
11968 break;
11969 }
11970 }
11971 }
11972 }
11973}
11974#endif
11975
11976/*
11977 * Return TRUE if format option 'x' is in effect.
11978 * Take care of no formatting when 'paste' is set.
11979 */
11980 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011981has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011982{
11983 if (p_paste)
11984 return FALSE;
11985 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11986}
11987
11988/*
11989 * Return TRUE if "x" is present in 'shortmess' option, or
11990 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11991 */
11992 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011993shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011994{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011995 return p_shm != NULL &&
11996 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011997 || (vim_strchr(p_shm, 'a') != NULL
11998 && vim_strchr((char_u *)SHM_A, x) != NULL));
11999}
12000
12001/*
12002 * paste_option_changed() - Called after p_paste was set or reset.
12003 */
12004 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012005paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012006{
12007 static int old_p_paste = FALSE;
12008 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012009 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012010#ifdef FEAT_CMDL_INFO
12011 static int save_ru = 0;
12012#endif
12013#ifdef FEAT_RIGHTLEFT
12014 static int save_ri = 0;
12015 static int save_hkmap = 0;
12016#endif
12017 buf_T *buf;
12018
12019 if (p_paste)
12020 {
12021 /*
12022 * Paste switched from off to on.
12023 * Save the current values, so they can be restored later.
12024 */
12025 if (!old_p_paste)
12026 {
12027 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012028 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029 {
12030 buf->b_p_tw_nopaste = buf->b_p_tw;
12031 buf->b_p_wm_nopaste = buf->b_p_wm;
12032 buf->b_p_sts_nopaste = buf->b_p_sts;
12033 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012034 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035 }
12036
12037 /* save global options */
12038 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012039 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012040#ifdef FEAT_CMDL_INFO
12041 save_ru = p_ru;
12042#endif
12043#ifdef FEAT_RIGHTLEFT
12044 save_ri = p_ri;
12045 save_hkmap = p_hkmap;
12046#endif
12047 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012048 p_ai_nopaste = p_ai;
12049 p_et_nopaste = p_et;
12050 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012051 p_tw_nopaste = p_tw;
12052 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012053 }
12054
12055 /*
12056 * Always set the option values, also when 'paste' is set when it is
12057 * already on.
12058 */
12059 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012060 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061 {
12062 buf->b_p_tw = 0; /* textwidth is 0 */
12063 buf->b_p_wm = 0; /* wrapmargin is 0 */
12064 buf->b_p_sts = 0; /* softtabstop is 0 */
12065 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012066 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012067 }
12068
12069 /* set global options */
12070 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012071 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012072#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012073 if (p_ru)
12074 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012075 p_ru = 0; /* no ruler */
12076#endif
12077#ifdef FEAT_RIGHTLEFT
12078 p_ri = 0; /* no reverse insert */
12079 p_hkmap = 0; /* no Hebrew keyboard */
12080#endif
12081 /* set global values for local buffer options */
12082 p_tw = 0;
12083 p_wm = 0;
12084 p_sts = 0;
12085 p_ai = 0;
12086 }
12087
12088 /*
12089 * Paste switched from on to off: Restore saved values.
12090 */
12091 else if (old_p_paste)
12092 {
12093 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012094 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 {
12096 buf->b_p_tw = buf->b_p_tw_nopaste;
12097 buf->b_p_wm = buf->b_p_wm_nopaste;
12098 buf->b_p_sts = buf->b_p_sts_nopaste;
12099 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012100 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012101 }
12102
12103 /* restore global options */
12104 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012105 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012106#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107 if (p_ru != save_ru)
12108 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 p_ru = save_ru;
12110#endif
12111#ifdef FEAT_RIGHTLEFT
12112 p_ri = save_ri;
12113 p_hkmap = save_hkmap;
12114#endif
12115 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012116 p_ai = p_ai_nopaste;
12117 p_et = p_et_nopaste;
12118 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119 p_tw = p_tw_nopaste;
12120 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 }
12122
12123 old_p_paste = p_paste;
12124}
12125
12126/*
12127 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12128 *
12129 * Reset 'compatible' and set the values for options that didn't get set yet
12130 * to the Vim defaults.
12131 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012132 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012133 */
12134 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012135vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012137 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012138 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012139 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140
12141 if (!option_was_set((char_u *)"cp"))
12142 {
12143 p_cp = FALSE;
12144 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12145 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12146 set_option_default(opt_idx, OPT_FREE, FALSE);
12147 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012148 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012150
12151 if (fname != NULL)
12152 {
12153 p = vim_getenv(envname, &dofree);
12154 if (p == NULL)
12155 {
12156 /* Set $MYVIMRC to the first vimrc file found. */
12157 p = FullName_save(fname, FALSE);
12158 if (p != NULL)
12159 {
12160 vim_setenv(envname, p);
12161 vim_free(p);
12162 }
12163 }
12164 else if (dofree)
12165 vim_free(p);
12166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167}
12168
12169/*
12170 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12171 */
12172 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012173change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012174{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012175 int opt_idx;
12176
Bram Moolenaar071d4272004-06-13 20:20:40 +000012177 if (p_cp != on)
12178 {
12179 p_cp = on;
12180 compatible_set();
12181 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012182 opt_idx = findoption((char_u *)"cp");
12183 if (opt_idx >= 0)
12184 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012185}
12186
12187/*
12188 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012189 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012190 */
12191 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012192option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193{
12194 int idx;
12195
12196 idx = findoption(name);
12197 if (idx < 0) /* unknown option */
12198 return FALSE;
12199 if (options[idx].flags & P_WAS_SET)
12200 return TRUE;
12201 return FALSE;
12202}
12203
12204/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012205 * Reset the flag indicating option "name" was set.
12206 */
12207 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012208reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012209{
12210 int idx = findoption(name);
12211
12212 if (idx >= 0)
12213 options[idx].flags &= ~P_WAS_SET;
12214}
12215
12216/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217 * compatible_set() - Called when 'compatible' has been set or unset.
12218 *
12219 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12220 * flag) to a Vi compatible value.
12221 * When 'compatible' is unset: Set all options that have a different default
12222 * for Vim (without the P_VI_DEF flag) to that default.
12223 */
12224 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012225compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012226{
12227 int opt_idx;
12228
12229 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12230 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12231 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12232 set_option_default(opt_idx, OPT_FREE, p_cp);
12233 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012234 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012235}
12236
12237#ifdef FEAT_LINEBREAK
12238
12239# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12240 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012241 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242# endif
12243
12244/*
12245 * fill_breakat_flags() -- called when 'breakat' changes value.
12246 */
12247 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012248fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012250 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251 int i;
12252
12253 for (i = 0; i < 256; i++)
12254 breakat_flags[i] = FALSE;
12255
12256 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012257 for (p = p_breakat; *p; p++)
12258 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259}
12260
12261# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012262 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012263# endif
12264
12265#endif
12266
12267/*
12268 * Check an option that can be a range of string values.
12269 *
12270 * Return OK for correct value, FAIL otherwise.
12271 * Empty is always OK.
12272 */
12273 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012274check_opt_strings(
12275 char_u *val,
12276 char **values,
12277 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278{
12279 return opt_strings_flags(val, values, NULL, list);
12280}
12281
12282/*
12283 * Handle an option that can be a range of string values.
12284 * Set a flag in "*flagp" for each string present.
12285 *
12286 * Return OK for correct value, FAIL otherwise.
12287 * Empty is always OK.
12288 */
12289 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012290opt_strings_flags(
12291 char_u *val, /* new value */
12292 char **values, /* array of valid string values */
12293 unsigned *flagp,
12294 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295{
12296 int i;
12297 int len;
12298 unsigned new_flags = 0;
12299
12300 while (*val)
12301 {
12302 for (i = 0; ; ++i)
12303 {
12304 if (values[i] == NULL) /* val not found in values[] */
12305 return FAIL;
12306
12307 len = (int)STRLEN(values[i]);
12308 if (STRNCMP(values[i], val, len) == 0
12309 && ((list && val[len] == ',') || val[len] == NUL))
12310 {
12311 val += len + (val[len] == ',');
12312 new_flags |= (1 << i);
12313 break; /* check next item in val list */
12314 }
12315 }
12316 }
12317 if (flagp != NULL)
12318 *flagp = new_flags;
12319
12320 return OK;
12321}
12322
12323/*
12324 * Read the 'wildmode' option, fill wim_flags[].
12325 */
12326 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012327check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012328{
12329 char_u new_wim_flags[4];
12330 char_u *p;
12331 int i;
12332 int idx = 0;
12333
12334 for (i = 0; i < 4; ++i)
12335 new_wim_flags[i] = 0;
12336
12337 for (p = p_wim; *p; ++p)
12338 {
12339 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12340 ;
12341 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12342 return FAIL;
12343 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12344 new_wim_flags[idx] |= WIM_LONGEST;
12345 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12346 new_wim_flags[idx] |= WIM_FULL;
12347 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12348 new_wim_flags[idx] |= WIM_LIST;
12349 else
12350 return FAIL;
12351 p += i;
12352 if (*p == NUL)
12353 break;
12354 if (*p == ',')
12355 {
12356 if (idx == 3)
12357 return FAIL;
12358 ++idx;
12359 }
12360 }
12361
12362 /* fill remaining entries with last flag */
12363 while (idx < 3)
12364 {
12365 new_wim_flags[idx + 1] = new_wim_flags[idx];
12366 ++idx;
12367 }
12368
12369 /* only when there are no errors, wim_flags[] is changed */
12370 for (i = 0; i < 4; ++i)
12371 wim_flags[i] = new_wim_flags[i];
12372 return OK;
12373}
12374
12375/*
12376 * Check if backspacing over something is allowed.
12377 */
12378 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012379can_bs(
12380 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381{
12382 switch (*p_bs)
12383 {
12384 case '2': return TRUE;
12385 case '1': return (what != BS_START);
12386 case '0': return FALSE;
12387 }
12388 return vim_strchr(p_bs, what) != NULL;
12389}
12390
12391/*
12392 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12393 * the file must be considered changed when the value is different.
12394 */
12395 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012396save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012397{
12398 buf->b_start_ffc = *buf->b_p_ff;
12399 buf->b_start_eol = buf->b_p_eol;
12400#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012401 buf->b_start_bomb = buf->b_p_bomb;
12402
Bram Moolenaar071d4272004-06-13 20:20:40 +000012403 /* Only use free/alloc when necessary, they take time. */
12404 if (buf->b_start_fenc == NULL
12405 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12406 {
12407 vim_free(buf->b_start_fenc);
12408 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12409 }
12410#endif
12411}
12412
12413/*
12414 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12415 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012416 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12417 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012418 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012419 * When "ignore_empty" is true don't consider a new, empty buffer to be
12420 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421 */
12422 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012423file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012424{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012425 /* In a buffer that was never loaded the options are not valid. */
12426 if (buf->b_flags & BF_NEVERLOADED)
12427 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012428 if (ignore_empty
12429 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012430 && buf->b_ml.ml_line_count == 1
12431 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12432 return FALSE;
12433 if (buf->b_start_ffc != *buf->b_p_ff)
12434 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012435 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012436 return TRUE;
12437#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012438 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12439 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440 if (buf->b_start_fenc == NULL)
12441 return (*buf->b_p_fenc != NUL);
12442 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12443#else
12444 return FALSE;
12445#endif
12446}
12447
12448/*
12449 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12450 */
12451 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012452check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012453{
12454 return check_opt_strings(p, p_ff_values, FALSE);
12455}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012456
12457/*
12458 * Return the effective shiftwidth value for current buffer, using the
12459 * 'tabstop' value when 'shiftwidth' is zero.
12460 */
12461 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012462get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012463{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012464 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012465}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012466
12467/*
12468 * Return the effective softtabstop value for the current buffer, using the
12469 * 'tabstop' value when 'softtabstop' is negative.
12470 */
12471 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012472get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012473{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012474 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012475}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012476
12477/*
12478 * Check matchpairs option for "*initc".
12479 * If there is a match set "*initc" to the matching character and "*findc" to
12480 * the opposite character. Set "*backwards" to the direction.
12481 * When "switchit" is TRUE swap the direction.
12482 */
12483 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012484find_mps_values(
12485 int *initc,
12486 int *findc,
12487 int *backwards,
12488 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012489{
12490 char_u *ptr;
12491
12492 ptr = curbuf->b_p_mps;
12493 while (*ptr != NUL)
12494 {
12495#ifdef FEAT_MBYTE
12496 if (has_mbyte)
12497 {
12498 char_u *prev;
12499
12500 if (mb_ptr2char(ptr) == *initc)
12501 {
12502 if (switchit)
12503 {
12504 *findc = *initc;
12505 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12506 *backwards = TRUE;
12507 }
12508 else
12509 {
12510 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12511 *backwards = FALSE;
12512 }
12513 return;
12514 }
12515 prev = ptr;
12516 ptr += mb_ptr2len(ptr) + 1;
12517 if (mb_ptr2char(ptr) == *initc)
12518 {
12519 if (switchit)
12520 {
12521 *findc = *initc;
12522 *initc = mb_ptr2char(prev);
12523 *backwards = FALSE;
12524 }
12525 else
12526 {
12527 *findc = mb_ptr2char(prev);
12528 *backwards = TRUE;
12529 }
12530 return;
12531 }
12532 ptr += mb_ptr2len(ptr);
12533 }
12534 else
12535#endif
12536 {
12537 if (*ptr == *initc)
12538 {
12539 if (switchit)
12540 {
12541 *backwards = TRUE;
12542 *findc = *initc;
12543 *initc = ptr[2];
12544 }
12545 else
12546 {
12547 *backwards = FALSE;
12548 *findc = ptr[2];
12549 }
12550 return;
12551 }
12552 ptr += 2;
12553 if (*ptr == *initc)
12554 {
12555 if (switchit)
12556 {
12557 *backwards = FALSE;
12558 *findc = *initc;
12559 *initc = ptr[-2];
12560 }
12561 else
12562 {
12563 *backwards = TRUE;
12564 *findc = ptr[-2];
12565 }
12566 return;
12567 }
12568 ++ptr;
12569 }
12570 if (*ptr == ',')
12571 ++ptr;
12572 }
12573}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012574
12575#if defined(FEAT_LINEBREAK) || defined(PROTO)
12576/*
12577 * This is called when 'breakindentopt' is changed and when a window is
12578 * initialized.
12579 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012580 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012581briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012582{
12583 char_u *p;
12584 int bri_shift = 0;
12585 long bri_min = 20;
12586 int bri_sbr = FALSE;
12587
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012588 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012589 while (*p != NUL)
12590 {
12591 if (STRNCMP(p, "shift:", 6) == 0
12592 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12593 {
12594 p += 6;
12595 bri_shift = getdigits(&p);
12596 }
12597 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12598 {
12599 p += 4;
12600 bri_min = getdigits(&p);
12601 }
12602 else if (STRNCMP(p, "sbr", 3) == 0)
12603 {
12604 p += 3;
12605 bri_sbr = TRUE;
12606 }
12607 if (*p != ',' && *p != NUL)
12608 return FAIL;
12609 if (*p == ',')
12610 ++p;
12611 }
12612
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012613 wp->w_p_brishift = bri_shift;
12614 wp->w_p_brimin = bri_min;
12615 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012616
12617 return OK;
12618}
12619#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012620
12621/*
12622 * Get the local or global value of 'backupcopy'.
12623 */
12624 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012625get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012626{
12627 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12628}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012629
12630#if defined(FEAT_SIGNS) || defined(PROTO)
12631/*
12632 * Return TRUE when window "wp" has a column to draw signs in.
12633 */
12634 int
12635signcolumn_on(win_T *wp)
12636{
12637 if (*wp->w_p_scl == 'n')
12638 return FALSE;
12639 if (*wp->w_p_scl == 'y')
12640 return TRUE;
12641 return (wp->w_buffer->b_signlist != NULL
12642# ifdef FEAT_NETBEANS_INTG
12643 || wp->w_buffer->b_has_sign_column
12644# endif
12645 );
12646}
12647#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012648
12649#if defined(FEAT_EVAL) || defined(PROTO)
12650/*
12651 * Get window or buffer local options.
12652 */
12653 dict_T *
12654get_winbuf_options(int bufopt)
12655{
12656 dict_T *d;
12657 int opt_idx;
12658
12659 d = dict_alloc();
12660 if (d == NULL)
12661 return NULL;
12662
12663 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12664 {
12665 struct vimoption *opt = &options[opt_idx];
12666
12667 if ((bufopt && (opt->indir & PV_BUF))
12668 || (!bufopt && (opt->indir & PV_WIN)))
12669 {
12670 char_u *varp = get_varp(opt);
12671
12672 if (varp != NULL)
12673 {
12674 if (opt->flags & P_STRING)
12675 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012676 else if (opt->flags & P_NUM)
12677 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012678 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012679 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012680 }
12681 }
12682 }
12683
12684 return d;
12685}
12686#endif