blob: 1b5144709123b794cc197e30155b0d7305215a30 [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.
Bram Moolenaar07268702018-03-01 21:57:32 +01003348 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349 */
3350 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003351set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352{
3353 char_u *p;
3354 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003355 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356
3357#ifdef FEAT_LANGMAP
3358 langmap_init();
3359#endif
3360
3361 /* Be Vi compatible by default */
3362 p_cp = TRUE;
3363
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003364 /* Use POSIX compatibility when $VIM_POSIX is set. */
3365 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003366 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003367 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003368 set_string_default("shm", (char_u *)"A");
3369 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003370
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 /*
3372 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003373 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003375 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003376#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003377 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003379 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380# endif
3381#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003382 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003383 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384
3385#ifdef FEAT_WILDIGN
3386 /*
3387 * Set the default for 'backupskip' to include environment variables for
3388 * temp files.
3389 */
3390 {
3391# ifdef UNIX
3392 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3393# else
3394 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3395# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003396 int len;
3397 garray_T ga;
3398 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399
3400 ga_init2(&ga, 1, 100);
3401 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3402 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003403 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404# ifdef UNIX
3405 if (*names[n] == NUL)
3406 p = (char_u *)"/tmp";
3407 else
3408# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003409 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003410 if (p != NULL && *p != NUL)
3411 {
3412 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003413 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 if (ga_grow(&ga, len) == OK)
3415 {
3416 if (ga.ga_len > 0)
3417 STRCAT(ga.ga_data, ",");
3418 STRCAT(ga.ga_data, p);
3419 add_pathsep(ga.ga_data);
3420 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421 ga.ga_len += len;
3422 }
3423 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003424 if (mustfree)
3425 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426 }
3427 if (ga.ga_data != NULL)
3428 {
3429 set_string_default("bsk", ga.ga_data);
3430 vim_free(ga.ga_data);
3431 }
3432 }
3433#endif
3434
3435 /*
3436 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3437 */
3438 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003439 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003441#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3442 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3443#endif
3444 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003446 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003447 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448#else
3449# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003450 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003451 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003453 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454# endif
3455#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003456 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003457 opt_idx = findoption((char_u *)"maxmem");
3458 if (opt_idx >= 0)
3459 {
3460#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003461 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3462 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003463#endif
3464 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3465 }
3466 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467 }
3468
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469#ifdef FEAT_SEARCHPATH
3470 {
3471 char_u *cdpath;
3472 char_u *buf;
3473 int i;
3474 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003475 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476
3477 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003478 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 if (cdpath != NULL)
3480 {
3481 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3482 if (buf != NULL)
3483 {
3484 buf[0] = ','; /* start with ",", current dir first */
3485 j = 1;
3486 for (i = 0; cdpath[i] != NUL; ++i)
3487 {
3488 if (vim_ispathlistsep(cdpath[i]))
3489 buf[j++] = ',';
3490 else
3491 {
3492 if (cdpath[i] == ' ' || cdpath[i] == ',')
3493 buf[j++] = '\\';
3494 buf[j++] = cdpath[i];
3495 }
3496 }
3497 buf[j] = NUL;
3498 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003499 if (opt_idx >= 0)
3500 {
3501 options[opt_idx].def_val[VI_DEFAULT] = buf;
3502 options[opt_idx].flags |= P_DEF_ALLOCED;
3503 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003504 else
3505 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003507 if (mustfree)
3508 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509 }
3510 }
3511#endif
3512
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003513#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514 /* Set print encoding on platforms that don't default to latin1 */
3515 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003516# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003517 (char_u *)"cp1252"
3518# else
3519# ifdef VMS
3520 (char_u *)"dec-mcs"
3521# else
3522# ifdef EBCDIC
3523 (char_u *)"ebcdic-uk"
3524# else
3525# ifdef MAC
3526 (char_u *)"mac-roman"
3527# else /* HPUX */
3528 (char_u *)"hp-roman8"
3529# endif
3530# endif
3531# endif
3532# endif
3533 );
3534#endif
3535
3536#ifdef FEAT_POSTSCRIPT
3537 /* 'printexpr' must be allocated to be able to evaluate it. */
3538 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003539# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003540 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541# else
3542# ifdef VMS
3543 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3544
3545# else
3546 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3547# endif
3548# endif
3549 );
3550#endif
3551
3552 /*
3553 * Set all the options (except the terminal options) to their default
3554 * value. Also set the global value for local options.
3555 */
3556 set_options_default(0);
3557
Bram Moolenaar07268702018-03-01 21:57:32 +01003558#ifdef CLEAN_RUNTIMEPATH
3559 if (clean_arg)
3560 {
3561 opt_idx = findoption((char_u *)"runtimepath");
3562 if (opt_idx >= 0)
3563 {
3564 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3565 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3566 }
3567 opt_idx = findoption((char_u *)"packpath");
3568 if (opt_idx >= 0)
3569 {
3570 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3571 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3572 }
3573 }
3574#endif
3575
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576#ifdef FEAT_GUI
3577 if (found_reverse_arg)
3578 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3579#endif
3580
3581 curbuf->b_p_initialized = TRUE;
3582 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003583 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584 check_buf_options(curbuf);
3585 check_win_options(curwin);
3586 check_options();
3587
3588 /* Must be before option_expand(), because that one needs vim_isIDc() */
3589 didset_options();
3590
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003591#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003592 /* Use the current chartab for the generic chartab. This is not in
3593 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003594 init_spell_chartab();
3595#endif
3596
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597 /*
3598 * Expand environment variables and things like "~" for the defaults.
3599 * If option_expand() returns non-NULL the variable is expanded. This can
3600 * only happen for non-indirect options.
3601 * Also set the default to the expanded value, so ":set" does not list
3602 * them.
3603 * Don't set the P_ALLOCED flag, because we don't want to free the
3604 * default.
3605 */
3606 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3607 {
3608 if ((options[opt_idx].flags & P_GETTEXT)
3609 && options[opt_idx].var != NULL)
3610 p = (char_u *)_(*(char **)options[opt_idx].var);
3611 else
3612 p = option_expand(opt_idx, NULL);
3613 if (p != NULL && (p = vim_strsave(p)) != NULL)
3614 {
3615 *(char_u **)options[opt_idx].var = p;
3616 /* VIMEXP
3617 * Defaults for all expanded options are currently the same for Vi
3618 * and Vim. When this changes, add some code here! Also need to
3619 * split P_DEF_ALLOCED in two.
3620 */
3621 if (options[opt_idx].flags & P_DEF_ALLOCED)
3622 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3623 options[opt_idx].def_val[VI_DEFAULT] = p;
3624 options[opt_idx].flags |= P_DEF_ALLOCED;
3625 }
3626 }
3627
Bram Moolenaar071d4272004-06-13 20:20:40 +00003628 save_file_ff(curbuf); /* Buffer is unchanged */
3629
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630#if defined(FEAT_ARABIC)
3631 /* Detect use of mlterm.
3632 * Mlterm is a terminal emulator akin to xterm that has some special
3633 * abilities (bidi namely).
3634 * NOTE: mlterm's author is being asked to 'set' a variable
3635 * instead of an environment variable due to inheritance.
3636 */
3637 if (mch_getenv((char_u *)"MLTERM") != NULL)
3638 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3639#endif
3640
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003641 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642
3643#ifdef FEAT_MBYTE
3644# if defined(WIN3264) && defined(FEAT_GETTEXT)
3645 /*
3646 * If $LANG isn't set, try to get a good value for it. This makes the
3647 * right language be used automatically. Don't do this for English.
3648 */
3649 if (mch_getenv((char_u *)"LANG") == NULL)
3650 {
3651 char buf[20];
3652
3653 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3654 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3655 * only the first two. */
3656 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3657 (LPTSTR)buf, 20);
3658 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3659 {
3660 /* There are a few exceptions (probably more) */
3661 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3662 STRCPY(buf, "zh_TW");
3663 else if (STRNICMP(buf, "chs", 3) == 0
3664 || STRNICMP(buf, "zhc", 3) == 0)
3665 STRCPY(buf, "zh_CN");
3666 else if (STRNICMP(buf, "jp", 2) == 0)
3667 STRCPY(buf, "ja");
3668 else
3669 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003670 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671 }
3672 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003673# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003674# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003675 /* Moved to os_mac_conv.c to avoid dependency problems. */
3676 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003677# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678# endif
3679
3680 /* enc_locale() will try to find the encoding of the current locale. */
3681 p = enc_locale();
3682 if (p != NULL)
3683 {
3684 char_u *save_enc;
3685
3686 /* Try setting 'encoding' and check if the value is valid.
3687 * If not, go back to the default "latin1". */
3688 save_enc = p_enc;
3689 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003690 if (STRCMP(p_enc, "gb18030") == 0)
3691 {
3692 /* We don't support "gb18030", but "cp936" is a good substitute
3693 * for practical purposes, thus use that. It's not an alias to
3694 * still support conversion between gb18030 and utf-8. */
3695 p_enc = vim_strsave((char_u *)"cp936");
3696 vim_free(p);
3697 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 if (mb_init() == NULL)
3699 {
3700 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003701 if (opt_idx >= 0)
3702 {
3703 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3704 options[opt_idx].flags |= P_DEF_ALLOCED;
3705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706
Bram Moolenaard0573012017-10-28 21:11:06 +02003707#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003708 if (STRCMP(p_enc, "latin1") == 0
3709# ifdef FEAT_MBYTE
3710 || enc_utf8
3711# endif
3712 )
3713 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003714 /* Adjust the default for 'isprint' and 'iskeyword' to match
3715 * latin1. Also set the defaults for when 'nocompatible' is
3716 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003717 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003718 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003719 set_string_option_direct((char_u *)"isk", -1,
3720 ISK_LATIN1, OPT_FREE, SID_NONE);
3721 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003722 if (opt_idx >= 0)
3723 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003724 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003725 if (opt_idx >= 0)
3726 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003727 (void)init_chartab();
3728 }
3729#endif
3730
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731# if defined(WIN3264) && !defined(FEAT_GUI)
3732 /* Win32 console: When GetACP() returns a different value from
3733 * GetConsoleCP() set 'termencoding'. */
3734 if (GetACP() != GetConsoleCP())
3735 {
3736 char buf[50];
3737
3738 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3739 p_tenc = vim_strsave((char_u *)buf);
3740 if (p_tenc != NULL)
3741 {
3742 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003743 if (opt_idx >= 0)
3744 {
3745 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3746 options[opt_idx].flags |= P_DEF_ALLOCED;
3747 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 convert_setup(&input_conv, p_tenc, p_enc);
3749 convert_setup(&output_conv, p_enc, p_tenc);
3750 }
3751 else
3752 p_tenc = empty_option;
3753 }
3754# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003755# if defined(WIN3264) && defined(FEAT_MBYTE)
3756 /* $HOME may have characters in active code page. */
3757 init_homedir();
3758# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 }
3760 else
3761 {
3762 vim_free(p_enc);
3763 p_enc = save_enc;
3764 }
3765 }
3766#endif
3767
3768#ifdef FEAT_MULTI_LANG
3769 /* Set the default for 'helplang'. */
3770 set_helplang_default(get_mess_lang());
3771#endif
3772}
3773
3774/*
3775 * Set an option to its default value.
3776 * This does not take care of side effects!
3777 */
3778 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003779set_option_default(
3780 int opt_idx,
3781 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3782 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783{
3784 char_u *varp; /* pointer to variable for current option */
3785 int dvi; /* index in def_val[] */
3786 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003787 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3789
3790 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3791 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003792 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 {
3794 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3795 if (flags & P_STRING)
3796 {
3797 /* Use set_string_option_direct() for local options to handle
3798 * freeing and allocating the value. */
3799 if (options[opt_idx].indir != PV_NONE)
3800 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003801 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802 else
3803 {
3804 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3805 free_string_option(*(char_u **)(varp));
3806 *(char_u **)varp = options[opt_idx].def_val[dvi];
3807 options[opt_idx].flags &= ~P_ALLOCED;
3808 }
3809 }
3810 else if (flags & P_NUM)
3811 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003812 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 win_comp_scroll(curwin);
3814 else
3815 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003816 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 /* May also set global value for local option. */
3818 if (both)
3819 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3820 *(long *)varp;
3821 }
3822 }
3823 else /* P_BOOL */
3824 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003825 /* the cast to long is required for Manx C, long_i is needed for
3826 * MSVC */
3827 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003828#ifdef UNIX
3829 /* 'modeline' defaults to off for root */
3830 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3831 *(int *)varp = FALSE;
3832#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 /* May also set global value for local option. */
3834 if (both)
3835 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3836 *(int *)varp;
3837 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003838
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003839 /* The default value is not insecure. */
3840 flagsp = insecure_flag(opt_idx, opt_flags);
3841 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842 }
3843
3844#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003845 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846#endif
3847}
3848
3849/*
3850 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003851 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 */
3853 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003854set_options_default(
3855 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856{
3857 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003859 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860
3861 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003862 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003863#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003864 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003865 || (TRUE
3866# if defined(FEAT_MBYTE)
3867 && options[i].var != (char_u *)&p_enc
3868# endif
3869# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003870 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003871 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003872# endif
3873 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003874#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003875 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876 set_option_default(i, opt_flags, p_cp);
3877
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003879 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003881#ifdef FEAT_CINDENT
3882 parse_cino(curbuf);
3883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884}
3885
3886/*
3887 * Set the Vi-default value of a string option.
3888 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003889 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003891 static void
3892set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893{
3894 char_u *p;
3895 int opt_idx;
3896
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003897 if (escape && vim_strchr(val, ' ') != NULL)
3898 p = vim_strsave_escaped(val, (char_u *)" ");
3899 else
3900 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 if (p != NULL) /* we don't want a NULL */
3902 {
3903 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003904 if (opt_idx >= 0)
3905 {
3906 if (options[opt_idx].flags & P_DEF_ALLOCED)
3907 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3908 options[opt_idx].def_val[VI_DEFAULT] = p;
3909 options[opt_idx].flags |= P_DEF_ALLOCED;
3910 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 }
3912}
3913
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003914 void
3915set_string_default(char *name, char_u *val)
3916{
3917 set_string_default_esc(name, val, FALSE);
3918}
3919
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920/*
3921 * Set the Vi-default value of a number option.
3922 * Used for 'lines' and 'columns'.
3923 */
3924 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003925set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003927 int opt_idx;
3928
3929 opt_idx = findoption((char_u *)name);
3930 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003931 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932}
3933
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003934#if defined(EXITFREE) || defined(PROTO)
3935/*
3936 * Free all options.
3937 */
3938 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003939free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003940{
3941 int i;
3942
3943 for (i = 0; !istermoption(&options[i]); i++)
3944 {
3945 if (options[i].indir == PV_NONE)
3946 {
3947 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003948 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003949 free_string_option(*(char_u **)options[i].var);
3950 if (options[i].flags & P_DEF_ALLOCED)
3951 free_string_option(options[i].def_val[VI_DEFAULT]);
3952 }
3953 else if (options[i].var != VAR_WIN
3954 && (options[i].flags & P_STRING))
3955 /* buffer-local option: free global value */
3956 free_string_option(*(char_u **)options[i].var);
3957 }
3958}
3959#endif
3960
3961
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962/*
3963 * Initialize the options, part two: After getting Rows and Columns and
3964 * setting 'term'.
3965 */
3966 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003967set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003969 int idx;
3970
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003972 * 'scroll' defaults to half the window height. The stored default is zero,
3973 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003975 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003976 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003977 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 comp_col();
3979
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003980 /*
3981 * 'window' is only for backwards compatibility with Vi.
3982 * Default is Rows - 1.
3983 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003984 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003985 p_window = Rows - 1;
3986 set_number_default("window", Rows - 1);
3987
Bram Moolenaarf740b292006-02-16 22:11:02 +00003988 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003989#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003990 /*
3991 * If 'background' wasn't set by the user, try guessing the value,
3992 * depending on the terminal name. Only need to check for terminals
3993 * with a dark background, that can handle color.
3994 */
3995 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003996 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3997 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003999 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004000 /* don't mark it as set, when starting the GUI it may be
4001 * changed again */
4002 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 }
4004#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004005
4006#ifdef CURSOR_SHAPE
4007 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4008#endif
4009#ifdef FEAT_MOUSESHAPE
4010 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4011#endif
4012#ifdef FEAT_PRINTER
4013 (void)parse_printoptions(); /* parse 'printoptions' default value */
4014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015}
4016
4017/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004018 * Return "dark" or "light" depending on the kind of terminal.
4019 * This is just guessing! Recognized are:
4020 * "linux" Linux console
4021 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004022 * "cygwin.*" Cygwin shell
4023 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004024 * We also check the COLORFGBG environment variable, which is set by
4025 * rxvt and derivatives. This variable contains either two or three
4026 * values separated by semicolons; we want the last value in either
4027 * case. If this value is 0-6 or 8, our background is dark.
4028 */
4029 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004030term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004031{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004032#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004033 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004034 return (char_u *)"dark";
4035#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004036 char_u *p;
4037
Bram Moolenaarf740b292006-02-16 22:11:02 +00004038 if (STRCMP(T_NAME, "linux") == 0
4039 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004040 || STRNCMP(T_NAME, "cygwin", 6) == 0
4041 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004042 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4043 && (p = vim_strrchr(p, ';')) != NULL
4044 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4045 && p[2] == NUL))
4046 return (char_u *)"dark";
4047 return (char_u *)"light";
4048#endif
4049}
4050
4051/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 * Initialize the options, part three: After reading the .vimrc
4053 */
4054 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004055set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004057#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058/*
4059 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4060 * This is done after other initializations, where 'shell' might have been
4061 * set, but only if they have not been set before.
4062 */
4063 char_u *p;
4064 int idx_srr;
4065 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004066# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 int idx_sp;
4068 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070
4071 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004072 if (idx_srr < 0)
4073 do_srr = FALSE;
4074 else
4075 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004076# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004078 if (idx_sp < 0)
4079 do_sp = FALSE;
4080 else
4081 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004082# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004083 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 if (p != NULL)
4085 {
4086 /*
4087 * Default for p_sp is "| tee", for p_srr is ">".
4088 * For known shells it is changed here to include stderr.
4089 */
4090 if ( fnamecmp(p, "csh") == 0
4091 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004092# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 || fnamecmp(p, "csh.exe") == 0
4094 || fnamecmp(p, "tcsh.exe") == 0
4095# endif
4096 )
4097 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 if (do_sp)
4100 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004101# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004103# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004105# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4107 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 if (do_srr)
4110 {
4111 p_srr = (char_u *)">&";
4112 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4113 }
4114 }
4115 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004116 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 if ( fnamecmp(p, "sh") == 0
4118 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004119 || fnamecmp(p, "mksh") == 0
4120 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004122 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004124 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004125# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 || fnamecmp(p, "cmd") == 0
4127 || fnamecmp(p, "sh.exe") == 0
4128 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004129 || fnamecmp(p, "mksh.exe") == 0
4130 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004132 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 || fnamecmp(p, "bash.exe") == 0
4134 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004136 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004138# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 if (do_sp)
4140 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004141# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004143# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004145# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4147 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004148# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 if (do_srr)
4150 {
4151 p_srr = (char_u *)">%s 2>&1";
4152 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4153 }
4154 }
4155 vim_free(p);
4156 }
4157#endif
4158
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004159#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004161 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4162 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 * This is done after other initializations, where 'shell' might have been
4164 * set, but only if they have not been set before. Default for p_shcf is
4165 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004166 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004167 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004168 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 {
4170 int idx3;
4171
4172 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004173 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 {
4175 p_shcf = (char_u *)"-c";
4176 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4177 }
4178
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 /* Somehow Win32 requires the quotes around the redirection too */
4180 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004181 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182 {
4183 p_sxq = (char_u *)"\"";
4184 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4185 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004187 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4188 {
4189 int idx3;
4190
4191 /*
4192 * cmd.exe on Windows will strip the first and last double quote given
4193 * on the command line, e.g. most of the time things like:
4194 * cmd /c "my path/to/echo" "my args to echo"
4195 * become:
4196 * my path/to/echo" "my args to echo
4197 * when executed.
4198 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004199 * To avoid this, set shellxquote to surround the command in
4200 * parenthesis. This appears to make most commands work, without
4201 * breaking commands that worked previously, such as
4202 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004203 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004204 idx3 = findoption((char_u *)"sxq");
4205 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4206 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004207 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004208 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4209 }
4210
Bram Moolenaara64ba222012-02-12 23:23:31 +01004211 idx3 = findoption((char_u *)"shcf");
4212 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4213 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004214 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004215 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4216 }
4217 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004218#endif
4219
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004220 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004221 {
4222 int idx_ffs = findoption((char_u *)"ffs");
4223
4224 /* Apply the first entry of 'fileformats' to the initial buffer. */
4225 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4226 set_fileformat(default_fileformat(), OPT_LOCAL);
4227 }
4228
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229#ifdef FEAT_TITLE
4230 set_title_defaults();
4231#endif
4232}
4233
4234#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4235/*
4236 * When 'helplang' is still at its default value, set it to "lang".
4237 * Only the first two characters of "lang" are used.
4238 */
4239 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004240set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241{
4242 int idx;
4243
4244 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4245 return;
4246 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004247 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248 {
4249 if (options[idx].flags & P_ALLOCED)
4250 free_string_option(p_hlg);
4251 p_hlg = vim_strsave(lang);
4252 if (p_hlg == NULL)
4253 p_hlg = empty_option;
4254 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004255 {
4256 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4257 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4258 {
4259 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4260 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4261 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004263 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004264 options[idx].flags |= P_ALLOCED;
4265 }
4266}
4267#endif
4268
4269#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004270static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004271
4272 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004273gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274{
4275 if (gui_get_lightness(gui.back_pixel) < 127)
4276 return (char_u *)"dark";
4277 return (char_u *)"light";
4278}
4279
4280/*
4281 * Option initializations that can only be done after opening the GUI window.
4282 */
4283 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004284init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004285{
4286 /* Set the 'background' option according to the lightness of the
4287 * background color, unless the user has set it already. */
4288 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4289 {
4290 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4291 highlight_changed();
4292 }
4293}
4294#endif
4295
4296#ifdef FEAT_TITLE
4297/*
4298 * 'title' and 'icon' only default to true if they have not been set or reset
4299 * in .vimrc and we can read the old value.
4300 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4301 * they can be reset. This reduces startup time when using X on a remote
4302 * machine.
4303 */
4304 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004305set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004306{
4307 int idx1;
4308 long val;
4309
4310 /*
4311 * If GUI is (going to be) used, we can always set the window title and
4312 * icon name. Saves a bit of time, because the X11 display server does
4313 * not need to be contacted.
4314 */
4315 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004316 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004317 {
4318#ifdef FEAT_GUI
4319 if (gui.starting || gui.in_use)
4320 val = TRUE;
4321 else
4322#endif
4323 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004324 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 p_title = val;
4326 }
4327 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004328 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329 {
4330#ifdef FEAT_GUI
4331 if (gui.starting || gui.in_use)
4332 val = TRUE;
4333 else
4334#endif
4335 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004336 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004337 p_icon = val;
4338 }
4339}
4340#endif
4341
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004342#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4343 static void
4344trigger_optionsset_string(
4345 int opt_idx,
4346 int opt_flags,
4347 char_u *oldval,
4348 char_u *newval)
4349{
4350 if (oldval != NULL && newval != NULL)
4351 {
4352 char_u buf_type[7];
4353
4354 sprintf((char *)buf_type, "%s",
4355 (opt_flags & OPT_LOCAL) ? "local" : "global");
4356 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4357 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4358 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4359 apply_autocmds(EVENT_OPTIONSET,
4360 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4361 reset_v_option_vars();
4362 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004363}
4364#endif
4365
Bram Moolenaar071d4272004-06-13 20:20:40 +00004366/*
4367 * Parse 'arg' for option settings.
4368 *
4369 * 'arg' may be IObuff, but only when no errors can be present and option
4370 * does not need to be expanded with option_expand().
4371 * "opt_flags":
4372 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004373 * OPT_GLOBAL for ":setglobal"
4374 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004376 * OPT_WINONLY to only set window-local options
4377 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004378 *
4379 * returns FAIL if an error is detected, OK otherwise
4380 */
4381 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004382do_set(
4383 char_u *arg, /* option string (may be written to!) */
4384 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385{
4386 int opt_idx;
4387 char_u *errmsg;
4388 char_u errbuf[80];
4389 char_u *startarg;
4390 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4391 int nextchar; /* next non-white char after option name */
4392 int afterchar; /* character just after option name */
4393 int len;
4394 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004395 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396 int key;
4397 long_u flags; /* flags for current option */
4398 char_u *varp = NULL; /* pointer to variable for current option */
4399 int did_show = FALSE; /* already showed one value */
4400 int adding; /* "opt+=arg" */
4401 int prepending; /* "opt^=arg" */
4402 int removing; /* "opt-=arg" */
4403 int cp_val = 0;
4404 char_u key_name[2];
4405
4406 if (*arg == NUL)
4407 {
4408 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004409 did_show = TRUE;
4410 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 }
4412
4413 while (*arg != NUL) /* loop to process all options */
4414 {
4415 errmsg = NULL;
4416 startarg = arg; /* remember for error message */
4417
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004418 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4419 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 {
4421 /*
4422 * ":set all" show all options.
4423 * ":set all&" set all options to their default value.
4424 */
4425 arg += 3;
4426 if (*arg == '&')
4427 {
4428 ++arg;
4429 /* Only for :set command set global value of local options. */
4430 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004431 didset_options();
4432 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004433 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004434 }
4435 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004436 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004438 did_show = TRUE;
4439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004440 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004441 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004442 {
4443 showoptions(2, opt_flags);
4444 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004445 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004446 arg += 7;
4447 }
4448 else
4449 {
4450 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004451 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004452 {
4453 prefix = 0;
4454 arg += 2;
4455 }
4456 else if (STRNCMP(arg, "inv", 3) == 0)
4457 {
4458 prefix = 2;
4459 arg += 3;
4460 }
4461
4462 /* find end of name */
4463 key = 0;
4464 if (*arg == '<')
4465 {
4466 nextchar = 0;
4467 opt_idx = -1;
4468 /* look out for <t_>;> */
4469 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4470 len = 5;
4471 else
4472 {
4473 len = 1;
4474 while (arg[len] != NUL && arg[len] != '>')
4475 ++len;
4476 }
4477 if (arg[len] != '>')
4478 {
4479 errmsg = e_invarg;
4480 goto skip;
4481 }
4482 arg[len] = NUL; /* put NUL after name */
4483 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4484 opt_idx = findoption(arg + 1);
4485 arg[len++] = '>'; /* restore '>' */
4486 if (opt_idx == -1)
4487 key = find_key_option(arg + 1);
4488 }
4489 else
4490 {
4491 len = 0;
4492 /*
4493 * The two characters after "t_" may not be alphanumeric.
4494 */
4495 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4496 len = 4;
4497 else
4498 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4499 ++len;
4500 nextchar = arg[len];
4501 arg[len] = NUL; /* put NUL after name */
4502 opt_idx = findoption(arg);
4503 arg[len] = nextchar; /* restore nextchar */
4504 if (opt_idx == -1)
4505 key = find_key_option(arg);
4506 }
4507
4508 /* remember character after option name */
4509 afterchar = arg[len];
4510
4511 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004512 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004513 ++len;
4514
4515 adding = FALSE;
4516 prepending = FALSE;
4517 removing = FALSE;
4518 if (arg[len] != NUL && arg[len + 1] == '=')
4519 {
4520 if (arg[len] == '+')
4521 {
4522 adding = TRUE; /* "+=" */
4523 ++len;
4524 }
4525 else if (arg[len] == '^')
4526 {
4527 prepending = TRUE; /* "^=" */
4528 ++len;
4529 }
4530 else if (arg[len] == '-')
4531 {
4532 removing = TRUE; /* "-=" */
4533 ++len;
4534 }
4535 }
4536 nextchar = arg[len];
4537
4538 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4539 {
4540 errmsg = (char_u *)N_("E518: Unknown option");
4541 goto skip;
4542 }
4543
4544 if (opt_idx >= 0)
4545 {
4546 if (options[opt_idx].var == NULL) /* hidden option: skip */
4547 {
4548 /* Only give an error message when requesting the value of
4549 * a hidden option, ignore setting it. */
4550 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4551 && (!(options[opt_idx].flags & P_BOOL)
4552 || nextchar == '?'))
4553 errmsg = (char_u *)N_("E519: Option not supported");
4554 goto skip;
4555 }
4556
4557 flags = options[opt_idx].flags;
4558 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4559 }
4560 else
4561 {
4562 flags = P_STRING;
4563 if (key < 0)
4564 {
4565 key_name[0] = KEY2TERMCAP0(key);
4566 key_name[1] = KEY2TERMCAP1(key);
4567 }
4568 else
4569 {
4570 key_name[0] = KS_KEY;
4571 key_name[1] = (key & 0xff);
4572 }
4573 }
4574
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004575 /* Skip all options that are not window-local (used when showing
4576 * an already loaded buffer in a window). */
4577 if ((opt_flags & OPT_WINONLY)
4578 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4579 goto skip;
4580
Bram Moolenaara3227e22006-03-08 21:32:40 +00004581 /* Skip all options that are window-local (used for :vimgrep). */
4582 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4583 && options[opt_idx].var == VAR_WIN)
4584 goto skip;
4585
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004586 /* Disallow changing some options from modelines. */
4587 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004588 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004589 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004590 {
4591 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4592 goto skip;
4593 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004594#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004595 /* In diff mode some options are overruled. This avoids that
4596 * 'foldmethod' becomes "marker" instead of "diff" and that
4597 * "wrap" gets set. */
4598 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004599 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004600 && (
4601#ifdef FEAT_FOLDING
4602 options[opt_idx].indir == PV_FDM ||
4603#endif
4604 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004605 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004606#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004607 }
4608
4609#ifdef HAVE_SANDBOX
4610 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004611 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004612 {
4613 errmsg = (char_u *)_(e_sandbox);
4614 goto skip;
4615 }
4616#endif
4617
4618 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4619 {
4620 arg += len;
4621 cp_val = p_cp;
4622 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4623 {
4624 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4625 {
4626 cp_val = FALSE;
4627 arg += 3;
4628 }
4629 else /* "opt&vi": set to Vi default */
4630 {
4631 cp_val = TRUE;
4632 arg += 2;
4633 }
4634 }
4635 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004636 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004637 {
4638 errmsg = e_trailing;
4639 goto skip;
4640 }
4641 }
4642
4643 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004644 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4645 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004646 */
4647 if (nextchar == '?'
4648 || (prefix == 1
4649 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4650 && !(flags & P_BOOL)))
4651 {
4652 /*
4653 * print value
4654 */
4655 if (did_show)
4656 msg_putchar('\n'); /* cursor below last one */
4657 else
4658 {
4659 gotocmdline(TRUE); /* cursor at status line */
4660 did_show = TRUE; /* remember that we did a line */
4661 }
4662 if (opt_idx >= 0)
4663 {
4664 showoneopt(&options[opt_idx], opt_flags);
4665#ifdef FEAT_EVAL
4666 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004667 {
4668 /* Mention where the option was last set. */
4669 if (varp == options[opt_idx].var)
4670 last_set_msg(options[opt_idx].scriptID);
4671 else if ((int)options[opt_idx].indir & PV_WIN)
4672 last_set_msg(curwin->w_p_scriptID[
4673 (int)options[opt_idx].indir & PV_MASK]);
4674 else if ((int)options[opt_idx].indir & PV_BUF)
4675 last_set_msg(curbuf->b_p_scriptID[
4676 (int)options[opt_idx].indir & PV_MASK]);
4677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004678#endif
4679 }
4680 else
4681 {
4682 char_u *p;
4683
4684 p = find_termcode(key_name);
4685 if (p == NULL)
4686 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004687 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004688 goto skip;
4689 }
4690 else
4691 (void)show_one_termcode(key_name, p, TRUE);
4692 }
4693 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004694 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004695 errmsg = e_trailing;
4696 }
4697 else
4698 {
4699 if (flags & P_BOOL) /* boolean */
4700 {
4701 if (nextchar == '=' || nextchar == ':')
4702 {
4703 errmsg = e_invarg;
4704 goto skip;
4705 }
4706
4707 /*
4708 * ":set opt!": invert
4709 * ":set opt&": reset to default value
4710 * ":set opt<": reset to global value
4711 */
4712 if (nextchar == '!')
4713 value = *(int *)(varp) ^ 1;
4714 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004715 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 ((flags & P_VI_DEF) || cp_val)
4717 ? VI_DEFAULT : VIM_DEFAULT];
4718 else if (nextchar == '<')
4719 {
4720 /* For 'autoread' -1 means to use global value. */
4721 if ((int *)varp == &curbuf->b_p_ar
4722 && opt_flags == OPT_LOCAL)
4723 value = -1;
4724 else
4725 value = *(int *)get_varp_scope(&(options[opt_idx]),
4726 OPT_GLOBAL);
4727 }
4728 else
4729 {
4730 /*
4731 * ":set invopt": invert
4732 * ":set opt" or ":set noopt": set or reset
4733 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004734 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004735 {
4736 errmsg = e_trailing;
4737 goto skip;
4738 }
4739 if (prefix == 2) /* inv */
4740 value = *(int *)(varp) ^ 1;
4741 else
4742 value = prefix;
4743 }
4744
4745 errmsg = set_bool_option(opt_idx, varp, (int)value,
4746 opt_flags);
4747 }
4748 else /* numeric or string */
4749 {
4750 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4751 || prefix != 1)
4752 {
4753 errmsg = e_invarg;
4754 goto skip;
4755 }
4756
4757 if (flags & P_NUM) /* numeric */
4758 {
4759 /*
4760 * Different ways to set a number option:
4761 * & set to default value
4762 * < set to global value
4763 * <xx> accept special key codes for 'wildchar'
4764 * c accept any non-digit for 'wildchar'
4765 * [-]0-9 set number
4766 * other error
4767 */
4768 ++arg;
4769 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004770 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004771 ((flags & P_VI_DEF) || cp_val)
4772 ? VI_DEFAULT : VIM_DEFAULT];
4773 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004774 {
4775 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4776 * use the global value. */
4777 if ((long *)varp == &curbuf->b_p_ul
4778 && opt_flags == OPT_LOCAL)
4779 value = NO_LOCAL_UNDOLEVEL;
4780 else
4781 value = *(long *)get_varp_scope(
4782 &(options[opt_idx]), OPT_GLOBAL);
4783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004784 else if (((long *)varp == &p_wc
4785 || (long *)varp == &p_wcm)
4786 && (*arg == '<'
4787 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004788 || (*arg != NUL
4789 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004790 && !VIM_ISDIGIT(*arg))))
4791 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004792 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004793 if (value == 0 && (long *)varp != &p_wcm)
4794 {
4795 errmsg = e_invarg;
4796 goto skip;
4797 }
4798 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4800 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004801 /* Allow negative (for 'undolevels'), octal and
4802 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004803 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4804 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004805 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004806 {
4807 errmsg = e_invarg;
4808 goto skip;
4809 }
4810 }
4811 else
4812 {
4813 errmsg = (char_u *)N_("E521: Number required after =");
4814 goto skip;
4815 }
4816
4817 if (adding)
4818 value = *(long *)varp + value;
4819 if (prepending)
4820 value = *(long *)varp * value;
4821 if (removing)
4822 value = *(long *)varp - value;
4823 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004824 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004825 }
4826 else if (opt_idx >= 0) /* string */
4827 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004828 char_u *save_arg = NULL;
4829 char_u *s = NULL;
4830 char_u *oldval = NULL; /* previous value if *varp */
4831 char_u *newval;
4832 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004833#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004834 char_u *saved_origval = NULL;
4835 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004836#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004837 unsigned newlen;
4838 int comma;
4839 int bs;
4840 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 was allocated */
4842
4843 /* When using ":set opt=val" for a global option
4844 * with a local value the local value will be
4845 * reset, use the global value here. */
4846 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004847 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004848 varp = options[opt_idx].var;
4849
4850 /* The old value is kept until we are sure that the
4851 * new value is valid. */
4852 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004853
4854 /* When setting the local value of a global
4855 * option, the old value may be the global value. */
4856 if (((int)options[opt_idx].indir & PV_BOTH)
4857 && (opt_flags & OPT_LOCAL))
4858 origval = *(char_u **)get_varp(
4859 &options[opt_idx]);
4860 else
4861 origval = oldval;
4862
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 if (nextchar == '&') /* set to default val */
4864 {
4865 newval = options[opt_idx].def_val[
4866 ((flags & P_VI_DEF) || cp_val)
4867 ? VI_DEFAULT : VIM_DEFAULT];
4868 if ((char_u **)varp == &p_bg)
4869 {
4870 /* guess the value of 'background' */
4871#ifdef FEAT_GUI
4872 if (gui.in_use)
4873 newval = gui_bg_default();
4874 else
4875#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004876 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004877 }
4878
4879 /* expand environment variables and ~ (since the
4880 * default value was already expanded, only
4881 * required when an environment variable was set
4882 * later */
4883 if (newval == NULL)
4884 newval = empty_option;
4885 else
4886 {
4887 s = option_expand(opt_idx, newval);
4888 if (s == NULL)
4889 s = newval;
4890 newval = vim_strsave(s);
4891 }
4892 new_value_alloced = TRUE;
4893 }
4894 else if (nextchar == '<') /* set to global val */
4895 {
4896 newval = vim_strsave(*(char_u **)get_varp_scope(
4897 &(options[opt_idx]), OPT_GLOBAL));
4898 new_value_alloced = TRUE;
4899 }
4900 else
4901 {
4902 ++arg; /* jump to after the '=' or ':' */
4903
4904 /*
4905 * Set 'keywordprg' to ":help" if an empty
4906 * value was passed to :set by the user.
4907 * Misuse errbuf[] for the resulting string.
4908 */
4909 if (varp == (char_u *)&p_kp
4910 && (*arg == NUL || *arg == ' '))
4911 {
4912 STRCPY(errbuf, ":help");
4913 save_arg = arg;
4914 arg = errbuf;
4915 }
4916 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004917 * Convert 'backspace' number to string, for
4918 * adding, prepending and removing string.
4919 */
4920 else if (varp == (char_u *)&p_bs
4921 && VIM_ISDIGIT(**(char_u **)varp))
4922 {
4923 i = getdigits((char_u **)varp);
4924 switch (i)
4925 {
4926 case 0:
4927 *(char_u **)varp = empty_option;
4928 break;
4929 case 1:
4930 *(char_u **)varp = vim_strsave(
4931 (char_u *)"indent,eol");
4932 break;
4933 case 2:
4934 *(char_u **)varp = vim_strsave(
4935 (char_u *)"indent,eol,start");
4936 break;
4937 }
4938 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004939 if (origval == oldval)
4940 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004941 oldval = *(char_u **)varp;
4942 }
4943 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004944 * Convert 'whichwrap' number to string, for
4945 * backwards compatibility with Vim 3.0.
4946 * Misuse errbuf[] for the resulting string.
4947 */
4948 else if (varp == (char_u *)&p_ww
4949 && VIM_ISDIGIT(*arg))
4950 {
4951 *errbuf = NUL;
4952 i = getdigits(&arg);
4953 if (i & 1)
4954 STRCAT(errbuf, "b,");
4955 if (i & 2)
4956 STRCAT(errbuf, "s,");
4957 if (i & 4)
4958 STRCAT(errbuf, "h,l,");
4959 if (i & 8)
4960 STRCAT(errbuf, "<,>,");
4961 if (i & 16)
4962 STRCAT(errbuf, "[,],");
4963 if (*errbuf != NUL) /* remove trailing , */
4964 errbuf[STRLEN(errbuf) - 1] = NUL;
4965 save_arg = arg;
4966 arg = errbuf;
4967 }
4968 /*
4969 * Remove '>' before 'dir' and 'bdir', for
4970 * backwards compatibility with version 3.0
4971 */
4972 else if ( *arg == '>'
4973 && (varp == (char_u *)&p_dir
4974 || varp == (char_u *)&p_bdir))
4975 {
4976 ++arg;
4977 }
4978
Bram Moolenaar071d4272004-06-13 20:20:40 +00004979 /*
4980 * Copy the new string into allocated memory.
4981 * Can't use set_string_option_direct(), because
4982 * we need to remove the backslashes.
4983 */
4984 /* get a bit too much */
4985 newlen = (unsigned)STRLEN(arg) + 1;
4986 if (adding || prepending || removing)
4987 newlen += (unsigned)STRLEN(origval) + 1;
4988 newval = alloc(newlen);
4989 if (newval == NULL) /* out of mem, don't change */
4990 break;
4991 s = newval;
4992
4993 /*
4994 * Copy the string, skip over escaped chars.
4995 * For MS-DOS and WIN32 backslashes before normal
4996 * file name characters are not removed, and keep
4997 * backslash at start, for "\\machine\path", but
4998 * do remove it for "\\\\machine\\path".
4999 * The reverse is found in ExpandOldSetting().
5000 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005001 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005002 {
5003 if (*arg == '\\' && arg[1] != NUL
5004#ifdef BACKSLASH_IN_FILENAME
5005 && !((flags & P_EXPAND)
5006 && vim_isfilec(arg[1])
5007 && (arg[1] != '\\'
5008 || (s == newval
5009 && arg[2] != '\\')))
5010#endif
5011 )
5012 ++arg; /* remove backslash */
5013#ifdef FEAT_MBYTE
5014 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005015 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 {
5017 /* copy multibyte char */
5018 mch_memmove(s, arg, (size_t)i);
5019 arg += i;
5020 s += i;
5021 }
5022 else
5023#endif
5024 *s++ = *arg++;
5025 }
5026 *s = NUL;
5027
5028 /*
5029 * Expand environment variables and ~.
5030 * Don't do it when adding without inserting a
5031 * comma.
5032 */
5033 if (!(adding || prepending || removing)
5034 || (flags & P_COMMA))
5035 {
5036 s = option_expand(opt_idx, newval);
5037 if (s != NULL)
5038 {
5039 vim_free(newval);
5040 newlen = (unsigned)STRLEN(s) + 1;
5041 if (adding || prepending || removing)
5042 newlen += (unsigned)STRLEN(origval) + 1;
5043 newval = alloc(newlen);
5044 if (newval == NULL)
5045 break;
5046 STRCPY(newval, s);
5047 }
5048 }
5049
5050 /* locate newval[] in origval[] when removing it
5051 * and when adding to avoid duplicates */
5052 i = 0; /* init for GCC */
5053 if (removing || (flags & P_NODUP))
5054 {
5055 i = (int)STRLEN(newval);
5056 bs = 0;
5057 for (s = origval; *s; ++s)
5058 {
5059 if ((!(flags & P_COMMA)
5060 || s == origval
5061 || (s[-1] == ',' && !(bs & 1)))
5062 && STRNCMP(s, newval, i) == 0
5063 && (!(flags & P_COMMA)
5064 || s[i] == ','
5065 || s[i] == NUL))
5066 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005067 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005068 * even number of backslashes or a single
5069 * backslash preceded by a comma before it
5070 * is recognized as a separator */
5071 if ((s > origval + 1
5072 && s[-1] == '\\'
5073 && s[-2] != ',')
5074 || (s == origval + 1
5075 && s[-1] == '\\'))
5076
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 ++bs;
5078 else
5079 bs = 0;
5080 }
5081
5082 /* do not add if already there */
5083 if ((adding || prepending) && *s)
5084 {
5085 prepending = FALSE;
5086 adding = FALSE;
5087 STRCPY(newval, origval);
5088 }
5089 }
5090
5091 /* concatenate the two strings; add a ',' if
5092 * needed */
5093 if (adding || prepending)
5094 {
5095 comma = ((flags & P_COMMA) && *origval != NUL
5096 && *newval != NUL);
5097 if (adding)
5098 {
5099 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005100 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005101 if (comma && i > 1
5102 && (flags & P_ONECOMMA) == P_ONECOMMA
5103 && origval[i - 1] == ','
5104 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005105 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 mch_memmove(newval + i + comma, newval,
5107 STRLEN(newval) + 1);
5108 mch_memmove(newval, origval, (size_t)i);
5109 }
5110 else
5111 {
5112 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005113 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005114 }
5115 if (comma)
5116 newval[i] = ',';
5117 }
5118
5119 /* Remove newval[] from origval[]. (Note: "i" has
5120 * been set above and is used here). */
5121 if (removing)
5122 {
5123 STRCPY(newval, origval);
5124 if (*s)
5125 {
5126 /* may need to remove a comma */
5127 if (flags & P_COMMA)
5128 {
5129 if (s == origval)
5130 {
5131 /* include comma after string */
5132 if (s[i] == ',')
5133 ++i;
5134 }
5135 else
5136 {
5137 /* include comma before string */
5138 --s;
5139 ++i;
5140 }
5141 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005142 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005143 }
5144 }
5145
5146 if (flags & P_FLAGLIST)
5147 {
5148 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005149 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005150 {
5151 /* if options have P_FLAGLIST and
5152 * P_ONECOMMA such as 'whichwrap' */
5153 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005154 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005155 if (*s != ',' && *(s + 1) == ','
5156 && vim_strchr(s + 2, *s) != NULL)
5157 {
5158 /* Remove the duplicated value and
5159 * the next comma. */
5160 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005161 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005164 else
5165 {
5166 if ((!(flags & P_COMMA) || *s != ',')
5167 && vim_strchr(s + 1, *s) != NULL)
5168 {
5169 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005170 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005171 }
5172 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005173 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175 }
5176
5177 if (save_arg != NULL) /* number for 'whichwrap' */
5178 arg = save_arg;
5179 new_value_alloced = TRUE;
5180 }
5181
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005182 /*
5183 * Set the new value.
5184 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 *(char_u **)(varp) = newval;
5186
Bram Moolenaar53744302015-07-17 17:38:22 +02005187#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005188 if (!starting
5189# ifdef FEAT_CRYPT
5190 && options[opt_idx].indir != PV_KEY
5191# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005192 && origval != NULL && newval != NULL)
5193 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005194 /* origval may be freed by
5195 * did_set_string_option(), make a copy. */
5196 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005197 /* newval (and varp) may become invalid if the
5198 * buffer is closed by autocommands. */
5199 saved_newval = vim_strsave(newval);
5200 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005201#endif
5202
Bram Moolenaar071d4272004-06-13 20:20:40 +00005203 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005204 * ":set" on local options. Note: when setting 'syntax'
5205 * or 'filetype' autocommands may be triggered that can
5206 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005207 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5208 new_value_alloced, oldval, errbuf, opt_flags);
5209
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005210#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5211 if (errmsg == NULL)
5212 trigger_optionsset_string(opt_idx, opt_flags,
5213 saved_origval, saved_newval);
5214 vim_free(saved_origval);
5215 vim_free(saved_newval);
5216#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005217 /* If error detected, print the error message. */
5218 if (errmsg != NULL)
5219 goto skip;
5220 }
5221 else /* key code option */
5222 {
5223 char_u *p;
5224
5225 if (nextchar == '&')
5226 {
5227 if (add_termcap_entry(key_name, TRUE) == FAIL)
5228 errmsg = (char_u *)N_("E522: Not found in termcap");
5229 }
5230 else
5231 {
5232 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005233 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234 if (*p == '\\' && p[1] != NUL)
5235 ++p;
5236 nextchar = *p;
5237 *p = NUL;
5238 add_termcode(key_name, arg, FALSE);
5239 *p = nextchar;
5240 }
5241 if (full_screen)
5242 ttest(FALSE);
5243 redraw_all_later(CLEAR);
5244 }
5245 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005246
Bram Moolenaar071d4272004-06-13 20:20:40 +00005247 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005248 did_set_option(opt_idx, opt_flags,
5249 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005250 }
5251
5252skip:
5253 /*
5254 * Advance to next argument.
5255 * - skip until a blank found, taking care of backslashes
5256 * - skip blanks
5257 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5258 */
5259 for (i = 0; i < 2 ; ++i)
5260 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005261 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005262 if (*arg++ == '\\' && *arg != NUL)
5263 ++arg;
5264 arg = skipwhite(arg);
5265 if (*arg != '=')
5266 break;
5267 }
5268 }
5269
5270 if (errmsg != NULL)
5271 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005272 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005273 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005274 if (i + (arg - startarg) < IOSIZE)
5275 {
5276 /* append the argument with the error */
5277 STRCAT(IObuff, ": ");
5278 mch_memmove(IObuff + i, startarg, (arg - startarg));
5279 IObuff[i + (arg - startarg)] = NUL;
5280 }
5281 /* make sure all characters are printable */
5282 trans_characters(IObuff, IOSIZE);
5283
5284 ++no_wait_return; /* wait_return done later */
5285 emsg(IObuff); /* show error highlighted */
5286 --no_wait_return;
5287
5288 return FAIL;
5289 }
5290
5291 arg = skipwhite(arg);
5292 }
5293
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005294theend:
5295 if (silent_mode && did_show)
5296 {
5297 /* After displaying option values in silent mode. */
5298 silent_mode = FALSE;
5299 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5300 msg_putchar('\n');
5301 cursor_on(); /* msg_start() switches it off */
5302 out_flush();
5303 silent_mode = TRUE;
5304 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5305 }
5306
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307 return OK;
5308}
5309
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005310/*
5311 * Call this when an option has been given a new value through a user command.
5312 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5313 */
5314 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005315did_set_option(
5316 int opt_idx,
5317 int opt_flags, /* possibly with OPT_MODELINE */
5318 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005319{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005320 long_u *p;
5321
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005322 options[opt_idx].flags |= P_WAS_SET;
5323
5324 /* When an option is set in the sandbox, from a modeline or in secure mode
5325 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005326 * flag. */
5327 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005328 if (secure
5329#ifdef HAVE_SANDBOX
5330 || sandbox != 0
5331#endif
5332 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005333 *p = *p | P_INSECURE;
5334 else if (new_value)
5335 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005336}
5337
Bram Moolenaar071d4272004-06-13 20:20:40 +00005338 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005339illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340{
5341 if (errbuf == NULL)
5342 return (char_u *)"";
5343 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005344 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345 return errbuf;
5346}
5347
5348/*
5349 * Convert a key name or string into a key value.
5350 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005351 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005353 int
5354string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355{
5356 if (*arg == '<')
5357 return find_key_option(arg + 1);
5358 if (*arg == '^')
5359 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005360 if (multi_byte)
5361 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362 return *arg;
5363}
5364
5365#ifdef FEAT_CMDWIN
5366/*
5367 * Check value of 'cedit' and set cedit_key.
5368 * Returns NULL if value is OK, error message otherwise.
5369 */
5370 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005371check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372{
5373 int n;
5374
5375 if (*p_cedit == NUL)
5376 cedit_key = -1;
5377 else
5378 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005379 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005380 if (vim_isprintc(n))
5381 return e_invarg;
5382 cedit_key = n;
5383 }
5384 return NULL;
5385}
5386#endif
5387
5388#ifdef FEAT_TITLE
5389/*
5390 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5391 * maketitle() to create and display it.
5392 * When switching the title or icon off, call mch_restore_title() to get
5393 * the old value back.
5394 */
5395 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005396did_set_title(
5397 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005398{
5399 if (starting != NO_SCREEN
5400#ifdef FEAT_GUI
5401 && !gui.starting
5402#endif
5403 )
5404 {
5405 maketitle();
5406 if (icon)
5407 {
5408 if (!p_icon)
5409 mch_restore_title(2);
5410 }
5411 else
5412 {
5413 if (!p_title)
5414 mch_restore_title(1);
5415 }
5416 }
5417}
5418#endif
5419
5420/*
5421 * set_options_bin - called when 'bin' changes value.
5422 */
5423 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005424set_options_bin(
5425 int oldval,
5426 int newval,
5427 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005428{
5429 /*
5430 * The option values that are changed when 'bin' changes are
5431 * copied when 'bin is set and restored when 'bin' is reset.
5432 */
5433 if (newval)
5434 {
5435 if (!oldval) /* switched on */
5436 {
5437 if (!(opt_flags & OPT_GLOBAL))
5438 {
5439 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5440 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5441 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5442 curbuf->b_p_et_nobin = curbuf->b_p_et;
5443 }
5444 if (!(opt_flags & OPT_LOCAL))
5445 {
5446 p_tw_nobin = p_tw;
5447 p_wm_nobin = p_wm;
5448 p_ml_nobin = p_ml;
5449 p_et_nobin = p_et;
5450 }
5451 }
5452
5453 if (!(opt_flags & OPT_GLOBAL))
5454 {
5455 curbuf->b_p_tw = 0; /* no automatic line wrap */
5456 curbuf->b_p_wm = 0; /* no automatic line wrap */
5457 curbuf->b_p_ml = 0; /* no modelines */
5458 curbuf->b_p_et = 0; /* no expandtab */
5459 }
5460 if (!(opt_flags & OPT_LOCAL))
5461 {
5462 p_tw = 0;
5463 p_wm = 0;
5464 p_ml = FALSE;
5465 p_et = FALSE;
5466 p_bin = TRUE; /* needed when called for the "-b" argument */
5467 }
5468 }
5469 else if (oldval) /* switched off */
5470 {
5471 if (!(opt_flags & OPT_GLOBAL))
5472 {
5473 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5474 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5475 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5476 curbuf->b_p_et = curbuf->b_p_et_nobin;
5477 }
5478 if (!(opt_flags & OPT_LOCAL))
5479 {
5480 p_tw = p_tw_nobin;
5481 p_wm = p_wm_nobin;
5482 p_ml = p_ml_nobin;
5483 p_et = p_et_nobin;
5484 }
5485 }
5486}
5487
5488#ifdef FEAT_VIMINFO
5489/*
5490 * Find the parameter represented by the given character (eg ', :, ", or /),
5491 * and return its associated value in the 'viminfo' string.
5492 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005493 * If the parameter is not specified in the string or there is no following
5494 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495 */
5496 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005497get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005498{
5499 char_u *p;
5500
5501 p = find_viminfo_parameter(type);
5502 if (p != NULL && VIM_ISDIGIT(*p))
5503 return atoi((char *)p);
5504 return -1;
5505}
5506
5507/*
5508 * Find the parameter represented by the given character (eg ''', ':', '"', or
5509 * '/') in the 'viminfo' option and return a pointer to the string after it.
5510 * Return NULL if the parameter is not specified in the string.
5511 */
5512 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005513find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514{
5515 char_u *p;
5516
5517 for (p = p_viminfo; *p; ++p)
5518 {
5519 if (*p == type)
5520 return p + 1;
5521 if (*p == 'n') /* 'n' is always the last one */
5522 break;
5523 p = vim_strchr(p, ','); /* skip until next ',' */
5524 if (p == NULL) /* hit the end without finding parameter */
5525 break;
5526 }
5527 return NULL;
5528}
5529#endif
5530
5531/*
5532 * Expand environment variables for some string options.
5533 * These string options cannot be indirect!
5534 * If "val" is NULL expand the current value of the option.
5535 * Return pointer to NameBuff, or NULL when not expanded.
5536 */
5537 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005538option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539{
5540 /* if option doesn't need expansion nothing to do */
5541 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5542 return NULL;
5543
5544 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5545 * expand_env() would truncate the string. */
5546 if (val != NULL && STRLEN(val) > MAXPATHL)
5547 return NULL;
5548
5549 if (val == NULL)
5550 val = *(char_u **)options[opt_idx].var;
5551
5552 /*
5553 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5554 * Escape spaces when expanding 'tags', they are used to separate file
5555 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005556 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557 */
5558 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005559 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005560#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005561 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5562#endif
5563 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5565 return NULL;
5566
5567 return NameBuff;
5568}
5569
5570/*
5571 * After setting various option values: recompute variables that depend on
5572 * option values.
5573 */
5574 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005575didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005576{
5577 /* initialize the table for 'iskeyword' et.al. */
5578 (void)init_chartab();
5579
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005580#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005584 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585#ifdef FEAT_SESSION
5586 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5587 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5588#endif
5589#ifdef FEAT_FOLDING
5590 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5591#endif
5592 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005593 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005594#ifdef FEAT_VIRTUALEDIT
5595 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5596#endif
5597#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5598 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5599#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005600#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005601 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005602 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005603 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005604 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005605#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005606#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5607 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5608#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005609#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005610 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5611#endif
5612#ifdef FEAT_CMDWIN
5613 /* set cedit_key */
5614 (void)check_cedit();
5615#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005616#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005617 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005618#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005619#ifdef FEAT_LINEBREAK
5620 /* initialize the table for 'breakat'. */
5621 fill_breakat_flags();
5622#endif
5623
5624}
5625
5626/*
5627 * More side effects of setting options.
5628 */
5629 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005630didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005631{
5632 /* Initialize the highlight_attr[] table. */
5633 (void)highlight_changed();
5634
5635 /* Parse default for 'wildmode' */
5636 check_opt_wim();
5637
5638 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005639 /* Parse default for 'fillchars'. */
5640 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005641
5642#ifdef FEAT_CLIPBOARD
5643 /* Parse default for 'clipboard' */
5644 (void)check_clipboard_option();
5645#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646}
5647
5648/*
5649 * Check for string options that are NULL (normally only termcap options).
5650 */
5651 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005652check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005653{
5654 int opt_idx;
5655
5656 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5657 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5658 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5659}
5660
5661/*
5662 * Check string options in a buffer for NULL value.
5663 */
5664 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005665check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667 check_string_option(&buf->b_p_bh);
5668 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669#ifdef FEAT_MBYTE
5670 check_string_option(&buf->b_p_fenc);
5671#endif
5672 check_string_option(&buf->b_p_ff);
5673#ifdef FEAT_FIND_ID
5674 check_string_option(&buf->b_p_def);
5675 check_string_option(&buf->b_p_inc);
5676# ifdef FEAT_EVAL
5677 check_string_option(&buf->b_p_inex);
5678# endif
5679#endif
5680#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5681 check_string_option(&buf->b_p_inde);
5682 check_string_option(&buf->b_p_indk);
5683#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005684#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5685 check_string_option(&buf->b_p_bexpr);
5686#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005687#if defined(FEAT_CRYPT)
5688 check_string_option(&buf->b_p_cm);
5689#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005690 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005691#if defined(FEAT_EVAL)
5692 check_string_option(&buf->b_p_fex);
5693#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694#ifdef FEAT_CRYPT
5695 check_string_option(&buf->b_p_key);
5696#endif
5697 check_string_option(&buf->b_p_kp);
5698 check_string_option(&buf->b_p_mps);
5699 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005700 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 check_string_option(&buf->b_p_isk);
5702#ifdef FEAT_COMMENTS
5703 check_string_option(&buf->b_p_com);
5704#endif
5705#ifdef FEAT_FOLDING
5706 check_string_option(&buf->b_p_cms);
5707#endif
5708 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005709#ifdef FEAT_TEXTOBJ
5710 check_string_option(&buf->b_p_qe);
5711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712#ifdef FEAT_SYN_HL
5713 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005714 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005715#endif
5716#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005717 check_string_option(&buf->b_s.b_p_spc);
5718 check_string_option(&buf->b_s.b_p_spf);
5719 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005720#endif
5721#ifdef FEAT_SEARCHPATH
5722 check_string_option(&buf->b_p_sua);
5723#endif
5724#ifdef FEAT_CINDENT
5725 check_string_option(&buf->b_p_cink);
5726 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005727 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728#endif
5729#ifdef FEAT_AUTOCMD
5730 check_string_option(&buf->b_p_ft);
5731#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005732#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5733 check_string_option(&buf->b_p_cinw);
5734#endif
5735#ifdef FEAT_INS_EXPAND
5736 check_string_option(&buf->b_p_cpt);
5737#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005738#ifdef FEAT_COMPL_FUNC
5739 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005740 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005741#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742#ifdef FEAT_KEYMAP
5743 check_string_option(&buf->b_p_keymap);
5744#endif
5745#ifdef FEAT_QUICKFIX
5746 check_string_option(&buf->b_p_gp);
5747 check_string_option(&buf->b_p_mp);
5748 check_string_option(&buf->b_p_efm);
5749#endif
5750 check_string_option(&buf->b_p_ep);
5751 check_string_option(&buf->b_p_path);
5752 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005753 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754#ifdef FEAT_INS_EXPAND
5755 check_string_option(&buf->b_p_dict);
5756 check_string_option(&buf->b_p_tsr);
5757#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005758#ifdef FEAT_LISP
5759 check_string_option(&buf->b_p_lw);
5760#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005761 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005762#ifdef FEAT_MBYTE
5763 check_string_option(&buf->b_p_menc);
5764#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765}
5766
5767/*
5768 * Free the string allocated for an option.
5769 * Checks for the string being empty_option. This may happen if we're out of
5770 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5771 * check_options().
5772 * Does NOT check for P_ALLOCED flag!
5773 */
5774 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005775free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776{
5777 if (p != empty_option)
5778 vim_free(p);
5779}
5780
5781 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005782clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783{
5784 if (*pp != empty_option)
5785 vim_free(*pp);
5786 *pp = empty_option;
5787}
5788
5789 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005790check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005791{
5792 if (*pp == NULL)
5793 *pp = empty_option;
5794}
5795
5796/*
5797 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5798 */
5799 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005800set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005801{
5802 int opt_idx;
5803
5804 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5805 if (options[opt_idx].var == (char_u *)p)
5806 {
5807 options[opt_idx].flags |= P_ALLOCED;
5808 return;
5809 }
5810 return; /* cannot happen: didn't find it! */
5811}
5812
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005813#if defined(FEAT_EVAL) || defined(PROTO)
5814/*
5815 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5816 * Return FALSE when it wasn't.
5817 * Return -1 for an unknown option.
5818 */
5819 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005820was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005821{
5822 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005823 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005824
5825 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005826 {
5827 flagp = insecure_flag(idx, opt_flags);
5828 return (*flagp & P_INSECURE) != 0;
5829 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005830 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005831 return -1;
5832}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833
5834/*
5835 * Get a pointer to the flags used for the P_INSECURE flag of option
5836 * "opt_idx". For some local options a local flags field is used.
5837 */
5838 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005839insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005840{
5841 if (opt_flags & OPT_LOCAL)
5842 switch ((int)options[opt_idx].indir)
5843 {
5844#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005845 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005846#endif
5847#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005848# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005849 case PV_FDE: return &curwin->w_p_fde_flags;
5850 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005851# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005852# ifdef FEAT_BEVAL
5853 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5854# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005855# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005856 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005857# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005858 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005859# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005860 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005861# endif
5862#endif
5863 }
5864
5865 /* Nothing special, return global flags field. */
5866 return &options[opt_idx].flags;
5867}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005868#endif
5869
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005870#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005871static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005872
5873/*
5874 * Redraw the window title and/or tab page text later.
5875 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005876static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005877{
5878 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005879 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005880}
5881#endif
5882
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883/*
5884 * Set a string option to a new value (without checking the effect).
5885 * The string is copied into allocated memory.
5886 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005887 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005888 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 */
5890 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005891set_string_option_direct(
5892 char_u *name,
5893 int opt_idx,
5894 char_u *val,
5895 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5896 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897{
5898 char_u *s;
5899 char_u **varp;
5900 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005901 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005902
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005905 idx = findoption(name);
5906 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005907 {
5908 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005909 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 }
5913
Bram Moolenaar89d40322006-08-29 15:30:07 +00005914 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005915 return;
5916
5917 s = vim_strsave(val);
5918 if (s != NULL)
5919 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005920 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005922 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923 free_string_option(*varp);
5924 *varp = s;
5925
5926 /* For buffer/window local option may also set the global value. */
5927 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005928 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929
Bram Moolenaar89d40322006-08-29 15:30:07 +00005930 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005931
5932 /* When setting both values of a global option with a local value,
5933 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005934 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935 {
5936 free_string_option(*varp);
5937 *varp = empty_option;
5938 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005939# ifdef FEAT_EVAL
5940 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005941 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005942 set_sid == 0 ? current_SID : set_sid);
5943# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944 }
5945}
5946
5947/*
5948 * Set global value for string option when it's a local option.
5949 */
5950 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005951set_string_option_global(
5952 int opt_idx, /* option index */
5953 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005954{
5955 char_u **p, *s;
5956
5957 /* the global value is always allocated */
5958 if (options[opt_idx].var == VAR_WIN)
5959 p = (char_u **)GLOBAL_WO(varp);
5960 else
5961 p = (char_u **)options[opt_idx].var;
5962 if (options[opt_idx].indir != PV_NONE
5963 && p != varp
5964 && (s = vim_strsave(*varp)) != NULL)
5965 {
5966 free_string_option(*p);
5967 *p = s;
5968 }
5969}
5970
5971/*
5972 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005973 *
5974 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005976 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005977set_string_option(
5978 int opt_idx,
5979 char_u *value,
5980 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005981{
5982 char_u *s;
5983 char_u **varp;
5984 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005985#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5986 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005988#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005989 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990
5991 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005992 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993
5994 s = vim_strsave(value);
5995 if (s != NULL)
5996 {
5997 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5998 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005999 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000 ? OPT_GLOBAL : OPT_LOCAL)
6001 : opt_flags);
6002 oldval = *varp;
6003 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006004
6005#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006006 if (!starting
6007# ifdef FEAT_CRYPT
6008 && options[opt_idx].indir != PV_KEY
6009# endif
6010 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006011 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006012 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006013 saved_newval = vim_strsave(s);
6014 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006015#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006016 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6017 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006018 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006019
Bram Moolenaar53744302015-07-17 17:38:22 +02006020#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006021 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006022 if (r == NULL)
6023 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006024 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006025 vim_free(saved_oldval);
6026 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006027#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006028 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006029 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006030}
6031
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006032#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006033/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006034 * Return TRUE if "val" is a valid 'filetype' name.
6035 * Also used for 'syntax' and 'keymap'.
6036 */
6037 static int
6038valid_filetype(char_u *val)
6039{
6040 char_u *s;
6041
6042 for (s = val; *s != NUL; ++s)
6043 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6044 return FALSE;
6045 return TRUE;
6046}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006047#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006048
6049/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006050 * Handle string options that need some action to perform when changed.
6051 * Returns NULL for success, or an error message for an error.
6052 */
6053 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006054did_set_string_option(
6055 int opt_idx, /* index in options[] table */
6056 char_u **varp, /* pointer to the option variable */
6057 int new_value_alloced, /* new value was allocated */
6058 char_u *oldval, /* previous value of the option */
6059 char_u *errbuf, /* buffer for errors, or NULL */
6060 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006061{
6062 char_u *errmsg = NULL;
6063 char_u *s, *p;
6064 int did_chartab = FALSE;
6065 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006066 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006067#ifdef FEAT_GUI
6068 /* set when changing an option that only requires a redraw in the GUI */
6069 int redraw_gui_only = FALSE;
6070#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006071#ifdef FEAT_AUTOCMD
6072 int ft_changed = FALSE;
6073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074
6075 /* Get the global option to compare with, otherwise we would have to check
6076 * two values for all local options. */
6077 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6078
6079 /* Disallow changing some options from secure mode */
6080 if ((secure
6081#ifdef HAVE_SANDBOX
6082 || sandbox != 0
6083#endif
6084 ) && (options[opt_idx].flags & P_SECURE))
6085 {
6086 errmsg = e_secure;
6087 }
6088
Bram Moolenaar7554da42016-11-25 22:04:13 +01006089 /* Check for a "normal" directory or file name in some options. Disallow a
6090 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006091 * are often illegal in a file name. Be more permissive if "secure" is off.
6092 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006093 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006094 && vim_strpbrk(*varp, (char_u *)(secure
6095 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006096 || ((options[opt_idx].flags & P_NDNAME)
6097 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006098 {
6099 errmsg = e_invarg;
6100 }
6101
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102 /* 'term' */
6103 else if (varp == &T_NAME)
6104 {
6105 if (T_NAME[0] == NUL)
6106 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6107#ifdef FEAT_GUI
6108 if (gui.in_use)
6109 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6110 else if (term_is_gui(T_NAME))
6111 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6112#endif
6113 else if (set_termname(T_NAME) == FAIL)
6114 errmsg = (char_u *)N_("E522: Not found in termcap");
6115 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006116 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 /* Screen colors may have changed. */
6118 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006119
6120 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6121 * P_ALLOCED flag on 'term'. */
6122 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006123 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006124 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006125 }
6126
6127 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006128 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006130 char_u *bkc = p_bkc;
6131 unsigned int *flags = &bkc_flags;
6132
6133 if (opt_flags & OPT_LOCAL)
6134 {
6135 bkc = curbuf->b_p_bkc;
6136 flags = &curbuf->b_bkc_flags;
6137 }
6138
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006139 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6140 /* make the local value empty: use the global value */
6141 *flags = 0;
6142 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006144 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6145 errmsg = e_invarg;
6146 if ((((int)*flags & BKC_AUTO) != 0)
6147 + (((int)*flags & BKC_YES) != 0)
6148 + (((int)*flags & BKC_NO) != 0) != 1)
6149 {
6150 /* Must have exactly one of "auto", "yes" and "no". */
6151 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6152 errmsg = e_invarg;
6153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154 }
6155 }
6156
6157 /* 'backupext' and 'patchmode' */
6158 else if (varp == &p_bex || varp == &p_pm)
6159 {
6160 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6161 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6162 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6163 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006164#ifdef FEAT_LINEBREAK
6165 /* 'breakindentopt' */
6166 else if (varp == &curwin->w_p_briopt)
6167 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006168 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006169 errmsg = e_invarg;
6170 }
6171#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006172
6173 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006174 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006175 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006176 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006177 */
6178 else if ( varp == &p_isi
6179 || varp == &(curbuf->b_p_isk)
6180 || varp == &p_isp
6181 || varp == &p_isf)
6182 {
6183 if (init_chartab() == FAIL)
6184 {
6185 did_chartab = TRUE; /* need to restore it below */
6186 errmsg = e_invarg; /* error in value */
6187 }
6188 }
6189
6190 /* 'helpfile' */
6191 else if (varp == &p_hf)
6192 {
6193 /* May compute new values for $VIM and $VIMRUNTIME */
6194 if (didset_vim)
6195 {
6196 vim_setenv((char_u *)"VIM", (char_u *)"");
6197 didset_vim = FALSE;
6198 }
6199 if (didset_vimruntime)
6200 {
6201 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6202 didset_vimruntime = FALSE;
6203 }
6204 }
6205
Bram Moolenaar1a384422010-07-14 19:53:30 +02006206#ifdef FEAT_SYN_HL
6207 /* 'colorcolumn' */
6208 else if (varp == &curwin->w_p_cc)
6209 errmsg = check_colorcolumn(curwin);
6210#endif
6211
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212#ifdef FEAT_MULTI_LANG
6213 /* 'helplang' */
6214 else if (varp == &p_hlg)
6215 {
6216 /* Check for "", "ab", "ab,cd", etc. */
6217 for (s = p_hlg; *s != NUL; s += 3)
6218 {
6219 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6220 {
6221 errmsg = e_invarg;
6222 break;
6223 }
6224 if (s[2] == NUL)
6225 break;
6226 }
6227 }
6228#endif
6229
6230 /* 'highlight' */
6231 else if (varp == &p_hl)
6232 {
6233 if (highlight_changed() == FAIL)
6234 errmsg = e_invarg; /* invalid flags */
6235 }
6236
6237 /* 'nrformats' */
6238 else if (gvarp == &p_nf)
6239 {
6240 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6241 errmsg = e_invarg;
6242 }
6243
6244#ifdef FEAT_SESSION
6245 /* 'sessionoptions' */
6246 else if (varp == &p_ssop)
6247 {
6248 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6249 errmsg = e_invarg;
6250 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6251 {
6252 /* Don't allow both "sesdir" and "curdir". */
6253 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6254 errmsg = e_invarg;
6255 }
6256 }
6257 /* 'viewoptions' */
6258 else if (varp == &p_vop)
6259 {
6260 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6261 errmsg = e_invarg;
6262 }
6263#endif
6264
6265 /* 'scrollopt' */
6266#ifdef FEAT_SCROLLBIND
6267 else if (varp == &p_sbo)
6268 {
6269 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6270 errmsg = e_invarg;
6271 }
6272#endif
6273
6274 /* 'ambiwidth' */
6275#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006276 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006277 {
6278 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6279 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006280 else if (set_chars_option(&p_lcs) != NULL)
6281 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006282 else if (set_chars_option(&p_fcs) != NULL)
6283 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006284 }
6285#endif
6286
6287 /* 'background' */
6288 else if (varp == &p_bg)
6289 {
6290 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6291 {
6292#ifdef FEAT_EVAL
6293 int dark = (*p_bg == 'd');
6294#endif
6295
6296 init_highlight(FALSE, FALSE);
6297
6298#ifdef FEAT_EVAL
6299 if (dark != (*p_bg == 'd')
6300 && get_var_value((char_u *)"g:colors_name") != NULL)
6301 {
6302 /* The color scheme must have set 'background' back to another
6303 * value, that's not what we want here. Disable the color
6304 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006305 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006306 free_string_option(p_bg);
6307 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6308 check_string_option(&p_bg);
6309 init_highlight(FALSE, FALSE);
6310 }
6311#endif
6312 }
6313 else
6314 errmsg = e_invarg;
6315 }
6316
6317 /* 'wildmode' */
6318 else if (varp == &p_wim)
6319 {
6320 if (check_opt_wim() == FAIL)
6321 errmsg = e_invarg;
6322 }
6323
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006324#ifdef FEAT_CMDL_COMPL
6325 /* 'wildoptions' */
6326 else if (varp == &p_wop)
6327 {
6328 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6329 errmsg = e_invarg;
6330 }
6331#endif
6332
Bram Moolenaar071d4272004-06-13 20:20:40 +00006333#ifdef FEAT_WAK
6334 /* 'winaltkeys' */
6335 else if (varp == &p_wak)
6336 {
6337 if (*p_wak == NUL
6338 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6339 errmsg = e_invarg;
6340# ifdef FEAT_MENU
6341# ifdef FEAT_GUI_MOTIF
6342 else if (gui.in_use)
6343 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6344# else
6345# ifdef FEAT_GUI_GTK
6346 else if (gui.in_use)
6347 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6348# endif
6349# endif
6350# endif
6351 }
6352#endif
6353
6354#ifdef FEAT_AUTOCMD
6355 /* 'eventignore' */
6356 else if (varp == &p_ei)
6357 {
6358 if (check_ei() == FAIL)
6359 errmsg = e_invarg;
6360 }
6361#endif
6362
6363#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006364 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6365 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6366 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367 {
6368 if (gvarp == &p_fenc)
6369 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006370 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371 errmsg = e_modifiable;
6372 else if (vim_strchr(*varp, ',') != NULL)
6373 /* No comma allowed in 'fileencoding'; catches confusing it
6374 * with 'fileencodings'. */
6375 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006376 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006377 {
6378# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006380 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006382 /* Add 'fileencoding' to the swap file. */
6383 ml_setflags(curbuf);
6384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006385 }
6386 if (errmsg == NULL)
6387 {
6388 /* canonize the value, so that STRCMP() can be used on it */
6389 p = enc_canonize(*varp);
6390 if (p != NULL)
6391 {
6392 vim_free(*varp);
6393 *varp = p;
6394 }
6395 if (varp == &p_enc)
6396 {
6397 errmsg = mb_init();
6398# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006399 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400# endif
6401 }
6402 }
6403
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006404# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006405 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6406 {
6407 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6408 if (STRCMP(p_tenc, "utf-8") != 0)
6409 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6410 }
6411# endif
6412
6413 if (errmsg == NULL)
6414 {
6415# ifdef FEAT_KEYMAP
6416 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6417 * (with another encoding). */
6418 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6419 (void)keymap_init();
6420# endif
6421
6422 /* When 'termencoding' is not empty and 'encoding' changes or when
6423 * 'termencoding' changes, need to setup for keyboard input and
6424 * display output conversion. */
6425 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6426 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006427 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6428 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6429 {
6430 EMSG3(_("E950: Cannot convert between %s and %s"),
6431 p_tenc, p_enc);
6432 errmsg = e_invarg;
6433 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006434 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006435
6436# if defined(WIN3264) && defined(FEAT_MBYTE)
6437 /* $HOME may have characters in active code page. */
6438 if (varp == &p_enc)
6439 init_homedir();
6440# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441 }
6442 }
6443#endif
6444
6445#if defined(FEAT_POSTSCRIPT)
6446 else if (varp == &p_penc)
6447 {
6448 /* Canonize printencoding if VIM standard one */
6449 p = enc_canonize(p_penc);
6450 if (p != NULL)
6451 {
6452 vim_free(p_penc);
6453 p_penc = p;
6454 }
6455 else
6456 {
6457 /* Ensure lower case and '-' for '_' */
6458 for (s = p_penc; *s != NUL; s++)
6459 {
6460 if (*s == '_')
6461 *s = '-';
6462 else
6463 *s = TOLOWER_ASC(*s);
6464 }
6465 }
6466 }
6467#endif
6468
Bram Moolenaar9372a112005-12-06 19:59:18 +00006469#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006470 else if (varp == &p_imak)
6471 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006472 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006473 errmsg = e_invarg;
6474 }
6475#endif
6476
6477#ifdef FEAT_KEYMAP
6478 else if (varp == &curbuf->b_p_keymap)
6479 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006480 if (!valid_filetype(*varp))
6481 errmsg = e_invarg;
6482 else
6483 /* load or unload key mapping tables */
6484 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006485
Bram Moolenaarfab06232009-03-04 03:13:35 +00006486 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006488 if (*curbuf->b_p_keymap != NUL)
6489 {
6490 /* Installed a new keymap, switch on using it. */
6491 curbuf->b_p_iminsert = B_IMODE_LMAP;
6492 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6493 curbuf->b_p_imsearch = B_IMODE_LMAP;
6494 }
6495 else
6496 {
6497 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6498 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6499 curbuf->b_p_iminsert = B_IMODE_NONE;
6500 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6501 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6502 }
6503 if ((opt_flags & OPT_LOCAL) == 0)
6504 {
6505 set_iminsert_global();
6506 set_imsearch_global();
6507 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006508 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006509 }
6510 }
6511#endif
6512
6513 /* 'fileformat' */
6514 else if (gvarp == &p_ff)
6515 {
6516 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6517 errmsg = e_modifiable;
6518 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6519 errmsg = e_invarg;
6520 else
6521 {
6522 /* may also change 'textmode' */
6523 if (get_fileformat(curbuf) == EOL_DOS)
6524 curbuf->b_p_tx = TRUE;
6525 else
6526 curbuf->b_p_tx = FALSE;
6527#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006528 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006530 /* update flag in swap file */
6531 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006532 /* Redraw needed when switching to/from "mac": a CR in the text
6533 * will be displayed differently. */
6534 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6535 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006536 }
6537 }
6538
6539 /* 'fileformats' */
6540 else if (varp == &p_ffs)
6541 {
6542 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6543 errmsg = e_invarg;
6544 else
6545 {
6546 /* also change 'textauto' */
6547 if (*p_ffs == NUL)
6548 p_ta = FALSE;
6549 else
6550 p_ta = TRUE;
6551 }
6552 }
6553
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006554#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 /* 'cryptkey' */
6556 else if (gvarp == &p_key)
6557 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006558# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006559 /* Make sure the ":set" command doesn't show the new value in the
6560 * history. */
6561 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006562# endif
6563 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6564 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006565 ml_set_crypt_key(curbuf, oldval,
6566 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006567 }
6568
6569 else if (gvarp == &p_cm)
6570 {
6571 if (opt_flags & OPT_LOCAL)
6572 p = curbuf->b_p_cm;
6573 else
6574 p = p_cm;
6575 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6576 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006577 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006578 errmsg = e_invarg;
6579 else
6580 {
6581 /* When setting the global value to empty, make it "zip". */
6582 if (*p_cm == NUL)
6583 {
6584 if (new_value_alloced)
6585 free_string_option(p_cm);
6586 p_cm = vim_strsave((char_u *)"zip");
6587 new_value_alloced = TRUE;
6588 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006589 /* When using ":set cm=name" the local value is going to be empty.
6590 * Do that here, otherwise the crypt functions will still use the
6591 * local value. */
6592 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6593 {
6594 free_string_option(curbuf->b_p_cm);
6595 curbuf->b_p_cm = empty_option;
6596 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006597
6598 /* Need to update the swapfile when the effective method changed.
6599 * Set "s" to the effective old value, "p" to the effective new
6600 * method and compare. */
6601 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6602 s = p_cm; /* was previously using the global value */
6603 else
6604 s = oldval;
6605 if (*curbuf->b_p_cm == NUL)
6606 p = p_cm; /* is now using the global value */
6607 else
6608 p = curbuf->b_p_cm;
6609 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006610 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006611
6612 /* If the global value changes need to update the swapfile for all
6613 * buffers using that value. */
6614 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6615 {
6616 buf_T *buf;
6617
Bram Moolenaar29323592016-07-24 22:04:11 +02006618 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006619 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006620 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006621 }
6622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623 }
6624#endif
6625
6626 /* 'matchpairs' */
6627 else if (gvarp == &p_mps)
6628 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006629#ifdef FEAT_MBYTE
6630 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006632 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006633 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006634 int x2 = -1;
6635 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006636
6637 if (*p != NUL)
6638 p += mb_ptr2len(p);
6639 if (*p != NUL)
6640 x2 = *p++;
6641 if (*p != NUL)
6642 {
6643 x3 = mb_ptr2char(p);
6644 p += mb_ptr2len(p);
6645 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006646 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006647 {
6648 errmsg = e_invarg;
6649 break;
6650 }
6651 if (*p == NUL)
6652 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006653 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006654 }
6655 else
6656#endif
6657 {
6658 /* Check for "x:y,x:y" */
6659 for (p = *varp; *p != NUL; p += 4)
6660 {
6661 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6662 {
6663 errmsg = e_invarg;
6664 break;
6665 }
6666 if (p[3] == NUL)
6667 break;
6668 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669 }
6670 }
6671
6672#ifdef FEAT_COMMENTS
6673 /* 'comments' */
6674 else if (gvarp == &p_com)
6675 {
6676 for (s = *varp; *s; )
6677 {
6678 while (*s && *s != ':')
6679 {
6680 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6681 && !VIM_ISDIGIT(*s) && *s != '-')
6682 {
6683 errmsg = illegal_char(errbuf, *s);
6684 break;
6685 }
6686 ++s;
6687 }
6688 if (*s++ == NUL)
6689 errmsg = (char_u *)N_("E524: Missing colon");
6690 else if (*s == ',' || *s == NUL)
6691 errmsg = (char_u *)N_("E525: Zero length string");
6692 if (errmsg != NULL)
6693 break;
6694 while (*s && *s != ',')
6695 {
6696 if (*s == '\\' && s[1] != NUL)
6697 ++s;
6698 ++s;
6699 }
6700 s = skip_to_option_part(s);
6701 }
6702 }
6703#endif
6704
6705 /* 'listchars' */
6706 else if (varp == &p_lcs)
6707 {
6708 errmsg = set_chars_option(varp);
6709 }
6710
Bram Moolenaar071d4272004-06-13 20:20:40 +00006711 /* 'fillchars' */
6712 else if (varp == &p_fcs)
6713 {
6714 errmsg = set_chars_option(varp);
6715 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006716
6717#ifdef FEAT_CMDWIN
6718 /* 'cedit' */
6719 else if (varp == &p_cedit)
6720 {
6721 errmsg = check_cedit();
6722 }
6723#endif
6724
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006725 /* 'verbosefile' */
6726 else if (varp == &p_vfile)
6727 {
6728 verbose_stop();
6729 if (*p_vfile != NUL && verbose_open() == FAIL)
6730 errmsg = e_invarg;
6731 }
6732
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733#ifdef FEAT_VIMINFO
6734 /* 'viminfo' */
6735 else if (varp == &p_viminfo)
6736 {
6737 for (s = p_viminfo; *s;)
6738 {
6739 /* Check it's a valid character */
6740 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6741 {
6742 errmsg = illegal_char(errbuf, *s);
6743 break;
6744 }
6745 if (*s == 'n') /* name is always last one */
6746 {
6747 break;
6748 }
6749 else if (*s == 'r') /* skip until next ',' */
6750 {
6751 while (*++s && *s != ',')
6752 ;
6753 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006754 else if (*s == '%')
6755 {
6756 /* optional number */
6757 while (vim_isdigit(*++s))
6758 ;
6759 }
6760 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006761 ++s; /* no extra chars */
6762 else /* must have a number */
6763 {
6764 while (vim_isdigit(*++s))
6765 ;
6766
6767 if (!VIM_ISDIGIT(*(s - 1)))
6768 {
6769 if (errbuf != NULL)
6770 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006771 sprintf((char *)errbuf,
6772 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 transchar_byte(*(s - 1)));
6774 errmsg = errbuf;
6775 }
6776 else
6777 errmsg = (char_u *)"";
6778 break;
6779 }
6780 }
6781 if (*s == ',')
6782 ++s;
6783 else if (*s)
6784 {
6785 if (errbuf != NULL)
6786 errmsg = (char_u *)N_("E527: Missing comma");
6787 else
6788 errmsg = (char_u *)"";
6789 break;
6790 }
6791 }
6792 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6793 errmsg = (char_u *)N_("E528: Must specify a ' value");
6794 }
6795#endif /* FEAT_VIMINFO */
6796
6797 /* terminal options */
6798 else if (istermoption(&options[opt_idx]) && full_screen)
6799 {
6800 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6801 if (varp == &T_CCO)
6802 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006803 int colors = atoi((char *)T_CCO);
6804
6805 /* Only reinitialize colors if t_Co value has really changed to
6806 * avoid expensive reload of colorscheme if t_Co is set to the
6807 * same value multiple times. */
6808 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006809 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006810 t_colors = colors;
6811 if (t_colors <= 1)
6812 {
6813 if (new_value_alloced)
6814 vim_free(T_CCO);
6815 T_CCO = empty_option;
6816 }
6817 /* We now have a different color setup, initialize it again. */
6818 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 }
6821 ttest(FALSE);
6822 if (varp == &T_ME)
6823 {
6824 out_str(T_ME);
6825 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006826#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006827 /* Since t_me has been set, this probably means that the user
6828 * wants to use this as default colors. Need to reset default
6829 * background/foreground colors. */
6830 mch_set_normal_colors();
6831#endif
6832 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006833 if (varp == &T_BE && termcap_active)
6834 {
6835 if (*T_BE == NUL)
6836 /* When clearing t_BE we assume the user no longer wants
6837 * bracketed paste, thus disable it by writing t_BD. */
6838 out_str(T_BD);
6839 else
6840 out_str(T_BE);
6841 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 }
6843
6844#ifdef FEAT_LINEBREAK
6845 /* 'showbreak' */
6846 else if (varp == &p_sbr)
6847 {
6848 for (s = p_sbr; *s; )
6849 {
6850 if (ptr2cells(s) != 1)
6851 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006852 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006853 }
6854 }
6855#endif
6856
6857#ifdef FEAT_GUI
6858 /* 'guifont' */
6859 else if (varp == &p_guifont)
6860 {
6861 if (gui.in_use)
6862 {
6863 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006864# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006865 /*
6866 * Put up a font dialog and let the user select a new value.
6867 * If this is cancelled go back to the old value but don't
6868 * give an error message.
6869 */
6870 if (STRCMP(p, "*") == 0)
6871 {
6872 p = gui_mch_font_dialog(oldval);
6873
6874 if (new_value_alloced)
6875 free_string_option(p_guifont);
6876
6877 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6878 new_value_alloced = TRUE;
6879 }
6880# endif
6881 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6882 {
6883# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6884 if (STRCMP(p_guifont, "*") == 0)
6885 {
6886 /* Dialog was cancelled: Keep the old value without giving
6887 * an error message. */
6888 if (new_value_alloced)
6889 free_string_option(p_guifont);
6890 p_guifont = vim_strsave(oldval);
6891 new_value_alloced = TRUE;
6892 }
6893 else
6894# endif
6895 errmsg = (char_u *)N_("E596: Invalid font(s)");
6896 }
6897 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006898 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 }
6900# ifdef FEAT_XFONTSET
6901 else if (varp == &p_guifontset)
6902 {
6903 if (STRCMP(p_guifontset, "*") == 0)
6904 errmsg = (char_u *)N_("E597: can't select fontset");
6905 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6906 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006907 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006908 }
6909# endif
6910# ifdef FEAT_MBYTE
6911 else if (varp == &p_guifontwide)
6912 {
6913 if (STRCMP(p_guifontwide, "*") == 0)
6914 errmsg = (char_u *)N_("E533: can't select wide font");
6915 else if (gui_get_wide_font() == FAIL)
6916 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006917 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918 }
6919# endif
6920#endif
6921
6922#ifdef CURSOR_SHAPE
6923 /* 'guicursor' */
6924 else if (varp == &p_guicursor)
6925 errmsg = parse_shape_opt(SHAPE_CURSOR);
6926#endif
6927
6928#ifdef FEAT_MOUSESHAPE
6929 /* 'mouseshape' */
6930 else if (varp == &p_mouseshape)
6931 {
6932 errmsg = parse_shape_opt(SHAPE_MOUSE);
6933 update_mouseshape(-1);
6934 }
6935#endif
6936
6937#ifdef FEAT_PRINTER
6938 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006939 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006940# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006941 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006942 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006943# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944#endif
6945
6946#ifdef FEAT_LANGMAP
6947 /* 'langmap' */
6948 else if (varp == &p_langmap)
6949 langmap_set();
6950#endif
6951
6952#ifdef FEAT_LINEBREAK
6953 /* 'breakat' */
6954 else if (varp == &p_breakat)
6955 fill_breakat_flags();
6956#endif
6957
6958#ifdef FEAT_TITLE
6959 /* 'titlestring' and 'iconstring' */
6960 else if (varp == &p_titlestring || varp == &p_iconstring)
6961 {
6962# ifdef FEAT_STL_OPT
6963 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6964
6965 /* NULL => statusline syntax */
6966 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6967 stl_syntax |= flagval;
6968 else
6969 stl_syntax &= ~flagval;
6970# endif
6971 did_set_title(varp == &p_iconstring);
6972
6973 }
6974#endif
6975
6976#ifdef FEAT_GUI
6977 /* 'guioptions' */
6978 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006979 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006981 redraw_gui_only = TRUE;
6982 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983#endif
6984
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006985#if defined(FEAT_GUI_TABLINE)
6986 /* 'guitablabel' */
6987 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006988 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006989 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006990 redraw_gui_only = TRUE;
6991 }
6992 /* 'guitabtooltip' */
6993 else if (varp == &p_gtt)
6994 {
6995 redraw_gui_only = TRUE;
6996 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006997#endif
6998
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7000 /* 'ttymouse' */
7001 else if (varp == &p_ttym)
7002 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007003 /* Switch the mouse off before changing the escape sequences used for
7004 * that. */
7005 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007006 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7007 errmsg = e_invarg;
7008 else
7009 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007010 if (termcap_active)
7011 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007012 }
7013#endif
7014
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 /* 'selection' */
7016 else if (varp == &p_sel)
7017 {
7018 if (*p_sel == NUL
7019 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7020 errmsg = e_invarg;
7021 }
7022
7023 /* 'selectmode' */
7024 else if (varp == &p_slm)
7025 {
7026 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7027 errmsg = e_invarg;
7028 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029
7030#ifdef FEAT_BROWSE
7031 /* 'browsedir' */
7032 else if (varp == &p_bsdir)
7033 {
7034 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7035 && !mch_isdir(p_bsdir))
7036 errmsg = e_invarg;
7037 }
7038#endif
7039
Bram Moolenaar071d4272004-06-13 20:20:40 +00007040 /* 'keymodel' */
7041 else if (varp == &p_km)
7042 {
7043 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7044 errmsg = e_invarg;
7045 else
7046 {
7047 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7048 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7049 }
7050 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007051
7052 /* 'mousemodel' */
7053 else if (varp == &p_mousem)
7054 {
7055 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7056 errmsg = e_invarg;
7057#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7058 else if (*p_mousem != *oldval)
7059 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7060 * to create or delete the popup menus. */
7061 gui_motif_update_mousemodel(root_menu);
7062#endif
7063 }
7064
7065 /* 'switchbuf' */
7066 else if (varp == &p_swb)
7067 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007068 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069 errmsg = e_invarg;
7070 }
7071
7072 /* 'debug' */
7073 else if (varp == &p_debug)
7074 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007075 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007076 errmsg = e_invarg;
7077 }
7078
7079 /* 'display' */
7080 else if (varp == &p_dy)
7081 {
7082 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7083 errmsg = e_invarg;
7084 else
7085 (void)init_chartab();
7086
7087 }
7088
Bram Moolenaar071d4272004-06-13 20:20:40 +00007089 /* 'eadirection' */
7090 else if (varp == &p_ead)
7091 {
7092 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7093 errmsg = e_invarg;
7094 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007095
7096#ifdef FEAT_CLIPBOARD
7097 /* 'clipboard' */
7098 else if (varp == &p_cb)
7099 errmsg = check_clipboard_option();
7100#endif
7101
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007102#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007103 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7104 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007105 else if (varp == &(curwin->w_s->b_p_spl)
7106 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007107 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007108 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007109 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007110 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007111 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007112 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007113 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007114 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007115 /* 'spellsuggest' */
7116 else if (varp == &p_sps)
7117 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007118 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007119 errmsg = e_invarg;
7120 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007121 /* 'mkspellmem' */
7122 else if (varp == &p_msm)
7123 {
7124 if (spell_check_msm() != OK)
7125 errmsg = e_invarg;
7126 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007127#endif
7128
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129 /* When 'bufhidden' is set, check for valid value. */
7130 else if (gvarp == &p_bh)
7131 {
7132 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7133 errmsg = e_invarg;
7134 }
7135
7136 /* When 'buftype' is set, check for valid value. */
7137 else if (gvarp == &p_bt)
7138 {
7139 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7140 errmsg = e_invarg;
7141 else
7142 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143 if (curwin->w_status_height)
7144 {
7145 curwin->w_redr_status = TRUE;
7146 redraw_later(VALID);
7147 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007149#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007150 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007151#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007152 }
7153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154
7155#ifdef FEAT_STL_OPT
7156 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007157 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158 {
7159 int wid;
7160
7161 if (varp == &p_ruf) /* reset ru_wid first */
7162 ru_wid = 0;
7163 s = *varp;
7164 if (varp == &p_ruf && *s == '%')
7165 {
7166 /* set ru_wid if 'ruf' starts with "%99(" */
7167 if (*++s == '-') /* ignore a '-' */
7168 s++;
7169 wid = getdigits(&s);
7170 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7171 ru_wid = wid;
7172 else
7173 errmsg = check_stl_option(p_ruf);
7174 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007175 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007176 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007177 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007178 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179 comp_col();
7180 }
7181#endif
7182
7183#ifdef FEAT_INS_EXPAND
7184 /* check if it is a valid value for 'complete' -- Acevedo */
7185 else if (gvarp == &p_cpt)
7186 {
7187 for (s = *varp; *s;)
7188 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007189 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190 s++;
7191 if (!*s)
7192 break;
7193 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7194 {
7195 errmsg = illegal_char(errbuf, *s);
7196 break;
7197 }
7198 if (*++s != NUL && *s != ',' && *s != ' ')
7199 {
7200 if (s[-1] == 'k' || s[-1] == 's')
7201 {
7202 /* skip optional filename after 'k' and 's' */
7203 while (*s && *s != ',' && *s != ' ')
7204 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007205 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206 ++s;
7207 ++s;
7208 }
7209 }
7210 else
7211 {
7212 if (errbuf != NULL)
7213 {
7214 sprintf((char *)errbuf,
7215 _("E535: Illegal character after <%c>"),
7216 *--s);
7217 errmsg = errbuf;
7218 }
7219 else
7220 errmsg = (char_u *)"";
7221 break;
7222 }
7223 }
7224 }
7225 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007226
7227 /* 'completeopt' */
7228 else if (varp == &p_cot)
7229 {
7230 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7231 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007232 else
7233 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007234 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007235#endif /* FEAT_INS_EXPAND */
7236
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007237#ifdef FEAT_SIGNS
7238 /* 'signcolumn' */
7239 else if (varp == &curwin->w_p_scl)
7240 {
7241 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7242 errmsg = e_invarg;
7243 }
7244#endif
7245
Bram Moolenaar071d4272004-06-13 20:20:40 +00007246
7247#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007248 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007249 else if (varp == &p_toolbar)
7250 {
7251 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7252 &toolbar_flags, TRUE) != OK)
7253 errmsg = e_invarg;
7254 else
7255 {
7256 out_flush();
7257 gui_mch_show_toolbar((toolbar_flags &
7258 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7259 }
7260 }
7261#endif
7262
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007263#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007264 /* 'toolbariconsize': GTK+ 2 only */
7265 else if (varp == &p_tbis)
7266 {
7267 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7268 errmsg = e_invarg;
7269 else
7270 {
7271 out_flush();
7272 gui_mch_show_toolbar((toolbar_flags &
7273 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7274 }
7275 }
7276#endif
7277
7278 /* 'pastetoggle': translate key codes like in a mapping */
7279 else if (varp == &p_pt)
7280 {
7281 if (*p_pt)
7282 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007283 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007284 if (p != NULL)
7285 {
7286 if (new_value_alloced)
7287 free_string_option(p_pt);
7288 p_pt = p;
7289 new_value_alloced = TRUE;
7290 }
7291 }
7292 }
7293
7294 /* 'backspace' */
7295 else if (varp == &p_bs)
7296 {
7297 if (VIM_ISDIGIT(*p_bs))
7298 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007299 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300 errmsg = e_invarg;
7301 }
7302 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7303 errmsg = e_invarg;
7304 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007305 else if (varp == &p_bo)
7306 {
7307 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7308 errmsg = e_invarg;
7309 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007311 /* 'tagcase' */
7312 else if (gvarp == &p_tc)
7313 {
7314 unsigned int *flags;
7315
7316 if (opt_flags & OPT_LOCAL)
7317 {
7318 p = curbuf->b_p_tc;
7319 flags = &curbuf->b_tc_flags;
7320 }
7321 else
7322 {
7323 p = p_tc;
7324 flags = &tc_flags;
7325 }
7326
7327 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7328 /* make the local value empty: use the global value */
7329 *flags = 0;
7330 else if (*p == NUL
7331 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7332 errmsg = e_invarg;
7333 }
7334
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007335#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336 /* 'casemap' */
7337 else if (varp == &p_cmp)
7338 {
7339 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7340 errmsg = e_invarg;
7341 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343
7344#ifdef FEAT_DIFF
7345 /* 'diffopt' */
7346 else if (varp == &p_dip)
7347 {
7348 if (diffopt_changed() == FAIL)
7349 errmsg = e_invarg;
7350 }
7351#endif
7352
7353#ifdef FEAT_FOLDING
7354 /* 'foldmethod' */
7355 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7356 {
7357 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7358 || *curwin->w_p_fdm == NUL)
7359 errmsg = e_invarg;
7360 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007361 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007362 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007363 if (foldmethodIsDiff(curwin))
7364 newFoldLevel();
7365 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007366 }
7367# ifdef FEAT_EVAL
7368 /* 'foldexpr' */
7369 else if (varp == &curwin->w_p_fde)
7370 {
7371 if (foldmethodIsExpr(curwin))
7372 foldUpdateAll(curwin);
7373 }
7374# endif
7375 /* 'foldmarker' */
7376 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7377 {
7378 p = vim_strchr(*varp, ',');
7379 if (p == NULL)
7380 errmsg = (char_u *)N_("E536: comma required");
7381 else if (p == *varp || p[1] == NUL)
7382 errmsg = e_invarg;
7383 else if (foldmethodIsMarker(curwin))
7384 foldUpdateAll(curwin);
7385 }
7386 /* 'commentstring' */
7387 else if (gvarp == &p_cms)
7388 {
7389 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7390 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7391 }
7392 /* 'foldopen' */
7393 else if (varp == &p_fdo)
7394 {
7395 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7396 errmsg = e_invarg;
7397 }
7398 /* 'foldclose' */
7399 else if (varp == &p_fcl)
7400 {
7401 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7402 errmsg = e_invarg;
7403 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007404 /* 'foldignore' */
7405 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7406 {
7407 if (foldmethodIsIndent(curwin))
7408 foldUpdateAll(curwin);
7409 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007410#endif
7411
7412#ifdef FEAT_VIRTUALEDIT
7413 /* 'virtualedit' */
7414 else if (varp == &p_ve)
7415 {
7416 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7417 errmsg = e_invarg;
7418 else if (STRCMP(p_ve, oldval) != 0)
7419 {
7420 /* Recompute cursor position in case the new 've' setting
7421 * changes something. */
7422 validate_virtcol();
7423 coladvance(curwin->w_virtcol);
7424 }
7425 }
7426#endif
7427
7428#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7429 else if (varp == &p_csqf)
7430 {
7431 if (p_csqf != NULL)
7432 {
7433 p = p_csqf;
7434 while (*p != NUL)
7435 {
7436 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7437 || p[1] == NUL
7438 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7439 || (p[2] != NUL && p[2] != ','))
7440 {
7441 errmsg = e_invarg;
7442 break;
7443 }
7444 else if (p[2] == NUL)
7445 break;
7446 else
7447 p += 3;
7448 }
7449 }
7450 }
7451#endif
7452
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007453#ifdef FEAT_CINDENT
7454 /* 'cinoptions' */
7455 else if (gvarp == &p_cino)
7456 {
7457 /* TODO: recognize errors */
7458 parse_cino(curbuf);
7459 }
7460#endif
7461
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007462#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007463 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007464 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007465 {
7466 if (!gui_mch_set_rendering_options(p_rop))
7467 errmsg = e_invarg;
7468 }
7469#endif
7470
Bram Moolenaard0b51382016-11-04 15:23:45 +01007471#ifdef FEAT_AUTOCMD
7472 else if (gvarp == &p_ft)
7473 {
7474 if (!valid_filetype(*varp))
7475 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007476 else
7477 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007478 }
7479#endif
7480
7481#ifdef FEAT_SYN_HL
7482 else if (gvarp == &p_syn)
7483 {
7484 if (!valid_filetype(*varp))
7485 errmsg = e_invarg;
7486 }
7487#endif
7488
Bram Moolenaar825680f2017-07-22 17:04:02 +02007489#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007490 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007491 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007492 {
7493 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7494 errmsg = e_invarg;
7495 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007496 /* 'termsize' */
7497 else if (varp == &curwin->w_p_tms)
7498 {
7499 if (*curwin->w_p_tms != NUL)
7500 {
7501 p = skipdigits(curwin->w_p_tms);
7502 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7503 errmsg = e_invarg;
7504 }
7505 }
7506#endif
7507
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 /* Options that are a list of flags. */
7509 else
7510 {
7511 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007512 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007514 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007515 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007516 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007517 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007518 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007520#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007521 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007522 p = (char_u *)COCU_ALL;
7523#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007524 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525 {
7526#ifdef FEAT_MOUSE
7527 p = (char_u *)MOUSE_ALL;
7528#else
7529 if (*p_mouse != NUL)
7530 errmsg = (char_u *)N_("E538: No mouse support");
7531#endif
7532 }
7533#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007534 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007535 p = (char_u *)GO_ALL;
7536#endif
7537 if (p != NULL)
7538 {
7539 for (s = *varp; *s; ++s)
7540 if (vim_strchr(p, *s) == NULL)
7541 {
7542 errmsg = illegal_char(errbuf, *s);
7543 break;
7544 }
7545 }
7546 }
7547
7548 /*
7549 * If error detected, restore the previous value.
7550 */
7551 if (errmsg != NULL)
7552 {
7553 if (new_value_alloced)
7554 free_string_option(*varp);
7555 *varp = oldval;
7556 /*
7557 * When resetting some values, need to act on it.
7558 */
7559 if (did_chartab)
7560 (void)init_chartab();
7561 if (varp == &p_hl)
7562 (void)highlight_changed();
7563 }
7564 else
7565 {
7566#ifdef FEAT_EVAL
7567 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007568 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007569#endif
7570 /*
7571 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007572 * Use "free_oldval", because recursiveness may change the flags under
7573 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007574 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007575 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007576 free_string_option(oldval);
7577 if (new_value_alloced)
7578 options[opt_idx].flags |= P_ALLOCED;
7579 else
7580 options[opt_idx].flags &= ~P_ALLOCED;
7581
7582 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007583 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007584 {
7585 /* global option with local value set to use global value; free
7586 * the local value and make it empty */
7587 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7588 free_string_option(*(char_u **)p);
7589 *(char_u **)p = empty_option;
7590 }
7591
7592 /* May set global value for local option. */
7593 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7594 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007595
7596#ifdef FEAT_AUTOCMD
7597 /*
7598 * Trigger the autocommand only after setting the flags.
7599 */
7600# ifdef FEAT_SYN_HL
7601 /* When 'syntax' is set, load the syntax of that name */
7602 if (varp == &(curbuf->b_p_syn))
7603 {
7604 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7605 curbuf->b_fname, TRUE, curbuf);
7606 }
7607# endif
7608 else if (varp == &(curbuf->b_p_ft))
7609 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007610 /* 'filetype' is set, trigger the FileType autocommand.
7611 * Skip this when called from a modeline and the filetype was
7612 * already set to this value. */
7613 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7614 {
7615 did_filetype = TRUE;
7616 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007617 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007618 /* Just in case the old "curbuf" is now invalid. */
7619 if (varp != &(curbuf->b_p_ft))
7620 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007621 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007622 }
7623#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007624#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007625 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007626 {
7627 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007628 char_u *q = curwin->w_s->b_p_spl;
7629
7630 /* Skip the first name if it is "cjk". */
7631 if (STRNCMP(q, "cjk,", 4) == 0)
7632 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007633
7634 /*
7635 * Source the spell/LANG.vim in 'runtimepath'.
7636 * They could set 'spellcapcheck' depending on the language.
7637 * Use the first name in 'spelllang' up to '_region' or
7638 * '.encoding'.
7639 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007640 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007641 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7642 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007643 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007644 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007645 }
7646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647 }
7648
7649#ifdef FEAT_MOUSE
7650 if (varp == &p_mouse)
7651 {
7652# ifdef FEAT_MOUSE_TTY
7653 if (*p_mouse == NUL)
7654 mch_setmouse(FALSE); /* switch mouse off */
7655 else
7656# endif
7657 setmouse(); /* in case 'mouse' changed */
7658 }
7659#endif
7660
Bram Moolenaar913077c2012-03-28 19:59:04 +02007661 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007662 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007663 curwin->w_set_curswant = TRUE;
7664
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007665#ifdef FEAT_GUI
7666 /* check redraw when it's not a GUI option or the GUI is active. */
7667 if (!redraw_gui_only || gui.in_use)
7668#endif
7669 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670
7671 return errmsg;
7672}
7673
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007674#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007675/*
7676 * Simple int comparison function for use with qsort()
7677 */
7678 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007679int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007680{
7681 return *(const int *)a - *(const int *)b;
7682}
7683
7684/*
7685 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7686 * Returns error message, NULL if it's OK.
7687 */
7688 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007689check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007690{
7691 char_u *s;
7692 int col;
7693 int count = 0;
7694 int color_cols[256];
7695 int i;
7696 int j = 0;
7697
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007698 if (wp->w_buffer == NULL)
7699 return NULL; /* buffer was closed */
7700
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007701 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007702 {
7703 if (*s == '-' || *s == '+')
7704 {
7705 /* -N and +N: add to 'textwidth' */
7706 col = (*s == '-') ? -1 : 1;
7707 ++s;
7708 if (!VIM_ISDIGIT(*s))
7709 return e_invarg;
7710 col = col * getdigits(&s);
7711 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007712 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007713 col += wp->w_buffer->b_p_tw;
7714 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007715 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007716 }
7717 else if (VIM_ISDIGIT(*s))
7718 col = getdigits(&s);
7719 else
7720 return e_invarg;
7721 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007722skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007723 if (*s == NUL)
7724 break;
7725 if (*s != ',')
7726 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007727 if (*++s == NUL)
7728 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007729 }
7730
7731 vim_free(wp->w_p_cc_cols);
7732 if (count == 0)
7733 wp->w_p_cc_cols = NULL;
7734 else
7735 {
7736 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7737 if (wp->w_p_cc_cols != NULL)
7738 {
7739 /* sort the columns for faster usage on screen redraw inside
7740 * win_line() */
7741 qsort(color_cols, count, sizeof(int), int_cmp);
7742
7743 for (i = 0; i < count; ++i)
7744 /* skip duplicates */
7745 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7746 wp->w_p_cc_cols[j++] = color_cols[i];
7747 wp->w_p_cc_cols[j] = -1; /* end marker */
7748 }
7749 }
7750
7751 return NULL; /* no error */
7752}
7753#endif
7754
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755/*
7756 * Handle setting 'listchars' or 'fillchars'.
7757 * Returns error message, NULL if it's OK.
7758 */
7759 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007760set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761{
7762 int round, i, len, entries;
7763 char_u *p, *s;
7764 int c1, c2 = 0;
7765 struct charstab
7766 {
7767 int *cp;
7768 char *name;
7769 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770 static struct charstab filltab[] =
7771 {
7772 {&fill_stl, "stl"},
7773 {&fill_stlnc, "stlnc"},
7774 {&fill_vert, "vert"},
7775 {&fill_fold, "fold"},
7776 {&fill_diff, "diff"},
7777 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 static struct charstab lcstab[] =
7779 {
7780 {&lcs_eol, "eol"},
7781 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007782 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007784 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785 {&lcs_tab2, "tab"},
7786 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007787#ifdef FEAT_CONCEAL
7788 {&lcs_conceal, "conceal"},
7789#else
7790 {NULL, "conceal"},
7791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792 };
7793 struct charstab *tab;
7794
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007796 {
7797 tab = lcstab;
7798 entries = sizeof(lcstab) / sizeof(struct charstab);
7799 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 else
7801 {
7802 tab = filltab;
7803 entries = sizeof(filltab) / sizeof(struct charstab);
7804 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007805
7806 /* first round: check for valid value, second round: assign values */
7807 for (round = 0; round <= 1; ++round)
7808 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007809 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810 {
7811 /* After checking that the value is valid: set defaults: space for
7812 * 'fillchars', NUL for 'listchars' */
7813 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007814 if (tab[i].cp != NULL)
7815 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816 if (varp == &p_lcs)
7817 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 else
7819 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820 }
7821 p = *varp;
7822 while (*p)
7823 {
7824 for (i = 0; i < entries; ++i)
7825 {
7826 len = (int)STRLEN(tab[i].name);
7827 if (STRNCMP(p, tab[i].name, len) == 0
7828 && p[len] == ':'
7829 && p[len + 1] != NUL)
7830 {
7831 s = p + len + 1;
7832#ifdef FEAT_MBYTE
7833 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007834 if (mb_char2cells(c1) > 1)
7835 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836#else
7837 c1 = *s++;
7838#endif
7839 if (tab[i].cp == &lcs_tab2)
7840 {
7841 if (*s == NUL)
7842 continue;
7843#ifdef FEAT_MBYTE
7844 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007845 if (mb_char2cells(c2) > 1)
7846 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007847#else
7848 c2 = *s++;
7849#endif
7850 }
7851 if (*s == ',' || *s == NUL)
7852 {
7853 if (round)
7854 {
7855 if (tab[i].cp == &lcs_tab2)
7856 {
7857 lcs_tab1 = c1;
7858 lcs_tab2 = c2;
7859 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007860 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861 *(tab[i].cp) = c1;
7862
7863 }
7864 p = s;
7865 break;
7866 }
7867 }
7868 }
7869
7870 if (i == entries)
7871 return e_invarg;
7872 if (*p == ',')
7873 ++p;
7874 }
7875 }
7876
7877 return NULL; /* no error */
7878}
7879
7880#ifdef FEAT_STL_OPT
7881/*
7882 * Check validity of options with the 'statusline' format.
7883 * Return error message or NULL.
7884 */
7885 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007886check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007887{
7888 int itemcnt = 0;
7889 int groupdepth = 0;
7890 static char_u errbuf[80];
7891
7892 while (*s && itemcnt < STL_MAX_ITEM)
7893 {
7894 /* Check for valid keys after % sequences */
7895 while (*s && *s != '%')
7896 s++;
7897 if (!*s)
7898 break;
7899 s++;
7900 if (*s != '%' && *s != ')')
7901 ++itemcnt;
7902 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7903 {
7904 s++;
7905 continue;
7906 }
7907 if (*s == ')')
7908 {
7909 s++;
7910 if (--groupdepth < 0)
7911 break;
7912 continue;
7913 }
7914 if (*s == '-')
7915 s++;
7916 while (VIM_ISDIGIT(*s))
7917 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007918 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 continue;
7920 if (*s == '.')
7921 {
7922 s++;
7923 while (*s && VIM_ISDIGIT(*s))
7924 s++;
7925 }
7926 if (*s == '(')
7927 {
7928 groupdepth++;
7929 continue;
7930 }
7931 if (vim_strchr(STL_ALL, *s) == NULL)
7932 {
7933 return illegal_char(errbuf, *s);
7934 }
7935 if (*s == '{')
7936 {
7937 s++;
7938 while (*s != '}' && *s)
7939 s++;
7940 if (*s != '}')
7941 return (char_u *)N_("E540: Unclosed expression sequence");
7942 }
7943 }
7944 if (itemcnt >= STL_MAX_ITEM)
7945 return (char_u *)N_("E541: too many items");
7946 if (groupdepth != 0)
7947 return (char_u *)N_("E542: unbalanced groups");
7948 return NULL;
7949}
7950#endif
7951
7952#ifdef FEAT_CLIPBOARD
7953/*
7954 * Extract the items in the 'clipboard' option and set global values.
7955 */
7956 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007957check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007959 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007960 int new_autoselect_star = FALSE;
7961 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007963 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 regprog_T *new_exclude_prog = NULL;
7965 char_u *errmsg = NULL;
7966 char_u *p;
7967
7968 for (p = p_cb; *p != NUL; )
7969 {
7970 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7971 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007972 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973 p += 7;
7974 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007975 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007976 && (p[11] == ',' || p[11] == NUL))
7977 {
7978 new_unnamed |= CLIP_UNNAMED_PLUS;
7979 p += 11;
7980 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007982 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007984 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 p += 10;
7986 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007987 else if (STRNCMP(p, "autoselectplus", 14) == 0
7988 && (p[14] == ',' || p[14] == NUL))
7989 {
7990 new_autoselect_plus = TRUE;
7991 p += 14;
7992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007994 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995 {
7996 new_autoselectml = TRUE;
7997 p += 12;
7998 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007999 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8000 {
8001 new_html = TRUE;
8002 p += 4;
8003 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8005 {
8006 p += 8;
8007 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8008 if (new_exclude_prog == NULL)
8009 errmsg = e_invarg;
8010 break;
8011 }
8012 else
8013 {
8014 errmsg = e_invarg;
8015 break;
8016 }
8017 if (*p == ',')
8018 ++p;
8019 }
8020 if (errmsg == NULL)
8021 {
8022 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008023 clip_autoselect_star = new_autoselect_star;
8024 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008026 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008027 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008028 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008029#ifdef FEAT_GUI_GTK
8030 if (gui.in_use)
8031 {
8032 gui_gtk_set_selection_targets();
8033 gui_gtk_set_dnd_targets();
8034 }
8035#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008036 }
8037 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008038 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008039
8040 return errmsg;
8041}
8042#endif
8043
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008044#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008045 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008046did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008047{
8048 char_u *errmsg = NULL;
8049 win_T *wp;
8050 int l;
8051
8052 if (is_spellfile)
8053 {
8054 l = (int)STRLEN(curwin->w_s->b_p_spf);
8055 if (l > 0 && (l < 4
8056 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8057 errmsg = e_invarg;
8058 }
8059
8060 if (errmsg == NULL)
8061 {
8062 FOR_ALL_WINDOWS(wp)
8063 if (wp->w_buffer == curbuf && wp->w_p_spell)
8064 {
8065 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008066 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008067 }
8068 }
8069 return errmsg;
8070}
8071
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008072/*
8073 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8074 * Return error message when failed, NULL when OK.
8075 */
8076 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008077compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008078{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008079 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008080 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008081
Bram Moolenaar860cae12010-06-05 23:22:07 +02008082 if (*synblock->b_p_spc == NUL)
8083 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008084 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008085 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008086 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008087 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008088 if (re != NULL)
8089 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008090 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008091 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008092 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008093 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008094 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008095 return e_invarg;
8096 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008097 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008098 }
8099
Bram Moolenaar473de612013-06-08 18:19:48 +02008100 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008101 return NULL;
8102}
8103#endif
8104
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008105#if defined(FEAT_EVAL) || defined(PROTO)
8106/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008107 * Set the scriptID for an option, taking care of setting the buffer- or
8108 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008109 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008110 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008111set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008112{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008113 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8114 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008115
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008116 /* Remember where the option was set. For local options need to do that
8117 * in the buffer or window structure. */
8118 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008119 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008120 if (both || (opt_flags & OPT_LOCAL))
8121 {
8122 if (indir & PV_BUF)
8123 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8124 else if (indir & PV_WIN)
8125 curwin->w_p_scriptID[indir & PV_MASK] = id;
8126 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008127}
8128#endif
8129
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130/*
8131 * Set the value of a boolean option, and take care of side effects.
8132 * Returns NULL for success, or an error message for an error.
8133 */
8134 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008135set_bool_option(
8136 int opt_idx, /* index in options[] table */
8137 char_u *varp, /* pointer to the option variable */
8138 int value, /* new value */
8139 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140{
8141 int old_value = *(int *)varp;
8142
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 /* Disallow changing some options from secure mode */
8144 if ((secure
8145#ifdef HAVE_SANDBOX
8146 || sandbox != 0
8147#endif
8148 ) && (options[opt_idx].flags & P_SECURE))
8149 return e_secure;
8150
8151 *(int *)varp = value; /* set the new value */
8152#ifdef FEAT_EVAL
8153 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008154 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155#endif
8156
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008157#ifdef FEAT_GUI
8158 need_mouse_correct = TRUE;
8159#endif
8160
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161 /* May set global value for local option. */
8162 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8163 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8164
8165 /*
8166 * Handle side effects of changing a bool option.
8167 */
8168
8169 /* 'compatible' */
8170 if ((int *)varp == &p_cp)
8171 {
8172 compatible_set();
8173 }
8174
Bram Moolenaar920694c2016-08-21 17:45:02 +02008175#ifdef FEAT_LANGMAP
8176 if ((int *)varp == &p_lrm)
8177 /* 'langremap' -> !'langnoremap' */
8178 p_lnr = !p_lrm;
8179 else if ((int *)varp == &p_lnr)
8180 /* 'langnoremap' -> !'langremap' */
8181 p_lrm = !p_lnr;
8182#endif
8183
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008184#ifdef FEAT_PERSISTENT_UNDO
8185 /* 'undofile' */
8186 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8187 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008188 /* Only take action when the option was set. When reset we do not
8189 * delete the undo file, the option may be set again without making
8190 * any changes in between. */
8191 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008192 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008193 char_u hash[UNDO_HASH_SIZE];
8194 buf_T *save_curbuf = curbuf;
8195
Bram Moolenaar29323592016-07-24 22:04:11 +02008196 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008197 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008198 /* When 'undofile' is set globally: for every buffer, otherwise
8199 * only for the current buffer: Try to read in the undofile,
8200 * if one exists, the buffer wasn't changed and the buffer was
8201 * loaded */
8202 if ((curbuf == save_curbuf
8203 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8204 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8205 {
8206 u_compute_hash(hash);
8207 u_read_undo(NULL, hash, curbuf->b_fname);
8208 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008209 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008210 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008211 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008212 }
8213#endif
8214
Bram Moolenaar071d4272004-06-13 20:20:40 +00008215 else if ((int *)varp == &curbuf->b_p_ro)
8216 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008217 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8219 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008220
8221 /* when 'readonly' is set may give W10 again */
8222 if (curbuf->b_p_ro)
8223 curbuf->b_did_warn = FALSE;
8224
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008226 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008227#endif
8228 }
8229
Bram Moolenaar9c449722010-07-20 18:44:27 +02008230#ifdef FEAT_GUI
8231 else if ((int *)varp == &p_mh)
8232 {
8233 if (!p_mh)
8234 gui_mch_mousehide(FALSE);
8235 }
8236#endif
8237
Bram Moolenaara539df02010-08-01 14:35:05 +02008238 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008240 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008241# ifdef FEAT_TERMINAL
8242 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008243 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008244 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008245 {
8246 curbuf->b_p_ma = FALSE;
8247 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8248 }
8249# endif
8250# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008251 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008252# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008253 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008254#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255 /* when 'endofline' is changed, redraw the window title */
8256 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008257 {
8258 redraw_titles();
8259 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008260 /* when 'fixeol' is changed, redraw the window title */
8261 else if ((int *)varp == &curbuf->b_p_fixeol)
8262 {
8263 redraw_titles();
8264 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008265# ifdef FEAT_MBYTE
8266 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008267 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008268 {
8269 redraw_titles();
8270 }
8271# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272#endif
8273
8274 /* when 'bin' is set also set some other options */
8275 else if ((int *)varp == &curbuf->b_p_bin)
8276 {
8277 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8278#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008279 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008280#endif
8281 }
8282
8283#ifdef FEAT_AUTOCMD
8284 /* when 'buflisted' changes, trigger autocommands */
8285 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8286 {
8287 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8288 NULL, NULL, TRUE, curbuf);
8289 }
8290#endif
8291
8292 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8293 else if ((int *)varp == &curbuf->b_p_swf)
8294 {
8295 if (curbuf->b_p_swf && p_uc)
8296 ml_open_file(curbuf); /* create the swap file */
8297 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008298 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8299 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 mf_close_file(curbuf, TRUE); /* remove the swap file */
8301 }
8302
8303 /* when 'terse' is set change 'shortmess' */
8304 else if ((int *)varp == &p_terse)
8305 {
8306 char_u *p;
8307
8308 p = vim_strchr(p_shm, SHM_SEARCH);
8309
8310 /* insert 's' in p_shm */
8311 if (p_terse && p == NULL)
8312 {
8313 STRCPY(IObuff, p_shm);
8314 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008315 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 }
8317 /* remove 's' from p_shm */
8318 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008319 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 }
8321
8322 /* when 'paste' is set or reset also change other options */
8323 else if ((int *)varp == &p_paste)
8324 {
8325 paste_option_changed();
8326 }
8327
8328 /* when 'insertmode' is set from an autocommand need to do work here */
8329 else if ((int *)varp == &p_im)
8330 {
8331 if (p_im)
8332 {
8333 if ((State & INSERT) == 0)
8334 need_start_insertmode = TRUE;
8335 stop_insert_mode = FALSE;
8336 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008337 /* only reset if it was set previously */
8338 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 {
8340 need_start_insertmode = FALSE;
8341 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008342 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 clear_cmdline = TRUE; /* remove "(insert)" */
8344 restart_edit = 0;
8345 }
8346 }
8347
8348 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8349 else if ((int *)varp == &p_ic && p_hls)
8350 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008351 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 }
8353
8354#ifdef FEAT_SEARCH_EXTRA
8355 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8356 else if ((int *)varp == &p_hls)
8357 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008358 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359 }
8360#endif
8361
8362#ifdef FEAT_SCROLLBIND
8363 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8364 * at the end of normal_cmd() */
8365 else if ((int *)varp == &curwin->w_p_scb)
8366 {
8367 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008368 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008370 curwin->w_scbind_pos = curwin->w_topline;
8371 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 }
8373#endif
8374
Bram Moolenaar4033c552017-09-16 20:54:51 +02008375#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376 /* There can be only one window with 'previewwindow' set. */
8377 else if ((int *)varp == &curwin->w_p_pvw)
8378 {
8379 if (curwin->w_p_pvw)
8380 {
8381 win_T *win;
8382
Bram Moolenaar29323592016-07-24 22:04:11 +02008383 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008384 if (win->w_p_pvw && win != curwin)
8385 {
8386 curwin->w_p_pvw = FALSE;
8387 return (char_u *)N_("E590: A preview window already exists");
8388 }
8389 }
8390 }
8391#endif
8392
8393 /* when 'textmode' is set or reset also change 'fileformat' */
8394 else if ((int *)varp == &curbuf->b_p_tx)
8395 {
8396 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8397 }
8398
8399 /* when 'textauto' is set or reset also change 'fileformats' */
8400 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401 set_string_option_direct((char_u *)"ffs", -1,
8402 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008403 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404
8405 /*
8406 * When 'lisp' option changes include/exclude '-' in
8407 * keyword characters.
8408 */
8409#ifdef FEAT_LISP
8410 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8411 {
8412 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8413 }
8414#endif
8415
8416#ifdef FEAT_TITLE
8417 /* when 'title' changed, may need to change the title; same for 'icon' */
8418 else if ((int *)varp == &p_title)
8419 {
8420 did_set_title(FALSE);
8421 }
8422
8423 else if ((int *)varp == &p_icon)
8424 {
8425 did_set_title(TRUE);
8426 }
8427#endif
8428
8429 else if ((int *)varp == &curbuf->b_changed)
8430 {
8431 if (!value)
8432 save_file_ff(curbuf); /* Buffer is unchanged */
8433#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008434 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008435#endif
8436#ifdef FEAT_AUTOCMD
8437 modified_was_set = value;
8438#endif
8439 }
8440
8441#ifdef BACKSLASH_IN_FILENAME
8442 else if ((int *)varp == &p_ssl)
8443 {
8444 if (p_ssl)
8445 {
8446 psepc = '/';
8447 psepcN = '\\';
8448 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449 }
8450 else
8451 {
8452 psepc = '\\';
8453 psepcN = '/';
8454 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455 }
8456
8457 /* need to adjust the file name arguments and buffer names. */
8458 buflist_slash_adjust();
8459 alist_slash_adjust();
8460# ifdef FEAT_EVAL
8461 scriptnames_slash_adjust();
8462# endif
8463 }
8464#endif
8465
8466 /* If 'wrap' is set, set w_leftcol to zero. */
8467 else if ((int *)varp == &curwin->w_p_wrap)
8468 {
8469 if (curwin->w_p_wrap)
8470 curwin->w_leftcol = 0;
8471 }
8472
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 else if ((int *)varp == &p_ea)
8474 {
8475 if (p_ea && !old_value)
8476 win_equal(curwin, FALSE, 0);
8477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478
8479 else if ((int *)varp == &p_wiv)
8480 {
8481 /*
8482 * When 'weirdinvert' changed, set/reset 't_xs'.
8483 * Then set 'weirdinvert' according to value of 't_xs'.
8484 */
8485 if (p_wiv && !old_value)
8486 T_XS = (char_u *)"y";
8487 else if (!p_wiv && old_value)
8488 T_XS = empty_option;
8489 p_wiv = (*T_XS != NUL);
8490 }
8491
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008492#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493 else if ((int *)varp == &p_beval)
8494 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008495 if (!balloonEvalForTerm)
8496 {
8497 if (p_beval && !old_value)
8498 gui_mch_enable_beval_area(balloonEval);
8499 else if (!p_beval && old_value)
8500 gui_mch_disable_beval_area(balloonEval);
8501 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008502 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008503#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008504#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008505 else if ((int *)varp == &p_bevalterm)
8506 {
8507 mch_bevalterm_changed();
8508 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008511#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512 else if ((int *)varp == &p_acd)
8513 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008514 /* Change directories when the 'acd' option is set now. */
8515 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516 }
8517#endif
8518
8519#ifdef FEAT_DIFF
8520 /* 'diff' */
8521 else if ((int *)varp == &curwin->w_p_diff)
8522 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008523 /* May add or remove the buffer from the list of diff buffers. */
8524 diff_buf_adjust(curwin);
8525# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526 if (foldmethodIsDiff(curwin))
8527 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008528# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529 }
8530#endif
8531
Bram Moolenaar819edbe2017-11-25 17:14:33 +01008532#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533 /* 'imdisable' */
8534 else if ((int *)varp == &p_imdisable)
8535 {
8536 /* Only de-activate it here, it will be enabled when changing mode. */
8537 if (p_imdisable)
8538 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008539 else if (State & INSERT)
8540 /* When the option is set from an autocommand, it may need to take
8541 * effect right away. */
8542 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008543 }
8544#endif
8545
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008546#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008547 /* 'spell' */
8548 else if ((int *)varp == &curwin->w_p_spell)
8549 {
8550 if (curwin->w_p_spell)
8551 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008552 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008553 if (errmsg != NULL)
8554 EMSG(_(errmsg));
8555 }
8556 }
8557#endif
8558
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559#ifdef FEAT_FKMAP
8560 else if ((int *)varp == &p_altkeymap)
8561 {
8562 if (old_value != p_altkeymap)
8563 {
8564 if (!p_altkeymap)
8565 {
8566 p_hkmap = p_fkmap;
8567 p_fkmap = 0;
8568 }
8569 else
8570 {
8571 p_fkmap = p_hkmap;
8572 p_hkmap = 0;
8573 }
8574 (void)init_chartab();
8575 }
8576 }
8577
8578 /*
8579 * In case some second language keymapping options have changed, check
8580 * and correct the setting in a consistent way.
8581 */
8582
8583 /*
8584 * If hkmap or fkmap are set, reset Arabic keymapping.
8585 */
8586 if ((p_hkmap || p_fkmap) && p_altkeymap)
8587 {
8588 p_altkeymap = p_fkmap;
8589# ifdef FEAT_ARABIC
8590 curwin->w_p_arab = FALSE;
8591# endif
8592 (void)init_chartab();
8593 }
8594
8595 /*
8596 * If hkmap set, reset Farsi keymapping.
8597 */
8598 if (p_hkmap && p_altkeymap)
8599 {
8600 p_altkeymap = 0;
8601 p_fkmap = 0;
8602# ifdef FEAT_ARABIC
8603 curwin->w_p_arab = FALSE;
8604# endif
8605 (void)init_chartab();
8606 }
8607
8608 /*
8609 * If fkmap set, reset Hebrew keymapping.
8610 */
8611 if (p_fkmap && !p_altkeymap)
8612 {
8613 p_altkeymap = 1;
8614 p_hkmap = 0;
8615# ifdef FEAT_ARABIC
8616 curwin->w_p_arab = FALSE;
8617# endif
8618 (void)init_chartab();
8619 }
8620#endif
8621
8622#ifdef FEAT_ARABIC
8623 if ((int *)varp == &curwin->w_p_arab)
8624 {
8625 if (curwin->w_p_arab)
8626 {
8627 /*
8628 * 'arabic' is set, handle various sub-settings.
8629 */
8630 if (!p_tbidi)
8631 {
8632 /* set rightleft mode */
8633 if (!curwin->w_p_rl)
8634 {
8635 curwin->w_p_rl = TRUE;
8636 changed_window_setting();
8637 }
8638
8639 /* Enable Arabic shaping (major part of what Arabic requires) */
8640 if (!p_arshape)
8641 {
8642 p_arshape = TRUE;
8643 redraw_later_clear();
8644 }
8645 }
8646
8647 /* Arabic requires a utf-8 encoding, inform the user if its not
8648 * set. */
8649 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008650 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008651 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8652
Bram Moolenaar8820b482017-03-16 17:23:31 +01008653 msg_source(HL_ATTR(HLF_W));
8654 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008655#ifdef FEAT_EVAL
8656 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8657#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659
8660# ifdef FEAT_MBYTE
8661 /* set 'delcombine' */
8662 p_deco = TRUE;
8663# endif
8664
8665# ifdef FEAT_KEYMAP
8666 /* Force-set the necessary keymap for arabic */
8667 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8668 OPT_LOCAL);
8669# endif
8670# ifdef FEAT_FKMAP
8671 p_altkeymap = 0;
8672 p_hkmap = 0;
8673 p_fkmap = 0;
8674 (void)init_chartab();
8675# endif
8676 }
8677 else
8678 {
8679 /*
8680 * 'arabic' is reset, handle various sub-settings.
8681 */
8682 if (!p_tbidi)
8683 {
8684 /* reset rightleft mode */
8685 if (curwin->w_p_rl)
8686 {
8687 curwin->w_p_rl = FALSE;
8688 changed_window_setting();
8689 }
8690
8691 /* 'arabicshape' isn't reset, it is a global option and
8692 * another window may still need it "on". */
8693 }
8694
8695 /* 'delcombine' isn't reset, it is a global option and another
8696 * window may still want it "on". */
8697
8698# ifdef FEAT_KEYMAP
8699 /* Revert to the default keymap */
8700 curbuf->b_p_iminsert = B_IMODE_NONE;
8701 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8702# endif
8703 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008704 }
8705
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008706#endif
8707
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008708#ifdef FEAT_TERMGUICOLORS
8709 /* 'termguicolors' */
8710 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008711 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008712# ifdef FEAT_VTP
8713 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8714 if (!has_vtp_working())
8715 {
8716 p_tgc = 0;
8717 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8718 }
8719 swap_tcap();
8720# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008721# ifdef FEAT_GUI
8722 if (!gui.in_use && !gui.starting)
8723# endif
8724 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008725# ifdef FEAT_VTP
8726 control_console_color_rgb();
8727 /* reset t_Co */
8728 if (STRCMP(T_NAME, "win32") == 0)
8729 set_termname(T_NAME);
8730# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008731 }
8732#endif
8733
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734 /*
8735 * End of handling side effects for bool options.
8736 */
8737
Bram Moolenaar53744302015-07-17 17:38:22 +02008738 /* after handling side effects, call autocommand */
8739
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 options[opt_idx].flags |= P_WAS_SET;
8741
Bram Moolenaar53744302015-07-17 17:38:22 +02008742#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8743 if (!starting)
8744 {
8745 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008746 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8747 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8748 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008749 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8750 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8751 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8752 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8753 reset_v_option_vars();
8754 }
8755#endif
8756
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008758 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008759 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008760 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 check_redraw(options[opt_idx].flags);
8762
8763 return NULL;
8764}
8765
8766/*
8767 * Set the value of a number option, and take care of side effects.
8768 * Returns NULL for success, or an error message for an error.
8769 */
8770 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008771set_num_option(
8772 int opt_idx, /* index in options[] table */
8773 char_u *varp, /* pointer to the option variable */
8774 long value, /* new value */
8775 char_u *errbuf, /* buffer for error messages */
8776 size_t errbuflen, /* length of "errbuf" */
8777 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778 OPT_MODELINE */
8779{
8780 char_u *errmsg = NULL;
8781 long old_value = *(long *)varp;
8782 long old_Rows = Rows; /* remember old Rows */
8783 long old_Columns = Columns; /* remember old Columns */
8784 long *pp = (long *)varp;
8785
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008786 /* Disallow changing some options from secure mode. */
8787 if ((secure
8788#ifdef HAVE_SANDBOX
8789 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008790#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008791 ) && (options[opt_idx].flags & P_SECURE))
8792 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008793
8794 *pp = value;
8795#ifdef FEAT_EVAL
8796 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008797 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008799#ifdef FEAT_GUI
8800 need_mouse_correct = TRUE;
8801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802
Bram Moolenaar14f24742012-08-08 18:01:05 +02008803 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 {
8805 errmsg = e_positive;
8806 curbuf->b_p_sw = curbuf->b_p_ts;
8807 }
8808
8809 /*
8810 * Number options that need some action when changed
8811 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008812 if (pp == &p_wh || pp == &p_hh)
8813 {
8814 if (p_wh < 1)
8815 {
8816 errmsg = e_positive;
8817 p_wh = 1;
8818 }
8819 if (p_wmh > p_wh)
8820 {
8821 errmsg = e_winheight;
8822 p_wh = p_wmh;
8823 }
8824 if (p_hh < 0)
8825 {
8826 errmsg = e_positive;
8827 p_hh = 0;
8828 }
8829
8830 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008831 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832 {
8833 if (pp == &p_wh && curwin->w_height < p_wh)
8834 win_setheight((int)p_wh);
8835 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8836 win_setheight((int)p_hh);
8837 }
8838 }
8839
8840 /* 'winminheight' */
8841 else if (pp == &p_wmh)
8842 {
8843 if (p_wmh < 0)
8844 {
8845 errmsg = e_positive;
8846 p_wmh = 0;
8847 }
8848 if (p_wmh > p_wh)
8849 {
8850 errmsg = e_winheight;
8851 p_wmh = p_wh;
8852 }
8853 win_setminheight();
8854 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008855 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 {
8857 if (p_wiw < 1)
8858 {
8859 errmsg = e_positive;
8860 p_wiw = 1;
8861 }
8862 if (p_wmw > p_wiw)
8863 {
8864 errmsg = e_winwidth;
8865 p_wiw = p_wmw;
8866 }
8867
8868 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008869 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 win_setwidth((int)p_wiw);
8871 }
8872
8873 /* 'winminwidth' */
8874 else if (pp == &p_wmw)
8875 {
8876 if (p_wmw < 0)
8877 {
8878 errmsg = e_positive;
8879 p_wmw = 0;
8880 }
8881 if (p_wmw > p_wiw)
8882 {
8883 errmsg = e_winwidth;
8884 p_wmw = p_wiw;
8885 }
8886 win_setminheight();
8887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008888
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889 /* (re)set last window status line */
8890 else if (pp == &p_ls)
8891 {
8892 last_status(FALSE);
8893 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008894
8895 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008896 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008897 {
8898 shell_new_rows(); /* recompute window positions and heights */
8899 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008900
8901#ifdef FEAT_GUI
8902 else if (pp == &p_linespace)
8903 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008904 /* Recompute gui.char_height and resize the Vim window to keep the
8905 * same number of lines. */
8906 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008907 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 }
8909#endif
8910
8911#ifdef FEAT_FOLDING
8912 /* 'foldlevel' */
8913 else if (pp == &curwin->w_p_fdl)
8914 {
8915 if (curwin->w_p_fdl < 0)
8916 curwin->w_p_fdl = 0;
8917 newFoldLevel();
8918 }
8919
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008920 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 else if (pp == &curwin->w_p_fml)
8922 {
8923 foldUpdateAll(curwin);
8924 }
8925
8926 /* 'foldnestmax' */
8927 else if (pp == &curwin->w_p_fdn)
8928 {
8929 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8930 foldUpdateAll(curwin);
8931 }
8932
8933 /* 'foldcolumn' */
8934 else if (pp == &curwin->w_p_fdc)
8935 {
8936 if (curwin->w_p_fdc < 0)
8937 {
8938 errmsg = e_positive;
8939 curwin->w_p_fdc = 0;
8940 }
8941 else if (curwin->w_p_fdc > 12)
8942 {
8943 errmsg = e_invarg;
8944 curwin->w_p_fdc = 12;
8945 }
8946 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008947#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008948
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008949#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008950 /* 'shiftwidth' or 'tabstop' */
8951 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8952 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008953# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008954 if (foldmethodIsIndent(curwin))
8955 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008956# endif
8957# ifdef FEAT_CINDENT
8958 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8959 * parse 'cinoptions'. */
8960 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8961 parse_cino(curbuf);
8962# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008966#ifdef FEAT_MBYTE
8967 /* 'maxcombine' */
8968 else if (pp == &p_mco)
8969 {
8970 if (p_mco > MAX_MCO)
8971 p_mco = MAX_MCO;
8972 else if (p_mco < 0)
8973 p_mco = 0;
8974 screenclear(); /* will re-allocate the screen */
8975 }
8976#endif
8977
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 else if (pp == &curbuf->b_p_iminsert)
8979 {
8980 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8981 {
8982 errmsg = e_invarg;
8983 curbuf->b_p_iminsert = B_IMODE_NONE;
8984 }
8985 p_iminsert = curbuf->b_p_iminsert;
8986 if (termcap_active) /* don't do this in the alternate screen */
8987 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008988#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008989 /* Show/unshow value of 'keymap' in status lines. */
8990 status_redraw_curbuf();
8991#endif
8992 }
8993
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008994#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8995 /* 'imstyle' */
8996 else if (pp == &p_imst)
8997 {
8998 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8999 errmsg = e_invarg;
9000 }
9001#endif
9002
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009003 else if (pp == &p_window)
9004 {
9005 if (p_window < 1)
9006 p_window = 1;
9007 else if (p_window >= Rows)
9008 p_window = Rows - 1;
9009 }
9010
Bram Moolenaar071d4272004-06-13 20:20:40 +00009011 else if (pp == &curbuf->b_p_imsearch)
9012 {
9013 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9014 {
9015 errmsg = e_invarg;
9016 curbuf->b_p_imsearch = B_IMODE_NONE;
9017 }
9018 p_imsearch = curbuf->b_p_imsearch;
9019 }
9020
9021#ifdef FEAT_TITLE
9022 /* if 'titlelen' has changed, redraw the title */
9023 else if (pp == &p_titlelen)
9024 {
9025 if (p_titlelen < 0)
9026 {
9027 errmsg = e_positive;
9028 p_titlelen = 85;
9029 }
9030 if (starting != NO_SCREEN && old_value != p_titlelen)
9031 need_maketitle = TRUE;
9032 }
9033#endif
9034
9035 /* if p_ch changed value, change the command line height */
9036 else if (pp == &p_ch)
9037 {
9038 if (p_ch < 1)
9039 {
9040 errmsg = e_positive;
9041 p_ch = 1;
9042 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009043 if (p_ch > Rows - min_rows() + 1)
9044 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009045
9046 /* Only compute the new window layout when startup has been
9047 * completed. Otherwise the frame sizes may be wrong. */
9048 if (p_ch != old_value && full_screen
9049#ifdef FEAT_GUI
9050 && !gui.starting
9051#endif
9052 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009053 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 }
9055
9056 /* when 'updatecount' changes from zero to non-zero, open swap files */
9057 else if (pp == &p_uc)
9058 {
9059 if (p_uc < 0)
9060 {
9061 errmsg = e_positive;
9062 p_uc = 100;
9063 }
9064 if (p_uc && !old_value)
9065 ml_open_files();
9066 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009067#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009068 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009069 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009070 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009071 {
9072 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009073 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009074 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009075 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009076 {
9077 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009078 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009079 }
9080 }
9081#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009082#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009083 else if (pp == &p_mzq)
9084 mzvim_reset_timer();
9085#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009086
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009087#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9088 /* 'pyxversion' */
9089 else if (pp == &p_pyx)
9090 {
9091 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9092 errmsg = e_invarg;
9093 }
9094#endif
9095
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 /* sync undo before 'undolevels' changes */
9097 else if (pp == &p_ul)
9098 {
9099 /* use the old value, otherwise u_sync() may not work properly */
9100 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009101 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102 p_ul = value;
9103 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009104 else if (pp == &curbuf->b_p_ul)
9105 {
9106 /* use the old value, otherwise u_sync() may not work properly */
9107 curbuf->b_p_ul = old_value;
9108 u_sync(TRUE);
9109 curbuf->b_p_ul = value;
9110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009112#ifdef FEAT_LINEBREAK
9113 /* 'numberwidth' must be positive */
9114 else if (pp == &curwin->w_p_nuw)
9115 {
9116 if (curwin->w_p_nuw < 1)
9117 {
9118 errmsg = e_positive;
9119 curwin->w_p_nuw = 1;
9120 }
9121 if (curwin->w_p_nuw > 10)
9122 {
9123 errmsg = e_invarg;
9124 curwin->w_p_nuw = 10;
9125 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009126 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009127 }
9128#endif
9129
Bram Moolenaar1a384422010-07-14 19:53:30 +02009130 else if (pp == &curbuf->b_p_tw)
9131 {
9132 if (curbuf->b_p_tw < 0)
9133 {
9134 errmsg = e_positive;
9135 curbuf->b_p_tw = 0;
9136 }
9137#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009138 {
9139 win_T *wp;
9140 tabpage_T *tp;
9141
9142 FOR_ALL_TAB_WINDOWS(tp, wp)
9143 check_colorcolumn(wp);
9144 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009145#endif
9146 }
9147
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 /*
9149 * Check the bounds for numeric options here
9150 */
9151 if (Rows < min_rows() && full_screen)
9152 {
9153 if (errbuf != NULL)
9154 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009155 vim_snprintf((char *)errbuf, errbuflen,
9156 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157 errmsg = errbuf;
9158 }
9159 Rows = min_rows();
9160 }
9161 if (Columns < MIN_COLUMNS && full_screen)
9162 {
9163 if (errbuf != NULL)
9164 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009165 vim_snprintf((char *)errbuf, errbuflen,
9166 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 errmsg = errbuf;
9168 }
9169 Columns = MIN_COLUMNS;
9170 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009171 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172
Bram Moolenaar071d4272004-06-13 20:20:40 +00009173 /*
9174 * If the screen (shell) height has been changed, assume it is the
9175 * physical screenheight.
9176 */
9177 if (old_Rows != Rows || old_Columns != Columns)
9178 {
9179 /* Changing the screen size is not allowed while updating the screen. */
9180 if (updating_screen)
9181 *pp = old_value;
9182 else if (full_screen
9183#ifdef FEAT_GUI
9184 && !gui.starting
9185#endif
9186 )
9187 set_shellsize((int)Columns, (int)Rows, TRUE);
9188 else
9189 {
9190 /* Postpone the resizing; check the size and cmdline position for
9191 * messages. */
9192 check_shellsize();
9193 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9194 cmdline_row = Rows - p_ch;
9195 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009196 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009197 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009198 }
9199
Bram Moolenaar071d4272004-06-13 20:20:40 +00009200 if (curbuf->b_p_ts <= 0)
9201 {
9202 errmsg = e_positive;
9203 curbuf->b_p_ts = 8;
9204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009205 if (p_tm < 0)
9206 {
9207 errmsg = e_positive;
9208 p_tm = 0;
9209 }
9210 if ((curwin->w_p_scr <= 0
9211 || (curwin->w_p_scr > curwin->w_height
9212 && curwin->w_height > 0))
9213 && full_screen)
9214 {
9215 if (pp == &(curwin->w_p_scr))
9216 {
9217 if (curwin->w_p_scr != 0)
9218 errmsg = e_scroll;
9219 win_comp_scroll(curwin);
9220 }
9221 /* If 'scroll' became invalid because of a side effect silently adjust
9222 * it. */
9223 else if (curwin->w_p_scr <= 0)
9224 curwin->w_p_scr = 1;
9225 else /* curwin->w_p_scr > curwin->w_height */
9226 curwin->w_p_scr = curwin->w_height;
9227 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009228 if (p_hi < 0)
9229 {
9230 errmsg = e_positive;
9231 p_hi = 0;
9232 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009233 else if (p_hi > 10000)
9234 {
9235 errmsg = e_invarg;
9236 p_hi = 10000;
9237 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009238 if (p_re < 0 || p_re > 2)
9239 {
9240 errmsg = e_invarg;
9241 p_re = 0;
9242 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 if (p_report < 0)
9244 {
9245 errmsg = e_positive;
9246 p_report = 1;
9247 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009248 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 {
9250 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9251 p_sj = Rows / 2;
9252 else
9253 {
9254 errmsg = e_scroll;
9255 p_sj = 1;
9256 }
9257 }
9258 if (p_so < 0 && full_screen)
9259 {
9260 errmsg = e_scroll;
9261 p_so = 0;
9262 }
9263 if (p_siso < 0 && full_screen)
9264 {
9265 errmsg = e_positive;
9266 p_siso = 0;
9267 }
9268#ifdef FEAT_CMDWIN
9269 if (p_cwh < 1)
9270 {
9271 errmsg = e_positive;
9272 p_cwh = 1;
9273 }
9274#endif
9275 if (p_ut < 0)
9276 {
9277 errmsg = e_positive;
9278 p_ut = 2000;
9279 }
9280 if (p_ss < 0)
9281 {
9282 errmsg = e_positive;
9283 p_ss = 0;
9284 }
9285
9286 /* May set global value for local option. */
9287 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9288 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9289
9290 options[opt_idx].flags |= P_WAS_SET;
9291
Bram Moolenaar53744302015-07-17 17:38:22 +02009292#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9293 if (!starting && errmsg == NULL)
9294 {
9295 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009296 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9297 vim_snprintf((char *)buf_new, 10, "%ld", value);
9298 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009299 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9300 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9301 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9302 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9303 reset_v_option_vars();
9304 }
9305#endif
9306
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009308 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009309 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009310 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009311 check_redraw(options[opt_idx].flags);
9312
9313 return errmsg;
9314}
9315
9316/*
9317 * Called after an option changed: check if something needs to be redrawn.
9318 */
9319 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009320check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009321{
9322 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009323 int doclear = (flags & P_RCLR) == P_RCLR;
9324 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009325
Bram Moolenaar071d4272004-06-13 20:20:40 +00009326 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9327 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328
9329 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9330 changed_window_setting();
9331 if (flags & P_RBUF)
9332 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009333 if (flags & P_RWINONLY)
9334 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009335 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336 redraw_all_later(CLEAR);
9337 else if (all)
9338 redraw_all_later(NOT_VALID);
9339}
9340
9341/*
9342 * Find index for option 'arg'.
9343 * Return -1 if not found.
9344 */
9345 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009346findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347{
9348 int opt_idx;
9349 char *s, *p;
9350 static short quick_tab[27] = {0, 0}; /* quick access table */
9351 int is_term_opt;
9352
9353 /*
9354 * For first call: Initialize the quick-access table.
9355 * It contains the index for the first option that starts with a certain
9356 * letter. There are 26 letters, plus the first "t_" option.
9357 */
9358 if (quick_tab[1] == 0)
9359 {
9360 p = options[0].fullname;
9361 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9362 {
9363 if (s[0] != p[0])
9364 {
9365 if (s[0] == 't' && s[1] == '_')
9366 quick_tab[26] = opt_idx;
9367 else
9368 quick_tab[CharOrdLow(s[0])] = opt_idx;
9369 }
9370 p = s;
9371 }
9372 }
9373
9374 /*
9375 * Check for name starting with an illegal character.
9376 */
9377#ifdef EBCDIC
9378 if (!islower(arg[0]))
9379#else
9380 if (arg[0] < 'a' || arg[0] > 'z')
9381#endif
9382 return -1;
9383
9384 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9385 if (is_term_opt)
9386 opt_idx = quick_tab[26];
9387 else
9388 opt_idx = quick_tab[CharOrdLow(arg[0])];
9389 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9390 {
9391 if (STRCMP(arg, s) == 0) /* match full name */
9392 break;
9393 }
9394 if (s == NULL && !is_term_opt)
9395 {
9396 opt_idx = quick_tab[CharOrdLow(arg[0])];
9397 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9398 {
9399 s = options[opt_idx].shortname;
9400 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9401 break;
9402 s = NULL;
9403 }
9404 }
9405 if (s == NULL)
9406 opt_idx = -1;
9407 return opt_idx;
9408}
9409
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009410#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009411/*
9412 * Get the value for an option.
9413 *
9414 * Returns:
9415 * Number or Toggle option: 1, *numval gets value.
9416 * String option: 0, *stringval gets allocated string.
9417 * Hidden Number or Toggle option: -1.
9418 * hidden String option: -2.
9419 * unknown option: -3.
9420 */
9421 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009422get_option_value(
9423 char_u *name,
9424 long *numval,
9425 char_u **stringval, /* NULL when only checking existence */
9426 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427{
9428 int opt_idx;
9429 char_u *varp;
9430
9431 opt_idx = findoption(name);
9432 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009433 {
9434 int key;
9435
9436 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9437 && (key = find_key_option(name)) != 0)
9438 {
9439 char_u key_name[2];
9440 char_u *p;
9441
9442 if (key < 0)
9443 {
9444 key_name[0] = KEY2TERMCAP0(key);
9445 key_name[1] = KEY2TERMCAP1(key);
9446 }
9447 else
9448 {
9449 key_name[0] = KS_KEY;
9450 key_name[1] = (key & 0xff);
9451 }
9452 p = find_termcode(key_name);
9453 if (p != NULL)
9454 {
9455 if (stringval != NULL)
9456 *stringval = vim_strsave(p);
9457 return 0;
9458 }
9459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009460 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009461 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462
9463 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9464
9465 if (options[opt_idx].flags & P_STRING)
9466 {
9467 if (varp == NULL) /* hidden option */
9468 return -2;
9469 if (stringval != NULL)
9470 {
9471#ifdef FEAT_CRYPT
9472 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009473 if ((char_u **)varp == &curbuf->b_p_key
9474 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475 *stringval = vim_strsave((char_u *)"*****");
9476 else
9477#endif
9478 *stringval = vim_strsave(*(char_u **)(varp));
9479 }
9480 return 0;
9481 }
9482
9483 if (varp == NULL) /* hidden option */
9484 return -1;
9485 if (options[opt_idx].flags & P_NUM)
9486 *numval = *(long *)varp;
9487 else
9488 {
9489 /* Special case: 'modified' is b_changed, but we also want to consider
9490 * it set when 'ff' or 'fenc' changed. */
9491 if ((int *)varp == &curbuf->b_changed)
9492 *numval = curbufIsChanged();
9493 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009494 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009495 }
9496 return 1;
9497}
9498#endif
9499
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009500#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009501/*
9502 * Returns the option attributes and its value. Unlike the above function it
9503 * will return either global value or local value of the option depending on
9504 * what was requested, but it will never return global value if it was
9505 * requested to return local one and vice versa. Neither it will return
9506 * buffer-local value if it was requested to return window-local one.
9507 *
9508 * Pretends that option is absent if it is not present in the requested scope
9509 * (i.e. has no global, window-local or buffer-local value depending on
9510 * opt_type). Uses
9511 *
9512 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009513 * 0 hidden or unknown option, also option that does not have requested
9514 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009515 * see SOPT_* in vim.h for other flags
9516 *
9517 * Possible opt_type values: see SREQ_* in vim.h
9518 */
9519 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009520get_option_value_strict(
9521 char_u *name,
9522 long *numval,
9523 char_u **stringval, /* NULL when only obtaining attributes */
9524 int opt_type,
9525 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009526{
9527 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009528 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009529 struct vimoption *p;
9530 int r = 0;
9531
9532 opt_idx = findoption(name);
9533 if (opt_idx < 0)
9534 return 0;
9535
9536 p = &(options[opt_idx]);
9537
9538 /* Hidden option */
9539 if (p->var == NULL)
9540 return 0;
9541
9542 if (p->flags & P_BOOL)
9543 r |= SOPT_BOOL;
9544 else if (p->flags & P_NUM)
9545 r |= SOPT_NUM;
9546 else if (p->flags & P_STRING)
9547 r |= SOPT_STRING;
9548
9549 if (p->indir == PV_NONE)
9550 {
9551 if (opt_type == SREQ_GLOBAL)
9552 r |= SOPT_GLOBAL;
9553 else
9554 return 0; /* Did not request global-only option */
9555 }
9556 else
9557 {
9558 if (p->indir & PV_BOTH)
9559 r |= SOPT_GLOBAL;
9560 else if (opt_type == SREQ_GLOBAL)
9561 return 0; /* Requested global option */
9562
9563 if (p->indir & PV_WIN)
9564 {
9565 if (opt_type == SREQ_BUF)
9566 return 0; /* Did not request window-local option */
9567 else
9568 r |= SOPT_WIN;
9569 }
9570 else if (p->indir & PV_BUF)
9571 {
9572 if (opt_type == SREQ_WIN)
9573 return 0; /* Did not request buffer-local option */
9574 else
9575 r |= SOPT_BUF;
9576 }
9577 }
9578
9579 if (stringval == NULL)
9580 return r;
9581
9582 if (opt_type == SREQ_GLOBAL)
9583 varp = p->var;
9584 else
9585 {
9586 if (opt_type == SREQ_BUF)
9587 {
9588 /* Special case: 'modified' is b_changed, but we also want to
9589 * consider it set when 'ff' or 'fenc' changed. */
9590 if (p->indir == PV_MOD)
9591 {
9592 *numval = bufIsChanged((buf_T *) from);
9593 varp = NULL;
9594 }
9595#ifdef FEAT_CRYPT
9596 else if (p->indir == PV_KEY)
9597 {
9598 /* never return the value of the crypt key */
9599 *stringval = NULL;
9600 varp = NULL;
9601 }
9602#endif
9603 else
9604 {
9605 aco_save_T aco;
9606 aucmd_prepbuf(&aco, (buf_T *) from);
9607 varp = get_varp(p);
9608 aucmd_restbuf(&aco);
9609 }
9610 }
9611 else if (opt_type == SREQ_WIN)
9612 {
9613 win_T *save_curwin;
9614 save_curwin = curwin;
9615 curwin = (win_T *) from;
9616 curbuf = curwin->w_buffer;
9617 varp = get_varp(p);
9618 curwin = save_curwin;
9619 curbuf = curwin->w_buffer;
9620 }
9621 if (varp == p->var)
9622 return (r | SOPT_UNSET);
9623 }
9624
9625 if (varp != NULL)
9626 {
9627 if (p->flags & P_STRING)
9628 *stringval = vim_strsave(*(char_u **)(varp));
9629 else if (p->flags & P_NUM)
9630 *numval = *(long *) varp;
9631 else
9632 *numval = *(int *)varp;
9633 }
9634
9635 return r;
9636}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009637
9638/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009639 * Iterate over options. First argument is a pointer to a pointer to a
9640 * structure inside options[] array, second is option type like in the above
9641 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009642 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009643 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009644 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009645 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009646 * first argument to NULL.
9647 *
9648 * Returns full option name for current option on each call.
9649 */
9650 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009651option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009652{
9653 struct vimoption *ret = NULL;
9654 do
9655 {
9656 if (*option == NULL)
9657 *option = (void *) options;
9658 else if (((struct vimoption *) (*option))->fullname == NULL)
9659 {
9660 *option = NULL;
9661 return NULL;
9662 }
9663 else
9664 *option = (void *) (((struct vimoption *) (*option)) + 1);
9665
9666 ret = ((struct vimoption *) (*option));
9667
9668 /* Hidden option */
9669 if (ret->var == NULL)
9670 {
9671 ret = NULL;
9672 continue;
9673 }
9674
9675 switch (opt_type)
9676 {
9677 case SREQ_GLOBAL:
9678 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9679 ret = NULL;
9680 break;
9681 case SREQ_BUF:
9682 if (!(ret->indir & PV_BUF))
9683 ret = NULL;
9684 break;
9685 case SREQ_WIN:
9686 if (!(ret->indir & PV_WIN))
9687 ret = NULL;
9688 break;
9689 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009690 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009691 return NULL;
9692 }
9693 }
9694 while (ret == NULL);
9695
9696 return (char_u *)ret->fullname;
9697}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009698#endif
9699
Bram Moolenaar071d4272004-06-13 20:20:40 +00009700/*
9701 * Set the value of option "name".
9702 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009703 *
9704 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009705 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009706 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009707set_option_value(
9708 char_u *name,
9709 long number,
9710 char_u *string,
9711 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009712{
9713 int opt_idx;
9714 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009715 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716
9717 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009718 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009719 {
9720 int key;
9721
9722 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9723 && (key = find_key_option(name)) != 0)
9724 {
9725 char_u key_name[2];
9726
9727 if (key < 0)
9728 {
9729 key_name[0] = KEY2TERMCAP0(key);
9730 key_name[1] = KEY2TERMCAP1(key);
9731 }
9732 else
9733 {
9734 key_name[0] = KS_KEY;
9735 key_name[1] = (key & 0xff);
9736 }
9737 add_termcode(key_name, string, FALSE);
9738 if (full_screen)
9739 ttest(FALSE);
9740 redraw_all_later(CLEAR);
9741 return NULL;
9742 }
9743
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009745 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009746 else
9747 {
9748 flags = options[opt_idx].flags;
9749#ifdef HAVE_SANDBOX
9750 /* Disallow changing some options in the sandbox */
9751 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009752 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009753 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009754 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009757 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009758 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759 else
9760 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009761 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762 if (varp != NULL) /* hidden option is not changed */
9763 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009764 if (number == 0 && string != NULL)
9765 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009766 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009767
9768 /* Either we are given a string or we are setting option
9769 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009770 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009771 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009772 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009773 {
9774 /* There's another character after zeros or the string
9775 * is empty. In both cases, we are trying to set a
9776 * num option using a string. */
9777 EMSG3(_("E521: Number required: &%s = '%s'"),
9778 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009779 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009780
9781 }
9782 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009784 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009785 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009786 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009787 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009788 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009789 }
9790 }
9791 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009792 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009793}
9794
9795/*
9796 * Get the terminal code for a terminal option.
9797 * Returns NULL when not found.
9798 */
9799 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009800get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009801{
9802 int opt_idx;
9803 char_u *varp;
9804
9805 if (tname[0] != 't' || tname[1] != '_' ||
9806 tname[2] == NUL || tname[3] == NUL)
9807 return NULL;
9808 if ((opt_idx = findoption(tname)) >= 0)
9809 {
9810 varp = get_varp(&(options[opt_idx]));
9811 if (varp != NULL)
9812 varp = *(char_u **)(varp);
9813 return varp;
9814 }
9815 return find_termcode(tname + 2);
9816}
9817
9818 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009819get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009820{
9821 int i;
9822
9823 i = findoption((char_u *)"hl");
9824 if (i >= 0)
9825 return options[i].def_val[VI_DEFAULT];
9826 return (char_u *)NULL;
9827}
9828
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009829#if defined(FEAT_MBYTE) || defined(PROTO)
9830 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009831get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009832{
9833 int i;
9834
9835 i = findoption((char_u *)"enc");
9836 if (i >= 0)
9837 return options[i].def_val[VI_DEFAULT];
9838 return (char_u *)NULL;
9839}
9840#endif
9841
Bram Moolenaar071d4272004-06-13 20:20:40 +00009842/*
9843 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9844 */
9845 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009846find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009847{
9848 int key;
9849 int modifiers;
9850
9851 /*
9852 * Don't use get_special_key_code() for t_xx, we don't want it to call
9853 * add_termcap_entry().
9854 */
9855 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9856 key = TERMCAP2KEY(arg[2], arg[3]);
9857 else
9858 {
9859 --arg; /* put arg at the '<' */
9860 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009861 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009862 if (modifiers) /* can't handle modifiers here */
9863 key = 0;
9864 }
9865 return key;
9866}
9867
9868/*
9869 * if 'all' == 0: show changed options
9870 * if 'all' == 1: show all normal options
9871 * if 'all' == 2: show all terminal options
9872 */
9873 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009874showoptions(
9875 int all,
9876 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877{
9878 struct vimoption *p;
9879 int col;
9880 int isterm;
9881 char_u *varp;
9882 struct vimoption **items;
9883 int item_count;
9884 int run;
9885 int row, rows;
9886 int cols;
9887 int i;
9888 int len;
9889
9890#define INC 20
9891#define GAP 3
9892
9893 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9894 PARAM_COUNT));
9895 if (items == NULL)
9896 return;
9897
9898 /* Highlight title */
9899 if (all == 2)
9900 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9901 else if (opt_flags & OPT_GLOBAL)
9902 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9903 else if (opt_flags & OPT_LOCAL)
9904 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9905 else
9906 MSG_PUTS_TITLE(_("\n--- Options ---"));
9907
9908 /*
9909 * do the loop two times:
9910 * 1. display the short items
9911 * 2. display the long items (only strings and numbers)
9912 */
9913 for (run = 1; run <= 2 && !got_int; ++run)
9914 {
9915 /*
9916 * collect the items in items[]
9917 */
9918 item_count = 0;
9919 for (p = &options[0]; p->fullname != NULL; p++)
9920 {
9921 varp = NULL;
9922 isterm = istermoption(p);
9923 if (opt_flags != 0)
9924 {
9925 if (p->indir != PV_NONE && !isterm)
9926 varp = get_varp_scope(p, opt_flags);
9927 }
9928 else
9929 varp = get_varp(p);
9930 if (varp != NULL
9931 && ((all == 2 && isterm)
9932 || (all == 1 && !isterm)
9933 || (all == 0 && !optval_default(p, varp))))
9934 {
9935 if (p->flags & P_BOOL)
9936 len = 1; /* a toggle option fits always */
9937 else
9938 {
9939 option_value2string(p, opt_flags);
9940 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9941 }
9942 if ((len <= INC - GAP && run == 1) ||
9943 (len > INC - GAP && run == 2))
9944 items[item_count++] = p;
9945 }
9946 }
9947
9948 /*
9949 * display the items
9950 */
9951 if (run == 1)
9952 {
9953 cols = (Columns + GAP - 3) / INC;
9954 if (cols == 0)
9955 cols = 1;
9956 rows = (item_count + cols - 1) / cols;
9957 }
9958 else /* run == 2 */
9959 rows = item_count;
9960 for (row = 0; row < rows && !got_int; ++row)
9961 {
9962 msg_putchar('\n'); /* go to next line */
9963 if (got_int) /* 'q' typed in more */
9964 break;
9965 col = 0;
9966 for (i = row; i < item_count; i += rows)
9967 {
9968 msg_col = col; /* make columns */
9969 showoneopt(items[i], opt_flags);
9970 col += INC;
9971 }
9972 out_flush();
9973 ui_breakcheck();
9974 }
9975 }
9976 vim_free(items);
9977}
9978
9979/*
9980 * Return TRUE if option "p" has its default value.
9981 */
9982 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009983optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984{
9985 int dvi;
9986
9987 if (varp == NULL)
9988 return TRUE; /* hidden option is always at default */
9989 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9990 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009991 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009993 /* the cast to long is required for Manx C, long_i is
9994 * needed for MSVC */
9995 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996 /* P_STRING */
9997 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9998}
9999
10000/*
10001 * showoneopt: show the value of one option
10002 * must not be called with a hidden option!
10003 */
10004 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010005showoneopt(
10006 struct vimoption *p,
10007 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010009 char_u *varp;
10010 int save_silent = silent_mode;
10011
10012 silent_mode = FALSE;
10013 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014
10015 varp = get_varp_scope(p, opt_flags);
10016
10017 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10018 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10019 ? !curbufIsChanged() : !*(int *)varp))
10020 MSG_PUTS("no");
10021 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10022 MSG_PUTS("--");
10023 else
10024 MSG_PUTS(" ");
10025 MSG_PUTS(p->fullname);
10026 if (!(p->flags & P_BOOL))
10027 {
10028 msg_putchar('=');
10029 /* put value string in NameBuff */
10030 option_value2string(p, opt_flags);
10031 msg_outtrans(NameBuff);
10032 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010033
10034 silent_mode = save_silent;
10035 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010036}
10037
10038/*
10039 * Write modified options as ":set" commands to a file.
10040 *
10041 * There are three values for "opt_flags":
10042 * OPT_GLOBAL: Write global option values and fresh values of
10043 * buffer-local options (used for start of a session
10044 * file).
10045 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10046 * curwin (used for a vimrc file).
10047 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10048 * and local values for window-local options of
10049 * curwin. Local values are also written when at the
10050 * default value, because a modeline or autocommand
10051 * may have set them when doing ":edit file" and the
10052 * user has set them back at the default or fresh
10053 * value.
10054 * When "local_only" is TRUE, don't write fresh
10055 * values, only local values (for ":mkview").
10056 * (fresh value = value used for a new buffer or window for a local option).
10057 *
10058 * Return FAIL on error, OK otherwise.
10059 */
10060 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010061makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062{
10063 struct vimoption *p;
10064 char_u *varp; /* currently used value */
10065 char_u *varp_fresh; /* local value */
10066 char_u *varp_local = NULL; /* fresh value */
10067 char *cmd;
10068 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010069 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070
10071 /*
10072 * The options that don't have a default (terminal name, columns, lines)
10073 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010074 * Do the loop over "options[]" twice: once for options with the
10075 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010076 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010077 for (pri = 1; pri >= 0; --pri)
10078 {
10079 for (p = &options[0]; !istermoption(p); p++)
10080 if (!(p->flags & P_NO_MKRC)
10081 && !istermoption(p)
10082 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010083 {
10084 /* skip global option when only doing locals */
10085 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10086 continue;
10087
10088 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10089 * file, they are always buffer-specific. */
10090 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10091 continue;
10092
10093 /* Global values are only written when not at the default value. */
10094 varp = get_varp_scope(p, opt_flags);
10095 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10096 continue;
10097
10098 round = 2;
10099 if (p->indir != PV_NONE)
10100 {
10101 if (p->var == VAR_WIN)
10102 {
10103 /* skip window-local option when only doing globals */
10104 if (!(opt_flags & OPT_LOCAL))
10105 continue;
10106 /* When fresh value of window-local option is not at the
10107 * default, need to write it too. */
10108 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10109 {
10110 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10111 if (!optval_default(p, varp_fresh))
10112 {
10113 round = 1;
10114 varp_local = varp;
10115 varp = varp_fresh;
10116 }
10117 }
10118 }
10119 }
10120
10121 /* Round 1: fresh value for window-local options.
10122 * Round 2: other values */
10123 for ( ; round <= 2; varp = varp_local, ++round)
10124 {
10125 if (round == 1 || (opt_flags & OPT_GLOBAL))
10126 cmd = "set";
10127 else
10128 cmd = "setlocal";
10129
10130 if (p->flags & P_BOOL)
10131 {
10132 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10133 return FAIL;
10134 }
10135 else if (p->flags & P_NUM)
10136 {
10137 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10138 return FAIL;
10139 }
10140 else /* P_STRING */
10141 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010142#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10143 int do_endif = FALSE;
10144
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145 /* Don't set 'syntax' and 'filetype' again if the value is
10146 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010147 if (
10148# if defined(FEAT_SYN_HL)
10149 p->indir == PV_SYN
10150# if defined(FEAT_AUTOCMD)
10151 ||
10152# endif
10153# endif
10154# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010155 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010156# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010157 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158 {
10159 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10160 *(char_u **)(varp)) < 0
10161 || put_eol(fd) < 0)
10162 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010163 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010165#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10167 (p->flags & P_EXPAND) != 0) == FAIL)
10168 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010169#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10170 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 {
10172 if (put_line(fd, "endif") == FAIL)
10173 return FAIL;
10174 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010175#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010176 }
10177 }
10178 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180 return OK;
10181}
10182
10183#if defined(FEAT_FOLDING) || defined(PROTO)
10184/*
10185 * Generate set commands for the local fold options only. Used when
10186 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10187 */
10188 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010189makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190{
10191 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10192# ifdef FEAT_EVAL
10193 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10194 == FAIL
10195# endif
10196 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10197 == FAIL
10198 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10199 == FAIL
10200 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10201 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10202 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10203 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10204 )
10205 return FAIL;
10206
10207 return OK;
10208}
10209#endif
10210
10211 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010212put_setstring(
10213 FILE *fd,
10214 char *cmd,
10215 char *name,
10216 char_u **valuep,
10217 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218{
10219 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010220 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221
10222 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10223 return FAIL;
10224 if (*valuep != NULL)
10225 {
10226 /* Output 'pastetoggle' as key names. For other
10227 * options some characters have to be escaped with
10228 * CTRL-V or backslash */
10229 if (valuep == &p_pt)
10230 {
10231 s = *valuep;
10232 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010233 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234 return FAIL;
10235 }
10236 else if (expand)
10237 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010238 buf = alloc(MAXPATHL);
10239 if (buf == NULL)
10240 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10242 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010243 {
10244 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010245 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010246 }
10247 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248 }
10249 else if (put_escstr(fd, *valuep, 2) == FAIL)
10250 return FAIL;
10251 }
10252 if (put_eol(fd) < 0)
10253 return FAIL;
10254 return OK;
10255}
10256
10257 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010258put_setnum(
10259 FILE *fd,
10260 char *cmd,
10261 char *name,
10262 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010263{
10264 long wc;
10265
10266 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10267 return FAIL;
10268 if (wc_use_keyname((char_u *)valuep, &wc))
10269 {
10270 /* print 'wildchar' and 'wildcharm' as a key name */
10271 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10272 return FAIL;
10273 }
10274 else if (fprintf(fd, "%ld", *valuep) < 0)
10275 return FAIL;
10276 if (put_eol(fd) < 0)
10277 return FAIL;
10278 return OK;
10279}
10280
10281 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010282put_setbool(
10283 FILE *fd,
10284 char *cmd,
10285 char *name,
10286 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010287{
Bram Moolenaar893de922007-10-02 18:40:57 +000010288 if (value < 0) /* global/local option using global value */
10289 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10291 || put_eol(fd) < 0)
10292 return FAIL;
10293 return OK;
10294}
10295
10296/*
10297 * Clear all the terminal options.
10298 * If the option has been allocated, free the memory.
10299 * Terminal options are never hidden or indirect.
10300 */
10301 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010302clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010304 /*
10305 * Reset a few things before clearing the old options. This may cause
10306 * outputting a few things that the terminal doesn't understand, but the
10307 * screen will be cleared later, so this is OK.
10308 */
10309#ifdef FEAT_MOUSE_TTY
10310 mch_setmouse(FALSE); /* switch mouse off */
10311#endif
10312#ifdef FEAT_TITLE
10313 mch_restore_title(3); /* restore window titles */
10314#endif
10315#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10316 /* When starting the GUI close the display opened for the clipboard.
10317 * After restoring the title, because that will need the display. */
10318 if (gui.starting)
10319 clear_xterm_clip();
10320#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010321 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010323 free_termoptions();
10324}
10325
10326 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010327free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010328{
10329 struct vimoption *p;
10330
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 for (p = &options[0]; p->fullname != NULL; p++)
10332 if (istermoption(p))
10333 {
10334 if (p->flags & P_ALLOCED)
10335 free_string_option(*(char_u **)(p->var));
10336 if (p->flags & P_DEF_ALLOCED)
10337 free_string_option(p->def_val[VI_DEFAULT]);
10338 *(char_u **)(p->var) = empty_option;
10339 p->def_val[VI_DEFAULT] = empty_option;
10340 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10341 }
10342 clear_termcodes();
10343}
10344
10345/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010346 * Free the string for one term option, if it was allocated.
10347 * Set the string to empty_option and clear allocated flag.
10348 * "var" points to the option value.
10349 */
10350 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010351free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010352{
10353 struct vimoption *p;
10354
10355 for (p = &options[0]; p->fullname != NULL; p++)
10356 if (p->var == var)
10357 {
10358 if (p->flags & P_ALLOCED)
10359 free_string_option(*(char_u **)(p->var));
10360 *(char_u **)(p->var) = empty_option;
10361 p->flags &= ~P_ALLOCED;
10362 break;
10363 }
10364}
10365
10366/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010367 * Set the terminal option defaults to the current value.
10368 * Used after setting the terminal name.
10369 */
10370 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010371set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372{
10373 struct vimoption *p;
10374
10375 for (p = &options[0]; p->fullname != NULL; p++)
10376 {
10377 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10378 {
10379 if (p->flags & P_DEF_ALLOCED)
10380 {
10381 free_string_option(p->def_val[VI_DEFAULT]);
10382 p->flags &= ~P_DEF_ALLOCED;
10383 }
10384 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10385 if (p->flags & P_ALLOCED)
10386 {
10387 p->flags |= P_DEF_ALLOCED;
10388 p->flags &= ~P_ALLOCED; /* don't free the value now */
10389 }
10390 }
10391 }
10392}
10393
10394/*
10395 * return TRUE if 'p' starts with 't_'
10396 */
10397 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010398istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399{
10400 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10401}
10402
10403/*
10404 * Compute columns for ruler and shown command. 'sc_col' is also used to
10405 * decide what the maximum length of a message on the status line can be.
10406 * If there is a status line for the last window, 'sc_col' is independent
10407 * of 'ru_col'.
10408 */
10409
10410#define COL_RULER 17 /* columns needed by standard ruler */
10411
10412 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010413comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010414{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010415#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010416 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417
10418 sc_col = 0;
10419 ru_col = 0;
10420 if (p_ru)
10421 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010422# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010423 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010424# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010425 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010426# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010427 /* no last status line, adjust sc_col */
10428 if (!last_has_status)
10429 sc_col = ru_col;
10430 }
10431 if (p_sc)
10432 {
10433 sc_col += SHOWCMD_COLS;
10434 if (!p_ru || last_has_status) /* no need for separating space */
10435 ++sc_col;
10436 }
10437 sc_col = Columns - sc_col;
10438 ru_col = Columns - ru_col;
10439 if (sc_col <= 0) /* screen too narrow, will become a mess */
10440 sc_col = 1;
10441 if (ru_col <= 0)
10442 ru_col = 1;
10443#else
10444 sc_col = Columns;
10445 ru_col = Columns;
10446#endif
10447}
10448
10449/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010450 * Unset local option value, similar to ":set opt<".
10451 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010453unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010454{
10455 struct vimoption *p;
10456 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010457 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010458
10459 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010460 if (opt_idx < 0)
10461 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010462 p = &(options[opt_idx]);
10463
10464 switch ((int)p->indir)
10465 {
10466 /* global option with local value: use local value if it's been set */
10467 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010468 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010469 break;
10470 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010471 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010472 break;
10473 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010474 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010475 break;
10476 case PV_AR:
10477 buf->b_p_ar = -1;
10478 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010479 case PV_BKC:
10480 clear_string_option(&buf->b_p_bkc);
10481 buf->b_bkc_flags = 0;
10482 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010483 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010484 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010485 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010486 case PV_TC:
10487 clear_string_option(&buf->b_p_tc);
10488 buf->b_tc_flags = 0;
10489 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010490#ifdef FEAT_FIND_ID
10491 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010492 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010493 break;
10494 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010495 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010496 break;
10497#endif
10498#ifdef FEAT_INS_EXPAND
10499 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010500 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010501 break;
10502 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010503 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010504 break;
10505#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010506 case PV_FP:
10507 clear_string_option(&buf->b_p_fp);
10508 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010509#ifdef FEAT_QUICKFIX
10510 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010511 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010512 break;
10513 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010514 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010515 break;
10516 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010517 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010518 break;
10519#endif
10520#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10521 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010522 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010523 break;
10524#endif
10525#if defined(FEAT_CRYPT)
10526 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010527 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010528 break;
10529#endif
10530#ifdef FEAT_STL_OPT
10531 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010532 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010533 break;
10534#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010535 case PV_UL:
10536 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10537 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010538#ifdef FEAT_LISP
10539 case PV_LW:
10540 clear_string_option(&buf->b_p_lw);
10541 break;
10542#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010543#ifdef FEAT_MBYTE
10544 case PV_MENC:
10545 clear_string_option(&buf->b_p_menc);
10546 break;
10547#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010548 }
10549}
10550
10551/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552 * Get pointer to option variable, depending on local or global scope.
10553 */
10554 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010555get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556{
10557 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10558 {
10559 if (p->var == VAR_WIN)
10560 return (char_u *)GLOBAL_WO(get_varp(p));
10561 return p->var;
10562 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010563 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564 {
10565 switch ((int)p->indir)
10566 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010567 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010569 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10570 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10571 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010573 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10574 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10575 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010576 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010577 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010578 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010580 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10581 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582#endif
10583#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10585 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010587#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10588 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10589#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010590#if defined(FEAT_CRYPT)
10591 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10592#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010593#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010594 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010595#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010596 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010597#ifdef FEAT_LISP
10598 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10599#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010600 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010601#ifdef FEAT_MBYTE
10602 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10603#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604 }
10605 return NULL; /* "cannot happen" */
10606 }
10607 return get_varp(p);
10608}
10609
10610/*
10611 * Get pointer to option variable.
10612 */
10613 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010614get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615{
10616 /* hidden option, always return NULL */
10617 if (p->var == NULL)
10618 return NULL;
10619
10620 switch ((int)p->indir)
10621 {
10622 case PV_NONE: return p->var;
10623
10624 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010625 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010627 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010629 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010631 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010632 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010633 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010635 case PV_TC: return *curbuf->b_p_tc != NUL
10636 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010637 case PV_BKC: return *curbuf->b_p_bkc != NUL
10638 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010640 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010641 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010642 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10644#endif
10645#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010646 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010648 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010649 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10650#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010651 case PV_FP: return *curbuf->b_p_fp != NUL
10652 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010654 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010656 case PV_GP: return *curbuf->b_p_gp != NUL
10657 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10658 case PV_MP: return *curbuf->b_p_mp != NUL
10659 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010660#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010661#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10662 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10663 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10664#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010665#if defined(FEAT_CRYPT)
10666 case PV_CM: return *curbuf->b_p_cm != NUL
10667 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10668#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010669#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010670 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010671 ? (char_u *)&(curwin->w_p_stl) : p->var;
10672#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010673 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10674 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010675#ifdef FEAT_LISP
10676 case PV_LW: return *curbuf->b_p_lw != NUL
10677 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10678#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010679#ifdef FEAT_MBYTE
10680 case PV_MENC: return *curbuf->b_p_menc != NUL
10681 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010683
10684#ifdef FEAT_ARABIC
10685 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10686#endif
10687 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010688#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010689 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10690#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010691#ifdef FEAT_SYN_HL
10692 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10693 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010694 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010696#ifdef FEAT_DIFF
10697 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10698#endif
10699#ifdef FEAT_FOLDING
10700 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10701 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10702 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10703 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10704 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10705 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10706 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10707# ifdef FEAT_EVAL
10708 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10709 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10710# endif
10711 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10712#endif
10713 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010714 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010715#ifdef FEAT_LINEBREAK
10716 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010719 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010720#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10722#endif
10723#ifdef FEAT_RIGHTLEFT
10724 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10725 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10726#endif
10727 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10728 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10729#ifdef FEAT_LINEBREAK
10730 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010731 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10732 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010733#endif
10734#ifdef FEAT_SCROLLBIND
10735 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10736#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010737#ifdef FEAT_CURSORBIND
10738 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10739#endif
10740#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010741 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10742 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10743#endif
10744#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010745 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010746 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010747#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748
10749 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10750 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10751#ifdef FEAT_MBYTE
10752 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10755 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010756 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10757 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10758#ifdef FEAT_CINDENT
10759 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10760 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10761 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10762#endif
10763#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10764 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10765#endif
10766#ifdef FEAT_COMMENTS
10767 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10768#endif
10769#ifdef FEAT_FOLDING
10770 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10771#endif
10772#ifdef FEAT_INS_EXPAND
10773 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10774#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010775#ifdef FEAT_COMPL_FUNC
10776 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010777 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010780 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10782#ifdef FEAT_MBYTE
10783 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10784#endif
10785 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10786#ifdef FEAT_AUTOCMD
10787 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10788#endif
10789 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010790 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10792 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10793 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10794 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10795#ifdef FEAT_FIND_ID
10796# ifdef FEAT_EVAL
10797 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10798# endif
10799#endif
10800#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10801 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10802 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10803#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010804#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010805 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807#ifdef FEAT_CRYPT
10808 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10809#endif
10810#ifdef FEAT_LISP
10811 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10812#endif
10813 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10814 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10815 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10816 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10817 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010819#ifdef FEAT_TEXTOBJ
10820 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10821#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10823#ifdef FEAT_SMARTINDENT
10824 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10825#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10828#ifdef FEAT_SEARCHPATH
10829 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10830#endif
10831 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10832#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010833 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010834 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10835#endif
10836#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010837 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10838 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10839 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840#endif
10841 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10842 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10843 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10844 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010845#ifdef FEAT_PERSISTENT_UNDO
10846 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10849#ifdef FEAT_KEYMAP
10850 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10851#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010852#ifdef FEAT_SIGNS
10853 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10854#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010855 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856 }
10857 /* always return a valid pointer to avoid a crash! */
10858 return (char_u *)&(curbuf->b_p_wm);
10859}
10860
10861/*
10862 * Get the value of 'equalprg', either the buffer-local one or the global one.
10863 */
10864 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010865get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866{
10867 if (*curbuf->b_p_ep == NUL)
10868 return p_ep;
10869 return curbuf->b_p_ep;
10870}
10871
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872/*
10873 * Copy options from one window to another.
10874 * Used when splitting a window.
10875 */
10876 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010877win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878{
10879 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10880 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10881# ifdef FEAT_RIGHTLEFT
10882# ifdef FEAT_FKMAP
10883 /* Is this right? */
10884 wp_to->w_farsi = wp_from->w_farsi;
10885# endif
10886# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010887#if defined(FEAT_LINEBREAK)
10888 briopt_check(wp_to);
10889#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891
10892/*
10893 * Copy the options from one winopt_T to another.
10894 * Doesn't free the old option values in "to", use clear_winopt() for that.
10895 * The 'scroll' option is not copied, because it depends on the window height.
10896 * The 'previewwindow' option is reset, there can be only one preview window.
10897 */
10898 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010899copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900{
10901#ifdef FEAT_ARABIC
10902 to->wo_arab = from->wo_arab;
10903#endif
10904 to->wo_list = from->wo_list;
10905 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010906 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010907#ifdef FEAT_LINEBREAK
10908 to->wo_nuw = from->wo_nuw;
10909#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010910#ifdef FEAT_RIGHTLEFT
10911 to->wo_rl = from->wo_rl;
10912 to->wo_rlc = vim_strsave(from->wo_rlc);
10913#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010914#ifdef FEAT_STL_OPT
10915 to->wo_stl = vim_strsave(from->wo_stl);
10916#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010917 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010918#ifdef FEAT_DIFF
10919 to->wo_wrap_save = from->wo_wrap_save;
10920#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921#ifdef FEAT_LINEBREAK
10922 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010923 to->wo_bri = from->wo_bri;
10924 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010925#endif
10926#ifdef FEAT_SCROLLBIND
10927 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010928 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010930#ifdef FEAT_CURSORBIND
10931 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010932 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010933#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010934#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010935 to->wo_spell = from->wo_spell;
10936#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010937#ifdef FEAT_SYN_HL
10938 to->wo_cuc = from->wo_cuc;
10939 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010940 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010941#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942#ifdef FEAT_DIFF
10943 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010944 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010946#ifdef FEAT_CONCEAL
10947 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010948 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010949#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010950#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010951 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010952 to->wo_tms = vim_strsave(from->wo_tms);
10953#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954#ifdef FEAT_FOLDING
10955 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010956 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010958 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010959 to->wo_fdi = vim_strsave(from->wo_fdi);
10960 to->wo_fml = from->wo_fml;
10961 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010962 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010964 to->wo_fdm_save = from->wo_diff_saved
10965 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010966 to->wo_fdn = from->wo_fdn;
10967# ifdef FEAT_EVAL
10968 to->wo_fde = vim_strsave(from->wo_fde);
10969 to->wo_fdt = vim_strsave(from->wo_fdt);
10970# endif
10971 to->wo_fmr = vim_strsave(from->wo_fmr);
10972#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010973#ifdef FEAT_SIGNS
10974 to->wo_scl = vim_strsave(from->wo_scl);
10975#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010976 check_winopt(to); /* don't want NULL pointers */
10977}
10978
10979/*
10980 * Check string options in a window for a NULL value.
10981 */
10982 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010983check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010984{
10985 check_winopt(&win->w_onebuf_opt);
10986 check_winopt(&win->w_allbuf_opt);
10987}
10988
10989/*
10990 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10991 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010992 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010993check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994{
10995#ifdef FEAT_FOLDING
10996 check_string_option(&wop->wo_fdi);
10997 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010998 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010999# ifdef FEAT_EVAL
11000 check_string_option(&wop->wo_fde);
11001 check_string_option(&wop->wo_fdt);
11002# endif
11003 check_string_option(&wop->wo_fmr);
11004#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011005#ifdef FEAT_SIGNS
11006 check_string_option(&wop->wo_scl);
11007#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011008#ifdef FEAT_RIGHTLEFT
11009 check_string_option(&wop->wo_rlc);
11010#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011011#ifdef FEAT_STL_OPT
11012 check_string_option(&wop->wo_stl);
11013#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011014#ifdef FEAT_SYN_HL
11015 check_string_option(&wop->wo_cc);
11016#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011017#ifdef FEAT_CONCEAL
11018 check_string_option(&wop->wo_cocu);
11019#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011020#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011021 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011022 check_string_option(&wop->wo_tms);
11023#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011024#ifdef FEAT_LINEBREAK
11025 check_string_option(&wop->wo_briopt);
11026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011027}
11028
11029/*
11030 * Free the allocated memory inside a winopt_T.
11031 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011032 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011033clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011034{
11035#ifdef FEAT_FOLDING
11036 clear_string_option(&wop->wo_fdi);
11037 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011038 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011039# ifdef FEAT_EVAL
11040 clear_string_option(&wop->wo_fde);
11041 clear_string_option(&wop->wo_fdt);
11042# endif
11043 clear_string_option(&wop->wo_fmr);
11044#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011045#ifdef FEAT_SIGNS
11046 clear_string_option(&wop->wo_scl);
11047#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011048#ifdef FEAT_LINEBREAK
11049 clear_string_option(&wop->wo_briopt);
11050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051#ifdef FEAT_RIGHTLEFT
11052 clear_string_option(&wop->wo_rlc);
11053#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011054#ifdef FEAT_STL_OPT
11055 clear_string_option(&wop->wo_stl);
11056#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011057#ifdef FEAT_SYN_HL
11058 clear_string_option(&wop->wo_cc);
11059#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011060#ifdef FEAT_CONCEAL
11061 clear_string_option(&wop->wo_cocu);
11062#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011063#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011064 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011065 clear_string_option(&wop->wo_tms);
11066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011067}
11068
11069/*
11070 * Copy global option values to local options for one buffer.
11071 * Used when creating a new buffer and sometimes when entering a buffer.
11072 * flags:
11073 * BCO_ENTER We will enter the buf buffer.
11074 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11075 * appropriate.
11076 * BCO_NOHELP Don't copy the values to a help buffer.
11077 */
11078 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011079buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080{
11081 int should_copy = TRUE;
11082 char_u *save_p_isk = NULL; /* init for GCC */
11083 int dont_do_help;
11084 int did_isk = FALSE;
11085
11086 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087 * Skip this when the option defaults have not been set yet. Happens when
11088 * main() allocates the first buffer.
11089 */
11090 if (p_cpo != NULL)
11091 {
11092 /*
11093 * Always copy when entering and 'cpo' contains 'S'.
11094 * Don't copy when already initialized.
11095 * Don't copy when 'cpo' contains 's' and not entering.
11096 * 'S' BCO_ENTER initialized 's' should_copy
11097 * yes yes X X TRUE
11098 * yes no yes X FALSE
11099 * no X yes X FALSE
11100 * X no no yes FALSE
11101 * X no no no TRUE
11102 * no yes no X TRUE
11103 */
11104 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11105 && (buf->b_p_initialized
11106 || (!(flags & BCO_ENTER)
11107 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11108 should_copy = FALSE;
11109
11110 if (should_copy || (flags & BCO_ALWAYS))
11111 {
11112 /* Don't copy the options specific to a help buffer when
11113 * BCO_NOHELP is given or the options were initialized already
11114 * (jumping back to a help file with CTRL-T or CTRL-O) */
11115 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11116 || buf->b_p_initialized;
11117 if (dont_do_help) /* don't free b_p_isk */
11118 {
11119 save_p_isk = buf->b_p_isk;
11120 buf->b_p_isk = NULL;
11121 }
11122 /*
11123 * Always free the allocated strings.
11124 * If not already initialized, set 'readonly' and copy 'fileformat'.
11125 */
11126 if (!buf->b_p_initialized)
11127 {
11128 free_buf_options(buf, TRUE);
11129 buf->b_p_ro = FALSE; /* don't copy readonly */
11130 buf->b_p_tx = p_tx;
11131#ifdef FEAT_MBYTE
11132 buf->b_p_fenc = vim_strsave(p_fenc);
11133#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011134 switch (*p_ffs)
11135 {
11136 case 'm':
11137 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11138 case 'd':
11139 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11140 case 'u':
11141 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11142 default:
11143 buf->b_p_ff = vim_strsave(p_ff);
11144 }
11145 if (buf->b_p_ff != NULL)
11146 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147 buf->b_p_bh = empty_option;
11148 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011149 }
11150 else
11151 free_buf_options(buf, FALSE);
11152
11153 buf->b_p_ai = p_ai;
11154 buf->b_p_ai_nopaste = p_ai_nopaste;
11155 buf->b_p_sw = p_sw;
11156 buf->b_p_tw = p_tw;
11157 buf->b_p_tw_nopaste = p_tw_nopaste;
11158 buf->b_p_tw_nobin = p_tw_nobin;
11159 buf->b_p_wm = p_wm;
11160 buf->b_p_wm_nopaste = p_wm_nopaste;
11161 buf->b_p_wm_nobin = p_wm_nobin;
11162 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011163#ifdef FEAT_MBYTE
11164 buf->b_p_bomb = p_bomb;
11165#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011166 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 buf->b_p_et = p_et;
11168 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011169 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011170 buf->b_p_ml = p_ml;
11171 buf->b_p_ml_nobin = p_ml_nobin;
11172 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011173 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011174#ifdef FEAT_INS_EXPAND
11175 buf->b_p_cpt = vim_strsave(p_cpt);
11176#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011177#ifdef FEAT_COMPL_FUNC
11178 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011179 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181 buf->b_p_sts = p_sts;
11182 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011183 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011184#ifdef FEAT_COMMENTS
11185 buf->b_p_com = vim_strsave(p_com);
11186#endif
11187#ifdef FEAT_FOLDING
11188 buf->b_p_cms = vim_strsave(p_cms);
11189#endif
11190 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011191 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011192 buf->b_p_nf = vim_strsave(p_nf);
11193 buf->b_p_mps = vim_strsave(p_mps);
11194#ifdef FEAT_SMARTINDENT
11195 buf->b_p_si = p_si;
11196#endif
11197 buf->b_p_ci = p_ci;
11198#ifdef FEAT_CINDENT
11199 buf->b_p_cin = p_cin;
11200 buf->b_p_cink = vim_strsave(p_cink);
11201 buf->b_p_cino = vim_strsave(p_cino);
11202#endif
11203#ifdef FEAT_AUTOCMD
11204 /* Don't copy 'filetype', it must be detected */
11205 buf->b_p_ft = empty_option;
11206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011207 buf->b_p_pi = p_pi;
11208#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11209 buf->b_p_cinw = vim_strsave(p_cinw);
11210#endif
11211#ifdef FEAT_LISP
11212 buf->b_p_lisp = p_lisp;
11213#endif
11214#ifdef FEAT_SYN_HL
11215 /* Don't copy 'syntax', it must be set */
11216 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011217 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011218 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011219#endif
11220#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011221 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011222 (void)compile_cap_prog(&buf->b_s);
11223 buf->b_s.b_p_spf = vim_strsave(p_spf);
11224 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225#endif
11226#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11227 buf->b_p_inde = vim_strsave(p_inde);
11228 buf->b_p_indk = vim_strsave(p_indk);
11229#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011230 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011231#if defined(FEAT_EVAL)
11232 buf->b_p_fex = vim_strsave(p_fex);
11233#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011234#ifdef FEAT_CRYPT
11235 buf->b_p_key = vim_strsave(p_key);
11236#endif
11237#ifdef FEAT_SEARCHPATH
11238 buf->b_p_sua = vim_strsave(p_sua);
11239#endif
11240#ifdef FEAT_KEYMAP
11241 buf->b_p_keymap = vim_strsave(p_keymap);
11242 buf->b_kmap_state |= KEYMAP_INIT;
11243#endif
11244 /* This isn't really an option, but copying the langmap and IME
11245 * state from the current buffer is better than resetting it. */
11246 buf->b_p_iminsert = p_iminsert;
11247 buf->b_p_imsearch = p_imsearch;
11248
11249 /* options that are normally global but also have a local value
11250 * are not copied, start using the global value */
11251 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011252 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011253 buf->b_p_bkc = empty_option;
11254 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011255#ifdef FEAT_QUICKFIX
11256 buf->b_p_gp = empty_option;
11257 buf->b_p_mp = empty_option;
11258 buf->b_p_efm = empty_option;
11259#endif
11260 buf->b_p_ep = empty_option;
11261 buf->b_p_kp = empty_option;
11262 buf->b_p_path = empty_option;
11263 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011264 buf->b_p_tc = empty_option;
11265 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266#ifdef FEAT_FIND_ID
11267 buf->b_p_def = empty_option;
11268 buf->b_p_inc = empty_option;
11269# ifdef FEAT_EVAL
11270 buf->b_p_inex = vim_strsave(p_inex);
11271# endif
11272#endif
11273#ifdef FEAT_INS_EXPAND
11274 buf->b_p_dict = empty_option;
11275 buf->b_p_tsr = empty_option;
11276#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011277#ifdef FEAT_TEXTOBJ
11278 buf->b_p_qe = vim_strsave(p_qe);
11279#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011280#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11281 buf->b_p_bexpr = empty_option;
11282#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011283#if defined(FEAT_CRYPT)
11284 buf->b_p_cm = empty_option;
11285#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011286#ifdef FEAT_PERSISTENT_UNDO
11287 buf->b_p_udf = p_udf;
11288#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011289#ifdef FEAT_LISP
11290 buf->b_p_lw = empty_option;
11291#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011292#ifdef FEAT_MBYTE
11293 buf->b_p_menc = empty_option;
11294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011295
11296 /*
11297 * Don't copy the options set by ex_help(), use the saved values,
11298 * when going from a help buffer to a non-help buffer.
11299 * Don't touch these at all when BCO_NOHELP is used and going from
11300 * or to a help buffer.
11301 */
11302 if (dont_do_help)
11303 buf->b_p_isk = save_p_isk;
11304 else
11305 {
11306 buf->b_p_isk = vim_strsave(p_isk);
11307 did_isk = TRUE;
11308 buf->b_p_ts = p_ts;
11309 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310 if (buf->b_p_bt[0] == 'h')
11311 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011312 buf->b_p_ma = p_ma;
11313 }
11314 }
11315
11316 /*
11317 * When the options should be copied (ignoring BCO_ALWAYS), set the
11318 * flag that indicates that the options have been initialized.
11319 */
11320 if (should_copy)
11321 buf->b_p_initialized = TRUE;
11322 }
11323
11324 check_buf_options(buf); /* make sure we don't have NULLs */
11325 if (did_isk)
11326 (void)buf_init_chartab(buf, FALSE);
11327}
11328
11329/*
11330 * Reset the 'modifiable' option and its default value.
11331 */
11332 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011333reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011334{
11335 int opt_idx;
11336
11337 curbuf->b_p_ma = FALSE;
11338 p_ma = FALSE;
11339 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011340 if (opt_idx >= 0)
11341 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342}
11343
11344/*
11345 * Set the global value for 'iminsert' to the local value.
11346 */
11347 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011348set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349{
11350 p_iminsert = curbuf->b_p_iminsert;
11351}
11352
11353/*
11354 * Set the global value for 'imsearch' to the local value.
11355 */
11356 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011357set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011358{
11359 p_imsearch = curbuf->b_p_imsearch;
11360}
11361
11362#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11363static int expand_option_idx = -1;
11364static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11365static int expand_option_flags = 0;
11366
11367 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011368set_context_in_set_cmd(
11369 expand_T *xp,
11370 char_u *arg,
11371 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372{
11373 int nextchar;
11374 long_u flags = 0; /* init for GCC */
11375 int opt_idx = 0; /* init for GCC */
11376 char_u *p;
11377 char_u *s;
11378 int is_term_option = FALSE;
11379 int key;
11380
11381 expand_option_flags = opt_flags;
11382
11383 xp->xp_context = EXPAND_SETTINGS;
11384 if (*arg == NUL)
11385 {
11386 xp->xp_pattern = arg;
11387 return;
11388 }
11389 p = arg + STRLEN(arg) - 1;
11390 if (*p == ' ' && *(p - 1) != '\\')
11391 {
11392 xp->xp_pattern = p + 1;
11393 return;
11394 }
11395 while (p > arg)
11396 {
11397 s = p;
11398 /* count number of backslashes before ' ' or ',' */
11399 if (*p == ' ' || *p == ',')
11400 {
11401 while (s > arg && *(s - 1) == '\\')
11402 --s;
11403 }
11404 /* break at a space with an even number of backslashes */
11405 if (*p == ' ' && ((p - s) & 1) == 0)
11406 {
11407 ++p;
11408 break;
11409 }
11410 --p;
11411 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011412 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011413 {
11414 xp->xp_context = EXPAND_BOOL_SETTINGS;
11415 p += 2;
11416 }
11417 if (STRNCMP(p, "inv", 3) == 0)
11418 {
11419 xp->xp_context = EXPAND_BOOL_SETTINGS;
11420 p += 3;
11421 }
11422 xp->xp_pattern = arg = p;
11423 if (*arg == '<')
11424 {
11425 while (*p != '>')
11426 if (*p++ == NUL) /* expand terminal option name */
11427 return;
11428 key = get_special_key_code(arg + 1);
11429 if (key == 0) /* unknown name */
11430 {
11431 xp->xp_context = EXPAND_NOTHING;
11432 return;
11433 }
11434 nextchar = *++p;
11435 is_term_option = TRUE;
11436 expand_option_name[2] = KEY2TERMCAP0(key);
11437 expand_option_name[3] = KEY2TERMCAP1(key);
11438 }
11439 else
11440 {
11441 if (p[0] == 't' && p[1] == '_')
11442 {
11443 p += 2;
11444 if (*p != NUL)
11445 ++p;
11446 if (*p == NUL)
11447 return; /* expand option name */
11448 nextchar = *++p;
11449 is_term_option = TRUE;
11450 expand_option_name[2] = p[-2];
11451 expand_option_name[3] = p[-1];
11452 }
11453 else
11454 {
11455 /* Allow * wildcard */
11456 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11457 p++;
11458 if (*p == NUL)
11459 return;
11460 nextchar = *p;
11461 *p = NUL;
11462 opt_idx = findoption(arg);
11463 *p = nextchar;
11464 if (opt_idx == -1 || options[opt_idx].var == NULL)
11465 {
11466 xp->xp_context = EXPAND_NOTHING;
11467 return;
11468 }
11469 flags = options[opt_idx].flags;
11470 if (flags & P_BOOL)
11471 {
11472 xp->xp_context = EXPAND_NOTHING;
11473 return;
11474 }
11475 }
11476 }
11477 /* handle "-=" and "+=" */
11478 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11479 {
11480 ++p;
11481 nextchar = '=';
11482 }
11483 if ((nextchar != '=' && nextchar != ':')
11484 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11485 {
11486 xp->xp_context = EXPAND_UNSUCCESSFUL;
11487 return;
11488 }
11489 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11490 {
11491 xp->xp_context = EXPAND_OLD_SETTING;
11492 if (is_term_option)
11493 expand_option_idx = -1;
11494 else
11495 expand_option_idx = opt_idx;
11496 xp->xp_pattern = p + 1;
11497 return;
11498 }
11499 xp->xp_context = EXPAND_NOTHING;
11500 if (is_term_option || (flags & P_NUM))
11501 return;
11502
11503 xp->xp_pattern = p + 1;
11504
11505 if (flags & P_EXPAND)
11506 {
11507 p = options[opt_idx].var;
11508 if (p == (char_u *)&p_bdir
11509 || p == (char_u *)&p_dir
11510 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011511 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011512 || p == (char_u *)&p_rtp
11513#ifdef FEAT_SEARCHPATH
11514 || p == (char_u *)&p_cdpath
11515#endif
11516#ifdef FEAT_SESSION
11517 || p == (char_u *)&p_vdir
11518#endif
11519 )
11520 {
11521 xp->xp_context = EXPAND_DIRECTORIES;
11522 if (p == (char_u *)&p_path
11523#ifdef FEAT_SEARCHPATH
11524 || p == (char_u *)&p_cdpath
11525#endif
11526 )
11527 xp->xp_backslash = XP_BS_THREE;
11528 else
11529 xp->xp_backslash = XP_BS_ONE;
11530 }
11531 else
11532 {
11533 xp->xp_context = EXPAND_FILES;
11534 /* for 'tags' need three backslashes for a space */
11535 if (p == (char_u *)&p_tags)
11536 xp->xp_backslash = XP_BS_THREE;
11537 else
11538 xp->xp_backslash = XP_BS_ONE;
11539 }
11540 }
11541
11542 /* For an option that is a list of file names, find the start of the
11543 * last file name. */
11544 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11545 {
11546 /* count number of backslashes before ' ' or ',' */
11547 if (*p == ' ' || *p == ',')
11548 {
11549 s = p;
11550 while (s > xp->xp_pattern && *(s - 1) == '\\')
11551 --s;
11552 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11553 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11554 {
11555 xp->xp_pattern = p + 1;
11556 break;
11557 }
11558 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011559
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011560#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011561 /* for 'spellsuggest' start at "file:" */
11562 if (options[opt_idx].var == (char_u *)&p_sps
11563 && STRNCMP(p, "file:", 5) == 0)
11564 {
11565 xp->xp_pattern = p + 5;
11566 break;
11567 }
11568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011569 }
11570
11571 return;
11572}
11573
11574 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011575ExpandSettings(
11576 expand_T *xp,
11577 regmatch_T *regmatch,
11578 int *num_file,
11579 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580{
11581 int num_normal = 0; /* Nr of matching non-term-code settings */
11582 int num_term = 0; /* Nr of matching terminal code settings */
11583 int opt_idx;
11584 int match;
11585 int count = 0;
11586 char_u *str;
11587 int loop;
11588 int is_term_opt;
11589 char_u name_buf[MAX_KEY_NAME_LEN];
11590 static char *(names[]) = {"all", "termcap"};
11591 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11592
11593 /* do this loop twice:
11594 * loop == 0: count the number of matching options
11595 * loop == 1: copy the matching options into allocated memory
11596 */
11597 for (loop = 0; loop <= 1; ++loop)
11598 {
11599 regmatch->rm_ic = ic;
11600 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11601 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011602 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11603 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011604 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11605 {
11606 if (loop == 0)
11607 num_normal++;
11608 else
11609 (*file)[count++] = vim_strsave((char_u *)names[match]);
11610 }
11611 }
11612 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11613 opt_idx++)
11614 {
11615 if (options[opt_idx].var == NULL)
11616 continue;
11617 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11618 && !(options[opt_idx].flags & P_BOOL))
11619 continue;
11620 is_term_opt = istermoption(&options[opt_idx]);
11621 if (is_term_opt && num_normal > 0)
11622 continue;
11623 match = FALSE;
11624 if (vim_regexec(regmatch, str, (colnr_T)0)
11625 || (options[opt_idx].shortname != NULL
11626 && vim_regexec(regmatch,
11627 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11628 match = TRUE;
11629 else if (is_term_opt)
11630 {
11631 name_buf[0] = '<';
11632 name_buf[1] = 't';
11633 name_buf[2] = '_';
11634 name_buf[3] = str[2];
11635 name_buf[4] = str[3];
11636 name_buf[5] = '>';
11637 name_buf[6] = NUL;
11638 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11639 {
11640 match = TRUE;
11641 str = name_buf;
11642 }
11643 }
11644 if (match)
11645 {
11646 if (loop == 0)
11647 {
11648 if (is_term_opt)
11649 num_term++;
11650 else
11651 num_normal++;
11652 }
11653 else
11654 (*file)[count++] = vim_strsave(str);
11655 }
11656 }
11657 /*
11658 * Check terminal key codes, these are not in the option table
11659 */
11660 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11661 {
11662 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11663 {
11664 if (!isprint(str[0]) || !isprint(str[1]))
11665 continue;
11666
11667 name_buf[0] = 't';
11668 name_buf[1] = '_';
11669 name_buf[2] = str[0];
11670 name_buf[3] = str[1];
11671 name_buf[4] = NUL;
11672
11673 match = FALSE;
11674 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11675 match = TRUE;
11676 else
11677 {
11678 name_buf[0] = '<';
11679 name_buf[1] = 't';
11680 name_buf[2] = '_';
11681 name_buf[3] = str[0];
11682 name_buf[4] = str[1];
11683 name_buf[5] = '>';
11684 name_buf[6] = NUL;
11685
11686 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11687 match = TRUE;
11688 }
11689 if (match)
11690 {
11691 if (loop == 0)
11692 num_term++;
11693 else
11694 (*file)[count++] = vim_strsave(name_buf);
11695 }
11696 }
11697
11698 /*
11699 * Check special key names.
11700 */
11701 regmatch->rm_ic = TRUE; /* ignore case here */
11702 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11703 {
11704 name_buf[0] = '<';
11705 STRCPY(name_buf + 1, str);
11706 STRCAT(name_buf, ">");
11707
11708 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11709 {
11710 if (loop == 0)
11711 num_term++;
11712 else
11713 (*file)[count++] = vim_strsave(name_buf);
11714 }
11715 }
11716 }
11717 if (loop == 0)
11718 {
11719 if (num_normal > 0)
11720 *num_file = num_normal;
11721 else if (num_term > 0)
11722 *num_file = num_term;
11723 else
11724 return OK;
11725 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11726 if (*file == NULL)
11727 {
11728 *file = (char_u **)"";
11729 return FAIL;
11730 }
11731 }
11732 }
11733 return OK;
11734}
11735
11736 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011737ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011738{
11739 char_u *var = NULL; /* init for GCC */
11740 char_u *buf;
11741
11742 *num_file = 0;
11743 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11744 if (*file == NULL)
11745 return FAIL;
11746
11747 /*
11748 * For a terminal key code expand_option_idx is < 0.
11749 */
11750 if (expand_option_idx < 0)
11751 {
11752 var = find_termcode(expand_option_name + 2);
11753 if (var == NULL)
11754 expand_option_idx = findoption(expand_option_name);
11755 }
11756
11757 if (expand_option_idx >= 0)
11758 {
11759 /* put string of option value in NameBuff */
11760 option_value2string(&options[expand_option_idx], expand_option_flags);
11761 var = NameBuff;
11762 }
11763 else if (var == NULL)
11764 var = (char_u *)"";
11765
11766 /* A backslash is required before some characters. This is the reverse of
11767 * what happens in do_set(). */
11768 buf = vim_strsave_escaped(var, escape_chars);
11769
11770 if (buf == NULL)
11771 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011772 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011773 return FAIL;
11774 }
11775
11776#ifdef BACKSLASH_IN_FILENAME
11777 /* For MS-Windows et al. we don't double backslashes at the start and
11778 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011779 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780 if (var[0] == '\\' && var[1] == '\\'
11781 && expand_option_idx >= 0
11782 && (options[expand_option_idx].flags & P_EXPAND)
11783 && vim_isfilec(var[2])
11784 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011785 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011786#endif
11787
11788 *file[0] = buf;
11789 *num_file = 1;
11790 return OK;
11791}
11792#endif
11793
11794/*
11795 * Get the value for the numeric or string option *opp in a nice format into
11796 * NameBuff[]. Must not be called with a hidden option!
11797 */
11798 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011799option_value2string(
11800 struct vimoption *opp,
11801 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802{
11803 char_u *varp;
11804
11805 varp = get_varp_scope(opp, opt_flags);
11806
11807 if (opp->flags & P_NUM)
11808 {
11809 long wc = 0;
11810
11811 if (wc_use_keyname(varp, &wc))
11812 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11813 else if (wc != 0)
11814 STRCPY(NameBuff, transchar((int)wc));
11815 else
11816 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11817 }
11818 else /* P_STRING */
11819 {
11820 varp = *(char_u **)(varp);
11821 if (varp == NULL) /* just in case */
11822 NameBuff[0] = NUL;
11823#ifdef FEAT_CRYPT
11824 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011825 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011826 STRCPY(NameBuff, "*****");
11827#endif
11828 else if (opp->flags & P_EXPAND)
11829 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11830 /* Translate 'pastetoggle' into special key names */
11831 else if ((char_u **)opp->var == &p_pt)
11832 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11833 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011834 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011835 }
11836}
11837
11838/*
11839 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11840 * printed as a keyname.
11841 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11842 */
11843 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011844wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845{
11846 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11847 {
11848 *wcp = *(long *)varp;
11849 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11850 return TRUE;
11851 }
11852 return FALSE;
11853}
11854
Bram Moolenaar01615492015-02-03 13:00:38 +010011855#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011857 * Any character has an equivalent 'langmap' character. This is used for
11858 * keyboards that have a special language mode that sends characters above
11859 * 128 (although other characters can be translated too). The "to" field is a
11860 * Vim command character. This avoids having to switch the keyboard back to
11861 * ASCII mode when leaving Insert mode.
11862 *
11863 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11864 * commands.
11865 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11866 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11867 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011869# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011870/*
11871 * With multi-byte support use growarray for 'langmap' chars >= 256
11872 */
11873typedef struct
11874{
11875 int from;
11876 int to;
11877} langmap_entry_T;
11878
11879static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011880static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881
11882/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011883 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11884 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011886 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011887langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011888{
11889 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011890 int a = 0;
11891 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011892
11893 /* Do a binary search for an existing entry. */
11894 while (a != b)
11895 {
11896 int i = (a + b) / 2;
11897 int d = entries[i].from - from;
11898
11899 if (d == 0)
11900 {
11901 entries[i].to = to;
11902 return;
11903 }
11904 if (d < 0)
11905 a = i + 1;
11906 else
11907 b = i;
11908 }
11909
11910 if (ga_grow(&langmap_mapga, 1) != OK)
11911 return; /* out of memory */
11912
11913 /* insert new entry at position "a" */
11914 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11915 mch_memmove(entries + 1, entries,
11916 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11917 ++langmap_mapga.ga_len;
11918 entries[0].from = from;
11919 entries[0].to = to;
11920}
11921
11922/*
11923 * Apply 'langmap' to multi-byte character "c" and return the result.
11924 */
11925 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011926langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011927{
11928 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11929 int a = 0;
11930 int b = langmap_mapga.ga_len;
11931
11932 while (a != b)
11933 {
11934 int i = (a + b) / 2;
11935 int d = entries[i].from - c;
11936
11937 if (d == 0)
11938 return entries[i].to; /* found matching entry */
11939 if (d < 0)
11940 a = i + 1;
11941 else
11942 b = i;
11943 }
11944 return c; /* no entry found, return "c" unmodified */
11945}
11946# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947
11948 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011949langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011950{
11951 int i;
11952
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011953 for (i = 0; i < 256; i++)
11954 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11955# ifdef FEAT_MBYTE
11956 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11957# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011958}
11959
11960/*
11961 * Called when langmap option is set; the language map can be
11962 * changed at any time!
11963 */
11964 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011965langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011966{
11967 char_u *p;
11968 char_u *p2;
11969 int from, to;
11970
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011971#ifdef FEAT_MBYTE
11972 ga_clear(&langmap_mapga); /* clear the previous map first */
11973#endif
11974 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011975
11976 for (p = p_langmap; p[0] != NUL; )
11977 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011978 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011979 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980 {
11981 if (p2[0] == '\\' && p2[1] != NUL)
11982 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983 }
11984 if (p2[0] == ';')
11985 ++p2; /* abcd;ABCD form, p2 points to A */
11986 else
11987 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11988 while (p[0])
11989 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011990 if (p[0] == ',')
11991 {
11992 ++p;
11993 break;
11994 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995 if (p[0] == '\\' && p[1] != NUL)
11996 ++p;
11997#ifdef FEAT_MBYTE
11998 from = (*mb_ptr2char)(p);
11999#else
12000 from = p[0];
12001#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012002 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012003 if (p2 == NULL)
12004 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012005 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012006 if (p[0] != ',')
12007 {
12008 if (p[0] == '\\')
12009 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012010#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012011 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012013 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012014#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012015 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012016 }
12017 else
12018 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012019 if (p2[0] != ',')
12020 {
12021 if (p2[0] == '\\')
12022 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012024 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012026 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012027#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012028 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029 }
12030 if (to == NUL)
12031 {
12032 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12033 transchar(from));
12034 return;
12035 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012036
12037#ifdef FEAT_MBYTE
12038 if (from >= 256)
12039 langmap_set_entry(from, to);
12040 else
12041#endif
12042 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012043
12044 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012045 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012046 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012047 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012048 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012049 if (*p == ';')
12050 {
12051 p = p2;
12052 if (p[0] != NUL)
12053 {
12054 if (p[0] != ',')
12055 {
12056 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12057 return;
12058 }
12059 ++p;
12060 }
12061 break;
12062 }
12063 }
12064 }
12065 }
12066}
12067#endif
12068
12069/*
12070 * Return TRUE if format option 'x' is in effect.
12071 * Take care of no formatting when 'paste' is set.
12072 */
12073 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012074has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012075{
12076 if (p_paste)
12077 return FALSE;
12078 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12079}
12080
12081/*
12082 * Return TRUE if "x" is present in 'shortmess' option, or
12083 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12084 */
12085 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012086shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012088 return p_shm != NULL &&
12089 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012090 || (vim_strchr(p_shm, 'a') != NULL
12091 && vim_strchr((char_u *)SHM_A, x) != NULL));
12092}
12093
12094/*
12095 * paste_option_changed() - Called after p_paste was set or reset.
12096 */
12097 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012098paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012099{
12100 static int old_p_paste = FALSE;
12101 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012102 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103#ifdef FEAT_CMDL_INFO
12104 static int save_ru = 0;
12105#endif
12106#ifdef FEAT_RIGHTLEFT
12107 static int save_ri = 0;
12108 static int save_hkmap = 0;
12109#endif
12110 buf_T *buf;
12111
12112 if (p_paste)
12113 {
12114 /*
12115 * Paste switched from off to on.
12116 * Save the current values, so they can be restored later.
12117 */
12118 if (!old_p_paste)
12119 {
12120 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012121 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012122 {
12123 buf->b_p_tw_nopaste = buf->b_p_tw;
12124 buf->b_p_wm_nopaste = buf->b_p_wm;
12125 buf->b_p_sts_nopaste = buf->b_p_sts;
12126 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012127 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128 }
12129
12130 /* save global options */
12131 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012132 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012133#ifdef FEAT_CMDL_INFO
12134 save_ru = p_ru;
12135#endif
12136#ifdef FEAT_RIGHTLEFT
12137 save_ri = p_ri;
12138 save_hkmap = p_hkmap;
12139#endif
12140 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012141 p_ai_nopaste = p_ai;
12142 p_et_nopaste = p_et;
12143 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012144 p_tw_nopaste = p_tw;
12145 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146 }
12147
12148 /*
12149 * Always set the option values, also when 'paste' is set when it is
12150 * already on.
12151 */
12152 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012153 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012154 {
12155 buf->b_p_tw = 0; /* textwidth is 0 */
12156 buf->b_p_wm = 0; /* wrapmargin is 0 */
12157 buf->b_p_sts = 0; /* softtabstop is 0 */
12158 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012159 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012160 }
12161
12162 /* set global options */
12163 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012164 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012166 if (p_ru)
12167 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168 p_ru = 0; /* no ruler */
12169#endif
12170#ifdef FEAT_RIGHTLEFT
12171 p_ri = 0; /* no reverse insert */
12172 p_hkmap = 0; /* no Hebrew keyboard */
12173#endif
12174 /* set global values for local buffer options */
12175 p_tw = 0;
12176 p_wm = 0;
12177 p_sts = 0;
12178 p_ai = 0;
12179 }
12180
12181 /*
12182 * Paste switched from on to off: Restore saved values.
12183 */
12184 else if (old_p_paste)
12185 {
12186 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012187 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012188 {
12189 buf->b_p_tw = buf->b_p_tw_nopaste;
12190 buf->b_p_wm = buf->b_p_wm_nopaste;
12191 buf->b_p_sts = buf->b_p_sts_nopaste;
12192 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012193 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012194 }
12195
12196 /* restore global options */
12197 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012198 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012199#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012200 if (p_ru != save_ru)
12201 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012202 p_ru = save_ru;
12203#endif
12204#ifdef FEAT_RIGHTLEFT
12205 p_ri = save_ri;
12206 p_hkmap = save_hkmap;
12207#endif
12208 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012209 p_ai = p_ai_nopaste;
12210 p_et = p_et_nopaste;
12211 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012212 p_tw = p_tw_nopaste;
12213 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012214 }
12215
12216 old_p_paste = p_paste;
12217}
12218
12219/*
12220 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12221 *
12222 * Reset 'compatible' and set the values for options that didn't get set yet
12223 * to the Vim defaults.
12224 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012225 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012226 */
12227 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012228vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012229{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012230 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012231 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012232 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012233
12234 if (!option_was_set((char_u *)"cp"))
12235 {
12236 p_cp = FALSE;
12237 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12238 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12239 set_option_default(opt_idx, OPT_FREE, FALSE);
12240 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012241 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012243
12244 if (fname != NULL)
12245 {
12246 p = vim_getenv(envname, &dofree);
12247 if (p == NULL)
12248 {
12249 /* Set $MYVIMRC to the first vimrc file found. */
12250 p = FullName_save(fname, FALSE);
12251 if (p != NULL)
12252 {
12253 vim_setenv(envname, p);
12254 vim_free(p);
12255 }
12256 }
12257 else if (dofree)
12258 vim_free(p);
12259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012260}
12261
12262/*
12263 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12264 */
12265 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012266change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012267{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012268 int opt_idx;
12269
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270 if (p_cp != on)
12271 {
12272 p_cp = on;
12273 compatible_set();
12274 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012275 opt_idx = findoption((char_u *)"cp");
12276 if (opt_idx >= 0)
12277 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278}
12279
12280/*
12281 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012282 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283 */
12284 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012285option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012286{
12287 int idx;
12288
12289 idx = findoption(name);
12290 if (idx < 0) /* unknown option */
12291 return FALSE;
12292 if (options[idx].flags & P_WAS_SET)
12293 return TRUE;
12294 return FALSE;
12295}
12296
12297/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012298 * Reset the flag indicating option "name" was set.
12299 */
12300 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012301reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012302{
12303 int idx = findoption(name);
12304
12305 if (idx >= 0)
12306 options[idx].flags &= ~P_WAS_SET;
12307}
12308
12309/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012310 * compatible_set() - Called when 'compatible' has been set or unset.
12311 *
12312 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12313 * flag) to a Vi compatible value.
12314 * When 'compatible' is unset: Set all options that have a different default
12315 * for Vim (without the P_VI_DEF flag) to that default.
12316 */
12317 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012318compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012319{
12320 int opt_idx;
12321
12322 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12323 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12324 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12325 set_option_default(opt_idx, OPT_FREE, p_cp);
12326 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012327 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012328}
12329
12330#ifdef FEAT_LINEBREAK
12331
12332# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12333 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012334 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012335# endif
12336
12337/*
12338 * fill_breakat_flags() -- called when 'breakat' changes value.
12339 */
12340 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012341fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012342{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012343 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012344 int i;
12345
12346 for (i = 0; i < 256; i++)
12347 breakat_flags[i] = FALSE;
12348
12349 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012350 for (p = p_breakat; *p; p++)
12351 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012352}
12353
12354# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012355 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012356# endif
12357
12358#endif
12359
12360/*
12361 * Check an option that can be a range of string values.
12362 *
12363 * Return OK for correct value, FAIL otherwise.
12364 * Empty is always OK.
12365 */
12366 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012367check_opt_strings(
12368 char_u *val,
12369 char **values,
12370 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012371{
12372 return opt_strings_flags(val, values, NULL, list);
12373}
12374
12375/*
12376 * Handle an option that can be a range of string values.
12377 * Set a flag in "*flagp" for each string present.
12378 *
12379 * Return OK for correct value, FAIL otherwise.
12380 * Empty is always OK.
12381 */
12382 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012383opt_strings_flags(
12384 char_u *val, /* new value */
12385 char **values, /* array of valid string values */
12386 unsigned *flagp,
12387 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012388{
12389 int i;
12390 int len;
12391 unsigned new_flags = 0;
12392
12393 while (*val)
12394 {
12395 for (i = 0; ; ++i)
12396 {
12397 if (values[i] == NULL) /* val not found in values[] */
12398 return FAIL;
12399
12400 len = (int)STRLEN(values[i]);
12401 if (STRNCMP(values[i], val, len) == 0
12402 && ((list && val[len] == ',') || val[len] == NUL))
12403 {
12404 val += len + (val[len] == ',');
12405 new_flags |= (1 << i);
12406 break; /* check next item in val list */
12407 }
12408 }
12409 }
12410 if (flagp != NULL)
12411 *flagp = new_flags;
12412
12413 return OK;
12414}
12415
12416/*
12417 * Read the 'wildmode' option, fill wim_flags[].
12418 */
12419 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012420check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421{
12422 char_u new_wim_flags[4];
12423 char_u *p;
12424 int i;
12425 int idx = 0;
12426
12427 for (i = 0; i < 4; ++i)
12428 new_wim_flags[i] = 0;
12429
12430 for (p = p_wim; *p; ++p)
12431 {
12432 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12433 ;
12434 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12435 return FAIL;
12436 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12437 new_wim_flags[idx] |= WIM_LONGEST;
12438 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12439 new_wim_flags[idx] |= WIM_FULL;
12440 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12441 new_wim_flags[idx] |= WIM_LIST;
12442 else
12443 return FAIL;
12444 p += i;
12445 if (*p == NUL)
12446 break;
12447 if (*p == ',')
12448 {
12449 if (idx == 3)
12450 return FAIL;
12451 ++idx;
12452 }
12453 }
12454
12455 /* fill remaining entries with last flag */
12456 while (idx < 3)
12457 {
12458 new_wim_flags[idx + 1] = new_wim_flags[idx];
12459 ++idx;
12460 }
12461
12462 /* only when there are no errors, wim_flags[] is changed */
12463 for (i = 0; i < 4; ++i)
12464 wim_flags[i] = new_wim_flags[i];
12465 return OK;
12466}
12467
12468/*
12469 * Check if backspacing over something is allowed.
12470 */
12471 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012472can_bs(
12473 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012474{
12475 switch (*p_bs)
12476 {
12477 case '2': return TRUE;
12478 case '1': return (what != BS_START);
12479 case '0': return FALSE;
12480 }
12481 return vim_strchr(p_bs, what) != NULL;
12482}
12483
12484/*
12485 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12486 * the file must be considered changed when the value is different.
12487 */
12488 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012489save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012490{
12491 buf->b_start_ffc = *buf->b_p_ff;
12492 buf->b_start_eol = buf->b_p_eol;
12493#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012494 buf->b_start_bomb = buf->b_p_bomb;
12495
Bram Moolenaar071d4272004-06-13 20:20:40 +000012496 /* Only use free/alloc when necessary, they take time. */
12497 if (buf->b_start_fenc == NULL
12498 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12499 {
12500 vim_free(buf->b_start_fenc);
12501 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12502 }
12503#endif
12504}
12505
12506/*
12507 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12508 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012509 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12510 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012511 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012512 * When "ignore_empty" is true don't consider a new, empty buffer to be
12513 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012514 */
12515 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012516file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012517{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012518 /* In a buffer that was never loaded the options are not valid. */
12519 if (buf->b_flags & BF_NEVERLOADED)
12520 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012521 if (ignore_empty
12522 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012523 && buf->b_ml.ml_line_count == 1
12524 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12525 return FALSE;
12526 if (buf->b_start_ffc != *buf->b_p_ff)
12527 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012528 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012529 return TRUE;
12530#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012531 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12532 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012533 if (buf->b_start_fenc == NULL)
12534 return (*buf->b_p_fenc != NUL);
12535 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12536#else
12537 return FALSE;
12538#endif
12539}
12540
12541/*
12542 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12543 */
12544 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012545check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012546{
12547 return check_opt_strings(p, p_ff_values, FALSE);
12548}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012549
12550/*
12551 * Return the effective shiftwidth value for current buffer, using the
12552 * 'tabstop' value when 'shiftwidth' is zero.
12553 */
12554 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012555get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012556{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012557 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012558}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012559
12560/*
12561 * Return the effective softtabstop value for the current buffer, using the
12562 * 'tabstop' value when 'softtabstop' is negative.
12563 */
12564 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012565get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012566{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012567 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012568}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012569
12570/*
12571 * Check matchpairs option for "*initc".
12572 * If there is a match set "*initc" to the matching character and "*findc" to
12573 * the opposite character. Set "*backwards" to the direction.
12574 * When "switchit" is TRUE swap the direction.
12575 */
12576 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012577find_mps_values(
12578 int *initc,
12579 int *findc,
12580 int *backwards,
12581 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012582{
12583 char_u *ptr;
12584
12585 ptr = curbuf->b_p_mps;
12586 while (*ptr != NUL)
12587 {
12588#ifdef FEAT_MBYTE
12589 if (has_mbyte)
12590 {
12591 char_u *prev;
12592
12593 if (mb_ptr2char(ptr) == *initc)
12594 {
12595 if (switchit)
12596 {
12597 *findc = *initc;
12598 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12599 *backwards = TRUE;
12600 }
12601 else
12602 {
12603 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12604 *backwards = FALSE;
12605 }
12606 return;
12607 }
12608 prev = ptr;
12609 ptr += mb_ptr2len(ptr) + 1;
12610 if (mb_ptr2char(ptr) == *initc)
12611 {
12612 if (switchit)
12613 {
12614 *findc = *initc;
12615 *initc = mb_ptr2char(prev);
12616 *backwards = FALSE;
12617 }
12618 else
12619 {
12620 *findc = mb_ptr2char(prev);
12621 *backwards = TRUE;
12622 }
12623 return;
12624 }
12625 ptr += mb_ptr2len(ptr);
12626 }
12627 else
12628#endif
12629 {
12630 if (*ptr == *initc)
12631 {
12632 if (switchit)
12633 {
12634 *backwards = TRUE;
12635 *findc = *initc;
12636 *initc = ptr[2];
12637 }
12638 else
12639 {
12640 *backwards = FALSE;
12641 *findc = ptr[2];
12642 }
12643 return;
12644 }
12645 ptr += 2;
12646 if (*ptr == *initc)
12647 {
12648 if (switchit)
12649 {
12650 *backwards = FALSE;
12651 *findc = *initc;
12652 *initc = ptr[-2];
12653 }
12654 else
12655 {
12656 *backwards = TRUE;
12657 *findc = ptr[-2];
12658 }
12659 return;
12660 }
12661 ++ptr;
12662 }
12663 if (*ptr == ',')
12664 ++ptr;
12665 }
12666}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012667
12668#if defined(FEAT_LINEBREAK) || defined(PROTO)
12669/*
12670 * This is called when 'breakindentopt' is changed and when a window is
12671 * initialized.
12672 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012673 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012674briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012675{
12676 char_u *p;
12677 int bri_shift = 0;
12678 long bri_min = 20;
12679 int bri_sbr = FALSE;
12680
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012681 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012682 while (*p != NUL)
12683 {
12684 if (STRNCMP(p, "shift:", 6) == 0
12685 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12686 {
12687 p += 6;
12688 bri_shift = getdigits(&p);
12689 }
12690 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12691 {
12692 p += 4;
12693 bri_min = getdigits(&p);
12694 }
12695 else if (STRNCMP(p, "sbr", 3) == 0)
12696 {
12697 p += 3;
12698 bri_sbr = TRUE;
12699 }
12700 if (*p != ',' && *p != NUL)
12701 return FAIL;
12702 if (*p == ',')
12703 ++p;
12704 }
12705
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012706 wp->w_p_brishift = bri_shift;
12707 wp->w_p_brimin = bri_min;
12708 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012709
12710 return OK;
12711}
12712#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012713
12714/*
12715 * Get the local or global value of 'backupcopy'.
12716 */
12717 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012718get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012719{
12720 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12721}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012722
12723#if defined(FEAT_SIGNS) || defined(PROTO)
12724/*
12725 * Return TRUE when window "wp" has a column to draw signs in.
12726 */
12727 int
12728signcolumn_on(win_T *wp)
12729{
12730 if (*wp->w_p_scl == 'n')
12731 return FALSE;
12732 if (*wp->w_p_scl == 'y')
12733 return TRUE;
12734 return (wp->w_buffer->b_signlist != NULL
12735# ifdef FEAT_NETBEANS_INTG
12736 || wp->w_buffer->b_has_sign_column
12737# endif
12738 );
12739}
12740#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012741
12742#if defined(FEAT_EVAL) || defined(PROTO)
12743/*
12744 * Get window or buffer local options.
12745 */
12746 dict_T *
12747get_winbuf_options(int bufopt)
12748{
12749 dict_T *d;
12750 int opt_idx;
12751
12752 d = dict_alloc();
12753 if (d == NULL)
12754 return NULL;
12755
12756 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12757 {
12758 struct vimoption *opt = &options[opt_idx];
12759
12760 if ((bufopt && (opt->indir & PV_BUF))
12761 || (!bufopt && (opt->indir & PV_WIN)))
12762 {
12763 char_u *varp = get_varp(opt);
12764
12765 if (varp != NULL)
12766 {
12767 if (opt->flags & P_STRING)
12768 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012769 else if (opt->flags & P_NUM)
12770 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012771 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012772 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012773 }
12774 }
12775 }
12776
12777 return d;
12778}
12779#endif