blob: 96620395102682a96a2742bf04ed2fe2121578cf [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,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100637#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638 (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},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100645 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100646#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100647 (char_u *)&p_bevalterm, PV_NONE,
648 {(char_u *)FALSE, (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100654 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
655#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
656 (char_u *)&p_bexpr, PV_BEXPR,
657 {(char_u *)"", (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
662 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"beautify", "bf", P_BOOL|P_VI_DEF,
664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200666 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
667 (char_u *)&p_bo, PV_NONE,
668 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
670 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000671 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000674 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
676#ifdef FEAT_MBYTE
677 (char_u *)&p_bomb, PV_BOMB,
678#else
679 (char_u *)NULL, PV_NONE,
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
683#ifdef FEAT_LINEBREAK
684 (char_u *)&p_breakat, PV_NONE,
685 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200691 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
692#ifdef FEAT_LINEBREAK
693 (char_u *)VAR_WIN, PV_BRI,
694 {(char_u *)FALSE, (char_u *)0L}
695#else
696 (char_u *)NULL, PV_NONE,
697 {(char_u *)0L, (char_u *)0L}
698#endif
699 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200700 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
701 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200702#ifdef FEAT_LINEBREAK
703 (char_u *)VAR_WIN, PV_BRIOPT,
704 {(char_u *)"", (char_u *)NULL}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)"", (char_u *)NULL}
708#endif
709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
711#ifdef FEAT_BROWSE
712 (char_u *)&p_bsdir, PV_NONE,
713 {(char_u *)"last", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_bh, PV_BH,
721 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
724 (char_u *)&p_bl, PV_BL,
725 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 (char_u *)&p_bt, PV_BT,
729 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200731 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000732#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733 (char_u *)&p_cmp, PV_NONE,
734 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000735#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 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
741#ifdef FEAT_SEARCHPATH
742 (char_u *)&p_cdpath, PV_NONE,
743 {(char_u *)",,", (char_u *)0L}
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 {"cedit", NULL, P_STRING,
750#ifdef FEAT_CMDWIN
751 (char_u *)&p_cedit, PV_NONE,
752 {(char_u *)"", (char_u *)CTRL_F_STR}
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 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
759#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
760 (char_u *)&p_ccv, PV_NONE,
761 {(char_u *)"", (char_u *)0L}
762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)0L, (char_u *)0L}
765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
768#ifdef FEAT_CINDENT
769 (char_u *)&p_cin, PV_CIN,
770#else
771 (char_u *)NULL, PV_NONE,
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinkeys", "cink", 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_cink, PV_CINK,
777 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
778#else
779 (char_u *)NULL, PV_NONE,
780 {(char_u *)0L, (char_u *)0L}
781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000782 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#ifdef FEAT_CINDENT
785 (char_u *)&p_cino, PV_CINO,
786#else
787 (char_u *)NULL, PV_NONE,
788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200790 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
792 (char_u *)&p_cinw, PV_CINW,
793 {(char_u *)"if,else,while,do,for,switch",
794 (char_u *)0L}
795#else
796 (char_u *)NULL, PV_NONE,
797 {(char_u *)0L, (char_u *)0L}
798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000799 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200800 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801#ifdef FEAT_CLIPBOARD
802 (char_u *)&p_cb, PV_NONE,
803# ifdef FEAT_XCLIPBOARD
804 {(char_u *)"autoselect,exclude:cons\\|linux",
805 (char_u *)0L}
806# else
807 {(char_u *)"", (char_u *)0L}
808# endif
809#else
810 (char_u *)NULL, PV_NONE,
811 {(char_u *)"", (char_u *)0L}
812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000813 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
815 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
818#ifdef FEAT_CMDWIN
819 (char_u *)&p_cwh, PV_NONE,
820#else
821 (char_u *)NULL, PV_NONE,
822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000823 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200824 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200825#ifdef FEAT_SYN_HL
826 (char_u *)VAR_WIN, PV_CC,
827#else
828 (char_u *)NULL, PV_NONE,
829#endif
830 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
832 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000833 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200834 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
835 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836#ifdef FEAT_COMMENTS
837 (char_u *)&p_com, PV_COM,
838 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
839 (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 Moolenaar913077c2012-03-28 19:59:04 +0200845 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846#ifdef FEAT_FOLDING
847 (char_u *)&p_cms, PV_CMS,
848 {(char_u *)"/*%s*/", (char_u *)0L}
849#else
850 (char_u *)NULL, PV_NONE,
851 {(char_u *)0L, (char_u *)0L}
852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000853 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000854 /* P_PRI_MKRC isn't needed here, optval_default()
855 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856 {"compatible", "cp", P_BOOL|P_RALL,
857 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200859 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000860#ifdef FEAT_INS_EXPAND
861 (char_u *)&p_cpt, PV_CPT,
862 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)0L, (char_u *)0L}
866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000867 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200868 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200869#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 (char_u *)VAR_WIN, PV_COCU,
871 {(char_u *)"", (char_u *)NULL}
872#else
873 (char_u *)NULL, PV_NONE,
874 {(char_u *)NULL, (char_u *)0L}
875#endif
876 SCRIPTID_INIT},
877 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
878#ifdef FEAT_CONCEAL
879 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200880#else
881 (char_u *)NULL, PV_NONE,
882#endif
883 {(char_u *)0L, (char_u *)0L}
884 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000885 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
886#ifdef FEAT_COMPL_FUNC
887 (char_u *)&p_cfu, PV_CFU,
888 {(char_u *)"", (char_u *)0L}
889#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 Moolenaar0e7c4b92015-06-20 15:30:03 +0200894 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000895#ifdef FEAT_INS_EXPAND
896 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000897 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000898#else
899 (char_u *)NULL, PV_NONE,
900 {(char_u *)0L, (char_u *)0L}
901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 {"confirm", "cf", P_BOOL|P_VI_DEF,
904#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
905 (char_u *)&p_confirm, PV_NONE,
906#else
907 (char_u *)NULL, PV_NONE,
908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
914 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000915 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
917 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000918 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
919 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200920 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200921#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200922 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200923 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200924#else
925 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200926 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200927#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
930#ifdef FEAT_CSCOPE
931 (char_u *)&p_cspc, PV_NONE,
932#else
933 (char_u *)NULL, PV_NONE,
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000936 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
937#ifdef FEAT_CSCOPE
938 (char_u *)&p_csprg, PV_NONE,
939 {(char_u *)"cscope", (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 Moolenaar0e7c4b92015-06-20 15:30:03 +0200945 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
947 (char_u *)&p_csqf, PV_NONE,
948 {(char_u *)"", (char_u *)0L}
949#else
950 (char_u *)NULL, PV_NONE,
951 {(char_u *)0L, (char_u *)0L}
952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000953 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200954 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
955#ifdef FEAT_CSCOPE
956 (char_u *)&p_csre, PV_NONE,
957#else
958 (char_u *)NULL, PV_NONE,
959#endif
960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
962#ifdef FEAT_CSCOPE
963 (char_u *)&p_cst, PV_NONE,
964#else
965 (char_u *)NULL, PV_NONE,
966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000967 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
969#ifdef FEAT_CSCOPE
970 (char_u *)&p_csto, PV_NONE,
971#else
972 (char_u *)NULL, PV_NONE,
973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000974 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
976#ifdef FEAT_CSCOPE
977 (char_u *)&p_csverbose, PV_NONE,
978#else
979 (char_u *)NULL, PV_NONE,
980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200982 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
983#ifdef FEAT_CURSORBIND
984 (char_u *)VAR_WIN, PV_CRBIND,
985#else
986 (char_u *)NULL, PV_NONE,
987#endif
988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000989 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
990#ifdef FEAT_SYN_HL
991 (char_u *)VAR_WIN, PV_CUC,
992#else
993 (char_u *)NULL, PV_NONE,
994#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000995 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100996 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997#ifdef FEAT_SYN_HL
998 (char_u *)VAR_WIN, PV_CUL,
999#else
1000 (char_u *)NULL, PV_NONE,
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"debug", NULL, P_STRING|P_VI_DEF,
1004 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001006 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001008 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001009 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)NULL, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1016#ifdef FEAT_MBYTE
1017 (char_u *)&p_deco, PV_NONE,
1018#else
1019 (char_u *)NULL, PV_NONE,
1020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001022 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001024 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#else
1026 (char_u *)NULL, PV_NONE,
1027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001028 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1030#ifdef FEAT_DIFF
1031 (char_u *)VAR_WIN, PV_DIFF,
1032#else
1033 (char_u *)NULL, PV_NONE,
1034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001036 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1038 (char_u *)&p_dex, PV_NONE,
1039 {(char_u *)"", (char_u *)0L}
1040#else
1041 (char_u *)NULL, PV_NONE,
1042 {(char_u *)0L, (char_u *)0L}
1043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001045 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1046 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047#ifdef FEAT_DIFF
1048 (char_u *)&p_dip, PV_NONE,
1049 {(char_u *)"filler", (char_u *)NULL}
1050#else
1051 (char_u *)NULL, PV_NONE,
1052 {(char_u *)"", (char_u *)NULL}
1053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1056#ifdef FEAT_DIGRAPHS
1057 (char_u *)&p_dg, PV_NONE,
1058#else
1059 (char_u *)NULL, PV_NONE,
1060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001062 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1063 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001066 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 (char_u *)&p_ead, PV_NONE,
1071 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1074 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001076 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1077#if defined(FEAT_MBYTE)
1078 (char_u *)&p_emoji, PV_NONE,
1079 {(char_u *)TRUE, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)0L, (char_u *)0L}
1083#endif
1084 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001085 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086#ifdef FEAT_MBYTE
1087 (char_u *)&p_enc, PV_NONE,
1088 {(char_u *)ENC_DFLT, (char_u *)0L}
1089#else
1090 (char_u *)NULL, PV_NONE,
1091 {(char_u *)0L, (char_u *)0L}
1092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1095 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1098 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001101 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1104 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1107#ifdef FEAT_QUICKFIX
1108 (char_u *)&p_ef, PV_NONE,
1109 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1110#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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001117 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#else
1120 (char_u *)NULL, PV_NONE,
1121 {(char_u *)NULL, (char_u *)0L}
1122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 {"esckeys", "ek", P_BOOL|P_VIM,
1125 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001127 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128#ifdef FEAT_AUTOCMD
1129 (char_u *)&p_ei, PV_NONE,
1130#else
1131 (char_u *)NULL, PV_NONE,
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1135 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1138 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1141 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_MBYTE
1143 (char_u *)&p_fenc, PV_FENC,
1144 {(char_u *)"", (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 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151#ifdef FEAT_MBYTE
1152 (char_u *)&p_fencs, PV_NONE,
1153 {(char_u *)"ucs-bom", (char_u *)0L}
1154#else
1155 (char_u *)NULL, PV_NONE,
1156 {(char_u *)0L, (char_u *)0L}
1157#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001158 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001159 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1160 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1166 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001167 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1168 (char_u *)&p_fic, PV_NONE,
1169 {
1170#ifdef CASE_INSENSITIVE_FILENAME
1171 (char_u *)TRUE,
1172#else
1173 (char_u *)FALSE,
1174#endif
1175 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001176 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177#ifdef FEAT_AUTOCMD
1178 (char_u *)&p_ft, PV_FT,
1179 {(char_u *)"", (char_u *)0L}
1180#else
1181 (char_u *)NULL, PV_NONE,
1182 {(char_u *)0L, (char_u *)0L}
1183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001185 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 (char_u *)&p_fcs, PV_NONE,
1187 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001189 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1190 (char_u *)&p_fixeol, PV_FIXEOL,
1191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1193#ifdef FEAT_FKMAP
1194 (char_u *)&p_fkmap, PV_NONE,
1195#else
1196 (char_u *)NULL, PV_NONE,
1197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"flash", "fl", P_BOOL|P_VI_DEF,
1200 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001202 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001203#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001205 {(char_u *)"", (char_u *)0L}
1206#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209#endif
1210 SCRIPTID_INIT},
1211 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1212#ifdef FEAT_FOLDING
1213 (char_u *)VAR_WIN, PV_FDC,
1214 {(char_u *)FALSE, (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 SCRIPTID_INIT},
1220 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1221#ifdef FEAT_FOLDING
1222 (char_u *)VAR_WIN, PV_FEN,
1223 {(char_u *)TRUE, (char_u *)0L}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
1228 SCRIPTID_INIT},
1229 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1230#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1231 (char_u *)VAR_WIN, PV_FDE,
1232 {(char_u *)"0", (char_u *)NULL}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|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_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001241 {(char_u *)"#", (char_u *)NULL}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250 {(char_u *)0L, (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
1255 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001256 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001259 {(char_u *)-1L, (char_u *)0L}
1260#else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)NULL, (char_u *)0L}
1263#endif
1264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001266 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001267#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001270#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001274 SCRIPTID_INIT},
1275 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1276#ifdef FEAT_FOLDING
1277 (char_u *)VAR_WIN, PV_FDM,
1278 {(char_u *)"manual", (char_u *)NULL}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
1284 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1285#ifdef FEAT_FOLDING
1286 (char_u *)VAR_WIN, PV_FML,
1287 {(char_u *)1L, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291#endif
1292 SCRIPTID_INIT},
1293 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1294#ifdef FEAT_FOLDING
1295 (char_u *)VAR_WIN, PV_FDN,
1296 {(char_u *)20L, (char_u *)0L}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
1301 SCRIPTID_INIT},
1302 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1303#ifdef FEAT_FOLDING
1304 (char_u *)&p_fdo, PV_NONE,
1305 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1306 (char_u *)0L}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
1312 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1313#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1314 (char_u *)VAR_WIN, PV_FDT,
1315 {(char_u *)"foldtext()", (char_u *)NULL}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)NULL, (char_u *)0L}
1319#endif
1320 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001321 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001322#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001323 (char_u *)&p_fex, PV_FEX,
1324 {(char_u *)"", (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)0L, (char_u *)0L}
1328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001329 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1331 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1333 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001334 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1335 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1337 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001339 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001341 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1342#ifdef HAVE_FSYNC
1343 (char_u *)&p_fs, PV_NONE,
1344 {(char_u *)TRUE, (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)FALSE, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1351 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"graphic", "gr", P_BOOL|P_VI_DEF,
1354 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001356 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357#ifdef FEAT_QUICKFIX
1358 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360#else
1361 (char_u *)NULL, PV_NONE,
1362 {(char_u *)NULL, (char_u *)0L}
1363#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1366#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001367 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {
1369# ifdef WIN3264
1370 /* may be changed to "grep -n" in os_win32.c */
1371 (char_u *)"findstr /n",
1372# else
1373# ifdef UNIX
1374 /* Add an extra file name so that grep will always
1375 * insert a file name in the match line. */
1376 (char_u *)"grep -n $* /dev/null",
1377# else
1378# ifdef VMS
1379 (char_u *)"SEARCH/NUMBERS ",
1380# else
1381 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382# endif
1383# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#else
1387 (char_u *)NULL, PV_NONE,
1388 {(char_u *)NULL, (char_u *)0L}
1389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001390 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001391 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392#ifdef CURSOR_SHAPE
1393 (char_u *)&p_guicursor, PV_NONE,
1394 {
1395# ifdef FEAT_GUI
1396 (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 +01001397# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1399# endif
1400 (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 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#ifdef FEAT_GUI
1408 (char_u *)&p_guifont, 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 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1417 (char_u *)&p_guifontset, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1426 (char_u *)&p_guifontwide, PV_NONE,
1427 {(char_u *)"", (char_u *)0L}
1428#else
1429 (char_u *)NULL, PV_NONE,
1430 {(char_u *)NULL, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001434#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 (char_u *)&p_ghr, PV_NONE,
1436#else
1437 (char_u *)NULL, PV_NONE,
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001441#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001443# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001444 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001446 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447# endif
1448#else
1449 (char_u *)NULL, PV_NONE,
1450 {(char_u *)NULL, (char_u *)0L}
1451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"guipty", NULL, P_BOOL|P_VI_DEF,
1454#if defined(FEAT_GUI)
1455 (char_u *)&p_guipty, PV_NONE,
1456#else
1457 (char_u *)NULL, PV_NONE,
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001460 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001461#if defined(FEAT_GUI_TABLINE)
1462 (char_u *)&p_gtl, 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 Moolenaarf9393ef2006-04-24 19:47:27 +00001469 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001470#if defined(FEAT_GUI_TABLINE)
1471 (char_u *)&p_gtt, PV_NONE,
1472 {(char_u *)"", (char_u *)0L}
1473#else
1474 (char_u *)NULL, PV_NONE,
1475 {(char_u *)NULL, (char_u *)0L}
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1479 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1482 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1484 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001488 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489#ifdef FEAT_MULTI_LANG
1490 (char_u *)&p_hlg, PV_NONE,
1491 {(char_u *)"", (char_u *)0L}
1492#else
1493 (char_u *)NULL, PV_NONE,
1494 {(char_u *)0L, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"hidden", "hid", P_BOOL|P_VI_DEF,
1498 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001500 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1503 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"history", "hi", P_NUM|P_VIM,
1505 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001506 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1508#ifdef FEAT_RIGHTLEFT
1509 (char_u *)&p_hkmap, PV_NONE,
1510#else
1511 (char_u *)NULL, PV_NONE,
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1515#ifdef FEAT_RIGHTLEFT
1516 (char_u *)&p_hkmapp, PV_NONE,
1517#else
1518 (char_u *)NULL, PV_NONE,
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1522 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 {"icon", NULL, P_BOOL|P_VI_DEF,
1525#ifdef FEAT_TITLE
1526 (char_u *)&p_icon, PV_NONE,
1527#else
1528 (char_u *)NULL, PV_NONE,
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"iconstring", NULL, P_STRING|P_VI_DEF,
1532#ifdef FEAT_TITLE
1533 (char_u *)&p_iconstring, PV_NONE,
1534#else
1535 (char_u *)NULL, PV_NONE,
1536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001537 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1539 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001541 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001542#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001543 (char_u *)&p_imaf, PV_NONE,
1544 {(char_u *)"", (char_u *)NULL}
1545# else
1546 (char_u *)NULL, PV_NONE,
1547 {(char_u *)NULL, (char_u *)0L}
1548# endif
1549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001551#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 (char_u *)&p_imak, PV_NONE,
1553#else
1554 (char_u *)NULL, PV_NONE,
1555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001558#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559 (char_u *)&p_imcmdline, PV_NONE,
1560#else
1561 (char_u *)NULL, PV_NONE,
1562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001565#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 (char_u *)&p_imdisable, PV_NONE,
1567#else
1568 (char_u *)NULL, PV_NONE,
1569#endif
1570#ifdef __sgi
1571 {(char_u *)TRUE, (char_u *)0L}
1572#else
1573 {(char_u *)FALSE, (char_u *)0L}
1574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001575 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576 {"iminsert", "imi", P_NUM|P_VI_DEF,
1577 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imsearch", "ims", P_NUM|P_VI_DEF,
1581 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001582 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001584 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001585#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001586 (char_u *)&p_imsf, PV_NONE,
1587 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001588#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001591#endif
1592 SCRIPTID_INIT},
1593 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1594#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1595 (char_u *)&p_imst, PV_NONE,
1596 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1603#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001604 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 {(char_u *)"^\\s*#\\s*include", (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 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1612#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1613 (char_u *)&p_inex, PV_INEX,
1614 {(char_u *)"", (char_u *)0L}
1615#else
1616 (char_u *)NULL, PV_NONE,
1617 {(char_u *)0L, (char_u *)0L}
1618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1621 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1624#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 (char_u *)&p_inde, PV_INDE,
1626 {(char_u *)"", (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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001632 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1634 (char_u *)&p_indk, PV_INDK,
1635 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1636#else
1637 (char_u *)NULL, PV_NONE,
1638 {(char_u *)0L, (char_u *)0L}
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"infercase", "inf", P_BOOL|P_VI_DEF,
1642 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1645 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1648 (char_u *)&p_isf, PV_NONE,
1649 {
1650#ifdef BACKSLASH_IN_FILENAME
1651 /* Excluded are: & and ^ are special in cmd.exe
1652 * ( and ) are used in text separating fnames */
1653 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1654#else
1655# ifdef AMIGA
1656 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1657# else
1658# ifdef VMS
1659 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1660# else /* UNIX et al. */
1661# ifdef EBCDIC
1662 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1663# else
1664 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1665# endif
1666# endif
1667# endif
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1671 (char_u *)&p_isi, PV_NONE,
1672 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001673#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 (char_u *)"@,48-57,_,128-167,224-235",
1675#else
1676# ifdef EBCDIC
1677 /* TODO: EBCDIC Check this! @ == isalpha()*/
1678 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1679 "112-120,128,140-142,156,158,172,"
1680 "174,186,191,203-207,219-225,235-239,"
1681 "251-254",
1682# else
1683 (char_u *)"@,48-57,_,192-255",
1684# endif
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1688 (char_u *)&p_isk, PV_ISK,
1689 {
1690#ifdef EBCDIC
1691 (char_u *)"@,240-249,_",
1692 /* TODO: EBCDIC Check this! @ == isalpha()*/
1693 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1694 "112-120,128,140-142,156,158,172,"
1695 "174,186,191,203-207,219-225,235-239,"
1696 "251-254",
1697#else
1698 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001699# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)"@,48-57,_,128-167,224-235"
1701# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001702 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703# endif
1704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1707 (char_u *)&p_isp, PV_NONE,
1708 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001709#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 (char_u *)"@,~-255",
1711#else
1712# ifdef EBCDIC
1713 /* all chars above 63 are printable */
1714 (char_u *)"63-255",
1715# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001716 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717# endif
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1721 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1724#ifdef FEAT_CRYPT
1725 (char_u *)&p_key, PV_KEY,
1726 {(char_u *)"", (char_u *)0L}
1727#else
1728 (char_u *)NULL, PV_NONE,
1729 {(char_u *)0L, (char_u *)0L}
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001732 {"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 +00001733#ifdef FEAT_KEYMAP
1734 (char_u *)&p_keymap, PV_KMAP,
1735 {(char_u *)"", (char_u *)0L}
1736#else
1737 (char_u *)NULL, PV_NONE,
1738 {(char_u *)"", (char_u *)0L}
1739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001740 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001741 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001745 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001747#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 (char_u *)":help",
1749#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001750# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001752# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001753# ifdef USEMAN_S
1754 (char_u *)"man -s",
1755# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001757# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758# endif
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001761 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#ifdef FEAT_LANGMAP
1763 (char_u *)&p_langmap, PV_NONE,
1764 {(char_u *)"", /* unmatched } */
1765#else
1766 (char_u *)NULL, PV_NONE,
1767 {(char_u *)NULL,
1768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001770 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1772 (char_u *)&p_lm, PV_NONE,
1773#else
1774 (char_u *)NULL, PV_NONE,
1775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001777 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1778#ifdef FEAT_LANGMAP
1779 (char_u *)&p_lnr, PV_NONE,
1780#else
1781 (char_u *)NULL, PV_NONE,
1782#endif
1783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001784 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1785#ifdef FEAT_LANGMAP
1786 (char_u *)&p_lrm, PV_NONE,
1787#else
1788 (char_u *)NULL, PV_NONE,
1789#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001790 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1795 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1798#ifdef FEAT_LINEBREAK
1799 (char_u *)VAR_WIN, PV_LBR,
1800#else
1801 (char_u *)NULL, PV_NONE,
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1805 (char_u *)&Rows, PV_NONE,
1806 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001807#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 (char_u *)25L,
1809#else
1810 (char_u *)24L,
1811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1814#ifdef FEAT_GUI
1815 (char_u *)&p_linespace, PV_NONE,
1816#else
1817 (char_u *)NULL, PV_NONE,
1818#endif
1819#ifdef FEAT_GUI_W32
1820 {(char_u *)1L, (char_u *)0L}
1821#else
1822 {(char_u *)0L, (char_u *)0L}
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"lisp", NULL, P_BOOL|P_VI_DEF,
1826#ifdef FEAT_LISP
1827 (char_u *)&p_lisp, PV_LISP,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001832 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001834 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1836#else
1837 (char_u *)NULL, PV_NONE,
1838 {(char_u *)"", (char_u *)0L}
1839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1842 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001844 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001846 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1848 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001850 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001851#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001852 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001853 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)"", (char_u *)0L}
1857#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001858 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001859 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001860#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001861 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001862 {(char_u *)TRUE, (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001866#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"magic", NULL, P_BOOL|P_VI_DEF,
1869 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001871 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872#ifdef FEAT_QUICKFIX
1873 (char_u *)&p_mef, PV_NONE,
1874 {(char_u *)"", (char_u *)0L}
1875#else
1876 (char_u *)NULL, PV_NONE,
1877 {(char_u *)NULL, (char_u *)0L}
1878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001880 {"makeencoding","menc", P_STRING|P_VI_DEF,
1881#ifdef FEAT_MBYTE
1882 (char_u *)&p_menc, PV_MENC,
1883 {(char_u *)"", (char_u *)0L}
1884#else
1885 (char_u *)NULL, PV_NONE,
1886 {(char_u *)0L, (char_u *)0L}
1887#endif
1888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1890#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001891 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892# ifdef VMS
1893 {(char_u *)"MMS", (char_u *)0L}
1894# else
1895 {(char_u *)"make", (char_u *)0L}
1896# endif
1897#else
1898 (char_u *)NULL, PV_NONE,
1899 {(char_u *)NULL, (char_u *)0L}
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001902 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1905 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"matchtime", "mat", P_NUM|P_VI_DEF,
1907 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001909 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001910#ifdef FEAT_MBYTE
1911 (char_u *)&p_mco, PV_NONE,
1912#else
1913 (char_u *)NULL, PV_NONE,
1914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1917#ifdef FEAT_EVAL
1918 (char_u *)&p_mfd, PV_NONE,
1919#else
1920 (char_u *)NULL, PV_NONE,
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1924 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"maxmem", "mm", P_NUM|P_VI_DEF,
1927 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1929 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001930 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1931 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001932 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1934 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"menuitems", "mis", P_NUM|P_VI_DEF,
1938#ifdef FEAT_MENU
1939 (char_u *)&p_mis, PV_NONE,
1940#else
1941 (char_u *)NULL, PV_NONE,
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"mesg", NULL, P_BOOL|P_VI_DEF,
1945 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001947 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001948#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001949 (char_u *)&p_msm, PV_NONE,
1950 {(char_u *)"460000,2000,500", (char_u *)0L}
1951#else
1952 (char_u *)NULL, PV_NONE,
1953 {(char_u *)0L, (char_u *)0L}
1954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"modeline", "ml", P_BOOL|P_VIM,
1957 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"modelines", "mls", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1963 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1966 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"more", NULL, P_BOOL|P_VIM,
1969 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1972 (char_u *)&p_mouse, PV_NONE,
1973 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001974#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 (char_u *)"a",
1976#else
1977 (char_u *)"",
1978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001979 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1981#ifdef FEAT_GUI
1982 (char_u *)&p_mousef, PV_NONE,
1983#else
1984 (char_u *)NULL, PV_NONE,
1985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1988#ifdef FEAT_GUI
1989 (char_u *)&p_mh, PV_NONE,
1990#else
1991 (char_u *)NULL, PV_NONE,
1992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1995 (char_u *)&p_mousem, PV_NONE,
1996 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001997#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 (char_u *)"popup",
1999#else
Bram Moolenaard0573012017-10-28 21:11:06 +02002000# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)"popup_setpos",
2002# else
2003 (char_u *)"extend",
2004# endif
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002007 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008#ifdef FEAT_MOUSESHAPE
2009 (char_u *)&p_mouseshape, PV_NONE,
2010 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2011#else
2012 (char_u *)NULL, PV_NONE,
2013 {(char_u *)NULL, (char_u *)0L}
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2017 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002019 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2020#if defined(DYNAMIC_MZSCHEME)
2021 (char_u *)&p_mzschemedll, PV_NONE,
2022 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)"", (char_u *)0L}
2026#endif
2027 SCRIPTID_INIT},
2028 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2029#if defined(DYNAMIC_MZSCHEME)
2030 (char_u *)&p_mzschemegcdll, PV_NONE,
2031 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)"", (char_u *)0L}
2035#endif
2036 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002037 {"mzquantum", "mzq", P_NUM,
2038#ifdef FEAT_MZSCHEME
2039 (char_u *)&p_mzq, PV_NONE,
2040#else
2041 (char_u *)NULL, PV_NONE,
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 {"novice", NULL, P_BOOL|P_VI_DEF,
2045 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002047 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002049 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2052 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002054 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2055#ifdef FEAT_LINEBREAK
2056 (char_u *)VAR_WIN, PV_NUW,
2057#else
2058 (char_u *)NULL, PV_NONE,
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002061 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002062#ifdef FEAT_COMPL_FUNC
2063 (char_u *)&p_ofu, PV_OFU,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)0L, (char_u *)0L}
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"open", NULL, P_BOOL|P_VI_DEF,
2071 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002073 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002074#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002075 (char_u *)&p_odev, PV_NONE,
2076#else
2077 (char_u *)NULL, PV_NONE,
2078#endif
2079 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002081 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2082 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"optimize", "opt", P_BOOL|P_VI_DEF,
2085 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002089 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002090 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2091 |P_SECURE,
2092 (char_u *)&p_pp, PV_NONE,
2093 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"paragraphs", "para", P_STRING|P_VI_DEF,
2096 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002097 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002099 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2103 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2106#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2107 (char_u *)&p_pex, PV_NONE,
2108 {(char_u *)"", (char_u *)0L}
2109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)0L, (char_u *)0L}
2112#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002114 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002118 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002120#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 (char_u *)".,,",
2122#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002126 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002127#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002128 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002129 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002134 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2136 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002138 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002139#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 (char_u *)&p_pvh, PV_NONE,
2141#else
2142 (char_u *)NULL, PV_NONE,
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002146#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 (char_u *)VAR_WIN, PV_PVW,
2148#else
2149 (char_u *)NULL, PV_NONE,
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002152 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153#ifdef FEAT_PRINTER
2154 (char_u *)&p_pdev, 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 Moolenaar071d4272004-06-13 20:20:40 +00002161 {"printencoding", "penc", P_STRING|P_VI_DEF,
2162#ifdef FEAT_POSTSCRIPT
2163 (char_u *)&p_penc, 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 Moolenaar031cb742016-11-24 21:46:19 +01002170 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171#ifdef FEAT_POSTSCRIPT
2172 (char_u *)&p_pexpr, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"printfont", "pfn", P_STRING|P_VI_DEF,
2180#ifdef FEAT_PRINTER
2181 (char_u *)&p_pfn, PV_NONE,
2182 {
2183# ifdef MSWIN
2184 (char_u *)"Courier_New:h10",
2185# else
2186 (char_u *)"courier",
2187# endif
2188 (char_u *)0L}
2189#else
2190 (char_u *)NULL, PV_NONE,
2191 {(char_u *)NULL, (char_u *)0L}
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2195#ifdef FEAT_PRINTER
2196 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002197 /* untranslated to avoid problems when 'encoding'
2198 * is changed */
2199 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200#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 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2206#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2207 (char_u *)&p_pmcs, 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 Moolenaar8299df92004-07-10 09:47:34 +00002214 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2215#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2216 (char_u *)&p_pmfn, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002223 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224#ifdef FEAT_PRINTER
2225 (char_u *)&p_popt, PV_NONE,
2226 {(char_u *)"", (char_u *)0L}
2227#else
2228 (char_u *)NULL, PV_NONE,
2229 {(char_u *)NULL, (char_u *)0L}
2230#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002231 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002233 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002235 {"pumheight", "ph", P_NUM|P_VI_DEF,
2236#ifdef FEAT_INS_EXPAND
2237 (char_u *)&p_ph, PV_NONE,
2238#else
2239 (char_u *)NULL, PV_NONE,
2240#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002242 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2243#ifdef FEAT_INS_EXPAND
2244 (char_u *)&p_pw, PV_NONE,
2245#else
2246 (char_u *)NULL, PV_NONE,
2247#endif
Bram Moolenaar42443c72018-02-10 18:28:52 +01002248 {(char_u *)15L, (char_u *)15L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002249 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002251 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002252 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002253#else
2254 (char_u *)NULL, PV_NONE,
2255 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002256#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002257 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002258 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2259#if defined(FEAT_PYTHON3)
2260 (char_u *)&p_py3home, PV_NONE,
2261 {(char_u *)"", (char_u *)0L}
2262#else
2263 (char_u *)NULL, PV_NONE,
2264 {(char_u *)NULL, (char_u *)0L}
2265#endif
2266 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002267 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002268#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002269 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002270 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002271#else
2272 (char_u *)NULL, PV_NONE,
2273 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002274#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002275 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002276 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2277#if defined(FEAT_PYTHON)
2278 (char_u *)&p_pyhome, PV_NONE,
2279 {(char_u *)"", (char_u *)0L}
2280#else
2281 (char_u *)NULL, PV_NONE,
2282 {(char_u *)NULL, (char_u *)0L}
2283#endif
2284 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002285 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2286#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2287 (char_u *)&p_pyx, PV_NONE,
2288#else
2289 (char_u *)NULL, PV_NONE,
2290#endif
2291 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2292 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002293 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2294#ifdef FEAT_TEXTOBJ
2295 (char_u *)&p_qe, PV_QE,
2296 {(char_u *)"\\", (char_u *)0L}
2297#else
2298 (char_u *)NULL, PV_NONE,
2299 {(char_u *)NULL, (char_u *)0L}
2300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2303 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"redraw", NULL, P_BOOL|P_VI_DEF,
2306 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002308 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2309#ifdef FEAT_RELTIME
2310 (char_u *)&p_rdt, PV_NONE,
2311#else
2312 (char_u *)NULL, PV_NONE,
2313#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002315 {"regexpengine", "re", P_NUM|P_VI_DEF,
2316 (char_u *)&p_re, PV_NONE,
2317 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002318 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2319 (char_u *)VAR_WIN, PV_RNU,
2320 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"remap", NULL, P_BOOL|P_VI_DEF,
2322 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002324 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002325#ifdef FEAT_RENDER_OPTIONS
2326 (char_u *)&p_rop, PV_NONE,
2327 {(char_u *)"", (char_u *)0L}
2328#else
2329 (char_u *)NULL, PV_NONE,
2330 {(char_u *)NULL, (char_u *)0L}
2331#endif
2332 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"report", NULL, P_NUM|P_VI_DEF,
2334 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2337#ifdef WIN3264
2338 (char_u *)&p_rs, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2344#ifdef FEAT_RIGHTLEFT
2345 (char_u *)&p_ri, PV_NONE,
2346#else
2347 (char_u *)NULL, PV_NONE,
2348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2351#ifdef FEAT_RIGHTLEFT
2352 (char_u *)VAR_WIN, PV_RL,
2353#else
2354 (char_u *)NULL, PV_NONE,
2355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2358#ifdef FEAT_RIGHTLEFT
2359 (char_u *)VAR_WIN, PV_RLC,
2360 {(char_u *)"search", (char_u *)NULL}
2361#else
2362 (char_u *)NULL, PV_NONE,
2363 {(char_u *)NULL, (char_u *)0L}
2364#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002366 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002367#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002368 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002369 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002370#else
2371 (char_u *)NULL, PV_NONE,
2372 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002373#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002374 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2376#ifdef FEAT_CMDL_INFO
2377 (char_u *)&p_ru, PV_NONE,
2378#else
2379 (char_u *)NULL, PV_NONE,
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2383#ifdef FEAT_STL_OPT
2384 (char_u *)&p_ruf, PV_NONE,
2385#else
2386 (char_u *)NULL, PV_NONE,
2387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002389 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2390 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2393 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2395 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002396 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2398#ifdef FEAT_SCROLLBIND
2399 (char_u *)VAR_WIN, PV_SCBIND,
2400#else
2401 (char_u *)NULL, PV_NONE,
2402#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2405 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2408 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002410 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411#ifdef FEAT_SCROLLBIND
2412 (char_u *)&p_sbo, PV_NONE,
2413 {(char_u *)"ver,jump", (char_u *)0L}
2414#else
2415 (char_u *)NULL, PV_NONE,
2416 {(char_u *)0L, (char_u *)0L}
2417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"sections", "sect", P_STRING|P_VI_DEF,
2420 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2422 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2424 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)"inclusive", (char_u *)0L}
2429 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002430 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002433 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434#ifdef FEAT_SESSION
2435 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002436 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 (char_u *)0L}
2438#else
2439 (char_u *)NULL, PV_NONE,
2440 {(char_u *)0L, (char_u *)0L}
2441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2444 (char_u *)&p_sh, PV_NONE,
2445 {
2446#ifdef VMS
2447 (char_u *)"-",
2448#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002449# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002451# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453# endif
2454#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2457 (char_u *)&p_shcf, PV_NONE,
2458 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002459#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 (char_u *)"/c",
2461#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2466#ifdef FEAT_QUICKFIX
2467 (char_u *)&p_sp, PV_NONE,
2468 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002469#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471#else
2472 (char_u *)">",
2473#endif
2474 (char_u *)0L}
2475#else
2476 (char_u *)NULL, PV_NONE,
2477 {(char_u *)0L, (char_u *)0L}
2478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2481 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2484 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2487#ifdef BACKSLASH_IN_FILENAME
2488 (char_u *)&p_ssl, PV_NONE,
2489#else
2490 (char_u *)NULL, PV_NONE,
2491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002493 {"shelltemp", "stmp", P_BOOL,
2494 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"shelltype", "st", P_NUM|P_VI_DEF,
2497#ifdef AMIGA
2498 (char_u *)&p_st, PV_NONE,
2499#else
2500 (char_u *)NULL, PV_NONE,
2501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002502 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2504 (char_u *)&p_sxq, PV_NONE,
2505 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002506#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 (char_u *)"\"",
2508#else
2509 (char_u *)"",
2510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002512 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2513 (char_u *)&p_sxe, PV_NONE,
2514 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002515#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002516 (char_u *)"\"&|<>()@^",
2517#else
2518 (char_u *)"",
2519#endif
2520 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2522 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2525 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2528 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)"", (char_u *)"filnxtToO"}
2530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2535#ifdef FEAT_LINEBREAK
2536 (char_u *)&p_sbr, PV_NONE,
2537#else
2538 (char_u *)NULL, PV_NONE,
2539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"showcmd", "sc", P_BOOL|P_VIM,
2542#ifdef FEAT_CMDL_INFO
2543 (char_u *)&p_sc, PV_NONE,
2544#else
2545 (char_u *)NULL, PV_NONE,
2546#endif
2547 {(char_u *)FALSE,
2548#ifdef UNIX
2549 (char_u *)FALSE
2550#else
2551 (char_u *)TRUE
2552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2555 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2558 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"showmode", "smd", P_BOOL|P_VIM,
2561 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002563 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002564 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2567 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2570 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002572 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2573#ifdef FEAT_SIGNS
2574 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002575 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002576#else
2577 (char_u *)NULL, PV_NONE,
2578 {(char_u *)NULL, (char_u *)0L}
2579#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002580 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002581 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2582 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2585 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2588#ifdef FEAT_SMARTINDENT
2589 (char_u *)&p_si, PV_SI,
2590#else
2591 (char_u *)NULL, PV_NONE,
2592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2595 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2598 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002599 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2601 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002602 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002603 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002604#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002605 (char_u *)VAR_WIN, PV_SPELL,
2606#else
2607 (char_u *)NULL, PV_NONE,
2608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002610 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002611#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002612 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002613 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002614#else
2615 (char_u *)NULL, PV_NONE,
2616 {(char_u *)0L, (char_u *)0L}
2617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002619 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2620 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002621#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002622 (char_u *)&p_spf, PV_SPF,
2623 {(char_u *)"", (char_u *)0L}
2624#else
2625 (char_u *)NULL, PV_NONE,
2626 {(char_u *)0L, (char_u *)0L}
2627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002629 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2630 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002631#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002632 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002633 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002634#else
2635 (char_u *)NULL, PV_NONE,
2636 {(char_u *)0L, (char_u *)0L}
2637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002638 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002639 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002640#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002641 (char_u *)&p_sps, PV_NONE,
2642 {(char_u *)"best", (char_u *)0L}
2643#else
2644 (char_u *)NULL, PV_NONE,
2645 {(char_u *)0L, (char_u *)0L}
2646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2655 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2658#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002659 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660#else
2661 (char_u *)NULL, PV_NONE,
2662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002664 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 (char_u *)&p_su, PV_NONE,
2666 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002668 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002669#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 (char_u *)&p_sua, PV_SUA,
2671 {(char_u *)"", (char_u *)0L}
2672#else
2673 (char_u *)NULL, PV_NONE,
2674 {(char_u *)0L, (char_u *)0L}
2675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2678 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002679 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"swapsync", "sws", P_STRING|P_VI_DEF,
2681 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002683 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002685 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002686 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2687#ifdef FEAT_SYN_HL
2688 (char_u *)&p_smc, PV_SMC,
2689 {(char_u *)3000L, (char_u *)0L}
2690#else
2691 (char_u *)NULL, PV_NONE,
2692 {(char_u *)0L, (char_u *)0L}
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002695 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696#ifdef FEAT_SYN_HL
2697 (char_u *)&p_syn, PV_SYN,
2698 {(char_u *)"", (char_u *)0L}
2699#else
2700 (char_u *)NULL, PV_NONE,
2701 {(char_u *)0L, (char_u *)0L}
2702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002704 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2705#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002706 (char_u *)&p_tal, PV_NONE,
2707#else
2708 (char_u *)NULL, PV_NONE,
2709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002711 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002712 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2715 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2718 (char_u *)&p_tbs, PV_NONE,
2719#ifdef VMS /* binary searching doesn't appear to work on VMS */
2720 {(char_u *)0L, (char_u *)0L}
2721#else
2722 {(char_u *)TRUE, (char_u *)0L}
2723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002725 {"tagcase", "tc", P_STRING|P_VIM,
2726 (char_u *)&p_tc, PV_TC,
2727 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"taglength", "tl", P_NUM|P_VI_DEF,
2729 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"tagrelative", "tr", P_BOOL|P_VIM,
2732 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002733 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002734 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002735 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 {
2737#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2738 (char_u *)"./tags,./TAGS,tags,TAGS",
2739#else
2740 (char_u *)"./tags,tags",
2741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002742 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2744 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002745 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002746 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002747#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002748 (char_u *)&p_tcldll, PV_NONE,
2749 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002750#else
2751 (char_u *)NULL, PV_NONE,
2752 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002753#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002754 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2756 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002757 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2759#ifdef FEAT_ARABIC
2760 (char_u *)&p_tbidi, PV_NONE,
2761#else
2762 (char_u *)NULL, PV_NONE,
2763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2766#ifdef FEAT_MBYTE
2767 (char_u *)&p_tenc, PV_NONE,
2768 {(char_u *)"", (char_u *)0L}
2769#else
2770 (char_u *)NULL, PV_NONE,
2771 {(char_u *)0L, (char_u *)0L}
2772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002774 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2775#ifdef FEAT_TERMGUICOLORS
2776 (char_u *)&p_tgc, PV_NONE,
2777 {(char_u *)FALSE, (char_u *)FALSE}
2778#else
2779 (char_u*)NULL, PV_NONE,
2780 {(char_u *)FALSE, (char_u *)FALSE}
2781#endif
2782 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002783 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2784#ifdef FEAT_TERMINAL
2785 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002786 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002787#else
2788 (char_u *)NULL, PV_NONE,
2789 {(char_u *)NULL, (char_u *)0L}
2790#endif
2791 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002792 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2793#ifdef FEAT_TERMINAL
2794 (char_u *)VAR_WIN, PV_TMS,
2795 {(char_u *)"", (char_u *)NULL}
2796#else
2797 (char_u *)NULL, PV_NONE,
2798 {(char_u *)NULL, (char_u *)0L}
2799#endif
2800 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 {"terse", NULL, P_BOOL|P_VI_DEF,
2802 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002803 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 {"textauto", "ta", P_BOOL|P_VIM,
2805 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2807 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2809 (char_u *)&p_tx, PV_TX,
2810 {
2811#ifdef USE_CRNL
2812 (char_u *)TRUE,
2813#else
2814 (char_u *)FALSE,
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002817 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002820 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002822 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823#else
2824 (char_u *)NULL, PV_NONE,
2825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2828 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"timeout", "to", P_BOOL|P_VI_DEF,
2831 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2834 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"title", NULL, P_BOOL|P_VI_DEF,
2837#ifdef FEAT_TITLE
2838 (char_u *)&p_title, PV_NONE,
2839#else
2840 (char_u *)NULL, PV_NONE,
2841#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"titlelen", NULL, P_NUM|P_VI_DEF,
2844#ifdef FEAT_TITLE
2845 (char_u *)&p_titlelen, PV_NONE,
2846#else
2847 (char_u *)NULL, PV_NONE,
2848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002850 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851#ifdef FEAT_TITLE
2852 (char_u *)&p_titleold, PV_NONE,
2853 {(char_u *)N_("Thanks for flying Vim"),
2854 (char_u *)0L}
2855#else
2856 (char_u *)NULL, PV_NONE,
2857 {(char_u *)0L, (char_u *)0L}
2858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"titlestring", NULL, P_STRING|P_VI_DEF,
2861#ifdef FEAT_TITLE
2862 (char_u *)&p_titlestring, PV_NONE,
2863#else
2864 (char_u *)NULL, PV_NONE,
2865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002867 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002868#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002871#else
2872 (char_u *)NULL, PV_NONE,
2873 {(char_u *)0L, (char_u *)0L}
2874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002877#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002879 {(char_u *)"small", (char_u *)0L}
2880#else
2881 (char_u *)NULL, PV_NONE,
2882 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002884 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2886 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002887 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2889 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2892 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2895 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2898#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2899 (char_u *)&p_ttym, PV_NONE,
2900#else
2901 (char_u *)NULL, PV_NONE,
2902#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002903 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2905 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002906 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2908 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002910 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2911 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002912#ifdef FEAT_PERSISTENT_UNDO
2913 (char_u *)&p_udir, PV_NONE,
2914 {(char_u *)".", (char_u *)0L}
2915#else
2916 (char_u *)NULL, PV_NONE,
2917 {(char_u *)0L, (char_u *)0L}
2918#endif
2919 SCRIPTID_INIT},
2920 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2921#ifdef FEAT_PERSISTENT_UNDO
2922 (char_u *)&p_udf, PV_UDF,
2923#else
2924 (char_u *)NULL, PV_NONE,
2925#endif
2926 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002928 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002930#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 (char_u *)1000L,
2932#else
2933 (char_u *)100L,
2934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002936 {"undoreload", "ur", P_NUM|P_VI_DEF,
2937 (char_u *)&p_ur, PV_NONE,
2938 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 {"updatecount", "uc", P_NUM|P_VI_DEF,
2940 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002941 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 {"updatetime", "ut", P_NUM|P_VI_DEF,
2943 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945 {"verbose", "vbs", P_NUM|P_VI_DEF,
2946 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002948 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2949 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2952#ifdef FEAT_SESSION
2953 (char_u *)&p_vdir, PV_NONE,
2954 {(char_u *)DFLT_VDIR, (char_u *)0L}
2955#else
2956 (char_u *)NULL, PV_NONE,
2957 {(char_u *)0L, (char_u *)0L}
2958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002959 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002960 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961#ifdef FEAT_SESSION
2962 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002963 {(char_u *)"folds,options,cursor,curdir",
2964 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965#else
2966 (char_u *)NULL, PV_NONE,
2967 {(char_u *)0L, (char_u *)0L}
2968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002969 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002970 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971#ifdef FEAT_VIMINFO
2972 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002973#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002974 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975#else
2976# ifdef AMIGA
2977 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002978 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002980 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981# endif
2982#endif
2983#else
2984 (char_u *)NULL, PV_NONE,
2985 {(char_u *)0L, (char_u *)0L}
2986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002988 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2989#ifdef FEAT_VIMINFO
2990 (char_u *)&p_viminfofile, PV_NONE,
2991 {(char_u *)"", (char_u *)0L}
2992#else
2993 (char_u *)NULL, PV_NONE,
2994 {(char_u *)0L, (char_u *)0L}
2995#endif
2996 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002997 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2998 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999#ifdef FEAT_VIRTUALEDIT
3000 (char_u *)&p_ve, PV_NONE,
3001 {(char_u *)"", (char_u *)""}
3002#else
3003 (char_u *)NULL, PV_NONE,
3004 {(char_u *)0L, (char_u *)0L}
3005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003006 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3008 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010 {"w300", NULL, P_NUM|P_VI_DEF,
3011 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003012 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 {"w1200", NULL, P_NUM|P_VI_DEF,
3014 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003015 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 {"w9600", NULL, P_NUM|P_VI_DEF,
3017 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003018 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 {"warn", NULL, P_BOOL|P_VI_DEF,
3020 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003021 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3023 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003025 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003027 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"wildchar", "wc", P_NUM|P_VIM,
3029 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003030 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3031 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003032 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003034 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003035 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036#ifdef FEAT_WILDIGN
3037 (char_u *)&p_wig, PV_NONE,
3038#else
3039 (char_u *)NULL, PV_NONE,
3040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003041 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003042 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3043 (char_u *)&p_wic, PV_NONE,
3044 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3046#ifdef FEAT_WILDMENU
3047 (char_u *)&p_wmnu, PV_NONE,
3048#else
3049 (char_u *)NULL, PV_NONE,
3050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003051 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003052 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003054 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003055 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3056#ifdef FEAT_CMDL_COMPL
3057 (char_u *)&p_wop, PV_NONE,
3058 {(char_u *)"", (char_u *)0L}
3059#else
3060 (char_u *)NULL, PV_NONE,
3061 {(char_u *)NULL, (char_u *)0L}
3062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3065#ifdef FEAT_WAK
3066 (char_u *)&p_wak, PV_NONE,
3067 {(char_u *)"menu", (char_u *)0L}
3068#else
3069 (char_u *)NULL, PV_NONE,
3070 {(char_u *)NULL, (char_u *)0L}
3071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003074 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003075 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003078 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003081 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003082 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003083 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003084 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003087 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003090 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003091 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003092#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003093 (char_u *)&p_winptydll, PV_NONE, {
3094# ifdef _WIN64
3095 (char_u *)"winpty64.dll",
3096# else
3097 (char_u *)"winpty32.dll",
3098# endif
3099 (char_u *)0L}
3100#else
3101 (char_u *)NULL, PV_NONE,
3102 {(char_u *)0L, (char_u *)0L}
3103#endif
3104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003107 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3109 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003110 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3112 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003113 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3115 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003116 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 {"write", NULL, P_BOOL|P_VI_DEF,
3118 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003119 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120 {"writeany", "wa", P_BOOL|P_VI_DEF,
3121 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003122 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3124 (char_u *)&p_wb, PV_NONE,
3125 {
3126#ifdef FEAT_WRITEBACKUP
3127 (char_u *)TRUE,
3128#else
3129 (char_u *)FALSE,
3130#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003131 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 {"writedelay", "wd", P_NUM|P_VI_DEF,
3133 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003134 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135
3136/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003137#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003139 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140
3141 p_term("t_AB", T_CAB)
3142 p_term("t_AF", T_CAF)
3143 p_term("t_AL", T_CAL)
3144 p_term("t_al", T_AL)
3145 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003146 p_term("t_BE", T_BE)
3147 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 p_term("t_cd", T_CD)
3149 p_term("t_ce", T_CE)
3150 p_term("t_cl", T_CL)
3151 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003152 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_Co", T_CCO)
3154 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003155 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 p_term("t_da", T_DA)
3159 p_term("t_db", T_DB)
3160 p_term("t_DL", T_CDL)
3161 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003162 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003163 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003165 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_IE", T_CIE)
3167 p_term("t_IS", T_CIS)
3168 p_term("t_ke", T_KE)
3169 p_term("t_ks", T_KS)
3170 p_term("t_le", T_LE)
3171 p_term("t_mb", T_MB)
3172 p_term("t_md", T_MD)
3173 p_term("t_me", T_ME)
3174 p_term("t_mr", T_MR)
3175 p_term("t_ms", T_MS)
3176 p_term("t_nd", T_ND)
3177 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003178 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003179 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003180 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003182 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 p_term("t_RV", T_CRV)
3184 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003185 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003187 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003188 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003189 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003191 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003193 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 p_term("t_te", T_TE)
3195 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003196 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003197 p_term("t_ts", T_TS)
3198 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 p_term("t_ue", T_UE)
3200 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003201 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 p_term("t_vb", T_VB)
3203 p_term("t_ve", T_VE)
3204 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003205 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206 p_term("t_vs", T_VS)
3207 p_term("t_WP", T_CWP)
3208 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003209 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210 p_term("t_xs", T_XS)
3211 p_term("t_ZH", T_CZH)
3212 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003213 p_term("t_8f", T_8F)
3214 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215
3216/* terminal key codes are not in here */
3217
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003218 /* end marker */
3219 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220};
3221
3222#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3223
3224#ifdef FEAT_MBYTE
3225static char *(p_ambw_values[]) = {"single", "double", NULL};
3226#endif
3227static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003228static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003230#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003231static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003232#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003233#ifdef FEAT_CMDL_COMPL
3234static char *(p_wop_values[]) = {"tagfile", NULL};
3235#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236#ifdef FEAT_WAK
3237static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3238#endif
3239static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3241static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243#ifdef FEAT_BROWSE
3244static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3245#endif
3246#ifdef FEAT_SCROLLBIND
3247static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3248#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003249static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003251#ifdef FEAT_AUTOCMD
3252static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3253#else
3254static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003256static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3258#ifdef FEAT_FOLDING
3259static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003260# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003262# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263 NULL};
3264static char *(p_fcl_values[]) = {"all", NULL};
3265#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003266#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003267static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003268#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003269#ifdef FEAT_SIGNS
3270static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static void set_option_default(int, int opt_flags, int compatible);
3274static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003275static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static char_u *term_bg_default(void);
3277static void did_set_option(int opt_idx, int opt_flags, int new_value);
3278static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281#endif
3282#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003285static char_u *option_expand(int opt_idx, char_u *val);
3286static void didset_options(void);
3287static void didset_options2(void);
3288static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003289#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003290static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003291#else
3292# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3293#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003294static void set_string_option_global(int opt_idx, char_u **varp);
3295static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3296static 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);
3297static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003298#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003304#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static char_u *did_set_spell_option(int is_spellfile);
3306static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003307#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003308#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003310#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003311static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3312static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3313static void check_redraw(long_u flags);
3314static int findoption(char_u *);
3315static int find_key_option(char_u *);
3316static void showoptions(int all, int opt_flags);
3317static int optval_default(struct vimoption *, char_u *varp);
3318static void showoneopt(struct vimoption *, int opt_flags);
3319static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3320static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3321static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3322static int istermoption(struct vimoption *);
3323static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3324static char_u *get_varp(struct vimoption *);
3325static void option_value2string(struct vimoption *, int opt_flags);
3326static void check_winopt(winopt_T *wop);
3327static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003329static void langmap_init(void);
3330static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003332static void paste_option_changed(void);
3333static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003335static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003337static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3338static int check_opt_strings(char_u *val, char **values, int);
3339static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003340#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003341static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343
3344/*
3345 * Initialize the options, first part.
3346 *
3347 * Called only once from main(), just after creating the first buffer.
3348 */
3349 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003350set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351{
3352 char_u *p;
3353 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003354 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355
3356#ifdef FEAT_LANGMAP
3357 langmap_init();
3358#endif
3359
3360 /* Be Vi compatible by default */
3361 p_cp = TRUE;
3362
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003363 /* Use POSIX compatibility when $VIM_POSIX is set. */
3364 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003365 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003366 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003367 set_string_default("shm", (char_u *)"A");
3368 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003369
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370 /*
3371 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003372 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003374 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003375#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003376 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003378 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379# endif
3380#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003381 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003382 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383
3384#ifdef FEAT_WILDIGN
3385 /*
3386 * Set the default for 'backupskip' to include environment variables for
3387 * temp files.
3388 */
3389 {
3390# ifdef UNIX
3391 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3392# else
3393 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3394# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003395 int len;
3396 garray_T ga;
3397 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398
3399 ga_init2(&ga, 1, 100);
3400 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3401 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003402 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403# ifdef UNIX
3404 if (*names[n] == NUL)
3405 p = (char_u *)"/tmp";
3406 else
3407# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003408 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409 if (p != NULL && *p != NUL)
3410 {
3411 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003412 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 if (ga_grow(&ga, len) == OK)
3414 {
3415 if (ga.ga_len > 0)
3416 STRCAT(ga.ga_data, ",");
3417 STRCAT(ga.ga_data, p);
3418 add_pathsep(ga.ga_data);
3419 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420 ga.ga_len += len;
3421 }
3422 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003423 if (mustfree)
3424 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425 }
3426 if (ga.ga_data != NULL)
3427 {
3428 set_string_default("bsk", ga.ga_data);
3429 vim_free(ga.ga_data);
3430 }
3431 }
3432#endif
3433
3434 /*
3435 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3436 */
3437 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003438 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003440#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3441 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3442#endif
3443 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003445 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003446 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447#else
3448# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003449 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003450 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003452 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453# endif
3454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003456 opt_idx = findoption((char_u *)"maxmem");
3457 if (opt_idx >= 0)
3458 {
3459#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003460 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3461 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003462#endif
3463 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3464 }
3465 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 }
3467
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468#ifdef FEAT_SEARCHPATH
3469 {
3470 char_u *cdpath;
3471 char_u *buf;
3472 int i;
3473 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003474 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475
3476 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003477 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478 if (cdpath != NULL)
3479 {
3480 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3481 if (buf != NULL)
3482 {
3483 buf[0] = ','; /* start with ",", current dir first */
3484 j = 1;
3485 for (i = 0; cdpath[i] != NUL; ++i)
3486 {
3487 if (vim_ispathlistsep(cdpath[i]))
3488 buf[j++] = ',';
3489 else
3490 {
3491 if (cdpath[i] == ' ' || cdpath[i] == ',')
3492 buf[j++] = '\\';
3493 buf[j++] = cdpath[i];
3494 }
3495 }
3496 buf[j] = NUL;
3497 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003498 if (opt_idx >= 0)
3499 {
3500 options[opt_idx].def_val[VI_DEFAULT] = buf;
3501 options[opt_idx].flags |= P_DEF_ALLOCED;
3502 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003503 else
3504 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003506 if (mustfree)
3507 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003508 }
3509 }
3510#endif
3511
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003512#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 /* Set print encoding on platforms that don't default to latin1 */
3514 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003515# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003516 (char_u *)"cp1252"
3517# else
3518# ifdef VMS
3519 (char_u *)"dec-mcs"
3520# else
3521# ifdef EBCDIC
3522 (char_u *)"ebcdic-uk"
3523# else
3524# ifdef MAC
3525 (char_u *)"mac-roman"
3526# else /* HPUX */
3527 (char_u *)"hp-roman8"
3528# endif
3529# endif
3530# endif
3531# endif
3532 );
3533#endif
3534
3535#ifdef FEAT_POSTSCRIPT
3536 /* 'printexpr' must be allocated to be able to evaluate it. */
3537 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003538# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003539 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540# else
3541# ifdef VMS
3542 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3543
3544# else
3545 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3546# endif
3547# endif
3548 );
3549#endif
3550
3551 /*
3552 * Set all the options (except the terminal options) to their default
3553 * value. Also set the global value for local options.
3554 */
3555 set_options_default(0);
3556
3557#ifdef FEAT_GUI
3558 if (found_reverse_arg)
3559 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3560#endif
3561
3562 curbuf->b_p_initialized = TRUE;
3563 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003564 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565 check_buf_options(curbuf);
3566 check_win_options(curwin);
3567 check_options();
3568
3569 /* Must be before option_expand(), because that one needs vim_isIDc() */
3570 didset_options();
3571
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003572#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003573 /* Use the current chartab for the generic chartab. This is not in
3574 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003575 init_spell_chartab();
3576#endif
3577
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578 /*
3579 * Expand environment variables and things like "~" for the defaults.
3580 * If option_expand() returns non-NULL the variable is expanded. This can
3581 * only happen for non-indirect options.
3582 * Also set the default to the expanded value, so ":set" does not list
3583 * them.
3584 * Don't set the P_ALLOCED flag, because we don't want to free the
3585 * default.
3586 */
3587 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3588 {
3589 if ((options[opt_idx].flags & P_GETTEXT)
3590 && options[opt_idx].var != NULL)
3591 p = (char_u *)_(*(char **)options[opt_idx].var);
3592 else
3593 p = option_expand(opt_idx, NULL);
3594 if (p != NULL && (p = vim_strsave(p)) != NULL)
3595 {
3596 *(char_u **)options[opt_idx].var = p;
3597 /* VIMEXP
3598 * Defaults for all expanded options are currently the same for Vi
3599 * and Vim. When this changes, add some code here! Also need to
3600 * split P_DEF_ALLOCED in two.
3601 */
3602 if (options[opt_idx].flags & P_DEF_ALLOCED)
3603 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3604 options[opt_idx].def_val[VI_DEFAULT] = p;
3605 options[opt_idx].flags |= P_DEF_ALLOCED;
3606 }
3607 }
3608
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 save_file_ff(curbuf); /* Buffer is unchanged */
3610
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611#if defined(FEAT_ARABIC)
3612 /* Detect use of mlterm.
3613 * Mlterm is a terminal emulator akin to xterm that has some special
3614 * abilities (bidi namely).
3615 * NOTE: mlterm's author is being asked to 'set' a variable
3616 * instead of an environment variable due to inheritance.
3617 */
3618 if (mch_getenv((char_u *)"MLTERM") != NULL)
3619 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3620#endif
3621
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003622 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623
3624#ifdef FEAT_MBYTE
3625# if defined(WIN3264) && defined(FEAT_GETTEXT)
3626 /*
3627 * If $LANG isn't set, try to get a good value for it. This makes the
3628 * right language be used automatically. Don't do this for English.
3629 */
3630 if (mch_getenv((char_u *)"LANG") == NULL)
3631 {
3632 char buf[20];
3633
3634 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3635 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3636 * only the first two. */
3637 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3638 (LPTSTR)buf, 20);
3639 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3640 {
3641 /* There are a few exceptions (probably more) */
3642 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3643 STRCPY(buf, "zh_TW");
3644 else if (STRNICMP(buf, "chs", 3) == 0
3645 || STRNICMP(buf, "zhc", 3) == 0)
3646 STRCPY(buf, "zh_CN");
3647 else if (STRNICMP(buf, "jp", 2) == 0)
3648 STRCPY(buf, "ja");
3649 else
3650 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003651 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 }
3653 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003654# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003655# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003656 /* Moved to os_mac_conv.c to avoid dependency problems. */
3657 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003658# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659# endif
3660
3661 /* enc_locale() will try to find the encoding of the current locale. */
3662 p = enc_locale();
3663 if (p != NULL)
3664 {
3665 char_u *save_enc;
3666
3667 /* Try setting 'encoding' and check if the value is valid.
3668 * If not, go back to the default "latin1". */
3669 save_enc = p_enc;
3670 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003671 if (STRCMP(p_enc, "gb18030") == 0)
3672 {
3673 /* We don't support "gb18030", but "cp936" is a good substitute
3674 * for practical purposes, thus use that. It's not an alias to
3675 * still support conversion between gb18030 and utf-8. */
3676 p_enc = vim_strsave((char_u *)"cp936");
3677 vim_free(p);
3678 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679 if (mb_init() == NULL)
3680 {
3681 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003682 if (opt_idx >= 0)
3683 {
3684 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3685 options[opt_idx].flags |= P_DEF_ALLOCED;
3686 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687
Bram Moolenaard0573012017-10-28 21:11:06 +02003688#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003689 if (STRCMP(p_enc, "latin1") == 0
3690# ifdef FEAT_MBYTE
3691 || enc_utf8
3692# endif
3693 )
3694 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003695 /* Adjust the default for 'isprint' and 'iskeyword' to match
3696 * latin1. Also set the defaults for when 'nocompatible' is
3697 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003698 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003699 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003700 set_string_option_direct((char_u *)"isk", -1,
3701 ISK_LATIN1, OPT_FREE, SID_NONE);
3702 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003703 if (opt_idx >= 0)
3704 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003705 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003706 if (opt_idx >= 0)
3707 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003708 (void)init_chartab();
3709 }
3710#endif
3711
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712# if defined(WIN3264) && !defined(FEAT_GUI)
3713 /* Win32 console: When GetACP() returns a different value from
3714 * GetConsoleCP() set 'termencoding'. */
3715 if (GetACP() != GetConsoleCP())
3716 {
3717 char buf[50];
3718
3719 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3720 p_tenc = vim_strsave((char_u *)buf);
3721 if (p_tenc != NULL)
3722 {
3723 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003724 if (opt_idx >= 0)
3725 {
3726 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3727 options[opt_idx].flags |= P_DEF_ALLOCED;
3728 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729 convert_setup(&input_conv, p_tenc, p_enc);
3730 convert_setup(&output_conv, p_enc, p_tenc);
3731 }
3732 else
3733 p_tenc = empty_option;
3734 }
3735# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003736# if defined(WIN3264) && defined(FEAT_MBYTE)
3737 /* $HOME may have characters in active code page. */
3738 init_homedir();
3739# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 }
3741 else
3742 {
3743 vim_free(p_enc);
3744 p_enc = save_enc;
3745 }
3746 }
3747#endif
3748
3749#ifdef FEAT_MULTI_LANG
3750 /* Set the default for 'helplang'. */
3751 set_helplang_default(get_mess_lang());
3752#endif
3753}
3754
3755/*
3756 * Set an option to its default value.
3757 * This does not take care of side effects!
3758 */
3759 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003760set_option_default(
3761 int opt_idx,
3762 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3763 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764{
3765 char_u *varp; /* pointer to variable for current option */
3766 int dvi; /* index in def_val[] */
3767 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003768 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3770
3771 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3772 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003773 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003774 {
3775 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3776 if (flags & P_STRING)
3777 {
3778 /* Use set_string_option_direct() for local options to handle
3779 * freeing and allocating the value. */
3780 if (options[opt_idx].indir != PV_NONE)
3781 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003782 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783 else
3784 {
3785 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3786 free_string_option(*(char_u **)(varp));
3787 *(char_u **)varp = options[opt_idx].def_val[dvi];
3788 options[opt_idx].flags &= ~P_ALLOCED;
3789 }
3790 }
3791 else if (flags & P_NUM)
3792 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003793 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 win_comp_scroll(curwin);
3795 else
3796 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003797 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 /* May also set global value for local option. */
3799 if (both)
3800 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3801 *(long *)varp;
3802 }
3803 }
3804 else /* P_BOOL */
3805 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003806 /* the cast to long is required for Manx C, long_i is needed for
3807 * MSVC */
3808 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003809#ifdef UNIX
3810 /* 'modeline' defaults to off for root */
3811 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3812 *(int *)varp = FALSE;
3813#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814 /* May also set global value for local option. */
3815 if (both)
3816 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3817 *(int *)varp;
3818 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003819
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003820 /* The default value is not insecure. */
3821 flagsp = insecure_flag(opt_idx, opt_flags);
3822 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 }
3824
3825#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003826 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003827#endif
3828}
3829
3830/*
3831 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003832 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 */
3834 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003835set_options_default(
3836 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837{
3838 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003840 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841
3842 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003843 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003844#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003845 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003846 || (TRUE
3847# if defined(FEAT_MBYTE)
3848 && options[i].var != (char_u *)&p_enc
3849# endif
3850# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003851 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003852 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003853# endif
3854 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003855#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003856 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857 set_option_default(i, opt_flags, p_cp);
3858
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003860 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003862#ifdef FEAT_CINDENT
3863 parse_cino(curbuf);
3864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865}
3866
3867/*
3868 * Set the Vi-default value of a string option.
3869 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003870 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003872 static void
3873set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874{
3875 char_u *p;
3876 int opt_idx;
3877
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003878 if (escape && vim_strchr(val, ' ') != NULL)
3879 p = vim_strsave_escaped(val, (char_u *)" ");
3880 else
3881 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882 if (p != NULL) /* we don't want a NULL */
3883 {
3884 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003885 if (opt_idx >= 0)
3886 {
3887 if (options[opt_idx].flags & P_DEF_ALLOCED)
3888 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3889 options[opt_idx].def_val[VI_DEFAULT] = p;
3890 options[opt_idx].flags |= P_DEF_ALLOCED;
3891 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892 }
3893}
3894
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003895 void
3896set_string_default(char *name, char_u *val)
3897{
3898 set_string_default_esc(name, val, FALSE);
3899}
3900
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901/*
3902 * Set the Vi-default value of a number option.
3903 * Used for 'lines' and 'columns'.
3904 */
3905 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003906set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003908 int opt_idx;
3909
3910 opt_idx = findoption((char_u *)name);
3911 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003912 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913}
3914
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003915#if defined(EXITFREE) || defined(PROTO)
3916/*
3917 * Free all options.
3918 */
3919 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003920free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003921{
3922 int i;
3923
3924 for (i = 0; !istermoption(&options[i]); i++)
3925 {
3926 if (options[i].indir == PV_NONE)
3927 {
3928 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003929 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003930 free_string_option(*(char_u **)options[i].var);
3931 if (options[i].flags & P_DEF_ALLOCED)
3932 free_string_option(options[i].def_val[VI_DEFAULT]);
3933 }
3934 else if (options[i].var != VAR_WIN
3935 && (options[i].flags & P_STRING))
3936 /* buffer-local option: free global value */
3937 free_string_option(*(char_u **)options[i].var);
3938 }
3939}
3940#endif
3941
3942
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943/*
3944 * Initialize the options, part two: After getting Rows and Columns and
3945 * setting 'term'.
3946 */
3947 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003948set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003950 int idx;
3951
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003953 * 'scroll' defaults to half the window height. The stored default is zero,
3954 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003956 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003957 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003958 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 comp_col();
3960
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003961 /*
3962 * 'window' is only for backwards compatibility with Vi.
3963 * Default is Rows - 1.
3964 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003965 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003966 p_window = Rows - 1;
3967 set_number_default("window", Rows - 1);
3968
Bram Moolenaarf740b292006-02-16 22:11:02 +00003969 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003970#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 /*
3972 * If 'background' wasn't set by the user, try guessing the value,
3973 * depending on the terminal name. Only need to check for terminals
3974 * with a dark background, that can handle color.
3975 */
3976 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003977 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3978 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003980 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003981 /* don't mark it as set, when starting the GUI it may be
3982 * changed again */
3983 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 }
3985#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003986
3987#ifdef CURSOR_SHAPE
3988 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3989#endif
3990#ifdef FEAT_MOUSESHAPE
3991 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3992#endif
3993#ifdef FEAT_PRINTER
3994 (void)parse_printoptions(); /* parse 'printoptions' default value */
3995#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003996}
3997
3998/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003999 * Return "dark" or "light" depending on the kind of terminal.
4000 * This is just guessing! Recognized are:
4001 * "linux" Linux console
4002 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004003 * "cygwin.*" Cygwin shell
4004 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004005 * We also check the COLORFGBG environment variable, which is set by
4006 * rxvt and derivatives. This variable contains either two or three
4007 * values separated by semicolons; we want the last value in either
4008 * case. If this value is 0-6 or 8, our background is dark.
4009 */
4010 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004011term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004012{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004013#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004014 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004015 return (char_u *)"dark";
4016#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004017 char_u *p;
4018
Bram Moolenaarf740b292006-02-16 22:11:02 +00004019 if (STRCMP(T_NAME, "linux") == 0
4020 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004021 || STRNCMP(T_NAME, "cygwin", 6) == 0
4022 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004023 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4024 && (p = vim_strrchr(p, ';')) != NULL
4025 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4026 && p[2] == NUL))
4027 return (char_u *)"dark";
4028 return (char_u *)"light";
4029#endif
4030}
4031
4032/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033 * Initialize the options, part three: After reading the .vimrc
4034 */
4035 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004036set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004038#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039/*
4040 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4041 * This is done after other initializations, where 'shell' might have been
4042 * set, but only if they have not been set before.
4043 */
4044 char_u *p;
4045 int idx_srr;
4046 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004047# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 int idx_sp;
4049 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004050# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051
4052 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004053 if (idx_srr < 0)
4054 do_srr = FALSE;
4055 else
4056 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004057# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004059 if (idx_sp < 0)
4060 do_sp = FALSE;
4061 else
4062 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004063# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004064 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 if (p != NULL)
4066 {
4067 /*
4068 * Default for p_sp is "| tee", for p_srr is ">".
4069 * For known shells it is changed here to include stderr.
4070 */
4071 if ( fnamecmp(p, "csh") == 0
4072 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 || fnamecmp(p, "csh.exe") == 0
4075 || fnamecmp(p, "tcsh.exe") == 0
4076# endif
4077 )
4078 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 if (do_sp)
4081 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004082# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4088 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 if (do_srr)
4091 {
4092 p_srr = (char_u *)">&";
4093 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4094 }
4095 }
4096 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004097 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 if ( fnamecmp(p, "sh") == 0
4099 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004100 || fnamecmp(p, "mksh") == 0
4101 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004103 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004105 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004106# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 || fnamecmp(p, "cmd") == 0
4108 || fnamecmp(p, "sh.exe") == 0
4109 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004110 || fnamecmp(p, "mksh.exe") == 0
4111 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004113 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 || fnamecmp(p, "bash.exe") == 0
4115 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004117 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 if (do_sp)
4121 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004122# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004124# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004126# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4128 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004129# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 if (do_srr)
4131 {
4132 p_srr = (char_u *)">%s 2>&1";
4133 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4134 }
4135 }
4136 vim_free(p);
4137 }
4138#endif
4139
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004140#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004142 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4143 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 * This is done after other initializations, where 'shell' might have been
4145 * set, but only if they have not been set before. Default for p_shcf is
4146 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004147 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004149 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 {
4151 int idx3;
4152
4153 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004154 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 {
4156 p_shcf = (char_u *)"-c";
4157 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4158 }
4159
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 /* Somehow Win32 requires the quotes around the redirection too */
4161 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004162 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 {
4164 p_sxq = (char_u *)"\"";
4165 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004167 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004168 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4169 {
4170 int idx3;
4171
4172 /*
4173 * cmd.exe on Windows will strip the first and last double quote given
4174 * on the command line, e.g. most of the time things like:
4175 * cmd /c "my path/to/echo" "my args to echo"
4176 * become:
4177 * my path/to/echo" "my args to echo
4178 * when executed.
4179 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004180 * To avoid this, set shellxquote to surround the command in
4181 * parenthesis. This appears to make most commands work, without
4182 * breaking commands that worked previously, such as
4183 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004184 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004185 idx3 = findoption((char_u *)"sxq");
4186 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4187 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004188 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004189 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4190 }
4191
Bram Moolenaara64ba222012-02-12 23:23:31 +01004192 idx3 = findoption((char_u *)"shcf");
4193 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4194 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004195 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004196 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4197 }
4198 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199#endif
4200
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004201 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004202 {
4203 int idx_ffs = findoption((char_u *)"ffs");
4204
4205 /* Apply the first entry of 'fileformats' to the initial buffer. */
4206 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4207 set_fileformat(default_fileformat(), OPT_LOCAL);
4208 }
4209
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210#ifdef FEAT_TITLE
4211 set_title_defaults();
4212#endif
4213}
4214
4215#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4216/*
4217 * When 'helplang' is still at its default value, set it to "lang".
4218 * Only the first two characters of "lang" are used.
4219 */
4220 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004221set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222{
4223 int idx;
4224
4225 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4226 return;
4227 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004228 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229 {
4230 if (options[idx].flags & P_ALLOCED)
4231 free_string_option(p_hlg);
4232 p_hlg = vim_strsave(lang);
4233 if (p_hlg == NULL)
4234 p_hlg = empty_option;
4235 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004236 {
4237 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4238 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4239 {
4240 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4241 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4242 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004244 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004245 options[idx].flags |= P_ALLOCED;
4246 }
4247}
4248#endif
4249
4250#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004251static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004252
4253 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004254gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004255{
4256 if (gui_get_lightness(gui.back_pixel) < 127)
4257 return (char_u *)"dark";
4258 return (char_u *)"light";
4259}
4260
4261/*
4262 * Option initializations that can only be done after opening the GUI window.
4263 */
4264 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004265init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004266{
4267 /* Set the 'background' option according to the lightness of the
4268 * background color, unless the user has set it already. */
4269 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4270 {
4271 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4272 highlight_changed();
4273 }
4274}
4275#endif
4276
4277#ifdef FEAT_TITLE
4278/*
4279 * 'title' and 'icon' only default to true if they have not been set or reset
4280 * in .vimrc and we can read the old value.
4281 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4282 * they can be reset. This reduces startup time when using X on a remote
4283 * machine.
4284 */
4285 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004286set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004287{
4288 int idx1;
4289 long val;
4290
4291 /*
4292 * If GUI is (going to be) used, we can always set the window title and
4293 * icon name. Saves a bit of time, because the X11 display server does
4294 * not need to be contacted.
4295 */
4296 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004297 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298 {
4299#ifdef FEAT_GUI
4300 if (gui.starting || gui.in_use)
4301 val = TRUE;
4302 else
4303#endif
4304 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004305 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004306 p_title = val;
4307 }
4308 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004309 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004310 {
4311#ifdef FEAT_GUI
4312 if (gui.starting || gui.in_use)
4313 val = TRUE;
4314 else
4315#endif
4316 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004317 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004318 p_icon = val;
4319 }
4320}
4321#endif
4322
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004323#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4324 static void
4325trigger_optionsset_string(
4326 int opt_idx,
4327 int opt_flags,
4328 char_u *oldval,
4329 char_u *newval)
4330{
4331 if (oldval != NULL && newval != NULL)
4332 {
4333 char_u buf_type[7];
4334
4335 sprintf((char *)buf_type, "%s",
4336 (opt_flags & OPT_LOCAL) ? "local" : "global");
4337 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4338 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4339 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4340 apply_autocmds(EVENT_OPTIONSET,
4341 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4342 reset_v_option_vars();
4343 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004344}
4345#endif
4346
Bram Moolenaar071d4272004-06-13 20:20:40 +00004347/*
4348 * Parse 'arg' for option settings.
4349 *
4350 * 'arg' may be IObuff, but only when no errors can be present and option
4351 * does not need to be expanded with option_expand().
4352 * "opt_flags":
4353 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004354 * OPT_GLOBAL for ":setglobal"
4355 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004356 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004357 * OPT_WINONLY to only set window-local options
4358 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359 *
4360 * returns FAIL if an error is detected, OK otherwise
4361 */
4362 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004363do_set(
4364 char_u *arg, /* option string (may be written to!) */
4365 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004366{
4367 int opt_idx;
4368 char_u *errmsg;
4369 char_u errbuf[80];
4370 char_u *startarg;
4371 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4372 int nextchar; /* next non-white char after option name */
4373 int afterchar; /* character just after option name */
4374 int len;
4375 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004376 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377 int key;
4378 long_u flags; /* flags for current option */
4379 char_u *varp = NULL; /* pointer to variable for current option */
4380 int did_show = FALSE; /* already showed one value */
4381 int adding; /* "opt+=arg" */
4382 int prepending; /* "opt^=arg" */
4383 int removing; /* "opt-=arg" */
4384 int cp_val = 0;
4385 char_u key_name[2];
4386
4387 if (*arg == NUL)
4388 {
4389 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004390 did_show = TRUE;
4391 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392 }
4393
4394 while (*arg != NUL) /* loop to process all options */
4395 {
4396 errmsg = NULL;
4397 startarg = arg; /* remember for error message */
4398
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004399 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4400 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004401 {
4402 /*
4403 * ":set all" show all options.
4404 * ":set all&" set all options to their default value.
4405 */
4406 arg += 3;
4407 if (*arg == '&')
4408 {
4409 ++arg;
4410 /* Only for :set command set global value of local options. */
4411 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004412 didset_options();
4413 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004414 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415 }
4416 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004417 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004418 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004419 did_show = TRUE;
4420 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004421 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004422 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004423 {
4424 showoptions(2, opt_flags);
4425 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004426 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004427 arg += 7;
4428 }
4429 else
4430 {
4431 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004432 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004433 {
4434 prefix = 0;
4435 arg += 2;
4436 }
4437 else if (STRNCMP(arg, "inv", 3) == 0)
4438 {
4439 prefix = 2;
4440 arg += 3;
4441 }
4442
4443 /* find end of name */
4444 key = 0;
4445 if (*arg == '<')
4446 {
4447 nextchar = 0;
4448 opt_idx = -1;
4449 /* look out for <t_>;> */
4450 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4451 len = 5;
4452 else
4453 {
4454 len = 1;
4455 while (arg[len] != NUL && arg[len] != '>')
4456 ++len;
4457 }
4458 if (arg[len] != '>')
4459 {
4460 errmsg = e_invarg;
4461 goto skip;
4462 }
4463 arg[len] = NUL; /* put NUL after name */
4464 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4465 opt_idx = findoption(arg + 1);
4466 arg[len++] = '>'; /* restore '>' */
4467 if (opt_idx == -1)
4468 key = find_key_option(arg + 1);
4469 }
4470 else
4471 {
4472 len = 0;
4473 /*
4474 * The two characters after "t_" may not be alphanumeric.
4475 */
4476 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4477 len = 4;
4478 else
4479 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4480 ++len;
4481 nextchar = arg[len];
4482 arg[len] = NUL; /* put NUL after name */
4483 opt_idx = findoption(arg);
4484 arg[len] = nextchar; /* restore nextchar */
4485 if (opt_idx == -1)
4486 key = find_key_option(arg);
4487 }
4488
4489 /* remember character after option name */
4490 afterchar = arg[len];
4491
4492 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004493 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004494 ++len;
4495
4496 adding = FALSE;
4497 prepending = FALSE;
4498 removing = FALSE;
4499 if (arg[len] != NUL && arg[len + 1] == '=')
4500 {
4501 if (arg[len] == '+')
4502 {
4503 adding = TRUE; /* "+=" */
4504 ++len;
4505 }
4506 else if (arg[len] == '^')
4507 {
4508 prepending = TRUE; /* "^=" */
4509 ++len;
4510 }
4511 else if (arg[len] == '-')
4512 {
4513 removing = TRUE; /* "-=" */
4514 ++len;
4515 }
4516 }
4517 nextchar = arg[len];
4518
4519 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4520 {
4521 errmsg = (char_u *)N_("E518: Unknown option");
4522 goto skip;
4523 }
4524
4525 if (opt_idx >= 0)
4526 {
4527 if (options[opt_idx].var == NULL) /* hidden option: skip */
4528 {
4529 /* Only give an error message when requesting the value of
4530 * a hidden option, ignore setting it. */
4531 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4532 && (!(options[opt_idx].flags & P_BOOL)
4533 || nextchar == '?'))
4534 errmsg = (char_u *)N_("E519: Option not supported");
4535 goto skip;
4536 }
4537
4538 flags = options[opt_idx].flags;
4539 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4540 }
4541 else
4542 {
4543 flags = P_STRING;
4544 if (key < 0)
4545 {
4546 key_name[0] = KEY2TERMCAP0(key);
4547 key_name[1] = KEY2TERMCAP1(key);
4548 }
4549 else
4550 {
4551 key_name[0] = KS_KEY;
4552 key_name[1] = (key & 0xff);
4553 }
4554 }
4555
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004556 /* Skip all options that are not window-local (used when showing
4557 * an already loaded buffer in a window). */
4558 if ((opt_flags & OPT_WINONLY)
4559 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4560 goto skip;
4561
Bram Moolenaara3227e22006-03-08 21:32:40 +00004562 /* Skip all options that are window-local (used for :vimgrep). */
4563 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4564 && options[opt_idx].var == VAR_WIN)
4565 goto skip;
4566
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004567 /* Disallow changing some options from modelines. */
4568 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004569 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004570 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004571 {
4572 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4573 goto skip;
4574 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004575#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004576 /* In diff mode some options are overruled. This avoids that
4577 * 'foldmethod' becomes "marker" instead of "diff" and that
4578 * "wrap" gets set. */
4579 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004580 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004581 && (
4582#ifdef FEAT_FOLDING
4583 options[opt_idx].indir == PV_FDM ||
4584#endif
4585 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004586 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004587#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004588 }
4589
4590#ifdef HAVE_SANDBOX
4591 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004592 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004593 {
4594 errmsg = (char_u *)_(e_sandbox);
4595 goto skip;
4596 }
4597#endif
4598
4599 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4600 {
4601 arg += len;
4602 cp_val = p_cp;
4603 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4604 {
4605 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4606 {
4607 cp_val = FALSE;
4608 arg += 3;
4609 }
4610 else /* "opt&vi": set to Vi default */
4611 {
4612 cp_val = TRUE;
4613 arg += 2;
4614 }
4615 }
4616 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004617 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004618 {
4619 errmsg = e_trailing;
4620 goto skip;
4621 }
4622 }
4623
4624 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004625 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4626 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004627 */
4628 if (nextchar == '?'
4629 || (prefix == 1
4630 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4631 && !(flags & P_BOOL)))
4632 {
4633 /*
4634 * print value
4635 */
4636 if (did_show)
4637 msg_putchar('\n'); /* cursor below last one */
4638 else
4639 {
4640 gotocmdline(TRUE); /* cursor at status line */
4641 did_show = TRUE; /* remember that we did a line */
4642 }
4643 if (opt_idx >= 0)
4644 {
4645 showoneopt(&options[opt_idx], opt_flags);
4646#ifdef FEAT_EVAL
4647 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004648 {
4649 /* Mention where the option was last set. */
4650 if (varp == options[opt_idx].var)
4651 last_set_msg(options[opt_idx].scriptID);
4652 else if ((int)options[opt_idx].indir & PV_WIN)
4653 last_set_msg(curwin->w_p_scriptID[
4654 (int)options[opt_idx].indir & PV_MASK]);
4655 else if ((int)options[opt_idx].indir & PV_BUF)
4656 last_set_msg(curbuf->b_p_scriptID[
4657 (int)options[opt_idx].indir & PV_MASK]);
4658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659#endif
4660 }
4661 else
4662 {
4663 char_u *p;
4664
4665 p = find_termcode(key_name);
4666 if (p == NULL)
4667 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004668 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004669 goto skip;
4670 }
4671 else
4672 (void)show_one_termcode(key_name, p, TRUE);
4673 }
4674 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004675 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004676 errmsg = e_trailing;
4677 }
4678 else
4679 {
4680 if (flags & P_BOOL) /* boolean */
4681 {
4682 if (nextchar == '=' || nextchar == ':')
4683 {
4684 errmsg = e_invarg;
4685 goto skip;
4686 }
4687
4688 /*
4689 * ":set opt!": invert
4690 * ":set opt&": reset to default value
4691 * ":set opt<": reset to global value
4692 */
4693 if (nextchar == '!')
4694 value = *(int *)(varp) ^ 1;
4695 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004696 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004697 ((flags & P_VI_DEF) || cp_val)
4698 ? VI_DEFAULT : VIM_DEFAULT];
4699 else if (nextchar == '<')
4700 {
4701 /* For 'autoread' -1 means to use global value. */
4702 if ((int *)varp == &curbuf->b_p_ar
4703 && opt_flags == OPT_LOCAL)
4704 value = -1;
4705 else
4706 value = *(int *)get_varp_scope(&(options[opt_idx]),
4707 OPT_GLOBAL);
4708 }
4709 else
4710 {
4711 /*
4712 * ":set invopt": invert
4713 * ":set opt" or ":set noopt": set or reset
4714 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004715 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 {
4717 errmsg = e_trailing;
4718 goto skip;
4719 }
4720 if (prefix == 2) /* inv */
4721 value = *(int *)(varp) ^ 1;
4722 else
4723 value = prefix;
4724 }
4725
4726 errmsg = set_bool_option(opt_idx, varp, (int)value,
4727 opt_flags);
4728 }
4729 else /* numeric or string */
4730 {
4731 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4732 || prefix != 1)
4733 {
4734 errmsg = e_invarg;
4735 goto skip;
4736 }
4737
4738 if (flags & P_NUM) /* numeric */
4739 {
4740 /*
4741 * Different ways to set a number option:
4742 * & set to default value
4743 * < set to global value
4744 * <xx> accept special key codes for 'wildchar'
4745 * c accept any non-digit for 'wildchar'
4746 * [-]0-9 set number
4747 * other error
4748 */
4749 ++arg;
4750 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004751 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004752 ((flags & P_VI_DEF) || cp_val)
4753 ? VI_DEFAULT : VIM_DEFAULT];
4754 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004755 {
4756 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4757 * use the global value. */
4758 if ((long *)varp == &curbuf->b_p_ul
4759 && opt_flags == OPT_LOCAL)
4760 value = NO_LOCAL_UNDOLEVEL;
4761 else
4762 value = *(long *)get_varp_scope(
4763 &(options[opt_idx]), OPT_GLOBAL);
4764 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004765 else if (((long *)varp == &p_wc
4766 || (long *)varp == &p_wcm)
4767 && (*arg == '<'
4768 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004769 || (*arg != NUL
4770 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004771 && !VIM_ISDIGIT(*arg))))
4772 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004773 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004774 if (value == 0 && (long *)varp != &p_wcm)
4775 {
4776 errmsg = e_invarg;
4777 goto skip;
4778 }
4779 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004780 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4781 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004782 /* Allow negative (for 'undolevels'), octal and
4783 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004784 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4785 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004786 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004787 {
4788 errmsg = e_invarg;
4789 goto skip;
4790 }
4791 }
4792 else
4793 {
4794 errmsg = (char_u *)N_("E521: Number required after =");
4795 goto skip;
4796 }
4797
4798 if (adding)
4799 value = *(long *)varp + value;
4800 if (prepending)
4801 value = *(long *)varp * value;
4802 if (removing)
4803 value = *(long *)varp - value;
4804 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004805 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004806 }
4807 else if (opt_idx >= 0) /* string */
4808 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004809 char_u *save_arg = NULL;
4810 char_u *s = NULL;
4811 char_u *oldval = NULL; /* previous value if *varp */
4812 char_u *newval;
4813 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004814#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004815 char_u *saved_origval = NULL;
4816 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004817#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004818 unsigned newlen;
4819 int comma;
4820 int bs;
4821 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 was allocated */
4823
4824 /* When using ":set opt=val" for a global option
4825 * with a local value the local value will be
4826 * reset, use the global value here. */
4827 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004828 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004829 varp = options[opt_idx].var;
4830
4831 /* The old value is kept until we are sure that the
4832 * new value is valid. */
4833 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004834
4835 /* When setting the local value of a global
4836 * option, the old value may be the global value. */
4837 if (((int)options[opt_idx].indir & PV_BOTH)
4838 && (opt_flags & OPT_LOCAL))
4839 origval = *(char_u **)get_varp(
4840 &options[opt_idx]);
4841 else
4842 origval = oldval;
4843
Bram Moolenaar071d4272004-06-13 20:20:40 +00004844 if (nextchar == '&') /* set to default val */
4845 {
4846 newval = options[opt_idx].def_val[
4847 ((flags & P_VI_DEF) || cp_val)
4848 ? VI_DEFAULT : VIM_DEFAULT];
4849 if ((char_u **)varp == &p_bg)
4850 {
4851 /* guess the value of 'background' */
4852#ifdef FEAT_GUI
4853 if (gui.in_use)
4854 newval = gui_bg_default();
4855 else
4856#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004857 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004858 }
4859
4860 /* expand environment variables and ~ (since the
4861 * default value was already expanded, only
4862 * required when an environment variable was set
4863 * later */
4864 if (newval == NULL)
4865 newval = empty_option;
4866 else
4867 {
4868 s = option_expand(opt_idx, newval);
4869 if (s == NULL)
4870 s = newval;
4871 newval = vim_strsave(s);
4872 }
4873 new_value_alloced = TRUE;
4874 }
4875 else if (nextchar == '<') /* set to global val */
4876 {
4877 newval = vim_strsave(*(char_u **)get_varp_scope(
4878 &(options[opt_idx]), OPT_GLOBAL));
4879 new_value_alloced = TRUE;
4880 }
4881 else
4882 {
4883 ++arg; /* jump to after the '=' or ':' */
4884
4885 /*
4886 * Set 'keywordprg' to ":help" if an empty
4887 * value was passed to :set by the user.
4888 * Misuse errbuf[] for the resulting string.
4889 */
4890 if (varp == (char_u *)&p_kp
4891 && (*arg == NUL || *arg == ' '))
4892 {
4893 STRCPY(errbuf, ":help");
4894 save_arg = arg;
4895 arg = errbuf;
4896 }
4897 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004898 * Convert 'backspace' number to string, for
4899 * adding, prepending and removing string.
4900 */
4901 else if (varp == (char_u *)&p_bs
4902 && VIM_ISDIGIT(**(char_u **)varp))
4903 {
4904 i = getdigits((char_u **)varp);
4905 switch (i)
4906 {
4907 case 0:
4908 *(char_u **)varp = empty_option;
4909 break;
4910 case 1:
4911 *(char_u **)varp = vim_strsave(
4912 (char_u *)"indent,eol");
4913 break;
4914 case 2:
4915 *(char_u **)varp = vim_strsave(
4916 (char_u *)"indent,eol,start");
4917 break;
4918 }
4919 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004920 if (origval == oldval)
4921 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004922 oldval = *(char_u **)varp;
4923 }
4924 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004925 * Convert 'whichwrap' number to string, for
4926 * backwards compatibility with Vim 3.0.
4927 * Misuse errbuf[] for the resulting string.
4928 */
4929 else if (varp == (char_u *)&p_ww
4930 && VIM_ISDIGIT(*arg))
4931 {
4932 *errbuf = NUL;
4933 i = getdigits(&arg);
4934 if (i & 1)
4935 STRCAT(errbuf, "b,");
4936 if (i & 2)
4937 STRCAT(errbuf, "s,");
4938 if (i & 4)
4939 STRCAT(errbuf, "h,l,");
4940 if (i & 8)
4941 STRCAT(errbuf, "<,>,");
4942 if (i & 16)
4943 STRCAT(errbuf, "[,],");
4944 if (*errbuf != NUL) /* remove trailing , */
4945 errbuf[STRLEN(errbuf) - 1] = NUL;
4946 save_arg = arg;
4947 arg = errbuf;
4948 }
4949 /*
4950 * Remove '>' before 'dir' and 'bdir', for
4951 * backwards compatibility with version 3.0
4952 */
4953 else if ( *arg == '>'
4954 && (varp == (char_u *)&p_dir
4955 || varp == (char_u *)&p_bdir))
4956 {
4957 ++arg;
4958 }
4959
Bram Moolenaar071d4272004-06-13 20:20:40 +00004960 /*
4961 * Copy the new string into allocated memory.
4962 * Can't use set_string_option_direct(), because
4963 * we need to remove the backslashes.
4964 */
4965 /* get a bit too much */
4966 newlen = (unsigned)STRLEN(arg) + 1;
4967 if (adding || prepending || removing)
4968 newlen += (unsigned)STRLEN(origval) + 1;
4969 newval = alloc(newlen);
4970 if (newval == NULL) /* out of mem, don't change */
4971 break;
4972 s = newval;
4973
4974 /*
4975 * Copy the string, skip over escaped chars.
4976 * For MS-DOS and WIN32 backslashes before normal
4977 * file name characters are not removed, and keep
4978 * backslash at start, for "\\machine\path", but
4979 * do remove it for "\\\\machine\\path".
4980 * The reverse is found in ExpandOldSetting().
4981 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004982 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004983 {
4984 if (*arg == '\\' && arg[1] != NUL
4985#ifdef BACKSLASH_IN_FILENAME
4986 && !((flags & P_EXPAND)
4987 && vim_isfilec(arg[1])
4988 && (arg[1] != '\\'
4989 || (s == newval
4990 && arg[2] != '\\')))
4991#endif
4992 )
4993 ++arg; /* remove backslash */
4994#ifdef FEAT_MBYTE
4995 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004996 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004997 {
4998 /* copy multibyte char */
4999 mch_memmove(s, arg, (size_t)i);
5000 arg += i;
5001 s += i;
5002 }
5003 else
5004#endif
5005 *s++ = *arg++;
5006 }
5007 *s = NUL;
5008
5009 /*
5010 * Expand environment variables and ~.
5011 * Don't do it when adding without inserting a
5012 * comma.
5013 */
5014 if (!(adding || prepending || removing)
5015 || (flags & P_COMMA))
5016 {
5017 s = option_expand(opt_idx, newval);
5018 if (s != NULL)
5019 {
5020 vim_free(newval);
5021 newlen = (unsigned)STRLEN(s) + 1;
5022 if (adding || prepending || removing)
5023 newlen += (unsigned)STRLEN(origval) + 1;
5024 newval = alloc(newlen);
5025 if (newval == NULL)
5026 break;
5027 STRCPY(newval, s);
5028 }
5029 }
5030
5031 /* locate newval[] in origval[] when removing it
5032 * and when adding to avoid duplicates */
5033 i = 0; /* init for GCC */
5034 if (removing || (flags & P_NODUP))
5035 {
5036 i = (int)STRLEN(newval);
5037 bs = 0;
5038 for (s = origval; *s; ++s)
5039 {
5040 if ((!(flags & P_COMMA)
5041 || s == origval
5042 || (s[-1] == ',' && !(bs & 1)))
5043 && STRNCMP(s, newval, i) == 0
5044 && (!(flags & P_COMMA)
5045 || s[i] == ','
5046 || s[i] == NUL))
5047 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005048 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005049 * even number of backslashes or a single
5050 * backslash preceded by a comma before it
5051 * is recognized as a separator */
5052 if ((s > origval + 1
5053 && s[-1] == '\\'
5054 && s[-2] != ',')
5055 || (s == origval + 1
5056 && s[-1] == '\\'))
5057
Bram Moolenaar071d4272004-06-13 20:20:40 +00005058 ++bs;
5059 else
5060 bs = 0;
5061 }
5062
5063 /* do not add if already there */
5064 if ((adding || prepending) && *s)
5065 {
5066 prepending = FALSE;
5067 adding = FALSE;
5068 STRCPY(newval, origval);
5069 }
5070 }
5071
5072 /* concatenate the two strings; add a ',' if
5073 * needed */
5074 if (adding || prepending)
5075 {
5076 comma = ((flags & P_COMMA) && *origval != NUL
5077 && *newval != NUL);
5078 if (adding)
5079 {
5080 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005081 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005082 if (comma && i > 1
5083 && (flags & P_ONECOMMA) == P_ONECOMMA
5084 && origval[i - 1] == ','
5085 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005086 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 mch_memmove(newval + i + comma, newval,
5088 STRLEN(newval) + 1);
5089 mch_memmove(newval, origval, (size_t)i);
5090 }
5091 else
5092 {
5093 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005094 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005095 }
5096 if (comma)
5097 newval[i] = ',';
5098 }
5099
5100 /* Remove newval[] from origval[]. (Note: "i" has
5101 * been set above and is used here). */
5102 if (removing)
5103 {
5104 STRCPY(newval, origval);
5105 if (*s)
5106 {
5107 /* may need to remove a comma */
5108 if (flags & P_COMMA)
5109 {
5110 if (s == origval)
5111 {
5112 /* include comma after string */
5113 if (s[i] == ',')
5114 ++i;
5115 }
5116 else
5117 {
5118 /* include comma before string */
5119 --s;
5120 ++i;
5121 }
5122 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005123 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005124 }
5125 }
5126
5127 if (flags & P_FLAGLIST)
5128 {
5129 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005130 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005131 {
5132 /* if options have P_FLAGLIST and
5133 * P_ONECOMMA such as 'whichwrap' */
5134 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005135 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005136 if (*s != ',' && *(s + 1) == ','
5137 && vim_strchr(s + 2, *s) != NULL)
5138 {
5139 /* Remove the duplicated value and
5140 * the next comma. */
5141 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005142 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005143 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005144 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005145 else
5146 {
5147 if ((!(flags & P_COMMA) || *s != ',')
5148 && vim_strchr(s + 1, *s) != NULL)
5149 {
5150 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005151 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005152 }
5153 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005154 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005155 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005156 }
5157
5158 if (save_arg != NULL) /* number for 'whichwrap' */
5159 arg = save_arg;
5160 new_value_alloced = TRUE;
5161 }
5162
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005163 /*
5164 * Set the new value.
5165 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005166 *(char_u **)(varp) = newval;
5167
Bram Moolenaar53744302015-07-17 17:38:22 +02005168#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005169 if (!starting
5170# ifdef FEAT_CRYPT
5171 && options[opt_idx].indir != PV_KEY
5172# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005173 && origval != NULL && newval != NULL)
5174 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005175 /* origval may be freed by
5176 * did_set_string_option(), make a copy. */
5177 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005178 /* newval (and varp) may become invalid if the
5179 * buffer is closed by autocommands. */
5180 saved_newval = vim_strsave(newval);
5181 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005182#endif
5183
Bram Moolenaar071d4272004-06-13 20:20:40 +00005184 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005185 * ":set" on local options. Note: when setting 'syntax'
5186 * or 'filetype' autocommands may be triggered that can
5187 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005188 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5189 new_value_alloced, oldval, errbuf, opt_flags);
5190
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005191#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5192 if (errmsg == NULL)
5193 trigger_optionsset_string(opt_idx, opt_flags,
5194 saved_origval, saved_newval);
5195 vim_free(saved_origval);
5196 vim_free(saved_newval);
5197#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005198 /* If error detected, print the error message. */
5199 if (errmsg != NULL)
5200 goto skip;
5201 }
5202 else /* key code option */
5203 {
5204 char_u *p;
5205
5206 if (nextchar == '&')
5207 {
5208 if (add_termcap_entry(key_name, TRUE) == FAIL)
5209 errmsg = (char_u *)N_("E522: Not found in termcap");
5210 }
5211 else
5212 {
5213 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005214 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005215 if (*p == '\\' && p[1] != NUL)
5216 ++p;
5217 nextchar = *p;
5218 *p = NUL;
5219 add_termcode(key_name, arg, FALSE);
5220 *p = nextchar;
5221 }
5222 if (full_screen)
5223 ttest(FALSE);
5224 redraw_all_later(CLEAR);
5225 }
5226 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005227
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005229 did_set_option(opt_idx, opt_flags,
5230 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005231 }
5232
5233skip:
5234 /*
5235 * Advance to next argument.
5236 * - skip until a blank found, taking care of backslashes
5237 * - skip blanks
5238 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5239 */
5240 for (i = 0; i < 2 ; ++i)
5241 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005242 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005243 if (*arg++ == '\\' && *arg != NUL)
5244 ++arg;
5245 arg = skipwhite(arg);
5246 if (*arg != '=')
5247 break;
5248 }
5249 }
5250
5251 if (errmsg != NULL)
5252 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005253 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005254 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255 if (i + (arg - startarg) < IOSIZE)
5256 {
5257 /* append the argument with the error */
5258 STRCAT(IObuff, ": ");
5259 mch_memmove(IObuff + i, startarg, (arg - startarg));
5260 IObuff[i + (arg - startarg)] = NUL;
5261 }
5262 /* make sure all characters are printable */
5263 trans_characters(IObuff, IOSIZE);
5264
5265 ++no_wait_return; /* wait_return done later */
5266 emsg(IObuff); /* show error highlighted */
5267 --no_wait_return;
5268
5269 return FAIL;
5270 }
5271
5272 arg = skipwhite(arg);
5273 }
5274
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005275theend:
5276 if (silent_mode && did_show)
5277 {
5278 /* After displaying option values in silent mode. */
5279 silent_mode = FALSE;
5280 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5281 msg_putchar('\n');
5282 cursor_on(); /* msg_start() switches it off */
5283 out_flush();
5284 silent_mode = TRUE;
5285 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5286 }
5287
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288 return OK;
5289}
5290
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005291/*
5292 * Call this when an option has been given a new value through a user command.
5293 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5294 */
5295 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005296did_set_option(
5297 int opt_idx,
5298 int opt_flags, /* possibly with OPT_MODELINE */
5299 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005300{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005301 long_u *p;
5302
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005303 options[opt_idx].flags |= P_WAS_SET;
5304
5305 /* When an option is set in the sandbox, from a modeline or in secure mode
5306 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005307 * flag. */
5308 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005309 if (secure
5310#ifdef HAVE_SANDBOX
5311 || sandbox != 0
5312#endif
5313 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005314 *p = *p | P_INSECURE;
5315 else if (new_value)
5316 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005317}
5318
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005320illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005321{
5322 if (errbuf == NULL)
5323 return (char_u *)"";
5324 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005325 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 return errbuf;
5327}
5328
5329/*
5330 * Convert a key name or string into a key value.
5331 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005332 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005334 int
5335string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336{
5337 if (*arg == '<')
5338 return find_key_option(arg + 1);
5339 if (*arg == '^')
5340 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005341 if (multi_byte)
5342 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343 return *arg;
5344}
5345
5346#ifdef FEAT_CMDWIN
5347/*
5348 * Check value of 'cedit' and set cedit_key.
5349 * Returns NULL if value is OK, error message otherwise.
5350 */
5351 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005352check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353{
5354 int n;
5355
5356 if (*p_cedit == NUL)
5357 cedit_key = -1;
5358 else
5359 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005360 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005361 if (vim_isprintc(n))
5362 return e_invarg;
5363 cedit_key = n;
5364 }
5365 return NULL;
5366}
5367#endif
5368
5369#ifdef FEAT_TITLE
5370/*
5371 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5372 * maketitle() to create and display it.
5373 * When switching the title or icon off, call mch_restore_title() to get
5374 * the old value back.
5375 */
5376 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005377did_set_title(
5378 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379{
5380 if (starting != NO_SCREEN
5381#ifdef FEAT_GUI
5382 && !gui.starting
5383#endif
5384 )
5385 {
5386 maketitle();
5387 if (icon)
5388 {
5389 if (!p_icon)
5390 mch_restore_title(2);
5391 }
5392 else
5393 {
5394 if (!p_title)
5395 mch_restore_title(1);
5396 }
5397 }
5398}
5399#endif
5400
5401/*
5402 * set_options_bin - called when 'bin' changes value.
5403 */
5404 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005405set_options_bin(
5406 int oldval,
5407 int newval,
5408 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005409{
5410 /*
5411 * The option values that are changed when 'bin' changes are
5412 * copied when 'bin is set and restored when 'bin' is reset.
5413 */
5414 if (newval)
5415 {
5416 if (!oldval) /* switched on */
5417 {
5418 if (!(opt_flags & OPT_GLOBAL))
5419 {
5420 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5421 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5422 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5423 curbuf->b_p_et_nobin = curbuf->b_p_et;
5424 }
5425 if (!(opt_flags & OPT_LOCAL))
5426 {
5427 p_tw_nobin = p_tw;
5428 p_wm_nobin = p_wm;
5429 p_ml_nobin = p_ml;
5430 p_et_nobin = p_et;
5431 }
5432 }
5433
5434 if (!(opt_flags & OPT_GLOBAL))
5435 {
5436 curbuf->b_p_tw = 0; /* no automatic line wrap */
5437 curbuf->b_p_wm = 0; /* no automatic line wrap */
5438 curbuf->b_p_ml = 0; /* no modelines */
5439 curbuf->b_p_et = 0; /* no expandtab */
5440 }
5441 if (!(opt_flags & OPT_LOCAL))
5442 {
5443 p_tw = 0;
5444 p_wm = 0;
5445 p_ml = FALSE;
5446 p_et = FALSE;
5447 p_bin = TRUE; /* needed when called for the "-b" argument */
5448 }
5449 }
5450 else if (oldval) /* switched off */
5451 {
5452 if (!(opt_flags & OPT_GLOBAL))
5453 {
5454 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5455 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5456 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5457 curbuf->b_p_et = curbuf->b_p_et_nobin;
5458 }
5459 if (!(opt_flags & OPT_LOCAL))
5460 {
5461 p_tw = p_tw_nobin;
5462 p_wm = p_wm_nobin;
5463 p_ml = p_ml_nobin;
5464 p_et = p_et_nobin;
5465 }
5466 }
5467}
5468
5469#ifdef FEAT_VIMINFO
5470/*
5471 * Find the parameter represented by the given character (eg ', :, ", or /),
5472 * and return its associated value in the 'viminfo' string.
5473 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005474 * If the parameter is not specified in the string or there is no following
5475 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005476 */
5477 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005478get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005479{
5480 char_u *p;
5481
5482 p = find_viminfo_parameter(type);
5483 if (p != NULL && VIM_ISDIGIT(*p))
5484 return atoi((char *)p);
5485 return -1;
5486}
5487
5488/*
5489 * Find the parameter represented by the given character (eg ''', ':', '"', or
5490 * '/') in the 'viminfo' option and return a pointer to the string after it.
5491 * Return NULL if the parameter is not specified in the string.
5492 */
5493 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005494find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495{
5496 char_u *p;
5497
5498 for (p = p_viminfo; *p; ++p)
5499 {
5500 if (*p == type)
5501 return p + 1;
5502 if (*p == 'n') /* 'n' is always the last one */
5503 break;
5504 p = vim_strchr(p, ','); /* skip until next ',' */
5505 if (p == NULL) /* hit the end without finding parameter */
5506 break;
5507 }
5508 return NULL;
5509}
5510#endif
5511
5512/*
5513 * Expand environment variables for some string options.
5514 * These string options cannot be indirect!
5515 * If "val" is NULL expand the current value of the option.
5516 * Return pointer to NameBuff, or NULL when not expanded.
5517 */
5518 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005519option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520{
5521 /* if option doesn't need expansion nothing to do */
5522 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5523 return NULL;
5524
5525 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5526 * expand_env() would truncate the string. */
5527 if (val != NULL && STRLEN(val) > MAXPATHL)
5528 return NULL;
5529
5530 if (val == NULL)
5531 val = *(char_u **)options[opt_idx].var;
5532
5533 /*
5534 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5535 * Escape spaces when expanding 'tags', they are used to separate file
5536 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005537 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005538 */
5539 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005540 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005541#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005542 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5543#endif
5544 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5546 return NULL;
5547
5548 return NameBuff;
5549}
5550
5551/*
5552 * After setting various option values: recompute variables that depend on
5553 * option values.
5554 */
5555 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005556didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557{
5558 /* initialize the table for 'iskeyword' et.al. */
5559 (void)init_chartab();
5560
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005561#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005563#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005565 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566#ifdef FEAT_SESSION
5567 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5568 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5569#endif
5570#ifdef FEAT_FOLDING
5571 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5572#endif
5573 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005574 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575#ifdef FEAT_VIRTUALEDIT
5576 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5577#endif
5578#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5579 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5580#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005581#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005582 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005583 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005584 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005585 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005587#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5588 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5589#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005590#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5592#endif
5593#ifdef FEAT_CMDWIN
5594 /* set cedit_key */
5595 (void)check_cedit();
5596#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005597#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005598 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005599#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005600#ifdef FEAT_LINEBREAK
5601 /* initialize the table for 'breakat'. */
5602 fill_breakat_flags();
5603#endif
5604
5605}
5606
5607/*
5608 * More side effects of setting options.
5609 */
5610 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005611didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005612{
5613 /* Initialize the highlight_attr[] table. */
5614 (void)highlight_changed();
5615
5616 /* Parse default for 'wildmode' */
5617 check_opt_wim();
5618
5619 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005620 /* Parse default for 'fillchars'. */
5621 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005622
5623#ifdef FEAT_CLIPBOARD
5624 /* Parse default for 'clipboard' */
5625 (void)check_clipboard_option();
5626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627}
5628
5629/*
5630 * Check for string options that are NULL (normally only termcap options).
5631 */
5632 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005633check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005634{
5635 int opt_idx;
5636
5637 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5638 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5639 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5640}
5641
5642/*
5643 * Check string options in a buffer for NULL value.
5644 */
5645 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005646check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005647{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648 check_string_option(&buf->b_p_bh);
5649 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650#ifdef FEAT_MBYTE
5651 check_string_option(&buf->b_p_fenc);
5652#endif
5653 check_string_option(&buf->b_p_ff);
5654#ifdef FEAT_FIND_ID
5655 check_string_option(&buf->b_p_def);
5656 check_string_option(&buf->b_p_inc);
5657# ifdef FEAT_EVAL
5658 check_string_option(&buf->b_p_inex);
5659# endif
5660#endif
5661#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5662 check_string_option(&buf->b_p_inde);
5663 check_string_option(&buf->b_p_indk);
5664#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005665#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5666 check_string_option(&buf->b_p_bexpr);
5667#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005668#if defined(FEAT_CRYPT)
5669 check_string_option(&buf->b_p_cm);
5670#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005671 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005672#if defined(FEAT_EVAL)
5673 check_string_option(&buf->b_p_fex);
5674#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675#ifdef FEAT_CRYPT
5676 check_string_option(&buf->b_p_key);
5677#endif
5678 check_string_option(&buf->b_p_kp);
5679 check_string_option(&buf->b_p_mps);
5680 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005681 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 check_string_option(&buf->b_p_isk);
5683#ifdef FEAT_COMMENTS
5684 check_string_option(&buf->b_p_com);
5685#endif
5686#ifdef FEAT_FOLDING
5687 check_string_option(&buf->b_p_cms);
5688#endif
5689 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005690#ifdef FEAT_TEXTOBJ
5691 check_string_option(&buf->b_p_qe);
5692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693#ifdef FEAT_SYN_HL
5694 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005695 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005696#endif
5697#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005698 check_string_option(&buf->b_s.b_p_spc);
5699 check_string_option(&buf->b_s.b_p_spf);
5700 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701#endif
5702#ifdef FEAT_SEARCHPATH
5703 check_string_option(&buf->b_p_sua);
5704#endif
5705#ifdef FEAT_CINDENT
5706 check_string_option(&buf->b_p_cink);
5707 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005708 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709#endif
5710#ifdef FEAT_AUTOCMD
5711 check_string_option(&buf->b_p_ft);
5712#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5714 check_string_option(&buf->b_p_cinw);
5715#endif
5716#ifdef FEAT_INS_EXPAND
5717 check_string_option(&buf->b_p_cpt);
5718#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005719#ifdef FEAT_COMPL_FUNC
5720 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005721 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005723#ifdef FEAT_KEYMAP
5724 check_string_option(&buf->b_p_keymap);
5725#endif
5726#ifdef FEAT_QUICKFIX
5727 check_string_option(&buf->b_p_gp);
5728 check_string_option(&buf->b_p_mp);
5729 check_string_option(&buf->b_p_efm);
5730#endif
5731 check_string_option(&buf->b_p_ep);
5732 check_string_option(&buf->b_p_path);
5733 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005734 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735#ifdef FEAT_INS_EXPAND
5736 check_string_option(&buf->b_p_dict);
5737 check_string_option(&buf->b_p_tsr);
5738#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005739#ifdef FEAT_LISP
5740 check_string_option(&buf->b_p_lw);
5741#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005742 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005743#ifdef FEAT_MBYTE
5744 check_string_option(&buf->b_p_menc);
5745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746}
5747
5748/*
5749 * Free the string allocated for an option.
5750 * Checks for the string being empty_option. This may happen if we're out of
5751 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5752 * check_options().
5753 * Does NOT check for P_ALLOCED flag!
5754 */
5755 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005756free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757{
5758 if (p != empty_option)
5759 vim_free(p);
5760}
5761
5762 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005763clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764{
5765 if (*pp != empty_option)
5766 vim_free(*pp);
5767 *pp = empty_option;
5768}
5769
5770 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005771check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772{
5773 if (*pp == NULL)
5774 *pp = empty_option;
5775}
5776
5777/*
5778 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5779 */
5780 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005781set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005782{
5783 int opt_idx;
5784
5785 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5786 if (options[opt_idx].var == (char_u *)p)
5787 {
5788 options[opt_idx].flags |= P_ALLOCED;
5789 return;
5790 }
5791 return; /* cannot happen: didn't find it! */
5792}
5793
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005794#if defined(FEAT_EVAL) || defined(PROTO)
5795/*
5796 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5797 * Return FALSE when it wasn't.
5798 * Return -1 for an unknown option.
5799 */
5800 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005801was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005802{
5803 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005804 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005805
5806 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005807 {
5808 flagp = insecure_flag(idx, opt_flags);
5809 return (*flagp & P_INSECURE) != 0;
5810 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005811 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005812 return -1;
5813}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005814
5815/*
5816 * Get a pointer to the flags used for the P_INSECURE flag of option
5817 * "opt_idx". For some local options a local flags field is used.
5818 */
5819 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005820insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005821{
5822 if (opt_flags & OPT_LOCAL)
5823 switch ((int)options[opt_idx].indir)
5824 {
5825#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005826 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005827#endif
5828#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005829# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005830 case PV_FDE: return &curwin->w_p_fde_flags;
5831 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005832# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005833# ifdef FEAT_BEVAL
5834 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5835# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005836# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005837 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005838# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005839 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005840# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005841 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005842# endif
5843#endif
5844 }
5845
5846 /* Nothing special, return global flags field. */
5847 return &options[opt_idx].flags;
5848}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005849#endif
5850
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005851#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005852static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005853
5854/*
5855 * Redraw the window title and/or tab page text later.
5856 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005857static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005858{
5859 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005860 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005861}
5862#endif
5863
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864/*
5865 * Set a string option to a new value (without checking the effect).
5866 * The string is copied into allocated memory.
5867 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005868 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005869 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870 */
5871 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005872set_string_option_direct(
5873 char_u *name,
5874 int opt_idx,
5875 char_u *val,
5876 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5877 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878{
5879 char_u *s;
5880 char_u **varp;
5881 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005882 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883
Bram Moolenaar89d40322006-08-29 15:30:07 +00005884 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005886 idx = findoption(name);
5887 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005888 {
5889 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005890 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005892 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 }
5894
Bram Moolenaar89d40322006-08-29 15:30:07 +00005895 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 return;
5897
5898 s = vim_strsave(val);
5899 if (s != NULL)
5900 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005901 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005902 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 free_string_option(*varp);
5905 *varp = s;
5906
5907 /* For buffer/window local option may also set the global value. */
5908 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005909 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910
Bram Moolenaar89d40322006-08-29 15:30:07 +00005911 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912
5913 /* When setting both values of a global option with a local value,
5914 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005915 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 {
5917 free_string_option(*varp);
5918 *varp = empty_option;
5919 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005920# ifdef FEAT_EVAL
5921 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005922 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005923 set_sid == 0 ? current_SID : set_sid);
5924# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925 }
5926}
5927
5928/*
5929 * Set global value for string option when it's a local option.
5930 */
5931 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005932set_string_option_global(
5933 int opt_idx, /* option index */
5934 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935{
5936 char_u **p, *s;
5937
5938 /* the global value is always allocated */
5939 if (options[opt_idx].var == VAR_WIN)
5940 p = (char_u **)GLOBAL_WO(varp);
5941 else
5942 p = (char_u **)options[opt_idx].var;
5943 if (options[opt_idx].indir != PV_NONE
5944 && p != varp
5945 && (s = vim_strsave(*varp)) != NULL)
5946 {
5947 free_string_option(*p);
5948 *p = s;
5949 }
5950}
5951
5952/*
5953 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005954 *
5955 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005957 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005958set_string_option(
5959 int opt_idx,
5960 char_u *value,
5961 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962{
5963 char_u *s;
5964 char_u **varp;
5965 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005966#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5967 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005968 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005969#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005970 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971
5972 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005973 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974
5975 s = vim_strsave(value);
5976 if (s != NULL)
5977 {
5978 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5979 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005980 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005981 ? OPT_GLOBAL : OPT_LOCAL)
5982 : opt_flags);
5983 oldval = *varp;
5984 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005985
5986#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005987 if (!starting
5988# ifdef FEAT_CRYPT
5989 && options[opt_idx].indir != PV_KEY
5990# endif
5991 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005992 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005993 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005994 saved_newval = vim_strsave(s);
5995 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005996#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005997 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5998 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005999 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006000
Bram Moolenaar53744302015-07-17 17:38:22 +02006001#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006002 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006003 if (r == NULL)
6004 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006005 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006006 vim_free(saved_oldval);
6007 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006010 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011}
6012
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006013#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006015 * Return TRUE if "val" is a valid 'filetype' name.
6016 * Also used for 'syntax' and 'keymap'.
6017 */
6018 static int
6019valid_filetype(char_u *val)
6020{
6021 char_u *s;
6022
6023 for (s = val; *s != NUL; ++s)
6024 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6025 return FALSE;
6026 return TRUE;
6027}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006028#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006029
6030/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006031 * Handle string options that need some action to perform when changed.
6032 * Returns NULL for success, or an error message for an error.
6033 */
6034 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006035did_set_string_option(
6036 int opt_idx, /* index in options[] table */
6037 char_u **varp, /* pointer to the option variable */
6038 int new_value_alloced, /* new value was allocated */
6039 char_u *oldval, /* previous value of the option */
6040 char_u *errbuf, /* buffer for errors, or NULL */
6041 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006042{
6043 char_u *errmsg = NULL;
6044 char_u *s, *p;
6045 int did_chartab = FALSE;
6046 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006047 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006048#ifdef FEAT_GUI
6049 /* set when changing an option that only requires a redraw in the GUI */
6050 int redraw_gui_only = FALSE;
6051#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006052#ifdef FEAT_AUTOCMD
6053 int ft_changed = FALSE;
6054#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006055
6056 /* Get the global option to compare with, otherwise we would have to check
6057 * two values for all local options. */
6058 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6059
6060 /* Disallow changing some options from secure mode */
6061 if ((secure
6062#ifdef HAVE_SANDBOX
6063 || sandbox != 0
6064#endif
6065 ) && (options[opt_idx].flags & P_SECURE))
6066 {
6067 errmsg = e_secure;
6068 }
6069
Bram Moolenaar7554da42016-11-25 22:04:13 +01006070 /* Check for a "normal" directory or file name in some options. Disallow a
6071 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006072 * are often illegal in a file name. Be more permissive if "secure" is off.
6073 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006074 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006075 && vim_strpbrk(*varp, (char_u *)(secure
6076 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006077 || ((options[opt_idx].flags & P_NDNAME)
6078 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006079 {
6080 errmsg = e_invarg;
6081 }
6082
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083 /* 'term' */
6084 else if (varp == &T_NAME)
6085 {
6086 if (T_NAME[0] == NUL)
6087 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6088#ifdef FEAT_GUI
6089 if (gui.in_use)
6090 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6091 else if (term_is_gui(T_NAME))
6092 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6093#endif
6094 else if (set_termname(T_NAME) == FAIL)
6095 errmsg = (char_u *)N_("E522: Not found in termcap");
6096 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006097 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006098 /* Screen colors may have changed. */
6099 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006100
6101 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6102 * P_ALLOCED flag on 'term'. */
6103 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006104 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006105 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106 }
6107
6108 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006109 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006111 char_u *bkc = p_bkc;
6112 unsigned int *flags = &bkc_flags;
6113
6114 if (opt_flags & OPT_LOCAL)
6115 {
6116 bkc = curbuf->b_p_bkc;
6117 flags = &curbuf->b_bkc_flags;
6118 }
6119
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006120 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6121 /* make the local value empty: use the global value */
6122 *flags = 0;
6123 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006125 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6126 errmsg = e_invarg;
6127 if ((((int)*flags & BKC_AUTO) != 0)
6128 + (((int)*flags & BKC_YES) != 0)
6129 + (((int)*flags & BKC_NO) != 0) != 1)
6130 {
6131 /* Must have exactly one of "auto", "yes" and "no". */
6132 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6133 errmsg = e_invarg;
6134 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135 }
6136 }
6137
6138 /* 'backupext' and 'patchmode' */
6139 else if (varp == &p_bex || varp == &p_pm)
6140 {
6141 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6142 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6143 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6144 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006145#ifdef FEAT_LINEBREAK
6146 /* 'breakindentopt' */
6147 else if (varp == &curwin->w_p_briopt)
6148 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006149 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006150 errmsg = e_invarg;
6151 }
6152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006153
6154 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006155 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006157 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006158 */
6159 else if ( varp == &p_isi
6160 || varp == &(curbuf->b_p_isk)
6161 || varp == &p_isp
6162 || varp == &p_isf)
6163 {
6164 if (init_chartab() == FAIL)
6165 {
6166 did_chartab = TRUE; /* need to restore it below */
6167 errmsg = e_invarg; /* error in value */
6168 }
6169 }
6170
6171 /* 'helpfile' */
6172 else if (varp == &p_hf)
6173 {
6174 /* May compute new values for $VIM and $VIMRUNTIME */
6175 if (didset_vim)
6176 {
6177 vim_setenv((char_u *)"VIM", (char_u *)"");
6178 didset_vim = FALSE;
6179 }
6180 if (didset_vimruntime)
6181 {
6182 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6183 didset_vimruntime = FALSE;
6184 }
6185 }
6186
Bram Moolenaar1a384422010-07-14 19:53:30 +02006187#ifdef FEAT_SYN_HL
6188 /* 'colorcolumn' */
6189 else if (varp == &curwin->w_p_cc)
6190 errmsg = check_colorcolumn(curwin);
6191#endif
6192
Bram Moolenaar071d4272004-06-13 20:20:40 +00006193#ifdef FEAT_MULTI_LANG
6194 /* 'helplang' */
6195 else if (varp == &p_hlg)
6196 {
6197 /* Check for "", "ab", "ab,cd", etc. */
6198 for (s = p_hlg; *s != NUL; s += 3)
6199 {
6200 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6201 {
6202 errmsg = e_invarg;
6203 break;
6204 }
6205 if (s[2] == NUL)
6206 break;
6207 }
6208 }
6209#endif
6210
6211 /* 'highlight' */
6212 else if (varp == &p_hl)
6213 {
6214 if (highlight_changed() == FAIL)
6215 errmsg = e_invarg; /* invalid flags */
6216 }
6217
6218 /* 'nrformats' */
6219 else if (gvarp == &p_nf)
6220 {
6221 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6222 errmsg = e_invarg;
6223 }
6224
6225#ifdef FEAT_SESSION
6226 /* 'sessionoptions' */
6227 else if (varp == &p_ssop)
6228 {
6229 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6230 errmsg = e_invarg;
6231 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6232 {
6233 /* Don't allow both "sesdir" and "curdir". */
6234 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6235 errmsg = e_invarg;
6236 }
6237 }
6238 /* 'viewoptions' */
6239 else if (varp == &p_vop)
6240 {
6241 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6242 errmsg = e_invarg;
6243 }
6244#endif
6245
6246 /* 'scrollopt' */
6247#ifdef FEAT_SCROLLBIND
6248 else if (varp == &p_sbo)
6249 {
6250 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6251 errmsg = e_invarg;
6252 }
6253#endif
6254
6255 /* 'ambiwidth' */
6256#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006257 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 {
6259 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6260 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006261 else if (set_chars_option(&p_lcs) != NULL)
6262 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006263 else if (set_chars_option(&p_fcs) != NULL)
6264 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265 }
6266#endif
6267
6268 /* 'background' */
6269 else if (varp == &p_bg)
6270 {
6271 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6272 {
6273#ifdef FEAT_EVAL
6274 int dark = (*p_bg == 'd');
6275#endif
6276
6277 init_highlight(FALSE, FALSE);
6278
6279#ifdef FEAT_EVAL
6280 if (dark != (*p_bg == 'd')
6281 && get_var_value((char_u *)"g:colors_name") != NULL)
6282 {
6283 /* The color scheme must have set 'background' back to another
6284 * value, that's not what we want here. Disable the color
6285 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006286 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006287 free_string_option(p_bg);
6288 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6289 check_string_option(&p_bg);
6290 init_highlight(FALSE, FALSE);
6291 }
6292#endif
6293 }
6294 else
6295 errmsg = e_invarg;
6296 }
6297
6298 /* 'wildmode' */
6299 else if (varp == &p_wim)
6300 {
6301 if (check_opt_wim() == FAIL)
6302 errmsg = e_invarg;
6303 }
6304
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006305#ifdef FEAT_CMDL_COMPL
6306 /* 'wildoptions' */
6307 else if (varp == &p_wop)
6308 {
6309 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6310 errmsg = e_invarg;
6311 }
6312#endif
6313
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314#ifdef FEAT_WAK
6315 /* 'winaltkeys' */
6316 else if (varp == &p_wak)
6317 {
6318 if (*p_wak == NUL
6319 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6320 errmsg = e_invarg;
6321# ifdef FEAT_MENU
6322# ifdef FEAT_GUI_MOTIF
6323 else if (gui.in_use)
6324 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6325# else
6326# ifdef FEAT_GUI_GTK
6327 else if (gui.in_use)
6328 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6329# endif
6330# endif
6331# endif
6332 }
6333#endif
6334
6335#ifdef FEAT_AUTOCMD
6336 /* 'eventignore' */
6337 else if (varp == &p_ei)
6338 {
6339 if (check_ei() == FAIL)
6340 errmsg = e_invarg;
6341 }
6342#endif
6343
6344#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006345 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6346 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6347 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 {
6349 if (gvarp == &p_fenc)
6350 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006351 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006352 errmsg = e_modifiable;
6353 else if (vim_strchr(*varp, ',') != NULL)
6354 /* No comma allowed in 'fileencoding'; catches confusing it
6355 * with 'fileencodings'. */
6356 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006358 {
6359# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006360 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006361 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006362# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006363 /* Add 'fileencoding' to the swap file. */
6364 ml_setflags(curbuf);
6365 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006366 }
6367 if (errmsg == NULL)
6368 {
6369 /* canonize the value, so that STRCMP() can be used on it */
6370 p = enc_canonize(*varp);
6371 if (p != NULL)
6372 {
6373 vim_free(*varp);
6374 *varp = p;
6375 }
6376 if (varp == &p_enc)
6377 {
6378 errmsg = mb_init();
6379# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006380 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381# endif
6382 }
6383 }
6384
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006385# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6387 {
6388 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6389 if (STRCMP(p_tenc, "utf-8") != 0)
6390 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6391 }
6392# endif
6393
6394 if (errmsg == NULL)
6395 {
6396# ifdef FEAT_KEYMAP
6397 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6398 * (with another encoding). */
6399 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6400 (void)keymap_init();
6401# endif
6402
6403 /* When 'termencoding' is not empty and 'encoding' changes or when
6404 * 'termencoding' changes, need to setup for keyboard input and
6405 * display output conversion. */
6406 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6407 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006408 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6409 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6410 {
6411 EMSG3(_("E950: Cannot convert between %s and %s"),
6412 p_tenc, p_enc);
6413 errmsg = e_invarg;
6414 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006416
6417# if defined(WIN3264) && defined(FEAT_MBYTE)
6418 /* $HOME may have characters in active code page. */
6419 if (varp == &p_enc)
6420 init_homedir();
6421# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006422 }
6423 }
6424#endif
6425
6426#if defined(FEAT_POSTSCRIPT)
6427 else if (varp == &p_penc)
6428 {
6429 /* Canonize printencoding if VIM standard one */
6430 p = enc_canonize(p_penc);
6431 if (p != NULL)
6432 {
6433 vim_free(p_penc);
6434 p_penc = p;
6435 }
6436 else
6437 {
6438 /* Ensure lower case and '-' for '_' */
6439 for (s = p_penc; *s != NUL; s++)
6440 {
6441 if (*s == '_')
6442 *s = '-';
6443 else
6444 *s = TOLOWER_ASC(*s);
6445 }
6446 }
6447 }
6448#endif
6449
Bram Moolenaar9372a112005-12-06 19:59:18 +00006450#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006451 else if (varp == &p_imak)
6452 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006453 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 errmsg = e_invarg;
6455 }
6456#endif
6457
6458#ifdef FEAT_KEYMAP
6459 else if (varp == &curbuf->b_p_keymap)
6460 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006461 if (!valid_filetype(*varp))
6462 errmsg = e_invarg;
6463 else
6464 /* load or unload key mapping tables */
6465 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466
Bram Moolenaarfab06232009-03-04 03:13:35 +00006467 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006469 if (*curbuf->b_p_keymap != NUL)
6470 {
6471 /* Installed a new keymap, switch on using it. */
6472 curbuf->b_p_iminsert = B_IMODE_LMAP;
6473 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6474 curbuf->b_p_imsearch = B_IMODE_LMAP;
6475 }
6476 else
6477 {
6478 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6479 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6480 curbuf->b_p_iminsert = B_IMODE_NONE;
6481 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6482 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6483 }
6484 if ((opt_flags & OPT_LOCAL) == 0)
6485 {
6486 set_iminsert_global();
6487 set_imsearch_global();
6488 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 }
6491 }
6492#endif
6493
6494 /* 'fileformat' */
6495 else if (gvarp == &p_ff)
6496 {
6497 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6498 errmsg = e_modifiable;
6499 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6500 errmsg = e_invarg;
6501 else
6502 {
6503 /* may also change 'textmode' */
6504 if (get_fileformat(curbuf) == EOL_DOS)
6505 curbuf->b_p_tx = TRUE;
6506 else
6507 curbuf->b_p_tx = FALSE;
6508#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006509 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006510#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006511 /* update flag in swap file */
6512 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006513 /* Redraw needed when switching to/from "mac": a CR in the text
6514 * will be displayed differently. */
6515 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6516 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006517 }
6518 }
6519
6520 /* 'fileformats' */
6521 else if (varp == &p_ffs)
6522 {
6523 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6524 errmsg = e_invarg;
6525 else
6526 {
6527 /* also change 'textauto' */
6528 if (*p_ffs == NUL)
6529 p_ta = FALSE;
6530 else
6531 p_ta = TRUE;
6532 }
6533 }
6534
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006535#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006536 /* 'cryptkey' */
6537 else if (gvarp == &p_key)
6538 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006539# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006540 /* Make sure the ":set" command doesn't show the new value in the
6541 * history. */
6542 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006543# endif
6544 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6545 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006546 ml_set_crypt_key(curbuf, oldval,
6547 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006548 }
6549
6550 else if (gvarp == &p_cm)
6551 {
6552 if (opt_flags & OPT_LOCAL)
6553 p = curbuf->b_p_cm;
6554 else
6555 p = p_cm;
6556 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6557 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006558 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006559 errmsg = e_invarg;
6560 else
6561 {
6562 /* When setting the global value to empty, make it "zip". */
6563 if (*p_cm == NUL)
6564 {
6565 if (new_value_alloced)
6566 free_string_option(p_cm);
6567 p_cm = vim_strsave((char_u *)"zip");
6568 new_value_alloced = TRUE;
6569 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006570 /* When using ":set cm=name" the local value is going to be empty.
6571 * Do that here, otherwise the crypt functions will still use the
6572 * local value. */
6573 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6574 {
6575 free_string_option(curbuf->b_p_cm);
6576 curbuf->b_p_cm = empty_option;
6577 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006578
6579 /* Need to update the swapfile when the effective method changed.
6580 * Set "s" to the effective old value, "p" to the effective new
6581 * method and compare. */
6582 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6583 s = p_cm; /* was previously using the global value */
6584 else
6585 s = oldval;
6586 if (*curbuf->b_p_cm == NUL)
6587 p = p_cm; /* is now using the global value */
6588 else
6589 p = curbuf->b_p_cm;
6590 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006591 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006592
6593 /* If the global value changes need to update the swapfile for all
6594 * buffers using that value. */
6595 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6596 {
6597 buf_T *buf;
6598
Bram Moolenaar29323592016-07-24 22:04:11 +02006599 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006600 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006601 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006602 }
6603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 }
6605#endif
6606
6607 /* 'matchpairs' */
6608 else if (gvarp == &p_mps)
6609 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006610#ifdef FEAT_MBYTE
6611 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006612 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006613 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006614 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006615 int x2 = -1;
6616 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006617
6618 if (*p != NUL)
6619 p += mb_ptr2len(p);
6620 if (*p != NUL)
6621 x2 = *p++;
6622 if (*p != NUL)
6623 {
6624 x3 = mb_ptr2char(p);
6625 p += mb_ptr2len(p);
6626 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006627 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006628 {
6629 errmsg = e_invarg;
6630 break;
6631 }
6632 if (*p == NUL)
6633 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006635 }
6636 else
6637#endif
6638 {
6639 /* Check for "x:y,x:y" */
6640 for (p = *varp; *p != NUL; p += 4)
6641 {
6642 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6643 {
6644 errmsg = e_invarg;
6645 break;
6646 }
6647 if (p[3] == NUL)
6648 break;
6649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650 }
6651 }
6652
6653#ifdef FEAT_COMMENTS
6654 /* 'comments' */
6655 else if (gvarp == &p_com)
6656 {
6657 for (s = *varp; *s; )
6658 {
6659 while (*s && *s != ':')
6660 {
6661 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6662 && !VIM_ISDIGIT(*s) && *s != '-')
6663 {
6664 errmsg = illegal_char(errbuf, *s);
6665 break;
6666 }
6667 ++s;
6668 }
6669 if (*s++ == NUL)
6670 errmsg = (char_u *)N_("E524: Missing colon");
6671 else if (*s == ',' || *s == NUL)
6672 errmsg = (char_u *)N_("E525: Zero length string");
6673 if (errmsg != NULL)
6674 break;
6675 while (*s && *s != ',')
6676 {
6677 if (*s == '\\' && s[1] != NUL)
6678 ++s;
6679 ++s;
6680 }
6681 s = skip_to_option_part(s);
6682 }
6683 }
6684#endif
6685
6686 /* 'listchars' */
6687 else if (varp == &p_lcs)
6688 {
6689 errmsg = set_chars_option(varp);
6690 }
6691
Bram Moolenaar071d4272004-06-13 20:20:40 +00006692 /* 'fillchars' */
6693 else if (varp == &p_fcs)
6694 {
6695 errmsg = set_chars_option(varp);
6696 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006697
6698#ifdef FEAT_CMDWIN
6699 /* 'cedit' */
6700 else if (varp == &p_cedit)
6701 {
6702 errmsg = check_cedit();
6703 }
6704#endif
6705
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006706 /* 'verbosefile' */
6707 else if (varp == &p_vfile)
6708 {
6709 verbose_stop();
6710 if (*p_vfile != NUL && verbose_open() == FAIL)
6711 errmsg = e_invarg;
6712 }
6713
Bram Moolenaar071d4272004-06-13 20:20:40 +00006714#ifdef FEAT_VIMINFO
6715 /* 'viminfo' */
6716 else if (varp == &p_viminfo)
6717 {
6718 for (s = p_viminfo; *s;)
6719 {
6720 /* Check it's a valid character */
6721 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6722 {
6723 errmsg = illegal_char(errbuf, *s);
6724 break;
6725 }
6726 if (*s == 'n') /* name is always last one */
6727 {
6728 break;
6729 }
6730 else if (*s == 'r') /* skip until next ',' */
6731 {
6732 while (*++s && *s != ',')
6733 ;
6734 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006735 else if (*s == '%')
6736 {
6737 /* optional number */
6738 while (vim_isdigit(*++s))
6739 ;
6740 }
6741 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006742 ++s; /* no extra chars */
6743 else /* must have a number */
6744 {
6745 while (vim_isdigit(*++s))
6746 ;
6747
6748 if (!VIM_ISDIGIT(*(s - 1)))
6749 {
6750 if (errbuf != NULL)
6751 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006752 sprintf((char *)errbuf,
6753 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 transchar_byte(*(s - 1)));
6755 errmsg = errbuf;
6756 }
6757 else
6758 errmsg = (char_u *)"";
6759 break;
6760 }
6761 }
6762 if (*s == ',')
6763 ++s;
6764 else if (*s)
6765 {
6766 if (errbuf != NULL)
6767 errmsg = (char_u *)N_("E527: Missing comma");
6768 else
6769 errmsg = (char_u *)"";
6770 break;
6771 }
6772 }
6773 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6774 errmsg = (char_u *)N_("E528: Must specify a ' value");
6775 }
6776#endif /* FEAT_VIMINFO */
6777
6778 /* terminal options */
6779 else if (istermoption(&options[opt_idx]) && full_screen)
6780 {
6781 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6782 if (varp == &T_CCO)
6783 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006784 int colors = atoi((char *)T_CCO);
6785
6786 /* Only reinitialize colors if t_Co value has really changed to
6787 * avoid expensive reload of colorscheme if t_Co is set to the
6788 * same value multiple times. */
6789 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006791 t_colors = colors;
6792 if (t_colors <= 1)
6793 {
6794 if (new_value_alloced)
6795 vim_free(T_CCO);
6796 T_CCO = empty_option;
6797 }
6798 /* We now have a different color setup, initialize it again. */
6799 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006800 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 }
6802 ttest(FALSE);
6803 if (varp == &T_ME)
6804 {
6805 out_str(T_ME);
6806 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006807#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006808 /* Since t_me has been set, this probably means that the user
6809 * wants to use this as default colors. Need to reset default
6810 * background/foreground colors. */
6811 mch_set_normal_colors();
6812#endif
6813 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006814 if (varp == &T_BE && termcap_active)
6815 {
6816 if (*T_BE == NUL)
6817 /* When clearing t_BE we assume the user no longer wants
6818 * bracketed paste, thus disable it by writing t_BD. */
6819 out_str(T_BD);
6820 else
6821 out_str(T_BE);
6822 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823 }
6824
6825#ifdef FEAT_LINEBREAK
6826 /* 'showbreak' */
6827 else if (varp == &p_sbr)
6828 {
6829 for (s = p_sbr; *s; )
6830 {
6831 if (ptr2cells(s) != 1)
6832 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006833 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006834 }
6835 }
6836#endif
6837
6838#ifdef FEAT_GUI
6839 /* 'guifont' */
6840 else if (varp == &p_guifont)
6841 {
6842 if (gui.in_use)
6843 {
6844 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006845# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006846 /*
6847 * Put up a font dialog and let the user select a new value.
6848 * If this is cancelled go back to the old value but don't
6849 * give an error message.
6850 */
6851 if (STRCMP(p, "*") == 0)
6852 {
6853 p = gui_mch_font_dialog(oldval);
6854
6855 if (new_value_alloced)
6856 free_string_option(p_guifont);
6857
6858 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6859 new_value_alloced = TRUE;
6860 }
6861# endif
6862 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6863 {
6864# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6865 if (STRCMP(p_guifont, "*") == 0)
6866 {
6867 /* Dialog was cancelled: Keep the old value without giving
6868 * an error message. */
6869 if (new_value_alloced)
6870 free_string_option(p_guifont);
6871 p_guifont = vim_strsave(oldval);
6872 new_value_alloced = TRUE;
6873 }
6874 else
6875# endif
6876 errmsg = (char_u *)N_("E596: Invalid font(s)");
6877 }
6878 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006879 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 }
6881# ifdef FEAT_XFONTSET
6882 else if (varp == &p_guifontset)
6883 {
6884 if (STRCMP(p_guifontset, "*") == 0)
6885 errmsg = (char_u *)N_("E597: can't select fontset");
6886 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6887 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006888 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006889 }
6890# endif
6891# ifdef FEAT_MBYTE
6892 else if (varp == &p_guifontwide)
6893 {
6894 if (STRCMP(p_guifontwide, "*") == 0)
6895 errmsg = (char_u *)N_("E533: can't select wide font");
6896 else if (gui_get_wide_font() == FAIL)
6897 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006898 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 }
6900# endif
6901#endif
6902
6903#ifdef CURSOR_SHAPE
6904 /* 'guicursor' */
6905 else if (varp == &p_guicursor)
6906 errmsg = parse_shape_opt(SHAPE_CURSOR);
6907#endif
6908
6909#ifdef FEAT_MOUSESHAPE
6910 /* 'mouseshape' */
6911 else if (varp == &p_mouseshape)
6912 {
6913 errmsg = parse_shape_opt(SHAPE_MOUSE);
6914 update_mouseshape(-1);
6915 }
6916#endif
6917
6918#ifdef FEAT_PRINTER
6919 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006920 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006921# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006922 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006923 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006924# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925#endif
6926
6927#ifdef FEAT_LANGMAP
6928 /* 'langmap' */
6929 else if (varp == &p_langmap)
6930 langmap_set();
6931#endif
6932
6933#ifdef FEAT_LINEBREAK
6934 /* 'breakat' */
6935 else if (varp == &p_breakat)
6936 fill_breakat_flags();
6937#endif
6938
6939#ifdef FEAT_TITLE
6940 /* 'titlestring' and 'iconstring' */
6941 else if (varp == &p_titlestring || varp == &p_iconstring)
6942 {
6943# ifdef FEAT_STL_OPT
6944 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6945
6946 /* NULL => statusline syntax */
6947 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6948 stl_syntax |= flagval;
6949 else
6950 stl_syntax &= ~flagval;
6951# endif
6952 did_set_title(varp == &p_iconstring);
6953
6954 }
6955#endif
6956
6957#ifdef FEAT_GUI
6958 /* 'guioptions' */
6959 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006960 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006962 redraw_gui_only = TRUE;
6963 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006964#endif
6965
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006966#if defined(FEAT_GUI_TABLINE)
6967 /* 'guitablabel' */
6968 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006969 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006970 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006971 redraw_gui_only = TRUE;
6972 }
6973 /* 'guitabtooltip' */
6974 else if (varp == &p_gtt)
6975 {
6976 redraw_gui_only = TRUE;
6977 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006978#endif
6979
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6981 /* 'ttymouse' */
6982 else if (varp == &p_ttym)
6983 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006984 /* Switch the mouse off before changing the escape sequences used for
6985 * that. */
6986 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6988 errmsg = e_invarg;
6989 else
6990 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006991 if (termcap_active)
6992 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 }
6994#endif
6995
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996 /* 'selection' */
6997 else if (varp == &p_sel)
6998 {
6999 if (*p_sel == NUL
7000 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7001 errmsg = e_invarg;
7002 }
7003
7004 /* 'selectmode' */
7005 else if (varp == &p_slm)
7006 {
7007 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7008 errmsg = e_invarg;
7009 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007010
7011#ifdef FEAT_BROWSE
7012 /* 'browsedir' */
7013 else if (varp == &p_bsdir)
7014 {
7015 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7016 && !mch_isdir(p_bsdir))
7017 errmsg = e_invarg;
7018 }
7019#endif
7020
Bram Moolenaar071d4272004-06-13 20:20:40 +00007021 /* 'keymodel' */
7022 else if (varp == &p_km)
7023 {
7024 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7025 errmsg = e_invarg;
7026 else
7027 {
7028 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7029 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7030 }
7031 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007032
7033 /* 'mousemodel' */
7034 else if (varp == &p_mousem)
7035 {
7036 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7037 errmsg = e_invarg;
7038#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7039 else if (*p_mousem != *oldval)
7040 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7041 * to create or delete the popup menus. */
7042 gui_motif_update_mousemodel(root_menu);
7043#endif
7044 }
7045
7046 /* 'switchbuf' */
7047 else if (varp == &p_swb)
7048 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007049 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 errmsg = e_invarg;
7051 }
7052
7053 /* 'debug' */
7054 else if (varp == &p_debug)
7055 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007056 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007057 errmsg = e_invarg;
7058 }
7059
7060 /* 'display' */
7061 else if (varp == &p_dy)
7062 {
7063 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7064 errmsg = e_invarg;
7065 else
7066 (void)init_chartab();
7067
7068 }
7069
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 /* 'eadirection' */
7071 else if (varp == &p_ead)
7072 {
7073 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7074 errmsg = e_invarg;
7075 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007076
7077#ifdef FEAT_CLIPBOARD
7078 /* 'clipboard' */
7079 else if (varp == &p_cb)
7080 errmsg = check_clipboard_option();
7081#endif
7082
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007083#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007084 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7085 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007086 else if (varp == &(curwin->w_s->b_p_spl)
7087 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007088 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007089 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007090 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007091 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007092 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007093 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007094 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007095 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007096 /* 'spellsuggest' */
7097 else if (varp == &p_sps)
7098 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007099 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007100 errmsg = e_invarg;
7101 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007102 /* 'mkspellmem' */
7103 else if (varp == &p_msm)
7104 {
7105 if (spell_check_msm() != OK)
7106 errmsg = e_invarg;
7107 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007108#endif
7109
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110 /* When 'bufhidden' is set, check for valid value. */
7111 else if (gvarp == &p_bh)
7112 {
7113 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7114 errmsg = e_invarg;
7115 }
7116
7117 /* When 'buftype' is set, check for valid value. */
7118 else if (gvarp == &p_bt)
7119 {
7120 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7121 errmsg = e_invarg;
7122 else
7123 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007124 if (curwin->w_status_height)
7125 {
7126 curwin->w_redr_status = TRUE;
7127 redraw_later(VALID);
7128 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007130#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007131 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 }
7134 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135
7136#ifdef FEAT_STL_OPT
7137 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007138 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007139 {
7140 int wid;
7141
7142 if (varp == &p_ruf) /* reset ru_wid first */
7143 ru_wid = 0;
7144 s = *varp;
7145 if (varp == &p_ruf && *s == '%')
7146 {
7147 /* set ru_wid if 'ruf' starts with "%99(" */
7148 if (*++s == '-') /* ignore a '-' */
7149 s++;
7150 wid = getdigits(&s);
7151 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7152 ru_wid = wid;
7153 else
7154 errmsg = check_stl_option(p_ruf);
7155 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007156 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007157 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007159 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007160 comp_col();
7161 }
7162#endif
7163
7164#ifdef FEAT_INS_EXPAND
7165 /* check if it is a valid value for 'complete' -- Acevedo */
7166 else if (gvarp == &p_cpt)
7167 {
7168 for (s = *varp; *s;)
7169 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007170 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007171 s++;
7172 if (!*s)
7173 break;
7174 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7175 {
7176 errmsg = illegal_char(errbuf, *s);
7177 break;
7178 }
7179 if (*++s != NUL && *s != ',' && *s != ' ')
7180 {
7181 if (s[-1] == 'k' || s[-1] == 's')
7182 {
7183 /* skip optional filename after 'k' and 's' */
7184 while (*s && *s != ',' && *s != ' ')
7185 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007186 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007187 ++s;
7188 ++s;
7189 }
7190 }
7191 else
7192 {
7193 if (errbuf != NULL)
7194 {
7195 sprintf((char *)errbuf,
7196 _("E535: Illegal character after <%c>"),
7197 *--s);
7198 errmsg = errbuf;
7199 }
7200 else
7201 errmsg = (char_u *)"";
7202 break;
7203 }
7204 }
7205 }
7206 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007207
7208 /* 'completeopt' */
7209 else if (varp == &p_cot)
7210 {
7211 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7212 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007213 else
7214 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007215 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007216#endif /* FEAT_INS_EXPAND */
7217
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007218#ifdef FEAT_SIGNS
7219 /* 'signcolumn' */
7220 else if (varp == &curwin->w_p_scl)
7221 {
7222 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7223 errmsg = e_invarg;
7224 }
7225#endif
7226
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227
7228#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007229 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007230 else if (varp == &p_toolbar)
7231 {
7232 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7233 &toolbar_flags, TRUE) != OK)
7234 errmsg = e_invarg;
7235 else
7236 {
7237 out_flush();
7238 gui_mch_show_toolbar((toolbar_flags &
7239 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7240 }
7241 }
7242#endif
7243
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007244#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007245 /* 'toolbariconsize': GTK+ 2 only */
7246 else if (varp == &p_tbis)
7247 {
7248 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7249 errmsg = e_invarg;
7250 else
7251 {
7252 out_flush();
7253 gui_mch_show_toolbar((toolbar_flags &
7254 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7255 }
7256 }
7257#endif
7258
7259 /* 'pastetoggle': translate key codes like in a mapping */
7260 else if (varp == &p_pt)
7261 {
7262 if (*p_pt)
7263 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007264 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265 if (p != NULL)
7266 {
7267 if (new_value_alloced)
7268 free_string_option(p_pt);
7269 p_pt = p;
7270 new_value_alloced = TRUE;
7271 }
7272 }
7273 }
7274
7275 /* 'backspace' */
7276 else if (varp == &p_bs)
7277 {
7278 if (VIM_ISDIGIT(*p_bs))
7279 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007280 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007281 errmsg = e_invarg;
7282 }
7283 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7284 errmsg = e_invarg;
7285 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007286 else if (varp == &p_bo)
7287 {
7288 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7289 errmsg = e_invarg;
7290 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007291
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007292 /* 'tagcase' */
7293 else if (gvarp == &p_tc)
7294 {
7295 unsigned int *flags;
7296
7297 if (opt_flags & OPT_LOCAL)
7298 {
7299 p = curbuf->b_p_tc;
7300 flags = &curbuf->b_tc_flags;
7301 }
7302 else
7303 {
7304 p = p_tc;
7305 flags = &tc_flags;
7306 }
7307
7308 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7309 /* make the local value empty: use the global value */
7310 *flags = 0;
7311 else if (*p == NUL
7312 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7313 errmsg = e_invarg;
7314 }
7315
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007316#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 /* 'casemap' */
7318 else if (varp == &p_cmp)
7319 {
7320 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7321 errmsg = e_invarg;
7322 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324
7325#ifdef FEAT_DIFF
7326 /* 'diffopt' */
7327 else if (varp == &p_dip)
7328 {
7329 if (diffopt_changed() == FAIL)
7330 errmsg = e_invarg;
7331 }
7332#endif
7333
7334#ifdef FEAT_FOLDING
7335 /* 'foldmethod' */
7336 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7337 {
7338 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7339 || *curwin->w_p_fdm == NUL)
7340 errmsg = e_invarg;
7341 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007342 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007344 if (foldmethodIsDiff(curwin))
7345 newFoldLevel();
7346 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007347 }
7348# ifdef FEAT_EVAL
7349 /* 'foldexpr' */
7350 else if (varp == &curwin->w_p_fde)
7351 {
7352 if (foldmethodIsExpr(curwin))
7353 foldUpdateAll(curwin);
7354 }
7355# endif
7356 /* 'foldmarker' */
7357 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7358 {
7359 p = vim_strchr(*varp, ',');
7360 if (p == NULL)
7361 errmsg = (char_u *)N_("E536: comma required");
7362 else if (p == *varp || p[1] == NUL)
7363 errmsg = e_invarg;
7364 else if (foldmethodIsMarker(curwin))
7365 foldUpdateAll(curwin);
7366 }
7367 /* 'commentstring' */
7368 else if (gvarp == &p_cms)
7369 {
7370 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7371 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7372 }
7373 /* 'foldopen' */
7374 else if (varp == &p_fdo)
7375 {
7376 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7377 errmsg = e_invarg;
7378 }
7379 /* 'foldclose' */
7380 else if (varp == &p_fcl)
7381 {
7382 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7383 errmsg = e_invarg;
7384 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007385 /* 'foldignore' */
7386 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7387 {
7388 if (foldmethodIsIndent(curwin))
7389 foldUpdateAll(curwin);
7390 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007391#endif
7392
7393#ifdef FEAT_VIRTUALEDIT
7394 /* 'virtualedit' */
7395 else if (varp == &p_ve)
7396 {
7397 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7398 errmsg = e_invarg;
7399 else if (STRCMP(p_ve, oldval) != 0)
7400 {
7401 /* Recompute cursor position in case the new 've' setting
7402 * changes something. */
7403 validate_virtcol();
7404 coladvance(curwin->w_virtcol);
7405 }
7406 }
7407#endif
7408
7409#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7410 else if (varp == &p_csqf)
7411 {
7412 if (p_csqf != NULL)
7413 {
7414 p = p_csqf;
7415 while (*p != NUL)
7416 {
7417 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7418 || p[1] == NUL
7419 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7420 || (p[2] != NUL && p[2] != ','))
7421 {
7422 errmsg = e_invarg;
7423 break;
7424 }
7425 else if (p[2] == NUL)
7426 break;
7427 else
7428 p += 3;
7429 }
7430 }
7431 }
7432#endif
7433
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007434#ifdef FEAT_CINDENT
7435 /* 'cinoptions' */
7436 else if (gvarp == &p_cino)
7437 {
7438 /* TODO: recognize errors */
7439 parse_cino(curbuf);
7440 }
7441#endif
7442
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007443#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007444 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007445 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007446 {
7447 if (!gui_mch_set_rendering_options(p_rop))
7448 errmsg = e_invarg;
7449 }
7450#endif
7451
Bram Moolenaard0b51382016-11-04 15:23:45 +01007452#ifdef FEAT_AUTOCMD
7453 else if (gvarp == &p_ft)
7454 {
7455 if (!valid_filetype(*varp))
7456 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007457 else
7458 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007459 }
7460#endif
7461
7462#ifdef FEAT_SYN_HL
7463 else if (gvarp == &p_syn)
7464 {
7465 if (!valid_filetype(*varp))
7466 errmsg = e_invarg;
7467 }
7468#endif
7469
Bram Moolenaar825680f2017-07-22 17:04:02 +02007470#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007471 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007472 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007473 {
7474 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7475 errmsg = e_invarg;
7476 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007477 /* 'termsize' */
7478 else if (varp == &curwin->w_p_tms)
7479 {
7480 if (*curwin->w_p_tms != NUL)
7481 {
7482 p = skipdigits(curwin->w_p_tms);
7483 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7484 errmsg = e_invarg;
7485 }
7486 }
7487#endif
7488
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 /* Options that are a list of flags. */
7490 else
7491 {
7492 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007493 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007494 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007495 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007497 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007499 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007500 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007501#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007502 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007503 p = (char_u *)COCU_ALL;
7504#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007505 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 {
7507#ifdef FEAT_MOUSE
7508 p = (char_u *)MOUSE_ALL;
7509#else
7510 if (*p_mouse != NUL)
7511 errmsg = (char_u *)N_("E538: No mouse support");
7512#endif
7513 }
7514#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007515 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516 p = (char_u *)GO_ALL;
7517#endif
7518 if (p != NULL)
7519 {
7520 for (s = *varp; *s; ++s)
7521 if (vim_strchr(p, *s) == NULL)
7522 {
7523 errmsg = illegal_char(errbuf, *s);
7524 break;
7525 }
7526 }
7527 }
7528
7529 /*
7530 * If error detected, restore the previous value.
7531 */
7532 if (errmsg != NULL)
7533 {
7534 if (new_value_alloced)
7535 free_string_option(*varp);
7536 *varp = oldval;
7537 /*
7538 * When resetting some values, need to act on it.
7539 */
7540 if (did_chartab)
7541 (void)init_chartab();
7542 if (varp == &p_hl)
7543 (void)highlight_changed();
7544 }
7545 else
7546 {
7547#ifdef FEAT_EVAL
7548 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007549 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007550#endif
7551 /*
7552 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007553 * Use "free_oldval", because recursiveness may change the flags under
7554 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007555 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007556 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557 free_string_option(oldval);
7558 if (new_value_alloced)
7559 options[opt_idx].flags |= P_ALLOCED;
7560 else
7561 options[opt_idx].flags &= ~P_ALLOCED;
7562
7563 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007564 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007565 {
7566 /* global option with local value set to use global value; free
7567 * the local value and make it empty */
7568 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7569 free_string_option(*(char_u **)p);
7570 *(char_u **)p = empty_option;
7571 }
7572
7573 /* May set global value for local option. */
7574 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7575 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007576
7577#ifdef FEAT_AUTOCMD
7578 /*
7579 * Trigger the autocommand only after setting the flags.
7580 */
7581# ifdef FEAT_SYN_HL
7582 /* When 'syntax' is set, load the syntax of that name */
7583 if (varp == &(curbuf->b_p_syn))
7584 {
7585 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7586 curbuf->b_fname, TRUE, curbuf);
7587 }
7588# endif
7589 else if (varp == &(curbuf->b_p_ft))
7590 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007591 /* 'filetype' is set, trigger the FileType autocommand.
7592 * Skip this when called from a modeline and the filetype was
7593 * already set to this value. */
7594 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7595 {
7596 did_filetype = TRUE;
7597 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007598 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007599 /* Just in case the old "curbuf" is now invalid. */
7600 if (varp != &(curbuf->b_p_ft))
7601 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007602 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007603 }
7604#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007605#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007606 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007607 {
7608 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007609 char_u *q = curwin->w_s->b_p_spl;
7610
7611 /* Skip the first name if it is "cjk". */
7612 if (STRNCMP(q, "cjk,", 4) == 0)
7613 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007614
7615 /*
7616 * Source the spell/LANG.vim in 'runtimepath'.
7617 * They could set 'spellcapcheck' depending on the language.
7618 * Use the first name in 'spelllang' up to '_region' or
7619 * '.encoding'.
7620 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007621 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007622 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7623 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007624 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007625 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007626 }
7627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007628 }
7629
7630#ifdef FEAT_MOUSE
7631 if (varp == &p_mouse)
7632 {
7633# ifdef FEAT_MOUSE_TTY
7634 if (*p_mouse == NUL)
7635 mch_setmouse(FALSE); /* switch mouse off */
7636 else
7637# endif
7638 setmouse(); /* in case 'mouse' changed */
7639 }
7640#endif
7641
Bram Moolenaar913077c2012-03-28 19:59:04 +02007642 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007643 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007644 curwin->w_set_curswant = TRUE;
7645
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007646#ifdef FEAT_GUI
7647 /* check redraw when it's not a GUI option or the GUI is active. */
7648 if (!redraw_gui_only || gui.in_use)
7649#endif
7650 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007651
7652 return errmsg;
7653}
7654
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007655#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007656/*
7657 * Simple int comparison function for use with qsort()
7658 */
7659 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007660int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007661{
7662 return *(const int *)a - *(const int *)b;
7663}
7664
7665/*
7666 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7667 * Returns error message, NULL if it's OK.
7668 */
7669 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007670check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007671{
7672 char_u *s;
7673 int col;
7674 int count = 0;
7675 int color_cols[256];
7676 int i;
7677 int j = 0;
7678
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007679 if (wp->w_buffer == NULL)
7680 return NULL; /* buffer was closed */
7681
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007682 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007683 {
7684 if (*s == '-' || *s == '+')
7685 {
7686 /* -N and +N: add to 'textwidth' */
7687 col = (*s == '-') ? -1 : 1;
7688 ++s;
7689 if (!VIM_ISDIGIT(*s))
7690 return e_invarg;
7691 col = col * getdigits(&s);
7692 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007693 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007694 col += wp->w_buffer->b_p_tw;
7695 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007696 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007697 }
7698 else if (VIM_ISDIGIT(*s))
7699 col = getdigits(&s);
7700 else
7701 return e_invarg;
7702 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007703skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007704 if (*s == NUL)
7705 break;
7706 if (*s != ',')
7707 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007708 if (*++s == NUL)
7709 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007710 }
7711
7712 vim_free(wp->w_p_cc_cols);
7713 if (count == 0)
7714 wp->w_p_cc_cols = NULL;
7715 else
7716 {
7717 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7718 if (wp->w_p_cc_cols != NULL)
7719 {
7720 /* sort the columns for faster usage on screen redraw inside
7721 * win_line() */
7722 qsort(color_cols, count, sizeof(int), int_cmp);
7723
7724 for (i = 0; i < count; ++i)
7725 /* skip duplicates */
7726 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7727 wp->w_p_cc_cols[j++] = color_cols[i];
7728 wp->w_p_cc_cols[j] = -1; /* end marker */
7729 }
7730 }
7731
7732 return NULL; /* no error */
7733}
7734#endif
7735
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736/*
7737 * Handle setting 'listchars' or 'fillchars'.
7738 * Returns error message, NULL if it's OK.
7739 */
7740 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007741set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007742{
7743 int round, i, len, entries;
7744 char_u *p, *s;
7745 int c1, c2 = 0;
7746 struct charstab
7747 {
7748 int *cp;
7749 char *name;
7750 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007751 static struct charstab filltab[] =
7752 {
7753 {&fill_stl, "stl"},
7754 {&fill_stlnc, "stlnc"},
7755 {&fill_vert, "vert"},
7756 {&fill_fold, "fold"},
7757 {&fill_diff, "diff"},
7758 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759 static struct charstab lcstab[] =
7760 {
7761 {&lcs_eol, "eol"},
7762 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007763 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007765 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766 {&lcs_tab2, "tab"},
7767 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007768#ifdef FEAT_CONCEAL
7769 {&lcs_conceal, "conceal"},
7770#else
7771 {NULL, "conceal"},
7772#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773 };
7774 struct charstab *tab;
7775
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777 {
7778 tab = lcstab;
7779 entries = sizeof(lcstab) / sizeof(struct charstab);
7780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781 else
7782 {
7783 tab = filltab;
7784 entries = sizeof(filltab) / sizeof(struct charstab);
7785 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007786
7787 /* first round: check for valid value, second round: assign values */
7788 for (round = 0; round <= 1; ++round)
7789 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007790 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 {
7792 /* After checking that the value is valid: set defaults: space for
7793 * 'fillchars', NUL for 'listchars' */
7794 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007795 if (tab[i].cp != NULL)
7796 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007797 if (varp == &p_lcs)
7798 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 else
7800 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 }
7802 p = *varp;
7803 while (*p)
7804 {
7805 for (i = 0; i < entries; ++i)
7806 {
7807 len = (int)STRLEN(tab[i].name);
7808 if (STRNCMP(p, tab[i].name, len) == 0
7809 && p[len] == ':'
7810 && p[len + 1] != NUL)
7811 {
7812 s = p + len + 1;
7813#ifdef FEAT_MBYTE
7814 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007815 if (mb_char2cells(c1) > 1)
7816 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007817#else
7818 c1 = *s++;
7819#endif
7820 if (tab[i].cp == &lcs_tab2)
7821 {
7822 if (*s == NUL)
7823 continue;
7824#ifdef FEAT_MBYTE
7825 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007826 if (mb_char2cells(c2) > 1)
7827 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828#else
7829 c2 = *s++;
7830#endif
7831 }
7832 if (*s == ',' || *s == NUL)
7833 {
7834 if (round)
7835 {
7836 if (tab[i].cp == &lcs_tab2)
7837 {
7838 lcs_tab1 = c1;
7839 lcs_tab2 = c2;
7840 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007841 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842 *(tab[i].cp) = c1;
7843
7844 }
7845 p = s;
7846 break;
7847 }
7848 }
7849 }
7850
7851 if (i == entries)
7852 return e_invarg;
7853 if (*p == ',')
7854 ++p;
7855 }
7856 }
7857
7858 return NULL; /* no error */
7859}
7860
7861#ifdef FEAT_STL_OPT
7862/*
7863 * Check validity of options with the 'statusline' format.
7864 * Return error message or NULL.
7865 */
7866 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007867check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868{
7869 int itemcnt = 0;
7870 int groupdepth = 0;
7871 static char_u errbuf[80];
7872
7873 while (*s && itemcnt < STL_MAX_ITEM)
7874 {
7875 /* Check for valid keys after % sequences */
7876 while (*s && *s != '%')
7877 s++;
7878 if (!*s)
7879 break;
7880 s++;
7881 if (*s != '%' && *s != ')')
7882 ++itemcnt;
7883 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7884 {
7885 s++;
7886 continue;
7887 }
7888 if (*s == ')')
7889 {
7890 s++;
7891 if (--groupdepth < 0)
7892 break;
7893 continue;
7894 }
7895 if (*s == '-')
7896 s++;
7897 while (VIM_ISDIGIT(*s))
7898 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007899 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 continue;
7901 if (*s == '.')
7902 {
7903 s++;
7904 while (*s && VIM_ISDIGIT(*s))
7905 s++;
7906 }
7907 if (*s == '(')
7908 {
7909 groupdepth++;
7910 continue;
7911 }
7912 if (vim_strchr(STL_ALL, *s) == NULL)
7913 {
7914 return illegal_char(errbuf, *s);
7915 }
7916 if (*s == '{')
7917 {
7918 s++;
7919 while (*s != '}' && *s)
7920 s++;
7921 if (*s != '}')
7922 return (char_u *)N_("E540: Unclosed expression sequence");
7923 }
7924 }
7925 if (itemcnt >= STL_MAX_ITEM)
7926 return (char_u *)N_("E541: too many items");
7927 if (groupdepth != 0)
7928 return (char_u *)N_("E542: unbalanced groups");
7929 return NULL;
7930}
7931#endif
7932
7933#ifdef FEAT_CLIPBOARD
7934/*
7935 * Extract the items in the 'clipboard' option and set global values.
7936 */
7937 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007938check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007940 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007941 int new_autoselect_star = FALSE;
7942 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007944 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 regprog_T *new_exclude_prog = NULL;
7946 char_u *errmsg = NULL;
7947 char_u *p;
7948
7949 for (p = p_cb; *p != NUL; )
7950 {
7951 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7952 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007953 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 p += 7;
7955 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007956 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007957 && (p[11] == ',' || p[11] == NUL))
7958 {
7959 new_unnamed |= CLIP_UNNAMED_PLUS;
7960 p += 11;
7961 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007963 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007965 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 p += 10;
7967 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007968 else if (STRNCMP(p, "autoselectplus", 14) == 0
7969 && (p[14] == ',' || p[14] == NUL))
7970 {
7971 new_autoselect_plus = TRUE;
7972 p += 14;
7973 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007974 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007975 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976 {
7977 new_autoselectml = TRUE;
7978 p += 12;
7979 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007980 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7981 {
7982 new_html = TRUE;
7983 p += 4;
7984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7986 {
7987 p += 8;
7988 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7989 if (new_exclude_prog == NULL)
7990 errmsg = e_invarg;
7991 break;
7992 }
7993 else
7994 {
7995 errmsg = e_invarg;
7996 break;
7997 }
7998 if (*p == ',')
7999 ++p;
8000 }
8001 if (errmsg == NULL)
8002 {
8003 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008004 clip_autoselect_star = new_autoselect_star;
8005 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008007 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008008 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008010#ifdef FEAT_GUI_GTK
8011 if (gui.in_use)
8012 {
8013 gui_gtk_set_selection_targets();
8014 gui_gtk_set_dnd_targets();
8015 }
8016#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 }
8018 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008019 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020
8021 return errmsg;
8022}
8023#endif
8024
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008025#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008026 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008027did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008028{
8029 char_u *errmsg = NULL;
8030 win_T *wp;
8031 int l;
8032
8033 if (is_spellfile)
8034 {
8035 l = (int)STRLEN(curwin->w_s->b_p_spf);
8036 if (l > 0 && (l < 4
8037 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8038 errmsg = e_invarg;
8039 }
8040
8041 if (errmsg == NULL)
8042 {
8043 FOR_ALL_WINDOWS(wp)
8044 if (wp->w_buffer == curbuf && wp->w_p_spell)
8045 {
8046 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008047 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008048 }
8049 }
8050 return errmsg;
8051}
8052
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008053/*
8054 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8055 * Return error message when failed, NULL when OK.
8056 */
8057 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008058compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008059{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008060 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008061 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008062
Bram Moolenaar860cae12010-06-05 23:22:07 +02008063 if (*synblock->b_p_spc == NUL)
8064 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008065 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008066 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008067 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008068 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008069 if (re != NULL)
8070 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008071 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008072 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008073 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008074 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008075 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008076 return e_invarg;
8077 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008078 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008079 }
8080
Bram Moolenaar473de612013-06-08 18:19:48 +02008081 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008082 return NULL;
8083}
8084#endif
8085
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008086#if defined(FEAT_EVAL) || defined(PROTO)
8087/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008088 * Set the scriptID for an option, taking care of setting the buffer- or
8089 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008090 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008091 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008092set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008093{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008094 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8095 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008096
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008097 /* Remember where the option was set. For local options need to do that
8098 * in the buffer or window structure. */
8099 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008100 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008101 if (both || (opt_flags & OPT_LOCAL))
8102 {
8103 if (indir & PV_BUF)
8104 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8105 else if (indir & PV_WIN)
8106 curwin->w_p_scriptID[indir & PV_MASK] = id;
8107 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008108}
8109#endif
8110
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111/*
8112 * Set the value of a boolean option, and take care of side effects.
8113 * Returns NULL for success, or an error message for an error.
8114 */
8115 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008116set_bool_option(
8117 int opt_idx, /* index in options[] table */
8118 char_u *varp, /* pointer to the option variable */
8119 int value, /* new value */
8120 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008121{
8122 int old_value = *(int *)varp;
8123
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 /* Disallow changing some options from secure mode */
8125 if ((secure
8126#ifdef HAVE_SANDBOX
8127 || sandbox != 0
8128#endif
8129 ) && (options[opt_idx].flags & P_SECURE))
8130 return e_secure;
8131
8132 *(int *)varp = value; /* set the new value */
8133#ifdef FEAT_EVAL
8134 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008135 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136#endif
8137
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008138#ifdef FEAT_GUI
8139 need_mouse_correct = TRUE;
8140#endif
8141
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 /* May set global value for local option. */
8143 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8144 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8145
8146 /*
8147 * Handle side effects of changing a bool option.
8148 */
8149
8150 /* 'compatible' */
8151 if ((int *)varp == &p_cp)
8152 {
8153 compatible_set();
8154 }
8155
Bram Moolenaar920694c2016-08-21 17:45:02 +02008156#ifdef FEAT_LANGMAP
8157 if ((int *)varp == &p_lrm)
8158 /* 'langremap' -> !'langnoremap' */
8159 p_lnr = !p_lrm;
8160 else if ((int *)varp == &p_lnr)
8161 /* 'langnoremap' -> !'langremap' */
8162 p_lrm = !p_lnr;
8163#endif
8164
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008165#ifdef FEAT_PERSISTENT_UNDO
8166 /* 'undofile' */
8167 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8168 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008169 /* Only take action when the option was set. When reset we do not
8170 * delete the undo file, the option may be set again without making
8171 * any changes in between. */
8172 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008173 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008174 char_u hash[UNDO_HASH_SIZE];
8175 buf_T *save_curbuf = curbuf;
8176
Bram Moolenaar29323592016-07-24 22:04:11 +02008177 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008178 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008179 /* When 'undofile' is set globally: for every buffer, otherwise
8180 * only for the current buffer: Try to read in the undofile,
8181 * if one exists, the buffer wasn't changed and the buffer was
8182 * loaded */
8183 if ((curbuf == save_curbuf
8184 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8185 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8186 {
8187 u_compute_hash(hash);
8188 u_read_undo(NULL, hash, curbuf->b_fname);
8189 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008190 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008191 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008192 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008193 }
8194#endif
8195
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196 else if ((int *)varp == &curbuf->b_p_ro)
8197 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008198 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8200 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008201
8202 /* when 'readonly' is set may give W10 again */
8203 if (curbuf->b_p_ro)
8204 curbuf->b_did_warn = FALSE;
8205
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008207 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008208#endif
8209 }
8210
Bram Moolenaar9c449722010-07-20 18:44:27 +02008211#ifdef FEAT_GUI
8212 else if ((int *)varp == &p_mh)
8213 {
8214 if (!p_mh)
8215 gui_mch_mousehide(FALSE);
8216 }
8217#endif
8218
Bram Moolenaara539df02010-08-01 14:35:05 +02008219 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008221 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008222# ifdef FEAT_TERMINAL
8223 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008224 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008225 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008226 {
8227 curbuf->b_p_ma = FALSE;
8228 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8229 }
8230# endif
8231# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008232 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008233# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008234 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008235#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008236 /* when 'endofline' is changed, redraw the window title */
8237 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008238 {
8239 redraw_titles();
8240 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008241 /* when 'fixeol' is changed, redraw the window title */
8242 else if ((int *)varp == &curbuf->b_p_fixeol)
8243 {
8244 redraw_titles();
8245 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008246# ifdef FEAT_MBYTE
8247 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008248 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008249 {
8250 redraw_titles();
8251 }
8252# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253#endif
8254
8255 /* when 'bin' is set also set some other options */
8256 else if ((int *)varp == &curbuf->b_p_bin)
8257 {
8258 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8259#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008260 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261#endif
8262 }
8263
8264#ifdef FEAT_AUTOCMD
8265 /* when 'buflisted' changes, trigger autocommands */
8266 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8267 {
8268 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8269 NULL, NULL, TRUE, curbuf);
8270 }
8271#endif
8272
8273 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8274 else if ((int *)varp == &curbuf->b_p_swf)
8275 {
8276 if (curbuf->b_p_swf && p_uc)
8277 ml_open_file(curbuf); /* create the swap file */
8278 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008279 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8280 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008281 mf_close_file(curbuf, TRUE); /* remove the swap file */
8282 }
8283
8284 /* when 'terse' is set change 'shortmess' */
8285 else if ((int *)varp == &p_terse)
8286 {
8287 char_u *p;
8288
8289 p = vim_strchr(p_shm, SHM_SEARCH);
8290
8291 /* insert 's' in p_shm */
8292 if (p_terse && p == NULL)
8293 {
8294 STRCPY(IObuff, p_shm);
8295 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008296 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 }
8298 /* remove 's' from p_shm */
8299 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008300 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 }
8302
8303 /* when 'paste' is set or reset also change other options */
8304 else if ((int *)varp == &p_paste)
8305 {
8306 paste_option_changed();
8307 }
8308
8309 /* when 'insertmode' is set from an autocommand need to do work here */
8310 else if ((int *)varp == &p_im)
8311 {
8312 if (p_im)
8313 {
8314 if ((State & INSERT) == 0)
8315 need_start_insertmode = TRUE;
8316 stop_insert_mode = FALSE;
8317 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008318 /* only reset if it was set previously */
8319 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 {
8321 need_start_insertmode = FALSE;
8322 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008323 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 clear_cmdline = TRUE; /* remove "(insert)" */
8325 restart_edit = 0;
8326 }
8327 }
8328
8329 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8330 else if ((int *)varp == &p_ic && p_hls)
8331 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008332 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008333 }
8334
8335#ifdef FEAT_SEARCH_EXTRA
8336 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8337 else if ((int *)varp == &p_hls)
8338 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008339 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340 }
8341#endif
8342
8343#ifdef FEAT_SCROLLBIND
8344 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8345 * at the end of normal_cmd() */
8346 else if ((int *)varp == &curwin->w_p_scb)
8347 {
8348 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008349 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008351 curwin->w_scbind_pos = curwin->w_topline;
8352 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 }
8354#endif
8355
Bram Moolenaar4033c552017-09-16 20:54:51 +02008356#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008357 /* There can be only one window with 'previewwindow' set. */
8358 else if ((int *)varp == &curwin->w_p_pvw)
8359 {
8360 if (curwin->w_p_pvw)
8361 {
8362 win_T *win;
8363
Bram Moolenaar29323592016-07-24 22:04:11 +02008364 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365 if (win->w_p_pvw && win != curwin)
8366 {
8367 curwin->w_p_pvw = FALSE;
8368 return (char_u *)N_("E590: A preview window already exists");
8369 }
8370 }
8371 }
8372#endif
8373
8374 /* when 'textmode' is set or reset also change 'fileformat' */
8375 else if ((int *)varp == &curbuf->b_p_tx)
8376 {
8377 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8378 }
8379
8380 /* when 'textauto' is set or reset also change 'fileformats' */
8381 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008382 set_string_option_direct((char_u *)"ffs", -1,
8383 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008384 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385
8386 /*
8387 * When 'lisp' option changes include/exclude '-' in
8388 * keyword characters.
8389 */
8390#ifdef FEAT_LISP
8391 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8392 {
8393 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8394 }
8395#endif
8396
8397#ifdef FEAT_TITLE
8398 /* when 'title' changed, may need to change the title; same for 'icon' */
8399 else if ((int *)varp == &p_title)
8400 {
8401 did_set_title(FALSE);
8402 }
8403
8404 else if ((int *)varp == &p_icon)
8405 {
8406 did_set_title(TRUE);
8407 }
8408#endif
8409
8410 else if ((int *)varp == &curbuf->b_changed)
8411 {
8412 if (!value)
8413 save_file_ff(curbuf); /* Buffer is unchanged */
8414#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008415 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416#endif
8417#ifdef FEAT_AUTOCMD
8418 modified_was_set = value;
8419#endif
8420 }
8421
8422#ifdef BACKSLASH_IN_FILENAME
8423 else if ((int *)varp == &p_ssl)
8424 {
8425 if (p_ssl)
8426 {
8427 psepc = '/';
8428 psepcN = '\\';
8429 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 }
8431 else
8432 {
8433 psepc = '\\';
8434 psepcN = '/';
8435 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 }
8437
8438 /* need to adjust the file name arguments and buffer names. */
8439 buflist_slash_adjust();
8440 alist_slash_adjust();
8441# ifdef FEAT_EVAL
8442 scriptnames_slash_adjust();
8443# endif
8444 }
8445#endif
8446
8447 /* If 'wrap' is set, set w_leftcol to zero. */
8448 else if ((int *)varp == &curwin->w_p_wrap)
8449 {
8450 if (curwin->w_p_wrap)
8451 curwin->w_leftcol = 0;
8452 }
8453
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454 else if ((int *)varp == &p_ea)
8455 {
8456 if (p_ea && !old_value)
8457 win_equal(curwin, FALSE, 0);
8458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008459
8460 else if ((int *)varp == &p_wiv)
8461 {
8462 /*
8463 * When 'weirdinvert' changed, set/reset 't_xs'.
8464 * Then set 'weirdinvert' according to value of 't_xs'.
8465 */
8466 if (p_wiv && !old_value)
8467 T_XS = (char_u *)"y";
8468 else if (!p_wiv && old_value)
8469 T_XS = empty_option;
8470 p_wiv = (*T_XS != NUL);
8471 }
8472
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008473#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 else if ((int *)varp == &p_beval)
8475 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008476 if (!balloonEvalForTerm)
8477 {
8478 if (p_beval && !old_value)
8479 gui_mch_enable_beval_area(balloonEval);
8480 else if (!p_beval && old_value)
8481 gui_mch_disable_beval_area(balloonEval);
8482 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008484#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008485#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008486 else if ((int *)varp == &p_bevalterm)
8487 {
8488 mch_bevalterm_changed();
8489 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008490#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008492#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493 else if ((int *)varp == &p_acd)
8494 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008495 /* Change directories when the 'acd' option is set now. */
8496 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008497 }
8498#endif
8499
8500#ifdef FEAT_DIFF
8501 /* 'diff' */
8502 else if ((int *)varp == &curwin->w_p_diff)
8503 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008504 /* May add or remove the buffer from the list of diff buffers. */
8505 diff_buf_adjust(curwin);
8506# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507 if (foldmethodIsDiff(curwin))
8508 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008509# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 }
8511#endif
8512
Bram Moolenaar819edbe2017-11-25 17:14:33 +01008513#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008514 /* 'imdisable' */
8515 else if ((int *)varp == &p_imdisable)
8516 {
8517 /* Only de-activate it here, it will be enabled when changing mode. */
8518 if (p_imdisable)
8519 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008520 else if (State & INSERT)
8521 /* When the option is set from an autocommand, it may need to take
8522 * effect right away. */
8523 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524 }
8525#endif
8526
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008527#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008528 /* 'spell' */
8529 else if ((int *)varp == &curwin->w_p_spell)
8530 {
8531 if (curwin->w_p_spell)
8532 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008533 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008534 if (errmsg != NULL)
8535 EMSG(_(errmsg));
8536 }
8537 }
8538#endif
8539
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540#ifdef FEAT_FKMAP
8541 else if ((int *)varp == &p_altkeymap)
8542 {
8543 if (old_value != p_altkeymap)
8544 {
8545 if (!p_altkeymap)
8546 {
8547 p_hkmap = p_fkmap;
8548 p_fkmap = 0;
8549 }
8550 else
8551 {
8552 p_fkmap = p_hkmap;
8553 p_hkmap = 0;
8554 }
8555 (void)init_chartab();
8556 }
8557 }
8558
8559 /*
8560 * In case some second language keymapping options have changed, check
8561 * and correct the setting in a consistent way.
8562 */
8563
8564 /*
8565 * If hkmap or fkmap are set, reset Arabic keymapping.
8566 */
8567 if ((p_hkmap || p_fkmap) && p_altkeymap)
8568 {
8569 p_altkeymap = p_fkmap;
8570# ifdef FEAT_ARABIC
8571 curwin->w_p_arab = FALSE;
8572# endif
8573 (void)init_chartab();
8574 }
8575
8576 /*
8577 * If hkmap set, reset Farsi keymapping.
8578 */
8579 if (p_hkmap && p_altkeymap)
8580 {
8581 p_altkeymap = 0;
8582 p_fkmap = 0;
8583# ifdef FEAT_ARABIC
8584 curwin->w_p_arab = FALSE;
8585# endif
8586 (void)init_chartab();
8587 }
8588
8589 /*
8590 * If fkmap set, reset Hebrew keymapping.
8591 */
8592 if (p_fkmap && !p_altkeymap)
8593 {
8594 p_altkeymap = 1;
8595 p_hkmap = 0;
8596# ifdef FEAT_ARABIC
8597 curwin->w_p_arab = FALSE;
8598# endif
8599 (void)init_chartab();
8600 }
8601#endif
8602
8603#ifdef FEAT_ARABIC
8604 if ((int *)varp == &curwin->w_p_arab)
8605 {
8606 if (curwin->w_p_arab)
8607 {
8608 /*
8609 * 'arabic' is set, handle various sub-settings.
8610 */
8611 if (!p_tbidi)
8612 {
8613 /* set rightleft mode */
8614 if (!curwin->w_p_rl)
8615 {
8616 curwin->w_p_rl = TRUE;
8617 changed_window_setting();
8618 }
8619
8620 /* Enable Arabic shaping (major part of what Arabic requires) */
8621 if (!p_arshape)
8622 {
8623 p_arshape = TRUE;
8624 redraw_later_clear();
8625 }
8626 }
8627
8628 /* Arabic requires a utf-8 encoding, inform the user if its not
8629 * set. */
8630 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008631 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008632 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8633
Bram Moolenaar8820b482017-03-16 17:23:31 +01008634 msg_source(HL_ATTR(HLF_W));
8635 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008636#ifdef FEAT_EVAL
8637 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8638#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008639 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640
8641# ifdef FEAT_MBYTE
8642 /* set 'delcombine' */
8643 p_deco = TRUE;
8644# endif
8645
8646# ifdef FEAT_KEYMAP
8647 /* Force-set the necessary keymap for arabic */
8648 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8649 OPT_LOCAL);
8650# endif
8651# ifdef FEAT_FKMAP
8652 p_altkeymap = 0;
8653 p_hkmap = 0;
8654 p_fkmap = 0;
8655 (void)init_chartab();
8656# endif
8657 }
8658 else
8659 {
8660 /*
8661 * 'arabic' is reset, handle various sub-settings.
8662 */
8663 if (!p_tbidi)
8664 {
8665 /* reset rightleft mode */
8666 if (curwin->w_p_rl)
8667 {
8668 curwin->w_p_rl = FALSE;
8669 changed_window_setting();
8670 }
8671
8672 /* 'arabicshape' isn't reset, it is a global option and
8673 * another window may still need it "on". */
8674 }
8675
8676 /* 'delcombine' isn't reset, it is a global option and another
8677 * window may still want it "on". */
8678
8679# ifdef FEAT_KEYMAP
8680 /* Revert to the default keymap */
8681 curbuf->b_p_iminsert = B_IMODE_NONE;
8682 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8683# endif
8684 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008685 }
8686
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008687#endif
8688
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008689#ifdef FEAT_TERMGUICOLORS
8690 /* 'termguicolors' */
8691 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008692 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008693# ifdef FEAT_VTP
8694 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8695 if (!has_vtp_working())
8696 {
8697 p_tgc = 0;
8698 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8699 }
8700 swap_tcap();
8701# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008702# ifdef FEAT_GUI
8703 if (!gui.in_use && !gui.starting)
8704# endif
8705 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008706# ifdef FEAT_VTP
8707 control_console_color_rgb();
8708 /* reset t_Co */
8709 if (STRCMP(T_NAME, "win32") == 0)
8710 set_termname(T_NAME);
8711# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008712 }
8713#endif
8714
Bram Moolenaar071d4272004-06-13 20:20:40 +00008715 /*
8716 * End of handling side effects for bool options.
8717 */
8718
Bram Moolenaar53744302015-07-17 17:38:22 +02008719 /* after handling side effects, call autocommand */
8720
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 options[opt_idx].flags |= P_WAS_SET;
8722
Bram Moolenaar53744302015-07-17 17:38:22 +02008723#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8724 if (!starting)
8725 {
8726 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008727 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8728 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8729 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008730 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8731 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8732 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8733 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8734 reset_v_option_vars();
8735 }
8736#endif
8737
Bram Moolenaar071d4272004-06-13 20:20:40 +00008738 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008739 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008740 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008741 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742 check_redraw(options[opt_idx].flags);
8743
8744 return NULL;
8745}
8746
8747/*
8748 * Set the value of a number option, and take care of side effects.
8749 * Returns NULL for success, or an error message for an error.
8750 */
8751 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008752set_num_option(
8753 int opt_idx, /* index in options[] table */
8754 char_u *varp, /* pointer to the option variable */
8755 long value, /* new value */
8756 char_u *errbuf, /* buffer for error messages */
8757 size_t errbuflen, /* length of "errbuf" */
8758 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008759 OPT_MODELINE */
8760{
8761 char_u *errmsg = NULL;
8762 long old_value = *(long *)varp;
8763 long old_Rows = Rows; /* remember old Rows */
8764 long old_Columns = Columns; /* remember old Columns */
8765 long *pp = (long *)varp;
8766
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008767 /* Disallow changing some options from secure mode. */
8768 if ((secure
8769#ifdef HAVE_SANDBOX
8770 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008772 ) && (options[opt_idx].flags & P_SECURE))
8773 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008774
8775 *pp = value;
8776#ifdef FEAT_EVAL
8777 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008778 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008779#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008780#ifdef FEAT_GUI
8781 need_mouse_correct = TRUE;
8782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008783
Bram Moolenaar14f24742012-08-08 18:01:05 +02008784 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008785 {
8786 errmsg = e_positive;
8787 curbuf->b_p_sw = curbuf->b_p_ts;
8788 }
8789
8790 /*
8791 * Number options that need some action when changed
8792 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008793 if (pp == &p_wh || pp == &p_hh)
8794 {
8795 if (p_wh < 1)
8796 {
8797 errmsg = e_positive;
8798 p_wh = 1;
8799 }
8800 if (p_wmh > p_wh)
8801 {
8802 errmsg = e_winheight;
8803 p_wh = p_wmh;
8804 }
8805 if (p_hh < 0)
8806 {
8807 errmsg = e_positive;
8808 p_hh = 0;
8809 }
8810
8811 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008812 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813 {
8814 if (pp == &p_wh && curwin->w_height < p_wh)
8815 win_setheight((int)p_wh);
8816 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8817 win_setheight((int)p_hh);
8818 }
8819 }
8820
8821 /* 'winminheight' */
8822 else if (pp == &p_wmh)
8823 {
8824 if (p_wmh < 0)
8825 {
8826 errmsg = e_positive;
8827 p_wmh = 0;
8828 }
8829 if (p_wmh > p_wh)
8830 {
8831 errmsg = e_winheight;
8832 p_wmh = p_wh;
8833 }
8834 win_setminheight();
8835 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008836 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 {
8838 if (p_wiw < 1)
8839 {
8840 errmsg = e_positive;
8841 p_wiw = 1;
8842 }
8843 if (p_wmw > p_wiw)
8844 {
8845 errmsg = e_winwidth;
8846 p_wiw = p_wmw;
8847 }
8848
8849 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008850 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 win_setwidth((int)p_wiw);
8852 }
8853
8854 /* 'winminwidth' */
8855 else if (pp == &p_wmw)
8856 {
8857 if (p_wmw < 0)
8858 {
8859 errmsg = e_positive;
8860 p_wmw = 0;
8861 }
8862 if (p_wmw > p_wiw)
8863 {
8864 errmsg = e_winwidth;
8865 p_wmw = p_wiw;
8866 }
8867 win_setminheight();
8868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 /* (re)set last window status line */
8871 else if (pp == &p_ls)
8872 {
8873 last_status(FALSE);
8874 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008875
8876 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008877 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008878 {
8879 shell_new_rows(); /* recompute window positions and heights */
8880 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881
8882#ifdef FEAT_GUI
8883 else if (pp == &p_linespace)
8884 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008885 /* Recompute gui.char_height and resize the Vim window to keep the
8886 * same number of lines. */
8887 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008888 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889 }
8890#endif
8891
8892#ifdef FEAT_FOLDING
8893 /* 'foldlevel' */
8894 else if (pp == &curwin->w_p_fdl)
8895 {
8896 if (curwin->w_p_fdl < 0)
8897 curwin->w_p_fdl = 0;
8898 newFoldLevel();
8899 }
8900
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008901 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902 else if (pp == &curwin->w_p_fml)
8903 {
8904 foldUpdateAll(curwin);
8905 }
8906
8907 /* 'foldnestmax' */
8908 else if (pp == &curwin->w_p_fdn)
8909 {
8910 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8911 foldUpdateAll(curwin);
8912 }
8913
8914 /* 'foldcolumn' */
8915 else if (pp == &curwin->w_p_fdc)
8916 {
8917 if (curwin->w_p_fdc < 0)
8918 {
8919 errmsg = e_positive;
8920 curwin->w_p_fdc = 0;
8921 }
8922 else if (curwin->w_p_fdc > 12)
8923 {
8924 errmsg = e_invarg;
8925 curwin->w_p_fdc = 12;
8926 }
8927 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008928#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008930#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008931 /* 'shiftwidth' or 'tabstop' */
8932 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8933 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008934# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 if (foldmethodIsIndent(curwin))
8936 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008937# endif
8938# ifdef FEAT_CINDENT
8939 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8940 * parse 'cinoptions'. */
8941 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8942 parse_cino(curbuf);
8943# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008945#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008947#ifdef FEAT_MBYTE
8948 /* 'maxcombine' */
8949 else if (pp == &p_mco)
8950 {
8951 if (p_mco > MAX_MCO)
8952 p_mco = MAX_MCO;
8953 else if (p_mco < 0)
8954 p_mco = 0;
8955 screenclear(); /* will re-allocate the screen */
8956 }
8957#endif
8958
Bram Moolenaar071d4272004-06-13 20:20:40 +00008959 else if (pp == &curbuf->b_p_iminsert)
8960 {
8961 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8962 {
8963 errmsg = e_invarg;
8964 curbuf->b_p_iminsert = B_IMODE_NONE;
8965 }
8966 p_iminsert = curbuf->b_p_iminsert;
8967 if (termcap_active) /* don't do this in the alternate screen */
8968 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008969#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 /* Show/unshow value of 'keymap' in status lines. */
8971 status_redraw_curbuf();
8972#endif
8973 }
8974
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008975#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8976 /* 'imstyle' */
8977 else if (pp == &p_imst)
8978 {
8979 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8980 errmsg = e_invarg;
8981 }
8982#endif
8983
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008984 else if (pp == &p_window)
8985 {
8986 if (p_window < 1)
8987 p_window = 1;
8988 else if (p_window >= Rows)
8989 p_window = Rows - 1;
8990 }
8991
Bram Moolenaar071d4272004-06-13 20:20:40 +00008992 else if (pp == &curbuf->b_p_imsearch)
8993 {
8994 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8995 {
8996 errmsg = e_invarg;
8997 curbuf->b_p_imsearch = B_IMODE_NONE;
8998 }
8999 p_imsearch = curbuf->b_p_imsearch;
9000 }
9001
9002#ifdef FEAT_TITLE
9003 /* if 'titlelen' has changed, redraw the title */
9004 else if (pp == &p_titlelen)
9005 {
9006 if (p_titlelen < 0)
9007 {
9008 errmsg = e_positive;
9009 p_titlelen = 85;
9010 }
9011 if (starting != NO_SCREEN && old_value != p_titlelen)
9012 need_maketitle = TRUE;
9013 }
9014#endif
9015
9016 /* if p_ch changed value, change the command line height */
9017 else if (pp == &p_ch)
9018 {
9019 if (p_ch < 1)
9020 {
9021 errmsg = e_positive;
9022 p_ch = 1;
9023 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009024 if (p_ch > Rows - min_rows() + 1)
9025 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009026
9027 /* Only compute the new window layout when startup has been
9028 * completed. Otherwise the frame sizes may be wrong. */
9029 if (p_ch != old_value && full_screen
9030#ifdef FEAT_GUI
9031 && !gui.starting
9032#endif
9033 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009034 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035 }
9036
9037 /* when 'updatecount' changes from zero to non-zero, open swap files */
9038 else if (pp == &p_uc)
9039 {
9040 if (p_uc < 0)
9041 {
9042 errmsg = e_positive;
9043 p_uc = 100;
9044 }
9045 if (p_uc && !old_value)
9046 ml_open_files();
9047 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009048#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009049 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009050 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009051 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009052 {
9053 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009054 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009055 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009056 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009057 {
9058 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009059 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009060 }
9061 }
9062#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009063#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009064 else if (pp == &p_mzq)
9065 mzvim_reset_timer();
9066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009067
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009068#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9069 /* 'pyxversion' */
9070 else if (pp == &p_pyx)
9071 {
9072 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9073 errmsg = e_invarg;
9074 }
9075#endif
9076
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077 /* sync undo before 'undolevels' changes */
9078 else if (pp == &p_ul)
9079 {
9080 /* use the old value, otherwise u_sync() may not work properly */
9081 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009082 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083 p_ul = value;
9084 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009085 else if (pp == &curbuf->b_p_ul)
9086 {
9087 /* use the old value, otherwise u_sync() may not work properly */
9088 curbuf->b_p_ul = old_value;
9089 u_sync(TRUE);
9090 curbuf->b_p_ul = value;
9091 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009093#ifdef FEAT_LINEBREAK
9094 /* 'numberwidth' must be positive */
9095 else if (pp == &curwin->w_p_nuw)
9096 {
9097 if (curwin->w_p_nuw < 1)
9098 {
9099 errmsg = e_positive;
9100 curwin->w_p_nuw = 1;
9101 }
9102 if (curwin->w_p_nuw > 10)
9103 {
9104 errmsg = e_invarg;
9105 curwin->w_p_nuw = 10;
9106 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009107 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009108 }
9109#endif
9110
Bram Moolenaar1a384422010-07-14 19:53:30 +02009111 else if (pp == &curbuf->b_p_tw)
9112 {
9113 if (curbuf->b_p_tw < 0)
9114 {
9115 errmsg = e_positive;
9116 curbuf->b_p_tw = 0;
9117 }
9118#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009119 {
9120 win_T *wp;
9121 tabpage_T *tp;
9122
9123 FOR_ALL_TAB_WINDOWS(tp, wp)
9124 check_colorcolumn(wp);
9125 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009126#endif
9127 }
9128
Bram Moolenaar071d4272004-06-13 20:20:40 +00009129 /*
9130 * Check the bounds for numeric options here
9131 */
9132 if (Rows < min_rows() && full_screen)
9133 {
9134 if (errbuf != NULL)
9135 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009136 vim_snprintf((char *)errbuf, errbuflen,
9137 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138 errmsg = errbuf;
9139 }
9140 Rows = min_rows();
9141 }
9142 if (Columns < MIN_COLUMNS && full_screen)
9143 {
9144 if (errbuf != NULL)
9145 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009146 vim_snprintf((char *)errbuf, errbuflen,
9147 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 errmsg = errbuf;
9149 }
9150 Columns = MIN_COLUMNS;
9151 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009152 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009153
Bram Moolenaar071d4272004-06-13 20:20:40 +00009154 /*
9155 * If the screen (shell) height has been changed, assume it is the
9156 * physical screenheight.
9157 */
9158 if (old_Rows != Rows || old_Columns != Columns)
9159 {
9160 /* Changing the screen size is not allowed while updating the screen. */
9161 if (updating_screen)
9162 *pp = old_value;
9163 else if (full_screen
9164#ifdef FEAT_GUI
9165 && !gui.starting
9166#endif
9167 )
9168 set_shellsize((int)Columns, (int)Rows, TRUE);
9169 else
9170 {
9171 /* Postpone the resizing; check the size and cmdline position for
9172 * messages. */
9173 check_shellsize();
9174 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9175 cmdline_row = Rows - p_ch;
9176 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009177 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009178 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179 }
9180
Bram Moolenaar071d4272004-06-13 20:20:40 +00009181 if (curbuf->b_p_ts <= 0)
9182 {
9183 errmsg = e_positive;
9184 curbuf->b_p_ts = 8;
9185 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186 if (p_tm < 0)
9187 {
9188 errmsg = e_positive;
9189 p_tm = 0;
9190 }
9191 if ((curwin->w_p_scr <= 0
9192 || (curwin->w_p_scr > curwin->w_height
9193 && curwin->w_height > 0))
9194 && full_screen)
9195 {
9196 if (pp == &(curwin->w_p_scr))
9197 {
9198 if (curwin->w_p_scr != 0)
9199 errmsg = e_scroll;
9200 win_comp_scroll(curwin);
9201 }
9202 /* If 'scroll' became invalid because of a side effect silently adjust
9203 * it. */
9204 else if (curwin->w_p_scr <= 0)
9205 curwin->w_p_scr = 1;
9206 else /* curwin->w_p_scr > curwin->w_height */
9207 curwin->w_p_scr = curwin->w_height;
9208 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009209 if (p_hi < 0)
9210 {
9211 errmsg = e_positive;
9212 p_hi = 0;
9213 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009214 else if (p_hi > 10000)
9215 {
9216 errmsg = e_invarg;
9217 p_hi = 10000;
9218 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009219 if (p_re < 0 || p_re > 2)
9220 {
9221 errmsg = e_invarg;
9222 p_re = 0;
9223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224 if (p_report < 0)
9225 {
9226 errmsg = e_positive;
9227 p_report = 1;
9228 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009229 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009230 {
9231 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9232 p_sj = Rows / 2;
9233 else
9234 {
9235 errmsg = e_scroll;
9236 p_sj = 1;
9237 }
9238 }
9239 if (p_so < 0 && full_screen)
9240 {
9241 errmsg = e_scroll;
9242 p_so = 0;
9243 }
9244 if (p_siso < 0 && full_screen)
9245 {
9246 errmsg = e_positive;
9247 p_siso = 0;
9248 }
9249#ifdef FEAT_CMDWIN
9250 if (p_cwh < 1)
9251 {
9252 errmsg = e_positive;
9253 p_cwh = 1;
9254 }
9255#endif
9256 if (p_ut < 0)
9257 {
9258 errmsg = e_positive;
9259 p_ut = 2000;
9260 }
9261 if (p_ss < 0)
9262 {
9263 errmsg = e_positive;
9264 p_ss = 0;
9265 }
9266
9267 /* May set global value for local option. */
9268 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9269 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9270
9271 options[opt_idx].flags |= P_WAS_SET;
9272
Bram Moolenaar53744302015-07-17 17:38:22 +02009273#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9274 if (!starting && errmsg == NULL)
9275 {
9276 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009277 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9278 vim_snprintf((char *)buf_new, 10, "%ld", value);
9279 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009280 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9281 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9282 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9283 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9284 reset_v_option_vars();
9285 }
9286#endif
9287
Bram Moolenaar071d4272004-06-13 20:20:40 +00009288 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009289 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009290 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009291 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292 check_redraw(options[opt_idx].flags);
9293
9294 return errmsg;
9295}
9296
9297/*
9298 * Called after an option changed: check if something needs to be redrawn.
9299 */
9300 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009301check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009302{
9303 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009304 int doclear = (flags & P_RCLR) == P_RCLR;
9305 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9308 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009309
9310 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9311 changed_window_setting();
9312 if (flags & P_RBUF)
9313 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009314 if (flags & P_RWINONLY)
9315 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009316 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009317 redraw_all_later(CLEAR);
9318 else if (all)
9319 redraw_all_later(NOT_VALID);
9320}
9321
9322/*
9323 * Find index for option 'arg'.
9324 * Return -1 if not found.
9325 */
9326 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009327findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328{
9329 int opt_idx;
9330 char *s, *p;
9331 static short quick_tab[27] = {0, 0}; /* quick access table */
9332 int is_term_opt;
9333
9334 /*
9335 * For first call: Initialize the quick-access table.
9336 * It contains the index for the first option that starts with a certain
9337 * letter. There are 26 letters, plus the first "t_" option.
9338 */
9339 if (quick_tab[1] == 0)
9340 {
9341 p = options[0].fullname;
9342 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9343 {
9344 if (s[0] != p[0])
9345 {
9346 if (s[0] == 't' && s[1] == '_')
9347 quick_tab[26] = opt_idx;
9348 else
9349 quick_tab[CharOrdLow(s[0])] = opt_idx;
9350 }
9351 p = s;
9352 }
9353 }
9354
9355 /*
9356 * Check for name starting with an illegal character.
9357 */
9358#ifdef EBCDIC
9359 if (!islower(arg[0]))
9360#else
9361 if (arg[0] < 'a' || arg[0] > 'z')
9362#endif
9363 return -1;
9364
9365 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9366 if (is_term_opt)
9367 opt_idx = quick_tab[26];
9368 else
9369 opt_idx = quick_tab[CharOrdLow(arg[0])];
9370 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9371 {
9372 if (STRCMP(arg, s) == 0) /* match full name */
9373 break;
9374 }
9375 if (s == NULL && !is_term_opt)
9376 {
9377 opt_idx = quick_tab[CharOrdLow(arg[0])];
9378 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9379 {
9380 s = options[opt_idx].shortname;
9381 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9382 break;
9383 s = NULL;
9384 }
9385 }
9386 if (s == NULL)
9387 opt_idx = -1;
9388 return opt_idx;
9389}
9390
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009391#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009392/*
9393 * Get the value for an option.
9394 *
9395 * Returns:
9396 * Number or Toggle option: 1, *numval gets value.
9397 * String option: 0, *stringval gets allocated string.
9398 * Hidden Number or Toggle option: -1.
9399 * hidden String option: -2.
9400 * unknown option: -3.
9401 */
9402 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009403get_option_value(
9404 char_u *name,
9405 long *numval,
9406 char_u **stringval, /* NULL when only checking existence */
9407 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009408{
9409 int opt_idx;
9410 char_u *varp;
9411
9412 opt_idx = findoption(name);
9413 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009414 {
9415 int key;
9416
9417 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9418 && (key = find_key_option(name)) != 0)
9419 {
9420 char_u key_name[2];
9421 char_u *p;
9422
9423 if (key < 0)
9424 {
9425 key_name[0] = KEY2TERMCAP0(key);
9426 key_name[1] = KEY2TERMCAP1(key);
9427 }
9428 else
9429 {
9430 key_name[0] = KS_KEY;
9431 key_name[1] = (key & 0xff);
9432 }
9433 p = find_termcode(key_name);
9434 if (p != NULL)
9435 {
9436 if (stringval != NULL)
9437 *stringval = vim_strsave(p);
9438 return 0;
9439 }
9440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009441 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443
9444 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9445
9446 if (options[opt_idx].flags & P_STRING)
9447 {
9448 if (varp == NULL) /* hidden option */
9449 return -2;
9450 if (stringval != NULL)
9451 {
9452#ifdef FEAT_CRYPT
9453 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009454 if ((char_u **)varp == &curbuf->b_p_key
9455 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009456 *stringval = vim_strsave((char_u *)"*****");
9457 else
9458#endif
9459 *stringval = vim_strsave(*(char_u **)(varp));
9460 }
9461 return 0;
9462 }
9463
9464 if (varp == NULL) /* hidden option */
9465 return -1;
9466 if (options[opt_idx].flags & P_NUM)
9467 *numval = *(long *)varp;
9468 else
9469 {
9470 /* Special case: 'modified' is b_changed, but we also want to consider
9471 * it set when 'ff' or 'fenc' changed. */
9472 if ((int *)varp == &curbuf->b_changed)
9473 *numval = curbufIsChanged();
9474 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009475 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476 }
9477 return 1;
9478}
9479#endif
9480
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009481#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009482/*
9483 * Returns the option attributes and its value. Unlike the above function it
9484 * will return either global value or local value of the option depending on
9485 * what was requested, but it will never return global value if it was
9486 * requested to return local one and vice versa. Neither it will return
9487 * buffer-local value if it was requested to return window-local one.
9488 *
9489 * Pretends that option is absent if it is not present in the requested scope
9490 * (i.e. has no global, window-local or buffer-local value depending on
9491 * opt_type). Uses
9492 *
9493 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009494 * 0 hidden or unknown option, also option that does not have requested
9495 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009496 * see SOPT_* in vim.h for other flags
9497 *
9498 * Possible opt_type values: see SREQ_* in vim.h
9499 */
9500 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009501get_option_value_strict(
9502 char_u *name,
9503 long *numval,
9504 char_u **stringval, /* NULL when only obtaining attributes */
9505 int opt_type,
9506 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009507{
9508 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009509 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009510 struct vimoption *p;
9511 int r = 0;
9512
9513 opt_idx = findoption(name);
9514 if (opt_idx < 0)
9515 return 0;
9516
9517 p = &(options[opt_idx]);
9518
9519 /* Hidden option */
9520 if (p->var == NULL)
9521 return 0;
9522
9523 if (p->flags & P_BOOL)
9524 r |= SOPT_BOOL;
9525 else if (p->flags & P_NUM)
9526 r |= SOPT_NUM;
9527 else if (p->flags & P_STRING)
9528 r |= SOPT_STRING;
9529
9530 if (p->indir == PV_NONE)
9531 {
9532 if (opt_type == SREQ_GLOBAL)
9533 r |= SOPT_GLOBAL;
9534 else
9535 return 0; /* Did not request global-only option */
9536 }
9537 else
9538 {
9539 if (p->indir & PV_BOTH)
9540 r |= SOPT_GLOBAL;
9541 else if (opt_type == SREQ_GLOBAL)
9542 return 0; /* Requested global option */
9543
9544 if (p->indir & PV_WIN)
9545 {
9546 if (opt_type == SREQ_BUF)
9547 return 0; /* Did not request window-local option */
9548 else
9549 r |= SOPT_WIN;
9550 }
9551 else if (p->indir & PV_BUF)
9552 {
9553 if (opt_type == SREQ_WIN)
9554 return 0; /* Did not request buffer-local option */
9555 else
9556 r |= SOPT_BUF;
9557 }
9558 }
9559
9560 if (stringval == NULL)
9561 return r;
9562
9563 if (opt_type == SREQ_GLOBAL)
9564 varp = p->var;
9565 else
9566 {
9567 if (opt_type == SREQ_BUF)
9568 {
9569 /* Special case: 'modified' is b_changed, but we also want to
9570 * consider it set when 'ff' or 'fenc' changed. */
9571 if (p->indir == PV_MOD)
9572 {
9573 *numval = bufIsChanged((buf_T *) from);
9574 varp = NULL;
9575 }
9576#ifdef FEAT_CRYPT
9577 else if (p->indir == PV_KEY)
9578 {
9579 /* never return the value of the crypt key */
9580 *stringval = NULL;
9581 varp = NULL;
9582 }
9583#endif
9584 else
9585 {
9586 aco_save_T aco;
9587 aucmd_prepbuf(&aco, (buf_T *) from);
9588 varp = get_varp(p);
9589 aucmd_restbuf(&aco);
9590 }
9591 }
9592 else if (opt_type == SREQ_WIN)
9593 {
9594 win_T *save_curwin;
9595 save_curwin = curwin;
9596 curwin = (win_T *) from;
9597 curbuf = curwin->w_buffer;
9598 varp = get_varp(p);
9599 curwin = save_curwin;
9600 curbuf = curwin->w_buffer;
9601 }
9602 if (varp == p->var)
9603 return (r | SOPT_UNSET);
9604 }
9605
9606 if (varp != NULL)
9607 {
9608 if (p->flags & P_STRING)
9609 *stringval = vim_strsave(*(char_u **)(varp));
9610 else if (p->flags & P_NUM)
9611 *numval = *(long *) varp;
9612 else
9613 *numval = *(int *)varp;
9614 }
9615
9616 return r;
9617}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009618
9619/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009620 * Iterate over options. First argument is a pointer to a pointer to a
9621 * structure inside options[] array, second is option type like in the above
9622 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009623 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009624 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009625 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009626 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009627 * first argument to NULL.
9628 *
9629 * Returns full option name for current option on each call.
9630 */
9631 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009632option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009633{
9634 struct vimoption *ret = NULL;
9635 do
9636 {
9637 if (*option == NULL)
9638 *option = (void *) options;
9639 else if (((struct vimoption *) (*option))->fullname == NULL)
9640 {
9641 *option = NULL;
9642 return NULL;
9643 }
9644 else
9645 *option = (void *) (((struct vimoption *) (*option)) + 1);
9646
9647 ret = ((struct vimoption *) (*option));
9648
9649 /* Hidden option */
9650 if (ret->var == NULL)
9651 {
9652 ret = NULL;
9653 continue;
9654 }
9655
9656 switch (opt_type)
9657 {
9658 case SREQ_GLOBAL:
9659 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9660 ret = NULL;
9661 break;
9662 case SREQ_BUF:
9663 if (!(ret->indir & PV_BUF))
9664 ret = NULL;
9665 break;
9666 case SREQ_WIN:
9667 if (!(ret->indir & PV_WIN))
9668 ret = NULL;
9669 break;
9670 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009671 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009672 return NULL;
9673 }
9674 }
9675 while (ret == NULL);
9676
9677 return (char_u *)ret->fullname;
9678}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009679#endif
9680
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681/*
9682 * Set the value of option "name".
9683 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009684 *
9685 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009686 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009687 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009688set_option_value(
9689 char_u *name,
9690 long number,
9691 char_u *string,
9692 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009693{
9694 int opt_idx;
9695 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009696 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009697
9698 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009699 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009700 {
9701 int key;
9702
9703 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9704 && (key = find_key_option(name)) != 0)
9705 {
9706 char_u key_name[2];
9707
9708 if (key < 0)
9709 {
9710 key_name[0] = KEY2TERMCAP0(key);
9711 key_name[1] = KEY2TERMCAP1(key);
9712 }
9713 else
9714 {
9715 key_name[0] = KS_KEY;
9716 key_name[1] = (key & 0xff);
9717 }
9718 add_termcode(key_name, string, FALSE);
9719 if (full_screen)
9720 ttest(FALSE);
9721 redraw_all_later(CLEAR);
9722 return NULL;
9723 }
9724
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727 else
9728 {
9729 flags = options[opt_idx].flags;
9730#ifdef HAVE_SANDBOX
9731 /* Disallow changing some options in the sandbox */
9732 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009733 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009735 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009736 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009738 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009739 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 else
9741 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009742 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009743 if (varp != NULL) /* hidden option is not changed */
9744 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009745 if (number == 0 && string != NULL)
9746 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009747 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009748
9749 /* Either we are given a string or we are setting option
9750 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009751 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009752 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009753 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009754 {
9755 /* There's another character after zeros or the string
9756 * is empty. In both cases, we are trying to set a
9757 * num option using a string. */
9758 EMSG3(_("E521: Number required: &%s = '%s'"),
9759 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009760 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009761
9762 }
9763 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009765 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009766 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009768 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009769 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770 }
9771 }
9772 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009773 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009774}
9775
9776/*
9777 * Get the terminal code for a terminal option.
9778 * Returns NULL when not found.
9779 */
9780 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009781get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782{
9783 int opt_idx;
9784 char_u *varp;
9785
9786 if (tname[0] != 't' || tname[1] != '_' ||
9787 tname[2] == NUL || tname[3] == NUL)
9788 return NULL;
9789 if ((opt_idx = findoption(tname)) >= 0)
9790 {
9791 varp = get_varp(&(options[opt_idx]));
9792 if (varp != NULL)
9793 varp = *(char_u **)(varp);
9794 return varp;
9795 }
9796 return find_termcode(tname + 2);
9797}
9798
9799 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009800get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009801{
9802 int i;
9803
9804 i = findoption((char_u *)"hl");
9805 if (i >= 0)
9806 return options[i].def_val[VI_DEFAULT];
9807 return (char_u *)NULL;
9808}
9809
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009810#if defined(FEAT_MBYTE) || defined(PROTO)
9811 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009812get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009813{
9814 int i;
9815
9816 i = findoption((char_u *)"enc");
9817 if (i >= 0)
9818 return options[i].def_val[VI_DEFAULT];
9819 return (char_u *)NULL;
9820}
9821#endif
9822
Bram Moolenaar071d4272004-06-13 20:20:40 +00009823/*
9824 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9825 */
9826 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009827find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009828{
9829 int key;
9830 int modifiers;
9831
9832 /*
9833 * Don't use get_special_key_code() for t_xx, we don't want it to call
9834 * add_termcap_entry().
9835 */
9836 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9837 key = TERMCAP2KEY(arg[2], arg[3]);
9838 else
9839 {
9840 --arg; /* put arg at the '<' */
9841 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009842 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009843 if (modifiers) /* can't handle modifiers here */
9844 key = 0;
9845 }
9846 return key;
9847}
9848
9849/*
9850 * if 'all' == 0: show changed options
9851 * if 'all' == 1: show all normal options
9852 * if 'all' == 2: show all terminal options
9853 */
9854 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009855showoptions(
9856 int all,
9857 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009858{
9859 struct vimoption *p;
9860 int col;
9861 int isterm;
9862 char_u *varp;
9863 struct vimoption **items;
9864 int item_count;
9865 int run;
9866 int row, rows;
9867 int cols;
9868 int i;
9869 int len;
9870
9871#define INC 20
9872#define GAP 3
9873
9874 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9875 PARAM_COUNT));
9876 if (items == NULL)
9877 return;
9878
9879 /* Highlight title */
9880 if (all == 2)
9881 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9882 else if (opt_flags & OPT_GLOBAL)
9883 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9884 else if (opt_flags & OPT_LOCAL)
9885 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9886 else
9887 MSG_PUTS_TITLE(_("\n--- Options ---"));
9888
9889 /*
9890 * do the loop two times:
9891 * 1. display the short items
9892 * 2. display the long items (only strings and numbers)
9893 */
9894 for (run = 1; run <= 2 && !got_int; ++run)
9895 {
9896 /*
9897 * collect the items in items[]
9898 */
9899 item_count = 0;
9900 for (p = &options[0]; p->fullname != NULL; p++)
9901 {
9902 varp = NULL;
9903 isterm = istermoption(p);
9904 if (opt_flags != 0)
9905 {
9906 if (p->indir != PV_NONE && !isterm)
9907 varp = get_varp_scope(p, opt_flags);
9908 }
9909 else
9910 varp = get_varp(p);
9911 if (varp != NULL
9912 && ((all == 2 && isterm)
9913 || (all == 1 && !isterm)
9914 || (all == 0 && !optval_default(p, varp))))
9915 {
9916 if (p->flags & P_BOOL)
9917 len = 1; /* a toggle option fits always */
9918 else
9919 {
9920 option_value2string(p, opt_flags);
9921 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9922 }
9923 if ((len <= INC - GAP && run == 1) ||
9924 (len > INC - GAP && run == 2))
9925 items[item_count++] = p;
9926 }
9927 }
9928
9929 /*
9930 * display the items
9931 */
9932 if (run == 1)
9933 {
9934 cols = (Columns + GAP - 3) / INC;
9935 if (cols == 0)
9936 cols = 1;
9937 rows = (item_count + cols - 1) / cols;
9938 }
9939 else /* run == 2 */
9940 rows = item_count;
9941 for (row = 0; row < rows && !got_int; ++row)
9942 {
9943 msg_putchar('\n'); /* go to next line */
9944 if (got_int) /* 'q' typed in more */
9945 break;
9946 col = 0;
9947 for (i = row; i < item_count; i += rows)
9948 {
9949 msg_col = col; /* make columns */
9950 showoneopt(items[i], opt_flags);
9951 col += INC;
9952 }
9953 out_flush();
9954 ui_breakcheck();
9955 }
9956 }
9957 vim_free(items);
9958}
9959
9960/*
9961 * Return TRUE if option "p" has its default value.
9962 */
9963 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009964optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965{
9966 int dvi;
9967
9968 if (varp == NULL)
9969 return TRUE; /* hidden option is always at default */
9970 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9971 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009972 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009974 /* the cast to long is required for Manx C, long_i is
9975 * needed for MSVC */
9976 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977 /* P_STRING */
9978 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9979}
9980
9981/*
9982 * showoneopt: show the value of one option
9983 * must not be called with a hidden option!
9984 */
9985 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009986showoneopt(
9987 struct vimoption *p,
9988 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009990 char_u *varp;
9991 int save_silent = silent_mode;
9992
9993 silent_mode = FALSE;
9994 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995
9996 varp = get_varp_scope(p, opt_flags);
9997
9998 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9999 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10000 ? !curbufIsChanged() : !*(int *)varp))
10001 MSG_PUTS("no");
10002 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10003 MSG_PUTS("--");
10004 else
10005 MSG_PUTS(" ");
10006 MSG_PUTS(p->fullname);
10007 if (!(p->flags & P_BOOL))
10008 {
10009 msg_putchar('=');
10010 /* put value string in NameBuff */
10011 option_value2string(p, opt_flags);
10012 msg_outtrans(NameBuff);
10013 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010014
10015 silent_mode = save_silent;
10016 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010017}
10018
10019/*
10020 * Write modified options as ":set" commands to a file.
10021 *
10022 * There are three values for "opt_flags":
10023 * OPT_GLOBAL: Write global option values and fresh values of
10024 * buffer-local options (used for start of a session
10025 * file).
10026 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10027 * curwin (used for a vimrc file).
10028 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10029 * and local values for window-local options of
10030 * curwin. Local values are also written when at the
10031 * default value, because a modeline or autocommand
10032 * may have set them when doing ":edit file" and the
10033 * user has set them back at the default or fresh
10034 * value.
10035 * When "local_only" is TRUE, don't write fresh
10036 * values, only local values (for ":mkview").
10037 * (fresh value = value used for a new buffer or window for a local option).
10038 *
10039 * Return FAIL on error, OK otherwise.
10040 */
10041 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010042makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043{
10044 struct vimoption *p;
10045 char_u *varp; /* currently used value */
10046 char_u *varp_fresh; /* local value */
10047 char_u *varp_local = NULL; /* fresh value */
10048 char *cmd;
10049 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010050 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010051
10052 /*
10053 * The options that don't have a default (terminal name, columns, lines)
10054 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010055 * Do the loop over "options[]" twice: once for options with the
10056 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010057 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010058 for (pri = 1; pri >= 0; --pri)
10059 {
10060 for (p = &options[0]; !istermoption(p); p++)
10061 if (!(p->flags & P_NO_MKRC)
10062 && !istermoption(p)
10063 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010064 {
10065 /* skip global option when only doing locals */
10066 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10067 continue;
10068
10069 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10070 * file, they are always buffer-specific. */
10071 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10072 continue;
10073
10074 /* Global values are only written when not at the default value. */
10075 varp = get_varp_scope(p, opt_flags);
10076 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10077 continue;
10078
10079 round = 2;
10080 if (p->indir != PV_NONE)
10081 {
10082 if (p->var == VAR_WIN)
10083 {
10084 /* skip window-local option when only doing globals */
10085 if (!(opt_flags & OPT_LOCAL))
10086 continue;
10087 /* When fresh value of window-local option is not at the
10088 * default, need to write it too. */
10089 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10090 {
10091 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10092 if (!optval_default(p, varp_fresh))
10093 {
10094 round = 1;
10095 varp_local = varp;
10096 varp = varp_fresh;
10097 }
10098 }
10099 }
10100 }
10101
10102 /* Round 1: fresh value for window-local options.
10103 * Round 2: other values */
10104 for ( ; round <= 2; varp = varp_local, ++round)
10105 {
10106 if (round == 1 || (opt_flags & OPT_GLOBAL))
10107 cmd = "set";
10108 else
10109 cmd = "setlocal";
10110
10111 if (p->flags & P_BOOL)
10112 {
10113 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10114 return FAIL;
10115 }
10116 else if (p->flags & P_NUM)
10117 {
10118 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10119 return FAIL;
10120 }
10121 else /* P_STRING */
10122 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010123#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10124 int do_endif = FALSE;
10125
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126 /* Don't set 'syntax' and 'filetype' again if the value is
10127 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010128 if (
10129# if defined(FEAT_SYN_HL)
10130 p->indir == PV_SYN
10131# if defined(FEAT_AUTOCMD)
10132 ||
10133# endif
10134# endif
10135# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010136 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010137# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010138 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139 {
10140 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10141 *(char_u **)(varp)) < 0
10142 || put_eol(fd) < 0)
10143 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010144 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010146#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10148 (p->flags & P_EXPAND) != 0) == FAIL)
10149 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010150#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10151 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152 {
10153 if (put_line(fd, "endif") == FAIL)
10154 return FAIL;
10155 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157 }
10158 }
10159 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010160 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161 return OK;
10162}
10163
10164#if defined(FEAT_FOLDING) || defined(PROTO)
10165/*
10166 * Generate set commands for the local fold options only. Used when
10167 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10168 */
10169 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010170makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171{
10172 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10173# ifdef FEAT_EVAL
10174 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10175 == FAIL
10176# endif
10177 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10178 == FAIL
10179 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10180 == FAIL
10181 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10182 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10183 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10184 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10185 )
10186 return FAIL;
10187
10188 return OK;
10189}
10190#endif
10191
10192 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010193put_setstring(
10194 FILE *fd,
10195 char *cmd,
10196 char *name,
10197 char_u **valuep,
10198 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199{
10200 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010201 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202
10203 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10204 return FAIL;
10205 if (*valuep != NULL)
10206 {
10207 /* Output 'pastetoggle' as key names. For other
10208 * options some characters have to be escaped with
10209 * CTRL-V or backslash */
10210 if (valuep == &p_pt)
10211 {
10212 s = *valuep;
10213 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010214 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 return FAIL;
10216 }
10217 else if (expand)
10218 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010219 buf = alloc(MAXPATHL);
10220 if (buf == NULL)
10221 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10223 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010224 {
10225 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010227 }
10228 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229 }
10230 else if (put_escstr(fd, *valuep, 2) == FAIL)
10231 return FAIL;
10232 }
10233 if (put_eol(fd) < 0)
10234 return FAIL;
10235 return OK;
10236}
10237
10238 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010239put_setnum(
10240 FILE *fd,
10241 char *cmd,
10242 char *name,
10243 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010244{
10245 long wc;
10246
10247 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10248 return FAIL;
10249 if (wc_use_keyname((char_u *)valuep, &wc))
10250 {
10251 /* print 'wildchar' and 'wildcharm' as a key name */
10252 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10253 return FAIL;
10254 }
10255 else if (fprintf(fd, "%ld", *valuep) < 0)
10256 return FAIL;
10257 if (put_eol(fd) < 0)
10258 return FAIL;
10259 return OK;
10260}
10261
10262 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010263put_setbool(
10264 FILE *fd,
10265 char *cmd,
10266 char *name,
10267 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268{
Bram Moolenaar893de922007-10-02 18:40:57 +000010269 if (value < 0) /* global/local option using global value */
10270 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10272 || put_eol(fd) < 0)
10273 return FAIL;
10274 return OK;
10275}
10276
10277/*
10278 * Clear all the terminal options.
10279 * If the option has been allocated, free the memory.
10280 * Terminal options are never hidden or indirect.
10281 */
10282 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010283clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010284{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285 /*
10286 * Reset a few things before clearing the old options. This may cause
10287 * outputting a few things that the terminal doesn't understand, but the
10288 * screen will be cleared later, so this is OK.
10289 */
10290#ifdef FEAT_MOUSE_TTY
10291 mch_setmouse(FALSE); /* switch mouse off */
10292#endif
10293#ifdef FEAT_TITLE
10294 mch_restore_title(3); /* restore window titles */
10295#endif
10296#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10297 /* When starting the GUI close the display opened for the clipboard.
10298 * After restoring the title, because that will need the display. */
10299 if (gui.starting)
10300 clear_xterm_clip();
10301#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010302 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010304 free_termoptions();
10305}
10306
10307 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010308free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010309{
10310 struct vimoption *p;
10311
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312 for (p = &options[0]; p->fullname != NULL; p++)
10313 if (istermoption(p))
10314 {
10315 if (p->flags & P_ALLOCED)
10316 free_string_option(*(char_u **)(p->var));
10317 if (p->flags & P_DEF_ALLOCED)
10318 free_string_option(p->def_val[VI_DEFAULT]);
10319 *(char_u **)(p->var) = empty_option;
10320 p->def_val[VI_DEFAULT] = empty_option;
10321 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10322 }
10323 clear_termcodes();
10324}
10325
10326/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010327 * Free the string for one term option, if it was allocated.
10328 * Set the string to empty_option and clear allocated flag.
10329 * "var" points to the option value.
10330 */
10331 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010332free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010333{
10334 struct vimoption *p;
10335
10336 for (p = &options[0]; p->fullname != NULL; p++)
10337 if (p->var == var)
10338 {
10339 if (p->flags & P_ALLOCED)
10340 free_string_option(*(char_u **)(p->var));
10341 *(char_u **)(p->var) = empty_option;
10342 p->flags &= ~P_ALLOCED;
10343 break;
10344 }
10345}
10346
10347/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348 * Set the terminal option defaults to the current value.
10349 * Used after setting the terminal name.
10350 */
10351 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010352set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353{
10354 struct vimoption *p;
10355
10356 for (p = &options[0]; p->fullname != NULL; p++)
10357 {
10358 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10359 {
10360 if (p->flags & P_DEF_ALLOCED)
10361 {
10362 free_string_option(p->def_val[VI_DEFAULT]);
10363 p->flags &= ~P_DEF_ALLOCED;
10364 }
10365 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10366 if (p->flags & P_ALLOCED)
10367 {
10368 p->flags |= P_DEF_ALLOCED;
10369 p->flags &= ~P_ALLOCED; /* don't free the value now */
10370 }
10371 }
10372 }
10373}
10374
10375/*
10376 * return TRUE if 'p' starts with 't_'
10377 */
10378 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010379istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010380{
10381 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10382}
10383
10384/*
10385 * Compute columns for ruler and shown command. 'sc_col' is also used to
10386 * decide what the maximum length of a message on the status line can be.
10387 * If there is a status line for the last window, 'sc_col' is independent
10388 * of 'ru_col'.
10389 */
10390
10391#define COL_RULER 17 /* columns needed by standard ruler */
10392
10393 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010394comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010396#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010397 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398
10399 sc_col = 0;
10400 ru_col = 0;
10401 if (p_ru)
10402 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010403# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010405# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010407# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408 /* no last status line, adjust sc_col */
10409 if (!last_has_status)
10410 sc_col = ru_col;
10411 }
10412 if (p_sc)
10413 {
10414 sc_col += SHOWCMD_COLS;
10415 if (!p_ru || last_has_status) /* no need for separating space */
10416 ++sc_col;
10417 }
10418 sc_col = Columns - sc_col;
10419 ru_col = Columns - ru_col;
10420 if (sc_col <= 0) /* screen too narrow, will become a mess */
10421 sc_col = 1;
10422 if (ru_col <= 0)
10423 ru_col = 1;
10424#else
10425 sc_col = Columns;
10426 ru_col = Columns;
10427#endif
10428}
10429
10430/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 * Unset local option value, similar to ":set opt<".
10432 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010433 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010434unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010435{
10436 struct vimoption *p;
10437 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010438 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010439
10440 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010441 if (opt_idx < 0)
10442 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010443 p = &(options[opt_idx]);
10444
10445 switch ((int)p->indir)
10446 {
10447 /* global option with local value: use local value if it's been set */
10448 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010449 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010450 break;
10451 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010452 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010453 break;
10454 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010455 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010456 break;
10457 case PV_AR:
10458 buf->b_p_ar = -1;
10459 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010460 case PV_BKC:
10461 clear_string_option(&buf->b_p_bkc);
10462 buf->b_bkc_flags = 0;
10463 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010464 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010465 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010467 case PV_TC:
10468 clear_string_option(&buf->b_p_tc);
10469 buf->b_tc_flags = 0;
10470 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010471#ifdef FEAT_FIND_ID
10472 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010473 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010474 break;
10475 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010476 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010477 break;
10478#endif
10479#ifdef FEAT_INS_EXPAND
10480 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010481 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010482 break;
10483 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010484 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010485 break;
10486#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010487 case PV_FP:
10488 clear_string_option(&buf->b_p_fp);
10489 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010490#ifdef FEAT_QUICKFIX
10491 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010492 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010493 break;
10494 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010495 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010496 break;
10497 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010498 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010499 break;
10500#endif
10501#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10502 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010503 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010504 break;
10505#endif
10506#if defined(FEAT_CRYPT)
10507 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010508 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010509 break;
10510#endif
10511#ifdef FEAT_STL_OPT
10512 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010513 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010514 break;
10515#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010516 case PV_UL:
10517 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10518 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010519#ifdef FEAT_LISP
10520 case PV_LW:
10521 clear_string_option(&buf->b_p_lw);
10522 break;
10523#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010524#ifdef FEAT_MBYTE
10525 case PV_MENC:
10526 clear_string_option(&buf->b_p_menc);
10527 break;
10528#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010529 }
10530}
10531
10532/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533 * Get pointer to option variable, depending on local or global scope.
10534 */
10535 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010536get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537{
10538 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10539 {
10540 if (p->var == VAR_WIN)
10541 return (char_u *)GLOBAL_WO(get_varp(p));
10542 return p->var;
10543 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010544 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545 {
10546 switch ((int)p->indir)
10547 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010548 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010550 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10551 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10552 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010554 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10555 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10556 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010557 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010558 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010559 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010561 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10562 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563#endif
10564#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010565 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10566 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010568#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10569 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10570#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010571#if defined(FEAT_CRYPT)
10572 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10573#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010574#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010575 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010576#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010577 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010578#ifdef FEAT_LISP
10579 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10580#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010581 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010582#ifdef FEAT_MBYTE
10583 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10584#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 }
10586 return NULL; /* "cannot happen" */
10587 }
10588 return get_varp(p);
10589}
10590
10591/*
10592 * Get pointer to option variable.
10593 */
10594 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010595get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596{
10597 /* hidden option, always return NULL */
10598 if (p->var == NULL)
10599 return NULL;
10600
10601 switch ((int)p->indir)
10602 {
10603 case PV_NONE: return p->var;
10604
10605 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010606 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010607 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010608 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010609 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010610 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010612 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010614 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010616 case PV_TC: return *curbuf->b_p_tc != NUL
10617 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010618 case PV_BKC: return *curbuf->b_p_bkc != NUL
10619 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010621 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010622 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010623 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010624 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10625#endif
10626#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010627 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010629 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10631#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010632 case PV_FP: return *curbuf->b_p_fp != NUL
10633 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010635 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010637 case PV_GP: return *curbuf->b_p_gp != NUL
10638 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10639 case PV_MP: return *curbuf->b_p_mp != NUL
10640 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010641#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010642#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10643 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10644 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10645#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010646#if defined(FEAT_CRYPT)
10647 case PV_CM: return *curbuf->b_p_cm != NUL
10648 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10649#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010650#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010651 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010652 ? (char_u *)&(curwin->w_p_stl) : p->var;
10653#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010654 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10655 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010656#ifdef FEAT_LISP
10657 case PV_LW: return *curbuf->b_p_lw != NUL
10658 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10659#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010660#ifdef FEAT_MBYTE
10661 case PV_MENC: return *curbuf->b_p_menc != NUL
10662 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10663#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010664
10665#ifdef FEAT_ARABIC
10666 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10667#endif
10668 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010669#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010670 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10671#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010672#ifdef FEAT_SYN_HL
10673 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10674 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010675 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010677#ifdef FEAT_DIFF
10678 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10679#endif
10680#ifdef FEAT_FOLDING
10681 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10682 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10683 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10684 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10685 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10686 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10687 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10688# ifdef FEAT_EVAL
10689 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10690 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10691# endif
10692 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10693#endif
10694 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010695 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010696#ifdef FEAT_LINEBREAK
10697 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010700 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010701#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010702 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10703#endif
10704#ifdef FEAT_RIGHTLEFT
10705 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10706 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10707#endif
10708 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10709 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10710#ifdef FEAT_LINEBREAK
10711 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010712 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10713 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010714#endif
10715#ifdef FEAT_SCROLLBIND
10716 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10717#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010718#ifdef FEAT_CURSORBIND
10719 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10720#endif
10721#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010722 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10723 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10724#endif
10725#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010726 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010727 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729
10730 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10731 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10732#ifdef FEAT_MBYTE
10733 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10734#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10736 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10738 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10739#ifdef FEAT_CINDENT
10740 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10741 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10742 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10743#endif
10744#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10745 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10746#endif
10747#ifdef FEAT_COMMENTS
10748 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10749#endif
10750#ifdef FEAT_FOLDING
10751 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10752#endif
10753#ifdef FEAT_INS_EXPAND
10754 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10755#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010756#ifdef FEAT_COMPL_FUNC
10757 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010758 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010759#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010761 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10763#ifdef FEAT_MBYTE
10764 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10765#endif
10766 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10767#ifdef FEAT_AUTOCMD
10768 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10769#endif
10770 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010771 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10773 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10774 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10775 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10776#ifdef FEAT_FIND_ID
10777# ifdef FEAT_EVAL
10778 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10779# endif
10780#endif
10781#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10782 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10783 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10784#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010785#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010786 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10787#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788#ifdef FEAT_CRYPT
10789 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10790#endif
10791#ifdef FEAT_LISP
10792 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10793#endif
10794 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10795 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10796 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10797 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10798 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010800#ifdef FEAT_TEXTOBJ
10801 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10802#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10804#ifdef FEAT_SMARTINDENT
10805 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10809#ifdef FEAT_SEARCHPATH
10810 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10811#endif
10812 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10813#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010814 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010815 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10816#endif
10817#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010818 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10819 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10820 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821#endif
10822 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10823 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10824 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10825 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010826#ifdef FEAT_PERSISTENT_UNDO
10827 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010829 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10830#ifdef FEAT_KEYMAP
10831 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10832#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010833#ifdef FEAT_SIGNS
10834 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10835#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010836 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837 }
10838 /* always return a valid pointer to avoid a crash! */
10839 return (char_u *)&(curbuf->b_p_wm);
10840}
10841
10842/*
10843 * Get the value of 'equalprg', either the buffer-local one or the global one.
10844 */
10845 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010846get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010847{
10848 if (*curbuf->b_p_ep == NUL)
10849 return p_ep;
10850 return curbuf->b_p_ep;
10851}
10852
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853/*
10854 * Copy options from one window to another.
10855 * Used when splitting a window.
10856 */
10857 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010858win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859{
10860 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10861 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10862# ifdef FEAT_RIGHTLEFT
10863# ifdef FEAT_FKMAP
10864 /* Is this right? */
10865 wp_to->w_farsi = wp_from->w_farsi;
10866# endif
10867# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010868#if defined(FEAT_LINEBREAK)
10869 briopt_check(wp_to);
10870#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872
10873/*
10874 * Copy the options from one winopt_T to another.
10875 * Doesn't free the old option values in "to", use clear_winopt() for that.
10876 * The 'scroll' option is not copied, because it depends on the window height.
10877 * The 'previewwindow' option is reset, there can be only one preview window.
10878 */
10879 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010880copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010881{
10882#ifdef FEAT_ARABIC
10883 to->wo_arab = from->wo_arab;
10884#endif
10885 to->wo_list = from->wo_list;
10886 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010887 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010888#ifdef FEAT_LINEBREAK
10889 to->wo_nuw = from->wo_nuw;
10890#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891#ifdef FEAT_RIGHTLEFT
10892 to->wo_rl = from->wo_rl;
10893 to->wo_rlc = vim_strsave(from->wo_rlc);
10894#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010895#ifdef FEAT_STL_OPT
10896 to->wo_stl = vim_strsave(from->wo_stl);
10897#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010898 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010899#ifdef FEAT_DIFF
10900 to->wo_wrap_save = from->wo_wrap_save;
10901#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902#ifdef FEAT_LINEBREAK
10903 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010904 to->wo_bri = from->wo_bri;
10905 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010906#endif
10907#ifdef FEAT_SCROLLBIND
10908 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010909 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010910#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010911#ifdef FEAT_CURSORBIND
10912 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010913 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010914#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010915#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010916 to->wo_spell = from->wo_spell;
10917#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010918#ifdef FEAT_SYN_HL
10919 to->wo_cuc = from->wo_cuc;
10920 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010921 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010922#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923#ifdef FEAT_DIFF
10924 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010925 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010926#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010927#ifdef FEAT_CONCEAL
10928 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010929 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010930#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010931#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010932 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010933 to->wo_tms = vim_strsave(from->wo_tms);
10934#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935#ifdef FEAT_FOLDING
10936 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010937 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010939 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 to->wo_fdi = vim_strsave(from->wo_fdi);
10941 to->wo_fml = from->wo_fml;
10942 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010943 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010945 to->wo_fdm_save = from->wo_diff_saved
10946 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947 to->wo_fdn = from->wo_fdn;
10948# ifdef FEAT_EVAL
10949 to->wo_fde = vim_strsave(from->wo_fde);
10950 to->wo_fdt = vim_strsave(from->wo_fdt);
10951# endif
10952 to->wo_fmr = vim_strsave(from->wo_fmr);
10953#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010954#ifdef FEAT_SIGNS
10955 to->wo_scl = vim_strsave(from->wo_scl);
10956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957 check_winopt(to); /* don't want NULL pointers */
10958}
10959
10960/*
10961 * Check string options in a window for a NULL value.
10962 */
10963 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010964check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010965{
10966 check_winopt(&win->w_onebuf_opt);
10967 check_winopt(&win->w_allbuf_opt);
10968}
10969
10970/*
10971 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10972 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010973 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010974check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975{
10976#ifdef FEAT_FOLDING
10977 check_string_option(&wop->wo_fdi);
10978 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010979 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010980# ifdef FEAT_EVAL
10981 check_string_option(&wop->wo_fde);
10982 check_string_option(&wop->wo_fdt);
10983# endif
10984 check_string_option(&wop->wo_fmr);
10985#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010986#ifdef FEAT_SIGNS
10987 check_string_option(&wop->wo_scl);
10988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989#ifdef FEAT_RIGHTLEFT
10990 check_string_option(&wop->wo_rlc);
10991#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010992#ifdef FEAT_STL_OPT
10993 check_string_option(&wop->wo_stl);
10994#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010995#ifdef FEAT_SYN_HL
10996 check_string_option(&wop->wo_cc);
10997#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010998#ifdef FEAT_CONCEAL
10999 check_string_option(&wop->wo_cocu);
11000#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011001#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011002 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011003 check_string_option(&wop->wo_tms);
11004#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011005#ifdef FEAT_LINEBREAK
11006 check_string_option(&wop->wo_briopt);
11007#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011008}
11009
11010/*
11011 * Free the allocated memory inside a winopt_T.
11012 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011014clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011015{
11016#ifdef FEAT_FOLDING
11017 clear_string_option(&wop->wo_fdi);
11018 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011019 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020# ifdef FEAT_EVAL
11021 clear_string_option(&wop->wo_fde);
11022 clear_string_option(&wop->wo_fdt);
11023# endif
11024 clear_string_option(&wop->wo_fmr);
11025#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011026#ifdef FEAT_SIGNS
11027 clear_string_option(&wop->wo_scl);
11028#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011029#ifdef FEAT_LINEBREAK
11030 clear_string_option(&wop->wo_briopt);
11031#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011032#ifdef FEAT_RIGHTLEFT
11033 clear_string_option(&wop->wo_rlc);
11034#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011035#ifdef FEAT_STL_OPT
11036 clear_string_option(&wop->wo_stl);
11037#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011038#ifdef FEAT_SYN_HL
11039 clear_string_option(&wop->wo_cc);
11040#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011041#ifdef FEAT_CONCEAL
11042 clear_string_option(&wop->wo_cocu);
11043#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011044#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011045 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011046 clear_string_option(&wop->wo_tms);
11047#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011048}
11049
11050/*
11051 * Copy global option values to local options for one buffer.
11052 * Used when creating a new buffer and sometimes when entering a buffer.
11053 * flags:
11054 * BCO_ENTER We will enter the buf buffer.
11055 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11056 * appropriate.
11057 * BCO_NOHELP Don't copy the values to a help buffer.
11058 */
11059 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011060buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011061{
11062 int should_copy = TRUE;
11063 char_u *save_p_isk = NULL; /* init for GCC */
11064 int dont_do_help;
11065 int did_isk = FALSE;
11066
11067 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011068 * Skip this when the option defaults have not been set yet. Happens when
11069 * main() allocates the first buffer.
11070 */
11071 if (p_cpo != NULL)
11072 {
11073 /*
11074 * Always copy when entering and 'cpo' contains 'S'.
11075 * Don't copy when already initialized.
11076 * Don't copy when 'cpo' contains 's' and not entering.
11077 * 'S' BCO_ENTER initialized 's' should_copy
11078 * yes yes X X TRUE
11079 * yes no yes X FALSE
11080 * no X yes X FALSE
11081 * X no no yes FALSE
11082 * X no no no TRUE
11083 * no yes no X TRUE
11084 */
11085 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11086 && (buf->b_p_initialized
11087 || (!(flags & BCO_ENTER)
11088 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11089 should_copy = FALSE;
11090
11091 if (should_copy || (flags & BCO_ALWAYS))
11092 {
11093 /* Don't copy the options specific to a help buffer when
11094 * BCO_NOHELP is given or the options were initialized already
11095 * (jumping back to a help file with CTRL-T or CTRL-O) */
11096 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11097 || buf->b_p_initialized;
11098 if (dont_do_help) /* don't free b_p_isk */
11099 {
11100 save_p_isk = buf->b_p_isk;
11101 buf->b_p_isk = NULL;
11102 }
11103 /*
11104 * Always free the allocated strings.
11105 * If not already initialized, set 'readonly' and copy 'fileformat'.
11106 */
11107 if (!buf->b_p_initialized)
11108 {
11109 free_buf_options(buf, TRUE);
11110 buf->b_p_ro = FALSE; /* don't copy readonly */
11111 buf->b_p_tx = p_tx;
11112#ifdef FEAT_MBYTE
11113 buf->b_p_fenc = vim_strsave(p_fenc);
11114#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011115 switch (*p_ffs)
11116 {
11117 case 'm':
11118 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11119 case 'd':
11120 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11121 case 'u':
11122 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11123 default:
11124 buf->b_p_ff = vim_strsave(p_ff);
11125 }
11126 if (buf->b_p_ff != NULL)
11127 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011128 buf->b_p_bh = empty_option;
11129 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130 }
11131 else
11132 free_buf_options(buf, FALSE);
11133
11134 buf->b_p_ai = p_ai;
11135 buf->b_p_ai_nopaste = p_ai_nopaste;
11136 buf->b_p_sw = p_sw;
11137 buf->b_p_tw = p_tw;
11138 buf->b_p_tw_nopaste = p_tw_nopaste;
11139 buf->b_p_tw_nobin = p_tw_nobin;
11140 buf->b_p_wm = p_wm;
11141 buf->b_p_wm_nopaste = p_wm_nopaste;
11142 buf->b_p_wm_nobin = p_wm_nobin;
11143 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011144#ifdef FEAT_MBYTE
11145 buf->b_p_bomb = p_bomb;
11146#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011147 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148 buf->b_p_et = p_et;
11149 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011150 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011151 buf->b_p_ml = p_ml;
11152 buf->b_p_ml_nobin = p_ml_nobin;
11153 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011154 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155#ifdef FEAT_INS_EXPAND
11156 buf->b_p_cpt = vim_strsave(p_cpt);
11157#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011158#ifdef FEAT_COMPL_FUNC
11159 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011160 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011161#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162 buf->b_p_sts = p_sts;
11163 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165#ifdef FEAT_COMMENTS
11166 buf->b_p_com = vim_strsave(p_com);
11167#endif
11168#ifdef FEAT_FOLDING
11169 buf->b_p_cms = vim_strsave(p_cms);
11170#endif
11171 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011172 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173 buf->b_p_nf = vim_strsave(p_nf);
11174 buf->b_p_mps = vim_strsave(p_mps);
11175#ifdef FEAT_SMARTINDENT
11176 buf->b_p_si = p_si;
11177#endif
11178 buf->b_p_ci = p_ci;
11179#ifdef FEAT_CINDENT
11180 buf->b_p_cin = p_cin;
11181 buf->b_p_cink = vim_strsave(p_cink);
11182 buf->b_p_cino = vim_strsave(p_cino);
11183#endif
11184#ifdef FEAT_AUTOCMD
11185 /* Don't copy 'filetype', it must be detected */
11186 buf->b_p_ft = empty_option;
11187#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188 buf->b_p_pi = p_pi;
11189#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11190 buf->b_p_cinw = vim_strsave(p_cinw);
11191#endif
11192#ifdef FEAT_LISP
11193 buf->b_p_lisp = p_lisp;
11194#endif
11195#ifdef FEAT_SYN_HL
11196 /* Don't copy 'syntax', it must be set */
11197 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011198 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011199 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011200#endif
11201#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011202 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011203 (void)compile_cap_prog(&buf->b_s);
11204 buf->b_s.b_p_spf = vim_strsave(p_spf);
11205 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206#endif
11207#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11208 buf->b_p_inde = vim_strsave(p_inde);
11209 buf->b_p_indk = vim_strsave(p_indk);
11210#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011211 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011212#if defined(FEAT_EVAL)
11213 buf->b_p_fex = vim_strsave(p_fex);
11214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011215#ifdef FEAT_CRYPT
11216 buf->b_p_key = vim_strsave(p_key);
11217#endif
11218#ifdef FEAT_SEARCHPATH
11219 buf->b_p_sua = vim_strsave(p_sua);
11220#endif
11221#ifdef FEAT_KEYMAP
11222 buf->b_p_keymap = vim_strsave(p_keymap);
11223 buf->b_kmap_state |= KEYMAP_INIT;
11224#endif
11225 /* This isn't really an option, but copying the langmap and IME
11226 * state from the current buffer is better than resetting it. */
11227 buf->b_p_iminsert = p_iminsert;
11228 buf->b_p_imsearch = p_imsearch;
11229
11230 /* options that are normally global but also have a local value
11231 * are not copied, start using the global value */
11232 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011233 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011234 buf->b_p_bkc = empty_option;
11235 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236#ifdef FEAT_QUICKFIX
11237 buf->b_p_gp = empty_option;
11238 buf->b_p_mp = empty_option;
11239 buf->b_p_efm = empty_option;
11240#endif
11241 buf->b_p_ep = empty_option;
11242 buf->b_p_kp = empty_option;
11243 buf->b_p_path = empty_option;
11244 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011245 buf->b_p_tc = empty_option;
11246 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247#ifdef FEAT_FIND_ID
11248 buf->b_p_def = empty_option;
11249 buf->b_p_inc = empty_option;
11250# ifdef FEAT_EVAL
11251 buf->b_p_inex = vim_strsave(p_inex);
11252# endif
11253#endif
11254#ifdef FEAT_INS_EXPAND
11255 buf->b_p_dict = empty_option;
11256 buf->b_p_tsr = empty_option;
11257#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011258#ifdef FEAT_TEXTOBJ
11259 buf->b_p_qe = vim_strsave(p_qe);
11260#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011261#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11262 buf->b_p_bexpr = empty_option;
11263#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011264#if defined(FEAT_CRYPT)
11265 buf->b_p_cm = empty_option;
11266#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011267#ifdef FEAT_PERSISTENT_UNDO
11268 buf->b_p_udf = p_udf;
11269#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011270#ifdef FEAT_LISP
11271 buf->b_p_lw = empty_option;
11272#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011273#ifdef FEAT_MBYTE
11274 buf->b_p_menc = empty_option;
11275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011276
11277 /*
11278 * Don't copy the options set by ex_help(), use the saved values,
11279 * when going from a help buffer to a non-help buffer.
11280 * Don't touch these at all when BCO_NOHELP is used and going from
11281 * or to a help buffer.
11282 */
11283 if (dont_do_help)
11284 buf->b_p_isk = save_p_isk;
11285 else
11286 {
11287 buf->b_p_isk = vim_strsave(p_isk);
11288 did_isk = TRUE;
11289 buf->b_p_ts = p_ts;
11290 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011291 if (buf->b_p_bt[0] == 'h')
11292 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011293 buf->b_p_ma = p_ma;
11294 }
11295 }
11296
11297 /*
11298 * When the options should be copied (ignoring BCO_ALWAYS), set the
11299 * flag that indicates that the options have been initialized.
11300 */
11301 if (should_copy)
11302 buf->b_p_initialized = TRUE;
11303 }
11304
11305 check_buf_options(buf); /* make sure we don't have NULLs */
11306 if (did_isk)
11307 (void)buf_init_chartab(buf, FALSE);
11308}
11309
11310/*
11311 * Reset the 'modifiable' option and its default value.
11312 */
11313 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011314reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315{
11316 int opt_idx;
11317
11318 curbuf->b_p_ma = FALSE;
11319 p_ma = FALSE;
11320 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011321 if (opt_idx >= 0)
11322 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323}
11324
11325/*
11326 * Set the global value for 'iminsert' to the local value.
11327 */
11328 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011329set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330{
11331 p_iminsert = curbuf->b_p_iminsert;
11332}
11333
11334/*
11335 * Set the global value for 'imsearch' to the local value.
11336 */
11337 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011338set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011339{
11340 p_imsearch = curbuf->b_p_imsearch;
11341}
11342
11343#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11344static int expand_option_idx = -1;
11345static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11346static int expand_option_flags = 0;
11347
11348 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011349set_context_in_set_cmd(
11350 expand_T *xp,
11351 char_u *arg,
11352 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353{
11354 int nextchar;
11355 long_u flags = 0; /* init for GCC */
11356 int opt_idx = 0; /* init for GCC */
11357 char_u *p;
11358 char_u *s;
11359 int is_term_option = FALSE;
11360 int key;
11361
11362 expand_option_flags = opt_flags;
11363
11364 xp->xp_context = EXPAND_SETTINGS;
11365 if (*arg == NUL)
11366 {
11367 xp->xp_pattern = arg;
11368 return;
11369 }
11370 p = arg + STRLEN(arg) - 1;
11371 if (*p == ' ' && *(p - 1) != '\\')
11372 {
11373 xp->xp_pattern = p + 1;
11374 return;
11375 }
11376 while (p > arg)
11377 {
11378 s = p;
11379 /* count number of backslashes before ' ' or ',' */
11380 if (*p == ' ' || *p == ',')
11381 {
11382 while (s > arg && *(s - 1) == '\\')
11383 --s;
11384 }
11385 /* break at a space with an even number of backslashes */
11386 if (*p == ' ' && ((p - s) & 1) == 0)
11387 {
11388 ++p;
11389 break;
11390 }
11391 --p;
11392 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011393 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394 {
11395 xp->xp_context = EXPAND_BOOL_SETTINGS;
11396 p += 2;
11397 }
11398 if (STRNCMP(p, "inv", 3) == 0)
11399 {
11400 xp->xp_context = EXPAND_BOOL_SETTINGS;
11401 p += 3;
11402 }
11403 xp->xp_pattern = arg = p;
11404 if (*arg == '<')
11405 {
11406 while (*p != '>')
11407 if (*p++ == NUL) /* expand terminal option name */
11408 return;
11409 key = get_special_key_code(arg + 1);
11410 if (key == 0) /* unknown name */
11411 {
11412 xp->xp_context = EXPAND_NOTHING;
11413 return;
11414 }
11415 nextchar = *++p;
11416 is_term_option = TRUE;
11417 expand_option_name[2] = KEY2TERMCAP0(key);
11418 expand_option_name[3] = KEY2TERMCAP1(key);
11419 }
11420 else
11421 {
11422 if (p[0] == 't' && p[1] == '_')
11423 {
11424 p += 2;
11425 if (*p != NUL)
11426 ++p;
11427 if (*p == NUL)
11428 return; /* expand option name */
11429 nextchar = *++p;
11430 is_term_option = TRUE;
11431 expand_option_name[2] = p[-2];
11432 expand_option_name[3] = p[-1];
11433 }
11434 else
11435 {
11436 /* Allow * wildcard */
11437 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11438 p++;
11439 if (*p == NUL)
11440 return;
11441 nextchar = *p;
11442 *p = NUL;
11443 opt_idx = findoption(arg);
11444 *p = nextchar;
11445 if (opt_idx == -1 || options[opt_idx].var == NULL)
11446 {
11447 xp->xp_context = EXPAND_NOTHING;
11448 return;
11449 }
11450 flags = options[opt_idx].flags;
11451 if (flags & P_BOOL)
11452 {
11453 xp->xp_context = EXPAND_NOTHING;
11454 return;
11455 }
11456 }
11457 }
11458 /* handle "-=" and "+=" */
11459 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11460 {
11461 ++p;
11462 nextchar = '=';
11463 }
11464 if ((nextchar != '=' && nextchar != ':')
11465 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11466 {
11467 xp->xp_context = EXPAND_UNSUCCESSFUL;
11468 return;
11469 }
11470 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11471 {
11472 xp->xp_context = EXPAND_OLD_SETTING;
11473 if (is_term_option)
11474 expand_option_idx = -1;
11475 else
11476 expand_option_idx = opt_idx;
11477 xp->xp_pattern = p + 1;
11478 return;
11479 }
11480 xp->xp_context = EXPAND_NOTHING;
11481 if (is_term_option || (flags & P_NUM))
11482 return;
11483
11484 xp->xp_pattern = p + 1;
11485
11486 if (flags & P_EXPAND)
11487 {
11488 p = options[opt_idx].var;
11489 if (p == (char_u *)&p_bdir
11490 || p == (char_u *)&p_dir
11491 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011492 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011493 || p == (char_u *)&p_rtp
11494#ifdef FEAT_SEARCHPATH
11495 || p == (char_u *)&p_cdpath
11496#endif
11497#ifdef FEAT_SESSION
11498 || p == (char_u *)&p_vdir
11499#endif
11500 )
11501 {
11502 xp->xp_context = EXPAND_DIRECTORIES;
11503 if (p == (char_u *)&p_path
11504#ifdef FEAT_SEARCHPATH
11505 || p == (char_u *)&p_cdpath
11506#endif
11507 )
11508 xp->xp_backslash = XP_BS_THREE;
11509 else
11510 xp->xp_backslash = XP_BS_ONE;
11511 }
11512 else
11513 {
11514 xp->xp_context = EXPAND_FILES;
11515 /* for 'tags' need three backslashes for a space */
11516 if (p == (char_u *)&p_tags)
11517 xp->xp_backslash = XP_BS_THREE;
11518 else
11519 xp->xp_backslash = XP_BS_ONE;
11520 }
11521 }
11522
11523 /* For an option that is a list of file names, find the start of the
11524 * last file name. */
11525 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11526 {
11527 /* count number of backslashes before ' ' or ',' */
11528 if (*p == ' ' || *p == ',')
11529 {
11530 s = p;
11531 while (s > xp->xp_pattern && *(s - 1) == '\\')
11532 --s;
11533 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11534 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11535 {
11536 xp->xp_pattern = p + 1;
11537 break;
11538 }
11539 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011540
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011541#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011542 /* for 'spellsuggest' start at "file:" */
11543 if (options[opt_idx].var == (char_u *)&p_sps
11544 && STRNCMP(p, "file:", 5) == 0)
11545 {
11546 xp->xp_pattern = p + 5;
11547 break;
11548 }
11549#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011550 }
11551
11552 return;
11553}
11554
11555 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011556ExpandSettings(
11557 expand_T *xp,
11558 regmatch_T *regmatch,
11559 int *num_file,
11560 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561{
11562 int num_normal = 0; /* Nr of matching non-term-code settings */
11563 int num_term = 0; /* Nr of matching terminal code settings */
11564 int opt_idx;
11565 int match;
11566 int count = 0;
11567 char_u *str;
11568 int loop;
11569 int is_term_opt;
11570 char_u name_buf[MAX_KEY_NAME_LEN];
11571 static char *(names[]) = {"all", "termcap"};
11572 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11573
11574 /* do this loop twice:
11575 * loop == 0: count the number of matching options
11576 * loop == 1: copy the matching options into allocated memory
11577 */
11578 for (loop = 0; loop <= 1; ++loop)
11579 {
11580 regmatch->rm_ic = ic;
11581 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11582 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011583 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11584 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011585 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11586 {
11587 if (loop == 0)
11588 num_normal++;
11589 else
11590 (*file)[count++] = vim_strsave((char_u *)names[match]);
11591 }
11592 }
11593 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11594 opt_idx++)
11595 {
11596 if (options[opt_idx].var == NULL)
11597 continue;
11598 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11599 && !(options[opt_idx].flags & P_BOOL))
11600 continue;
11601 is_term_opt = istermoption(&options[opt_idx]);
11602 if (is_term_opt && num_normal > 0)
11603 continue;
11604 match = FALSE;
11605 if (vim_regexec(regmatch, str, (colnr_T)0)
11606 || (options[opt_idx].shortname != NULL
11607 && vim_regexec(regmatch,
11608 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11609 match = TRUE;
11610 else if (is_term_opt)
11611 {
11612 name_buf[0] = '<';
11613 name_buf[1] = 't';
11614 name_buf[2] = '_';
11615 name_buf[3] = str[2];
11616 name_buf[4] = str[3];
11617 name_buf[5] = '>';
11618 name_buf[6] = NUL;
11619 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11620 {
11621 match = TRUE;
11622 str = name_buf;
11623 }
11624 }
11625 if (match)
11626 {
11627 if (loop == 0)
11628 {
11629 if (is_term_opt)
11630 num_term++;
11631 else
11632 num_normal++;
11633 }
11634 else
11635 (*file)[count++] = vim_strsave(str);
11636 }
11637 }
11638 /*
11639 * Check terminal key codes, these are not in the option table
11640 */
11641 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11642 {
11643 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11644 {
11645 if (!isprint(str[0]) || !isprint(str[1]))
11646 continue;
11647
11648 name_buf[0] = 't';
11649 name_buf[1] = '_';
11650 name_buf[2] = str[0];
11651 name_buf[3] = str[1];
11652 name_buf[4] = NUL;
11653
11654 match = FALSE;
11655 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11656 match = TRUE;
11657 else
11658 {
11659 name_buf[0] = '<';
11660 name_buf[1] = 't';
11661 name_buf[2] = '_';
11662 name_buf[3] = str[0];
11663 name_buf[4] = str[1];
11664 name_buf[5] = '>';
11665 name_buf[6] = NUL;
11666
11667 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11668 match = TRUE;
11669 }
11670 if (match)
11671 {
11672 if (loop == 0)
11673 num_term++;
11674 else
11675 (*file)[count++] = vim_strsave(name_buf);
11676 }
11677 }
11678
11679 /*
11680 * Check special key names.
11681 */
11682 regmatch->rm_ic = TRUE; /* ignore case here */
11683 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11684 {
11685 name_buf[0] = '<';
11686 STRCPY(name_buf + 1, str);
11687 STRCAT(name_buf, ">");
11688
11689 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11690 {
11691 if (loop == 0)
11692 num_term++;
11693 else
11694 (*file)[count++] = vim_strsave(name_buf);
11695 }
11696 }
11697 }
11698 if (loop == 0)
11699 {
11700 if (num_normal > 0)
11701 *num_file = num_normal;
11702 else if (num_term > 0)
11703 *num_file = num_term;
11704 else
11705 return OK;
11706 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11707 if (*file == NULL)
11708 {
11709 *file = (char_u **)"";
11710 return FAIL;
11711 }
11712 }
11713 }
11714 return OK;
11715}
11716
11717 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011718ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011719{
11720 char_u *var = NULL; /* init for GCC */
11721 char_u *buf;
11722
11723 *num_file = 0;
11724 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11725 if (*file == NULL)
11726 return FAIL;
11727
11728 /*
11729 * For a terminal key code expand_option_idx is < 0.
11730 */
11731 if (expand_option_idx < 0)
11732 {
11733 var = find_termcode(expand_option_name + 2);
11734 if (var == NULL)
11735 expand_option_idx = findoption(expand_option_name);
11736 }
11737
11738 if (expand_option_idx >= 0)
11739 {
11740 /* put string of option value in NameBuff */
11741 option_value2string(&options[expand_option_idx], expand_option_flags);
11742 var = NameBuff;
11743 }
11744 else if (var == NULL)
11745 var = (char_u *)"";
11746
11747 /* A backslash is required before some characters. This is the reverse of
11748 * what happens in do_set(). */
11749 buf = vim_strsave_escaped(var, escape_chars);
11750
11751 if (buf == NULL)
11752 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011753 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011754 return FAIL;
11755 }
11756
11757#ifdef BACKSLASH_IN_FILENAME
11758 /* For MS-Windows et al. we don't double backslashes at the start and
11759 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011760 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 if (var[0] == '\\' && var[1] == '\\'
11762 && expand_option_idx >= 0
11763 && (options[expand_option_idx].flags & P_EXPAND)
11764 && vim_isfilec(var[2])
11765 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011766 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767#endif
11768
11769 *file[0] = buf;
11770 *num_file = 1;
11771 return OK;
11772}
11773#endif
11774
11775/*
11776 * Get the value for the numeric or string option *opp in a nice format into
11777 * NameBuff[]. Must not be called with a hidden option!
11778 */
11779 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011780option_value2string(
11781 struct vimoption *opp,
11782 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011783{
11784 char_u *varp;
11785
11786 varp = get_varp_scope(opp, opt_flags);
11787
11788 if (opp->flags & P_NUM)
11789 {
11790 long wc = 0;
11791
11792 if (wc_use_keyname(varp, &wc))
11793 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11794 else if (wc != 0)
11795 STRCPY(NameBuff, transchar((int)wc));
11796 else
11797 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11798 }
11799 else /* P_STRING */
11800 {
11801 varp = *(char_u **)(varp);
11802 if (varp == NULL) /* just in case */
11803 NameBuff[0] = NUL;
11804#ifdef FEAT_CRYPT
11805 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011806 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807 STRCPY(NameBuff, "*****");
11808#endif
11809 else if (opp->flags & P_EXPAND)
11810 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11811 /* Translate 'pastetoggle' into special key names */
11812 else if ((char_u **)opp->var == &p_pt)
11813 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11814 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011815 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816 }
11817}
11818
11819/*
11820 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11821 * printed as a keyname.
11822 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11823 */
11824 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011825wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011826{
11827 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11828 {
11829 *wcp = *(long *)varp;
11830 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11831 return TRUE;
11832 }
11833 return FALSE;
11834}
11835
Bram Moolenaar01615492015-02-03 13:00:38 +010011836#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011838 * Any character has an equivalent 'langmap' character. This is used for
11839 * keyboards that have a special language mode that sends characters above
11840 * 128 (although other characters can be translated too). The "to" field is a
11841 * Vim command character. This avoids having to switch the keyboard back to
11842 * ASCII mode when leaving Insert mode.
11843 *
11844 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11845 * commands.
11846 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11847 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11848 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011849 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011850# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011851/*
11852 * With multi-byte support use growarray for 'langmap' chars >= 256
11853 */
11854typedef struct
11855{
11856 int from;
11857 int to;
11858} langmap_entry_T;
11859
11860static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011861static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011862
11863/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011864 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11865 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011866 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011867 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011868langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011869{
11870 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011871 int a = 0;
11872 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011873
11874 /* Do a binary search for an existing entry. */
11875 while (a != b)
11876 {
11877 int i = (a + b) / 2;
11878 int d = entries[i].from - from;
11879
11880 if (d == 0)
11881 {
11882 entries[i].to = to;
11883 return;
11884 }
11885 if (d < 0)
11886 a = i + 1;
11887 else
11888 b = i;
11889 }
11890
11891 if (ga_grow(&langmap_mapga, 1) != OK)
11892 return; /* out of memory */
11893
11894 /* insert new entry at position "a" */
11895 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11896 mch_memmove(entries + 1, entries,
11897 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11898 ++langmap_mapga.ga_len;
11899 entries[0].from = from;
11900 entries[0].to = to;
11901}
11902
11903/*
11904 * Apply 'langmap' to multi-byte character "c" and return the result.
11905 */
11906 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011907langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011908{
11909 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11910 int a = 0;
11911 int b = langmap_mapga.ga_len;
11912
11913 while (a != b)
11914 {
11915 int i = (a + b) / 2;
11916 int d = entries[i].from - c;
11917
11918 if (d == 0)
11919 return entries[i].to; /* found matching entry */
11920 if (d < 0)
11921 a = i + 1;
11922 else
11923 b = i;
11924 }
11925 return c; /* no entry found, return "c" unmodified */
11926}
11927# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011928
11929 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011930langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931{
11932 int i;
11933
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011934 for (i = 0; i < 256; i++)
11935 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11936# ifdef FEAT_MBYTE
11937 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11938# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011939}
11940
11941/*
11942 * Called when langmap option is set; the language map can be
11943 * changed at any time!
11944 */
11945 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011946langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947{
11948 char_u *p;
11949 char_u *p2;
11950 int from, to;
11951
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011952#ifdef FEAT_MBYTE
11953 ga_clear(&langmap_mapga); /* clear the previous map first */
11954#endif
11955 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956
11957 for (p = p_langmap; p[0] != NUL; )
11958 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011959 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011960 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011961 {
11962 if (p2[0] == '\\' && p2[1] != NUL)
11963 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011964 }
11965 if (p2[0] == ';')
11966 ++p2; /* abcd;ABCD form, p2 points to A */
11967 else
11968 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11969 while (p[0])
11970 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011971 if (p[0] == ',')
11972 {
11973 ++p;
11974 break;
11975 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976 if (p[0] == '\\' && p[1] != NUL)
11977 ++p;
11978#ifdef FEAT_MBYTE
11979 from = (*mb_ptr2char)(p);
11980#else
11981 from = p[0];
11982#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011983 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011984 if (p2 == NULL)
11985 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011986 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011987 if (p[0] != ',')
11988 {
11989 if (p[0] == '\\')
11990 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011991#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011992 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011994 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011996 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011997 }
11998 else
11999 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012000 if (p2[0] != ',')
12001 {
12002 if (p2[0] == '\\')
12003 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012004#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012005 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012006#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012007 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012008#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012009 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012010 }
12011 if (to == NUL)
12012 {
12013 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12014 transchar(from));
12015 return;
12016 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012017
12018#ifdef FEAT_MBYTE
12019 if (from >= 256)
12020 langmap_set_entry(from, to);
12021 else
12022#endif
12023 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012024
12025 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012026 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012027 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012028 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012029 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012030 if (*p == ';')
12031 {
12032 p = p2;
12033 if (p[0] != NUL)
12034 {
12035 if (p[0] != ',')
12036 {
12037 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12038 return;
12039 }
12040 ++p;
12041 }
12042 break;
12043 }
12044 }
12045 }
12046 }
12047}
12048#endif
12049
12050/*
12051 * Return TRUE if format option 'x' is in effect.
12052 * Take care of no formatting when 'paste' is set.
12053 */
12054 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012055has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056{
12057 if (p_paste)
12058 return FALSE;
12059 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12060}
12061
12062/*
12063 * Return TRUE if "x" is present in 'shortmess' option, or
12064 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12065 */
12066 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012067shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012069 return p_shm != NULL &&
12070 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012071 || (vim_strchr(p_shm, 'a') != NULL
12072 && vim_strchr((char_u *)SHM_A, x) != NULL));
12073}
12074
12075/*
12076 * paste_option_changed() - Called after p_paste was set or reset.
12077 */
12078 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012079paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012080{
12081 static int old_p_paste = FALSE;
12082 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012083 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012084#ifdef FEAT_CMDL_INFO
12085 static int save_ru = 0;
12086#endif
12087#ifdef FEAT_RIGHTLEFT
12088 static int save_ri = 0;
12089 static int save_hkmap = 0;
12090#endif
12091 buf_T *buf;
12092
12093 if (p_paste)
12094 {
12095 /*
12096 * Paste switched from off to on.
12097 * Save the current values, so they can be restored later.
12098 */
12099 if (!old_p_paste)
12100 {
12101 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012102 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 {
12104 buf->b_p_tw_nopaste = buf->b_p_tw;
12105 buf->b_p_wm_nopaste = buf->b_p_wm;
12106 buf->b_p_sts_nopaste = buf->b_p_sts;
12107 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012108 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 }
12110
12111 /* save global options */
12112 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012113 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114#ifdef FEAT_CMDL_INFO
12115 save_ru = p_ru;
12116#endif
12117#ifdef FEAT_RIGHTLEFT
12118 save_ri = p_ri;
12119 save_hkmap = p_hkmap;
12120#endif
12121 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012122 p_ai_nopaste = p_ai;
12123 p_et_nopaste = p_et;
12124 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012125 p_tw_nopaste = p_tw;
12126 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012127 }
12128
12129 /*
12130 * Always set the option values, also when 'paste' is set when it is
12131 * already on.
12132 */
12133 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012134 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012135 {
12136 buf->b_p_tw = 0; /* textwidth is 0 */
12137 buf->b_p_wm = 0; /* wrapmargin is 0 */
12138 buf->b_p_sts = 0; /* softtabstop is 0 */
12139 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012140 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141 }
12142
12143 /* set global options */
12144 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012145 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147 if (p_ru)
12148 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 p_ru = 0; /* no ruler */
12150#endif
12151#ifdef FEAT_RIGHTLEFT
12152 p_ri = 0; /* no reverse insert */
12153 p_hkmap = 0; /* no Hebrew keyboard */
12154#endif
12155 /* set global values for local buffer options */
12156 p_tw = 0;
12157 p_wm = 0;
12158 p_sts = 0;
12159 p_ai = 0;
12160 }
12161
12162 /*
12163 * Paste switched from on to off: Restore saved values.
12164 */
12165 else if (old_p_paste)
12166 {
12167 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012168 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012169 {
12170 buf->b_p_tw = buf->b_p_tw_nopaste;
12171 buf->b_p_wm = buf->b_p_wm_nopaste;
12172 buf->b_p_sts = buf->b_p_sts_nopaste;
12173 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012174 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175 }
12176
12177 /* restore global options */
12178 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012179 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012180#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012181 if (p_ru != save_ru)
12182 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183 p_ru = save_ru;
12184#endif
12185#ifdef FEAT_RIGHTLEFT
12186 p_ri = save_ri;
12187 p_hkmap = save_hkmap;
12188#endif
12189 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012190 p_ai = p_ai_nopaste;
12191 p_et = p_et_nopaste;
12192 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193 p_tw = p_tw_nopaste;
12194 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012195 }
12196
12197 old_p_paste = p_paste;
12198}
12199
12200/*
12201 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12202 *
12203 * Reset 'compatible' and set the values for options that didn't get set yet
12204 * to the Vim defaults.
12205 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012206 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012207 */
12208 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012209vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012210{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012211 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012212 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012213 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012214
12215 if (!option_was_set((char_u *)"cp"))
12216 {
12217 p_cp = FALSE;
12218 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12219 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12220 set_option_default(opt_idx, OPT_FREE, FALSE);
12221 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012222 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012223 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012224
12225 if (fname != NULL)
12226 {
12227 p = vim_getenv(envname, &dofree);
12228 if (p == NULL)
12229 {
12230 /* Set $MYVIMRC to the first vimrc file found. */
12231 p = FullName_save(fname, FALSE);
12232 if (p != NULL)
12233 {
12234 vim_setenv(envname, p);
12235 vim_free(p);
12236 }
12237 }
12238 else if (dofree)
12239 vim_free(p);
12240 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012241}
12242
12243/*
12244 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12245 */
12246 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012247change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012249 int opt_idx;
12250
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251 if (p_cp != on)
12252 {
12253 p_cp = on;
12254 compatible_set();
12255 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012256 opt_idx = findoption((char_u *)"cp");
12257 if (opt_idx >= 0)
12258 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259}
12260
12261/*
12262 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012263 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012264 */
12265 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012266option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012267{
12268 int idx;
12269
12270 idx = findoption(name);
12271 if (idx < 0) /* unknown option */
12272 return FALSE;
12273 if (options[idx].flags & P_WAS_SET)
12274 return TRUE;
12275 return FALSE;
12276}
12277
12278/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012279 * Reset the flag indicating option "name" was set.
12280 */
12281 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012282reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012283{
12284 int idx = findoption(name);
12285
12286 if (idx >= 0)
12287 options[idx].flags &= ~P_WAS_SET;
12288}
12289
12290/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012291 * compatible_set() - Called when 'compatible' has been set or unset.
12292 *
12293 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12294 * flag) to a Vi compatible value.
12295 * When 'compatible' is unset: Set all options that have a different default
12296 * for Vim (without the P_VI_DEF flag) to that default.
12297 */
12298 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012299compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012300{
12301 int opt_idx;
12302
12303 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12304 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12305 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12306 set_option_default(opt_idx, OPT_FREE, p_cp);
12307 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012308 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012309}
12310
12311#ifdef FEAT_LINEBREAK
12312
12313# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12314 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012315 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012316# endif
12317
12318/*
12319 * fill_breakat_flags() -- called when 'breakat' changes value.
12320 */
12321 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012322fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012323{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012324 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012325 int i;
12326
12327 for (i = 0; i < 256; i++)
12328 breakat_flags[i] = FALSE;
12329
12330 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012331 for (p = p_breakat; *p; p++)
12332 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012333}
12334
12335# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012336 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012337# endif
12338
12339#endif
12340
12341/*
12342 * Check an option that can be a range of string values.
12343 *
12344 * Return OK for correct value, FAIL otherwise.
12345 * Empty is always OK.
12346 */
12347 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012348check_opt_strings(
12349 char_u *val,
12350 char **values,
12351 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012352{
12353 return opt_strings_flags(val, values, NULL, list);
12354}
12355
12356/*
12357 * Handle an option that can be a range of string values.
12358 * Set a flag in "*flagp" for each string present.
12359 *
12360 * Return OK for correct value, FAIL otherwise.
12361 * Empty is always OK.
12362 */
12363 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012364opt_strings_flags(
12365 char_u *val, /* new value */
12366 char **values, /* array of valid string values */
12367 unsigned *flagp,
12368 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012369{
12370 int i;
12371 int len;
12372 unsigned new_flags = 0;
12373
12374 while (*val)
12375 {
12376 for (i = 0; ; ++i)
12377 {
12378 if (values[i] == NULL) /* val not found in values[] */
12379 return FAIL;
12380
12381 len = (int)STRLEN(values[i]);
12382 if (STRNCMP(values[i], val, len) == 0
12383 && ((list && val[len] == ',') || val[len] == NUL))
12384 {
12385 val += len + (val[len] == ',');
12386 new_flags |= (1 << i);
12387 break; /* check next item in val list */
12388 }
12389 }
12390 }
12391 if (flagp != NULL)
12392 *flagp = new_flags;
12393
12394 return OK;
12395}
12396
12397/*
12398 * Read the 'wildmode' option, fill wim_flags[].
12399 */
12400 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012401check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012402{
12403 char_u new_wim_flags[4];
12404 char_u *p;
12405 int i;
12406 int idx = 0;
12407
12408 for (i = 0; i < 4; ++i)
12409 new_wim_flags[i] = 0;
12410
12411 for (p = p_wim; *p; ++p)
12412 {
12413 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12414 ;
12415 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12416 return FAIL;
12417 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12418 new_wim_flags[idx] |= WIM_LONGEST;
12419 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12420 new_wim_flags[idx] |= WIM_FULL;
12421 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12422 new_wim_flags[idx] |= WIM_LIST;
12423 else
12424 return FAIL;
12425 p += i;
12426 if (*p == NUL)
12427 break;
12428 if (*p == ',')
12429 {
12430 if (idx == 3)
12431 return FAIL;
12432 ++idx;
12433 }
12434 }
12435
12436 /* fill remaining entries with last flag */
12437 while (idx < 3)
12438 {
12439 new_wim_flags[idx + 1] = new_wim_flags[idx];
12440 ++idx;
12441 }
12442
12443 /* only when there are no errors, wim_flags[] is changed */
12444 for (i = 0; i < 4; ++i)
12445 wim_flags[i] = new_wim_flags[i];
12446 return OK;
12447}
12448
12449/*
12450 * Check if backspacing over something is allowed.
12451 */
12452 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012453can_bs(
12454 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012455{
12456 switch (*p_bs)
12457 {
12458 case '2': return TRUE;
12459 case '1': return (what != BS_START);
12460 case '0': return FALSE;
12461 }
12462 return vim_strchr(p_bs, what) != NULL;
12463}
12464
12465/*
12466 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12467 * the file must be considered changed when the value is different.
12468 */
12469 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012470save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012471{
12472 buf->b_start_ffc = *buf->b_p_ff;
12473 buf->b_start_eol = buf->b_p_eol;
12474#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012475 buf->b_start_bomb = buf->b_p_bomb;
12476
Bram Moolenaar071d4272004-06-13 20:20:40 +000012477 /* Only use free/alloc when necessary, they take time. */
12478 if (buf->b_start_fenc == NULL
12479 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12480 {
12481 vim_free(buf->b_start_fenc);
12482 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12483 }
12484#endif
12485}
12486
12487/*
12488 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12489 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012490 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12491 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012492 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012493 * When "ignore_empty" is true don't consider a new, empty buffer to be
12494 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012495 */
12496 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012497file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012498{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012499 /* In a buffer that was never loaded the options are not valid. */
12500 if (buf->b_flags & BF_NEVERLOADED)
12501 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012502 if (ignore_empty
12503 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012504 && buf->b_ml.ml_line_count == 1
12505 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12506 return FALSE;
12507 if (buf->b_start_ffc != *buf->b_p_ff)
12508 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012509 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012510 return TRUE;
12511#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012512 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12513 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012514 if (buf->b_start_fenc == NULL)
12515 return (*buf->b_p_fenc != NUL);
12516 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12517#else
12518 return FALSE;
12519#endif
12520}
12521
12522/*
12523 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12524 */
12525 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012526check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012527{
12528 return check_opt_strings(p, p_ff_values, FALSE);
12529}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012530
12531/*
12532 * Return the effective shiftwidth value for current buffer, using the
12533 * 'tabstop' value when 'shiftwidth' is zero.
12534 */
12535 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012536get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012537{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012538 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012539}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012540
12541/*
12542 * Return the effective softtabstop value for the current buffer, using the
12543 * 'tabstop' value when 'softtabstop' is negative.
12544 */
12545 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012546get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012547{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012548 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012549}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012550
12551/*
12552 * Check matchpairs option for "*initc".
12553 * If there is a match set "*initc" to the matching character and "*findc" to
12554 * the opposite character. Set "*backwards" to the direction.
12555 * When "switchit" is TRUE swap the direction.
12556 */
12557 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012558find_mps_values(
12559 int *initc,
12560 int *findc,
12561 int *backwards,
12562 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012563{
12564 char_u *ptr;
12565
12566 ptr = curbuf->b_p_mps;
12567 while (*ptr != NUL)
12568 {
12569#ifdef FEAT_MBYTE
12570 if (has_mbyte)
12571 {
12572 char_u *prev;
12573
12574 if (mb_ptr2char(ptr) == *initc)
12575 {
12576 if (switchit)
12577 {
12578 *findc = *initc;
12579 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12580 *backwards = TRUE;
12581 }
12582 else
12583 {
12584 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12585 *backwards = FALSE;
12586 }
12587 return;
12588 }
12589 prev = ptr;
12590 ptr += mb_ptr2len(ptr) + 1;
12591 if (mb_ptr2char(ptr) == *initc)
12592 {
12593 if (switchit)
12594 {
12595 *findc = *initc;
12596 *initc = mb_ptr2char(prev);
12597 *backwards = FALSE;
12598 }
12599 else
12600 {
12601 *findc = mb_ptr2char(prev);
12602 *backwards = TRUE;
12603 }
12604 return;
12605 }
12606 ptr += mb_ptr2len(ptr);
12607 }
12608 else
12609#endif
12610 {
12611 if (*ptr == *initc)
12612 {
12613 if (switchit)
12614 {
12615 *backwards = TRUE;
12616 *findc = *initc;
12617 *initc = ptr[2];
12618 }
12619 else
12620 {
12621 *backwards = FALSE;
12622 *findc = ptr[2];
12623 }
12624 return;
12625 }
12626 ptr += 2;
12627 if (*ptr == *initc)
12628 {
12629 if (switchit)
12630 {
12631 *backwards = FALSE;
12632 *findc = *initc;
12633 *initc = ptr[-2];
12634 }
12635 else
12636 {
12637 *backwards = TRUE;
12638 *findc = ptr[-2];
12639 }
12640 return;
12641 }
12642 ++ptr;
12643 }
12644 if (*ptr == ',')
12645 ++ptr;
12646 }
12647}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012648
12649#if defined(FEAT_LINEBREAK) || defined(PROTO)
12650/*
12651 * This is called when 'breakindentopt' is changed and when a window is
12652 * initialized.
12653 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012654 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012655briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012656{
12657 char_u *p;
12658 int bri_shift = 0;
12659 long bri_min = 20;
12660 int bri_sbr = FALSE;
12661
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012662 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012663 while (*p != NUL)
12664 {
12665 if (STRNCMP(p, "shift:", 6) == 0
12666 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12667 {
12668 p += 6;
12669 bri_shift = getdigits(&p);
12670 }
12671 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12672 {
12673 p += 4;
12674 bri_min = getdigits(&p);
12675 }
12676 else if (STRNCMP(p, "sbr", 3) == 0)
12677 {
12678 p += 3;
12679 bri_sbr = TRUE;
12680 }
12681 if (*p != ',' && *p != NUL)
12682 return FAIL;
12683 if (*p == ',')
12684 ++p;
12685 }
12686
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012687 wp->w_p_brishift = bri_shift;
12688 wp->w_p_brimin = bri_min;
12689 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012690
12691 return OK;
12692}
12693#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012694
12695/*
12696 * Get the local or global value of 'backupcopy'.
12697 */
12698 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012699get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012700{
12701 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12702}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012703
12704#if defined(FEAT_SIGNS) || defined(PROTO)
12705/*
12706 * Return TRUE when window "wp" has a column to draw signs in.
12707 */
12708 int
12709signcolumn_on(win_T *wp)
12710{
12711 if (*wp->w_p_scl == 'n')
12712 return FALSE;
12713 if (*wp->w_p_scl == 'y')
12714 return TRUE;
12715 return (wp->w_buffer->b_signlist != NULL
12716# ifdef FEAT_NETBEANS_INTG
12717 || wp->w_buffer->b_has_sign_column
12718# endif
12719 );
12720}
12721#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012722
12723#if defined(FEAT_EVAL) || defined(PROTO)
12724/*
12725 * Get window or buffer local options.
12726 */
12727 dict_T *
12728get_winbuf_options(int bufopt)
12729{
12730 dict_T *d;
12731 int opt_idx;
12732
12733 d = dict_alloc();
12734 if (d == NULL)
12735 return NULL;
12736
12737 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12738 {
12739 struct vimoption *opt = &options[opt_idx];
12740
12741 if ((bufopt && (opt->indir & PV_BUF))
12742 || (!bufopt && (opt->indir & PV_WIN)))
12743 {
12744 char_u *varp = get_varp(opt);
12745
12746 if (varp != NULL)
12747 {
12748 if (opt->flags & P_STRING)
12749 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012750 else if (opt->flags & P_NUM)
12751 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012752 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012753 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012754 }
12755 }
12756 }
12757
12758 return d;
12759}
12760#endif