blob: 23474617c02c2730969d4b9374d0199534b98b42 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
225#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#ifdef FEAT_WINDOWS
249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200261# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200262# define PV_TMS OPT_WIN(WV_TMS)
263#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200264#ifdef FEAT_SIGNS
265# define PV_SCL OPT_WIN(WV_SCL)
266#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000267
268/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269typedef enum
270{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000271 PV_NONE = 0,
272 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273} idopt_T;
274
275/*
276 * Options local to a window have a value local to a buffer and global to all
277 * buffers. Indicate this by setting "var" to VAR_WIN.
278 */
279#define VAR_WIN ((char_u *)-1)
280
281/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000282 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283 * Only to be used in option.c!
284 */
285static int p_ai;
286static int p_bin;
287#ifdef FEAT_MBYTE
288static int p_bomb;
289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static char_u *p_bh;
291static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292static int p_bl;
293static int p_ci;
294#ifdef FEAT_CINDENT
295static int p_cin;
296static char_u *p_cink;
297static char_u *p_cino;
298#endif
299#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
300static char_u *p_cinw;
301#endif
302#ifdef FEAT_COMMENTS
303static char_u *p_com;
304#endif
305#ifdef FEAT_FOLDING
306static char_u *p_cms;
307#endif
308#ifdef FEAT_INS_EXPAND
309static char_u *p_cpt;
310#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000311#ifdef FEAT_COMPL_FUNC
312static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000313static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200316static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static int p_et;
318#ifdef FEAT_MBYTE
319static char_u *p_fenc;
320#endif
321static char_u *p_ff;
322static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000323static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324#ifdef FEAT_AUTOCMD
325static char_u *p_ft;
326#endif
327static long p_iminsert;
328static long p_imsearch;
329#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
330static char_u *p_inex;
331#endif
332#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
333static char_u *p_inde;
334static char_u *p_indk;
335#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000336#if defined(FEAT_EVAL)
337static char_u *p_fex;
338#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static int p_inf;
340static char_u *p_isk;
341#ifdef FEAT_CRYPT
342static char_u *p_key;
343#endif
344#ifdef FEAT_LISP
345static int p_lisp;
346#endif
347static int p_ml;
348static int p_ma;
349static int p_mod;
350static char_u *p_mps;
351static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000353#ifdef FEAT_TEXTOBJ
354static char_u *p_qe;
355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static int p_ro;
357#ifdef FEAT_SMARTINDENT
358static int p_si;
359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361static long p_sts;
362#if defined(FEAT_SEARCHPATH)
363static char_u *p_sua;
364#endif
365static long p_sw;
366static int p_swf;
367#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000368static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000370#endif
371#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000372static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000373static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000374static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375#endif
376static long p_ts;
377static long p_tw;
378static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200379#ifdef FEAT_PERSISTENT_UNDO
380static int p_udf;
381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382static long p_wm;
383#ifdef FEAT_KEYMAP
384static char_u *p_keymap;
385#endif
386
387/* Saved values for when 'bin' is set. */
388static int p_et_nobin;
389static int p_ml_nobin;
390static long p_tw_nobin;
391static long p_wm_nobin;
392
393/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200394static int p_ai_nopaste;
395static int p_et_nopaste;
396static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397static long p_tw_nopaste;
398static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399
400struct vimoption
401{
402 char *fullname; /* full option name */
403 char *shortname; /* permissible abbreviation */
404 long_u flags; /* see below */
405 char_u *var; /* global option: pointer to variable;
406 * window-local option: VAR_WIN;
407 * buffer-local option: global value */
408 idopt_T indir; /* global option: PV_NONE;
409 * local option: indirect option index */
410 char_u *def_val[2]; /* default values for variable (vi and vim) */
411#ifdef FEAT_EVAL
412 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000413# define SCRIPTID_INIT , 0
414#else
415# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416#endif
417};
418
419#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
420#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
421
422/*
423 * Flags
424 */
425#define P_BOOL 0x01 /* the option is boolean */
426#define P_NUM 0x02 /* the option is numeric */
427#define P_STRING 0x04 /* the option is a string */
428#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000429 must use free_string_option() when
430 assigning new value. Not set if default is
431 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
433 never be used for local or hidden options! */
434#define P_NODEFAULT 0x40 /* don't set to default value */
435#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
436 use vim_free() when assigning new value */
437#define P_WAS_SET 0x100 /* option has been set/reset */
438#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
439#define P_VI_DEF 0x400 /* Use Vi default for Vim */
440#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
441
442 /* when option changed, what to display: */
443#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100444#define P_RWIN 0x2000 /* redraw current window and recompute text */
445#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446#define P_RALL 0x6000 /* redraw all windows */
447#define P_RCLR 0x7000 /* clear and redraw all */
448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_COMMA 0x8000 /* comma separated list */
450#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
451 * commas */
452#define P_NODUP 0x20000L /* don't allow duplicate strings */
453#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200455#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
456#define P_GETTEXT 0x100000L /* expand default value with _() */
457#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
458#define P_NFNAME 0x400000L /* only normal file name chars allowed */
459#define P_INSECURE 0x800000L /* option was set from a modeline */
460#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100461 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200462#define P_NO_ML 0x2000000L /* not allowed in modeline */
463#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200464 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100465#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100466#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000467
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000468#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
469
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000470/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
471 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100472#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000473# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000474#else
475# define ISP_LATIN1 (char_u *)"@,161-255"
476#endif
477
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100478/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000479#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100480 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar21020352017-06-13 17:21:04 +0200481 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) \
Bram Moolenaar3633cf52017-07-31 22:29:35 +0200482 || defined(FEAT_CONCEAL) || defined(FEAT_QUICKFIX) \
483 || defined(FEAT_TERMINAL)
484# 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,$:StatusLineTerm"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000485#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100486# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000487#endif
488
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100489/* Default python version for pyx* commands */
490#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
491# define DEFAULT_PYTHON_VER 0
492#elif defined(FEAT_PYTHON3)
493# define DEFAULT_PYTHON_VER 3
494#elif defined(FEAT_PYTHON)
495# define DEFAULT_PYTHON_VER 2
496#else
497# define DEFAULT_PYTHON_VER 0
498#endif
499
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500/*
501 * options[] is initialized here.
502 * The order of the options MUST be alphabetic for ":set all" and findoption().
503 * All option names MUST start with a lowercase letter (for findoption()).
504 * Exception: "t_" options are at the end.
505 * The options with a NULL variable are 'hidden': a set command for them is
506 * ignored and they are not printed.
507 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100508static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200510 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511#ifdef FEAT_RIGHTLEFT
512 (char_u *)&p_aleph, PV_NONE,
513#else
514 (char_u *)NULL, PV_NONE,
515#endif
516 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100517#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 (char_u *)128L,
519#else
520 (char_u *)224L,
521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000522 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
524#if defined(FEAT_GUI) && defined(MACOS_X)
525 (char_u *)&p_antialias, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#else
528 (char_u *)NULL, PV_NONE,
529 {(char_u *)FALSE, (char_u *)FALSE}
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200532 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533#ifdef FEAT_ARABIC
534 (char_u *)VAR_WIN, PV_ARAB,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
540#ifdef FEAT_ARABIC
541 (char_u *)&p_arshape, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
547#ifdef FEAT_RIGHTLEFT
548 (char_u *)&p_ari, PV_NONE,
549#else
550 (char_u *)NULL, PV_NONE,
551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
554#ifdef FEAT_FKMAP
555 (char_u *)&p_altkeymap, PV_NONE,
556#else
557 (char_u *)NULL, PV_NONE,
558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
561#if defined(FEAT_MBYTE)
562 (char_u *)&p_ambw, PV_NONE,
563 {(char_u *)"single", (char_u *)0L}
564#else
565 (char_u *)NULL, PV_NONE,
566 {(char_u *)0L, (char_u *)0L}
567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100570#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100572 {(char_u *)FALSE, (char_u *)0L}
573#else
574 (char_u *)NULL, PV_NONE,
575 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100577 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autoindent", "ai", P_BOOL|P_VI_DEF,
579 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"autoprint", "ap", P_BOOL|P_VI_DEF,
582 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000585 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 {"autowrite", "aw", P_BOOL|P_VI_DEF,
588 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 {"autowriteall","awa", P_BOOL|P_VI_DEF,
591 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
594 (char_u *)&p_bg, PV_NONE,
595 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100596#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)"dark",
598#else
599 (char_u *)"light",
600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000601 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200602 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
606 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000607 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200608 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200609 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#ifdef UNIX
611 {(char_u *)"yes", (char_u *)"auto"}
612#else
613 {(char_u *)"auto", (char_u *)"auto"}
614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200616 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
617 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000620 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 (char_u *)&p_bex, PV_NONE,
622 {
623#ifdef VMS
624 (char_u *)"_",
625#else
626 (char_u *)"~",
627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200629 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630#ifdef FEAT_WILDIGN
631 (char_u *)&p_bsk, PV_NONE,
632 {(char_u *)"", (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100639#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100641 {(char_u *)600L, (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100646 SCRIPTID_INIT},
647 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
648#ifdef FEAT_BEVAL
649 (char_u *)&p_beval, PV_NONE,
650 {(char_u *)FALSE, (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
655 SCRIPTID_INIT},
656 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
657#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
658 (char_u *)&p_bexpr, PV_BEXPR,
659 {(char_u *)"", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"beautify", "bf", P_BOOL|P_VI_DEF,
666 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200668 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
669 (char_u *)&p_bo, PV_NONE,
670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
672 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000673 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000676 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
678#ifdef FEAT_MBYTE
679 (char_u *)&p_bomb, PV_BOMB,
680#else
681 (char_u *)NULL, PV_NONE,
682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000683 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
685#ifdef FEAT_LINEBREAK
686 (char_u *)&p_breakat, PV_NONE,
687 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
688#else
689 (char_u *)NULL, PV_NONE,
690 {(char_u *)0L, (char_u *)0L}
691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000692 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
694#ifdef FEAT_LINEBREAK
695 (char_u *)VAR_WIN, PV_BRI,
696 {(char_u *)FALSE, (char_u *)0L}
697#else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)0L, (char_u *)0L}
700#endif
701 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200702 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
703 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200704#ifdef FEAT_LINEBREAK
705 (char_u *)VAR_WIN, PV_BRIOPT,
706 {(char_u *)"", (char_u *)NULL}
707#else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)"", (char_u *)NULL}
710#endif
711 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
713#ifdef FEAT_BROWSE
714 (char_u *)&p_bsdir, PV_NONE,
715 {(char_u *)"last", (char_u *)0L}
716#else
717 (char_u *)NULL, PV_NONE,
718 {(char_u *)0L, (char_u *)0L}
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 (char_u *)&p_bh, PV_BH,
723 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
726 (char_u *)&p_bl, PV_BL,
727 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 (char_u *)&p_bt, PV_BT,
731 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000732 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200733 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000734#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735 (char_u *)&p_cmp, PV_NONE,
736 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000741 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
743#ifdef FEAT_SEARCHPATH
744 (char_u *)&p_cdpath, PV_NONE,
745 {(char_u *)",,", (char_u *)0L}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"cedit", NULL, P_STRING,
752#ifdef FEAT_CMDWIN
753 (char_u *)&p_cedit, PV_NONE,
754 {(char_u *)"", (char_u *)CTRL_F_STR}
755#else
756 (char_u *)NULL, PV_NONE,
757 {(char_u *)0L, (char_u *)0L}
758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000759 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
761#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
762 (char_u *)&p_ccv, PV_NONE,
763 {(char_u *)"", (char_u *)0L}
764#else
765 (char_u *)NULL, PV_NONE,
766 {(char_u *)0L, (char_u *)0L}
767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000768 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
770#ifdef FEAT_CINDENT
771 (char_u *)&p_cin, PV_CIN,
772#else
773 (char_u *)NULL, PV_NONE,
774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200776 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777#ifdef FEAT_CINDENT
778 (char_u *)&p_cink, PV_CINK,
779 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
780#else
781 (char_u *)NULL, PV_NONE,
782 {(char_u *)0L, (char_u *)0L}
783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200785 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_CINDENT
787 (char_u *)&p_cino, PV_CINO,
788#else
789 (char_u *)NULL, PV_NONE,
790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000791 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
794 (char_u *)&p_cinw, PV_CINW,
795 {(char_u *)"if,else,while,do,for,switch",
796 (char_u *)0L}
797#else
798 (char_u *)NULL, PV_NONE,
799 {(char_u *)0L, (char_u *)0L}
800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200802 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803#ifdef FEAT_CLIPBOARD
804 (char_u *)&p_cb, PV_NONE,
805# ifdef FEAT_XCLIPBOARD
806 {(char_u *)"autoselect,exclude:cons\\|linux",
807 (char_u *)0L}
808# else
809 {(char_u *)"", (char_u *)0L}
810# endif
811#else
812 (char_u *)NULL, PV_NONE,
813 {(char_u *)"", (char_u *)0L}
814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000815 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
817 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
820#ifdef FEAT_CMDWIN
821 (char_u *)&p_cwh, PV_NONE,
822#else
823 (char_u *)NULL, PV_NONE,
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200826 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200827#ifdef FEAT_SYN_HL
828 (char_u *)VAR_WIN, PV_CC,
829#else
830 (char_u *)NULL, PV_NONE,
831#endif
832 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
834 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200836 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
837 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_COMMENTS
839 (char_u *)&p_com, PV_COM,
840 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
841 (char_u *)0L}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)0L, (char_u *)0L}
845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000846 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200847 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848#ifdef FEAT_FOLDING
849 (char_u *)&p_cms, PV_CMS,
850 {(char_u *)"/*%s*/", (char_u *)0L}
851#else
852 (char_u *)NULL, PV_NONE,
853 {(char_u *)0L, (char_u *)0L}
854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000855 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000856 /* P_PRI_MKRC isn't needed here, optval_default()
857 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858 {"compatible", "cp", P_BOOL|P_RALL,
859 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000860 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200861 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862#ifdef FEAT_INS_EXPAND
863 (char_u *)&p_cpt, PV_CPT,
864 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
865#else
866 (char_u *)NULL, PV_NONE,
867 {(char_u *)0L, (char_u *)0L}
868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000869 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200872 (char_u *)VAR_WIN, PV_COCU,
873 {(char_u *)"", (char_u *)NULL}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)NULL, (char_u *)0L}
877#endif
878 SCRIPTID_INIT},
879 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
880#ifdef FEAT_CONCEAL
881 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200882#else
883 (char_u *)NULL, PV_NONE,
884#endif
885 {(char_u *)0L, (char_u *)0L}
886 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000887 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
888#ifdef FEAT_COMPL_FUNC
889 (char_u *)&p_cfu, PV_CFU,
890 {(char_u *)"", (char_u *)0L}
891#else
892 (char_u *)NULL, PV_NONE,
893 {(char_u *)0L, (char_u *)0L}
894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000895 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200896 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000897#ifdef FEAT_INS_EXPAND
898 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000899 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000900#else
901 (char_u *)NULL, PV_NONE,
902 {(char_u *)0L, (char_u *)0L}
903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"confirm", "cf", P_BOOL|P_VI_DEF,
906#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
907 (char_u *)&p_confirm, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
916 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
919 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
921 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200922 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200923#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200924 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200925 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200926#else
927 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200930 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_cspc, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csprg, PV_NONE,
941 {(char_u *)"cscope", (char_u *)0L}
942#else
943 (char_u *)NULL, PV_NONE,
944 {(char_u *)0L, (char_u *)0L}
945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000946 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200947 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
949 (char_u *)&p_csqf, PV_NONE,
950 {(char_u *)"", (char_u *)0L}
951#else
952 (char_u *)NULL, PV_NONE,
953 {(char_u *)0L, (char_u *)0L}
954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000955 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200956 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
957#ifdef FEAT_CSCOPE
958 (char_u *)&p_csre, PV_NONE,
959#else
960 (char_u *)NULL, PV_NONE,
961#endif
962 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
964#ifdef FEAT_CSCOPE
965 (char_u *)&p_cst, PV_NONE,
966#else
967 (char_u *)NULL, PV_NONE,
968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000969 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
971#ifdef FEAT_CSCOPE
972 (char_u *)&p_csto, PV_NONE,
973#else
974 (char_u *)NULL, PV_NONE,
975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000976 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
978#ifdef FEAT_CSCOPE
979 (char_u *)&p_csverbose, PV_NONE,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200984 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
985#ifdef FEAT_CURSORBIND
986 (char_u *)VAR_WIN, PV_CRBIND,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000991 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
992#ifdef FEAT_SYN_HL
993 (char_u *)VAR_WIN, PV_CUC,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100998 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000999#ifdef FEAT_SYN_HL
1000 (char_u *)VAR_WIN, PV_CUL,
1001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"debug", NULL, P_STRING|P_VI_DEF,
1006 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001008 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001010 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001011 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#else
1013 (char_u *)NULL, PV_NONE,
1014 {(char_u *)NULL, (char_u *)0L}
1015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1018#ifdef FEAT_MBYTE
1019 (char_u *)&p_deco, PV_NONE,
1020#else
1021 (char_u *)NULL, PV_NONE,
1022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001023 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001024 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001026 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027#else
1028 (char_u *)NULL, PV_NONE,
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1032#ifdef FEAT_DIFF
1033 (char_u *)VAR_WIN, PV_DIFF,
1034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001038 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1040 (char_u *)&p_dex, PV_NONE,
1041 {(char_u *)"", (char_u *)0L}
1042#else
1043 (char_u *)NULL, PV_NONE,
1044 {(char_u *)0L, (char_u *)0L}
1045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001047 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1048 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049#ifdef FEAT_DIFF
1050 (char_u *)&p_dip, PV_NONE,
1051 {(char_u *)"filler", (char_u *)NULL}
1052#else
1053 (char_u *)NULL, PV_NONE,
1054 {(char_u *)"", (char_u *)NULL}
1055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1058#ifdef FEAT_DIGRAPHS
1059 (char_u *)&p_dg, PV_NONE,
1060#else
1061 (char_u *)NULL, PV_NONE,
1062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001064 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1065 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001068 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001072#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 (char_u *)&p_ead, PV_NONE,
1074 {(char_u *)"both", (char_u *)0L}
1075#else
1076 (char_u *)NULL, PV_NONE,
1077 {(char_u *)NULL, (char_u *)0L}
1078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001079 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1081 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001083 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1084#if defined(FEAT_MBYTE)
1085 (char_u *)&p_emoji, PV_NONE,
1086 {(char_u *)TRUE, (char_u *)0L}
1087#else
1088 (char_u *)NULL, PV_NONE,
1089 {(char_u *)0L, (char_u *)0L}
1090#endif
1091 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001092 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093#ifdef FEAT_MBYTE
1094 (char_u *)&p_enc, PV_NONE,
1095 {(char_u *)ENC_DFLT, (char_u *)0L}
1096#else
1097 (char_u *)NULL, PV_NONE,
1098 {(char_u *)0L, (char_u *)0L}
1099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001100 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1102 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1105 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001108 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1111 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1114#ifdef FEAT_QUICKFIX
1115 (char_u *)&p_ef, PV_NONE,
1116 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1117#else
1118 (char_u *)NULL, PV_NONE,
1119 {(char_u *)NULL, (char_u *)0L}
1120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001122 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001124 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)NULL, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"esckeys", "ek", P_BOOL|P_VIM,
1132 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135#ifdef FEAT_AUTOCMD
1136 (char_u *)&p_ei, PV_NONE,
1137#else
1138 (char_u *)NULL, PV_NONE,
1139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1142 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1145 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1148 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149#ifdef FEAT_MBYTE
1150 (char_u *)&p_fenc, PV_FENC,
1151 {(char_u *)"", (char_u *)0L}
1152#else
1153 (char_u *)NULL, PV_NONE,
1154 {(char_u *)0L, (char_u *)0L}
1155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001157 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158#ifdef FEAT_MBYTE
1159 (char_u *)&p_fencs, PV_NONE,
1160 {(char_u *)"ucs-bom", (char_u *)0L}
1161#else
1162 (char_u *)NULL, PV_NONE,
1163 {(char_u *)0L, (char_u *)0L}
1164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001166 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1167 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001170 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1173 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001174 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1175 (char_u *)&p_fic, PV_NONE,
1176 {
1177#ifdef CASE_INSENSITIVE_FILENAME
1178 (char_u *)TRUE,
1179#else
1180 (char_u *)FALSE,
1181#endif
1182 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001183 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184#ifdef FEAT_AUTOCMD
1185 (char_u *)&p_ft, PV_FT,
1186 {(char_u *)"", (char_u *)0L}
1187#else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)0L, (char_u *)0L}
1190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001192 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1194 (char_u *)&p_fcs, PV_NONE,
1195 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1196#else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)"", (char_u *)0L}
1199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001201 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1202 (char_u *)&p_fixeol, PV_FIXEOL,
1203 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1205#ifdef FEAT_FKMAP
1206 (char_u *)&p_fkmap, PV_NONE,
1207#else
1208 (char_u *)NULL, PV_NONE,
1209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"flash", "fl", P_BOOL|P_VI_DEF,
1212 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001214 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001215#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001217 {(char_u *)"", (char_u *)0L}
1218#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)NULL, PV_NONE,
1220 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#endif
1222 SCRIPTID_INIT},
1223 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1224#ifdef FEAT_FOLDING
1225 (char_u *)VAR_WIN, PV_FDC,
1226 {(char_u *)FALSE, (char_u *)0L}
1227#else
1228 (char_u *)NULL, PV_NONE,
1229 {(char_u *)NULL, (char_u *)0L}
1230#endif
1231 SCRIPTID_INIT},
1232 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1233#ifdef FEAT_FOLDING
1234 (char_u *)VAR_WIN, PV_FEN,
1235 {(char_u *)TRUE, (char_u *)0L}
1236#else
1237 (char_u *)NULL, PV_NONE,
1238 {(char_u *)NULL, (char_u *)0L}
1239#endif
1240 SCRIPTID_INIT},
1241 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1242#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1243 (char_u *)VAR_WIN, PV_FDE,
1244 {(char_u *)"0", (char_u *)NULL}
1245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)NULL, (char_u *)0L}
1248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001251#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 {(char_u *)"#", (char_u *)NULL}
1254#else
1255 (char_u *)NULL, PV_NONE,
1256 {(char_u *)NULL, (char_u *)0L}
1257#endif
1258 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001260#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001262 {(char_u *)0L, (char_u *)0L}
1263#else
1264 (char_u *)NULL, PV_NONE,
1265 {(char_u *)NULL, (char_u *)0L}
1266#endif
1267 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001268 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001269#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001271 {(char_u *)-1L, (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)NULL, (char_u *)0L}
1275#endif
1276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001278 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001279#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001282#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 (char_u *)NULL, PV_NONE,
1284 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001286 SCRIPTID_INIT},
1287 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1288#ifdef FEAT_FOLDING
1289 (char_u *)VAR_WIN, PV_FDM,
1290 {(char_u *)"manual", (char_u *)NULL}
1291#else
1292 (char_u *)NULL, PV_NONE,
1293 {(char_u *)NULL, (char_u *)0L}
1294#endif
1295 SCRIPTID_INIT},
1296 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1297#ifdef FEAT_FOLDING
1298 (char_u *)VAR_WIN, PV_FML,
1299 {(char_u *)1L, (char_u *)0L}
1300#else
1301 (char_u *)NULL, PV_NONE,
1302 {(char_u *)NULL, (char_u *)0L}
1303#endif
1304 SCRIPTID_INIT},
1305 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1306#ifdef FEAT_FOLDING
1307 (char_u *)VAR_WIN, PV_FDN,
1308 {(char_u *)20L, (char_u *)0L}
1309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
1313 SCRIPTID_INIT},
1314 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1315#ifdef FEAT_FOLDING
1316 (char_u *)&p_fdo, PV_NONE,
1317 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1318 (char_u *)0L}
1319#else
1320 (char_u *)NULL, PV_NONE,
1321 {(char_u *)NULL, (char_u *)0L}
1322#endif
1323 SCRIPTID_INIT},
1324 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1325#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1326 (char_u *)VAR_WIN, PV_FDT,
1327 {(char_u *)"foldtext()", (char_u *)NULL}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)NULL, (char_u *)0L}
1331#endif
1332 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001333 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001334#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001335 (char_u *)&p_fex, PV_FEX,
1336 {(char_u *)"", (char_u *)0L}
1337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)0L, (char_u *)0L}
1340#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1343 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1345 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001346 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1347 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1349 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001351 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001353 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1354#ifdef HAVE_FSYNC
1355 (char_u *)&p_fs, PV_NONE,
1356 {(char_u *)TRUE, (char_u *)0L}
1357#else
1358 (char_u *)NULL, PV_NONE,
1359 {(char_u *)FALSE, (char_u *)0L}
1360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1363 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"graphic", "gr", P_BOOL|P_VI_DEF,
1366 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001368 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369#ifdef FEAT_QUICKFIX
1370 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372#else
1373 (char_u *)NULL, PV_NONE,
1374 {(char_u *)NULL, (char_u *)0L}
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1378#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001379 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {
1381# ifdef WIN3264
1382 /* may be changed to "grep -n" in os_win32.c */
1383 (char_u *)"findstr /n",
1384# else
1385# ifdef UNIX
1386 /* Add an extra file name so that grep will always
1387 * insert a file name in the match line. */
1388 (char_u *)"grep -n $* /dev/null",
1389# else
1390# ifdef VMS
1391 (char_u *)"SEARCH/NUMBERS ",
1392# else
1393 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394# endif
1395# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001403 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#ifdef CURSOR_SHAPE
1405 (char_u *)&p_guicursor, PV_NONE,
1406 {
1407# ifdef FEAT_GUI
1408 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001409# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1411# endif
1412 (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)NULL, (char_u *)0L}
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001418 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419#ifdef FEAT_GUI
1420 (char_u *)&p_guifont, PV_NONE,
1421 {(char_u *)"", (char_u *)0L}
1422#else
1423 (char_u *)NULL, PV_NONE,
1424 {(char_u *)NULL, (char_u *)0L}
1425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001427 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1429 (char_u *)&p_guifontset, PV_NONE,
1430 {(char_u *)"", (char_u *)0L}
1431#else
1432 (char_u *)NULL, PV_NONE,
1433 {(char_u *)NULL, (char_u *)0L}
1434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001436 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1438 (char_u *)&p_guifontwide, PV_NONE,
1439 {(char_u *)"", (char_u *)0L}
1440#else
1441 (char_u *)NULL, PV_NONE,
1442 {(char_u *)NULL, (char_u *)0L}
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001446#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 (char_u *)&p_ghr, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001453#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 (char_u *)&p_go, PV_NONE,
1455# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001456 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001458 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459# endif
1460#else
1461 (char_u *)NULL, PV_NONE,
1462 {(char_u *)NULL, (char_u *)0L}
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"guipty", NULL, P_BOOL|P_VI_DEF,
1466#if defined(FEAT_GUI)
1467 (char_u *)&p_guipty, PV_NONE,
1468#else
1469 (char_u *)NULL, PV_NONE,
1470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001472 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001473#if defined(FEAT_GUI_TABLINE)
1474 (char_u *)&p_gtl, PV_NONE,
1475 {(char_u *)"", (char_u *)0L}
1476#else
1477 (char_u *)NULL, PV_NONE,
1478 {(char_u *)NULL, (char_u *)0L}
1479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001481 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001482#if defined(FEAT_GUI_TABLINE)
1483 (char_u *)&p_gtt, PV_NONE,
1484 {(char_u *)"", (char_u *)0L}
1485#else
1486 (char_u *)NULL, PV_NONE,
1487 {(char_u *)NULL, (char_u *)0L}
1488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1491 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1494 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"helpheight", "hh", P_NUM|P_VI_DEF,
1498#ifdef FEAT_WINDOWS
1499 (char_u *)&p_hh, PV_NONE,
1500#else
1501 (char_u *)NULL, PV_NONE,
1502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001504 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505#ifdef FEAT_MULTI_LANG
1506 (char_u *)&p_hlg, PV_NONE,
1507 {(char_u *)"", (char_u *)0L}
1508#else
1509 (char_u *)NULL, PV_NONE,
1510 {(char_u *)0L, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {"hidden", "hid", P_BOOL|P_VI_DEF,
1514 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001516 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"history", "hi", P_NUM|P_VIM,
1521 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001522 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1524#ifdef FEAT_RIGHTLEFT
1525 (char_u *)&p_hkmap, PV_NONE,
1526#else
1527 (char_u *)NULL, PV_NONE,
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1531#ifdef FEAT_RIGHTLEFT
1532 (char_u *)&p_hkmapp, PV_NONE,
1533#else
1534 (char_u *)NULL, PV_NONE,
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1538 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"icon", NULL, P_BOOL|P_VI_DEF,
1541#ifdef FEAT_TITLE
1542 (char_u *)&p_icon, PV_NONE,
1543#else
1544 (char_u *)NULL, PV_NONE,
1545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 {"iconstring", NULL, P_STRING|P_VI_DEF,
1548#ifdef FEAT_TITLE
1549 (char_u *)&p_iconstring, PV_NONE,
1550#else
1551 (char_u *)NULL, PV_NONE,
1552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001553 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1555 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001557 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1558# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1559 (char_u *)&p_imaf, PV_NONE,
1560 {(char_u *)"", (char_u *)NULL}
1561# else
1562 (char_u *)NULL, PV_NONE,
1563 {(char_u *)NULL, (char_u *)0L}
1564# endif
1565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001567#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 (char_u *)&p_imak, PV_NONE,
1569#else
1570 (char_u *)NULL, PV_NONE,
1571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1574#ifdef USE_IM_CONTROL
1575 (char_u *)&p_imcmdline, PV_NONE,
1576#else
1577 (char_u *)NULL, PV_NONE,
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1581#ifdef USE_IM_CONTROL
1582 (char_u *)&p_imdisable, PV_NONE,
1583#else
1584 (char_u *)NULL, PV_NONE,
1585#endif
1586#ifdef __sgi
1587 {(char_u *)TRUE, (char_u *)0L}
1588#else
1589 {(char_u *)FALSE, (char_u *)0L}
1590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001592 {"iminsert", "imi", P_NUM|P_VI_DEF,
1593 (char_u *)&p_iminsert, PV_IMI,
1594#ifdef B_IMODE_IM
1595 {(char_u *)B_IMODE_IM, (char_u *)0L}
1596#else
1597 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"imsearch", "ims", P_NUM|P_VI_DEF,
1601 (char_u *)&p_imsearch, PV_IMS,
1602#ifdef B_IMODE_IM
1603 {(char_u *)B_IMODE_IM, (char_u *)0L}
1604#else
1605 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001607 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001608 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001609# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1610 (char_u *)&p_imsf, PV_NONE,
1611 {(char_u *)"", (char_u *)NULL}
1612# else
1613 (char_u *)NULL, PV_NONE,
1614 {(char_u *)NULL, (char_u *)0L}
1615# endif
1616 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1618#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001619 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1621#else
1622 (char_u *)NULL, PV_NONE,
1623 {(char_u *)0L, (char_u *)0L}
1624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1627#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1628 (char_u *)&p_inex, PV_INEX,
1629 {(char_u *)"", (char_u *)0L}
1630#else
1631 (char_u *)NULL, PV_NONE,
1632 {(char_u *)0L, (char_u *)0L}
1633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1636 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1639#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1640 (char_u *)&p_inde, PV_INDE,
1641 {(char_u *)"", (char_u *)0L}
1642#else
1643 (char_u *)NULL, PV_NONE,
1644 {(char_u *)0L, (char_u *)0L}
1645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001647 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1649 (char_u *)&p_indk, PV_INDK,
1650 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1651#else
1652 (char_u *)NULL, PV_NONE,
1653 {(char_u *)0L, (char_u *)0L}
1654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656 {"infercase", "inf", P_BOOL|P_VI_DEF,
1657 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1660 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1663 (char_u *)&p_isf, PV_NONE,
1664 {
1665#ifdef BACKSLASH_IN_FILENAME
1666 /* Excluded are: & and ^ are special in cmd.exe
1667 * ( and ) are used in text separating fnames */
1668 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1669#else
1670# ifdef AMIGA
1671 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1672# else
1673# ifdef VMS
1674 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1675# else /* UNIX et al. */
1676# ifdef EBCDIC
1677 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1678# else
1679 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1680# endif
1681# endif
1682# endif
1683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1686 (char_u *)&p_isi, PV_NONE,
1687 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001688#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 (char_u *)"@,48-57,_,128-167,224-235",
1690#else
1691# ifdef EBCDIC
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,_,192-255",
1699# endif
1700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001701 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1703 (char_u *)&p_isk, PV_ISK,
1704 {
1705#ifdef EBCDIC
1706 (char_u *)"@,240-249,_",
1707 /* TODO: EBCDIC Check this! @ == isalpha()*/
1708 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1709 "112-120,128,140-142,156,158,172,"
1710 "174,186,191,203-207,219-225,235-239,"
1711 "251-254",
1712#else
1713 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001714# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 (char_u *)"@,48-57,_,128-167,224-235"
1716# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001717 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718# endif
1719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001720 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1722 (char_u *)&p_isp, PV_NONE,
1723 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001724#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 || defined(VMS)
1726 (char_u *)"@,~-255",
1727#else
1728# ifdef EBCDIC
1729 /* all chars above 63 are printable */
1730 (char_u *)"63-255",
1731# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001732 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733# endif
1734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001735 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1737 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1740#ifdef FEAT_CRYPT
1741 (char_u *)&p_key, PV_KEY,
1742 {(char_u *)"", (char_u *)0L}
1743#else
1744 (char_u *)NULL, PV_NONE,
1745 {(char_u *)0L, (char_u *)0L}
1746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001747 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001748 {"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 +00001749#ifdef FEAT_KEYMAP
1750 (char_u *)&p_keymap, PV_KMAP,
1751 {(char_u *)"", (char_u *)0L}
1752#else
1753 (char_u *)NULL, PV_NONE,
1754 {(char_u *)"", (char_u *)0L}
1755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001757 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001760 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001761 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001763#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 (char_u *)":help",
1765#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001766# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001768# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001769# ifdef USEMAN_S
1770 (char_u *)"man -s",
1771# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001773# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774# endif
1775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001777 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778#ifdef FEAT_LANGMAP
1779 (char_u *)&p_langmap, PV_NONE,
1780 {(char_u *)"", /* unmatched } */
1781#else
1782 (char_u *)NULL, PV_NONE,
1783 {(char_u *)NULL,
1784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001786 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1788 (char_u *)&p_lm, PV_NONE,
1789#else
1790 (char_u *)NULL, PV_NONE,
1791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001793 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1794#ifdef FEAT_LANGMAP
1795 (char_u *)&p_lnr, PV_NONE,
1796#else
1797 (char_u *)NULL, PV_NONE,
1798#endif
1799 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001800 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1801#ifdef FEAT_LANGMAP
1802 (char_u *)&p_lrm, PV_NONE,
1803#else
1804 (char_u *)NULL, PV_NONE,
1805#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001806 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1808#ifdef FEAT_WINDOWS
1809 (char_u *)&p_ls, PV_NONE,
1810#else
1811 (char_u *)NULL, PV_NONE,
1812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1815 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1818#ifdef FEAT_LINEBREAK
1819 (char_u *)VAR_WIN, PV_LBR,
1820#else
1821 (char_u *)NULL, PV_NONE,
1822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1825 (char_u *)&Rows, PV_NONE,
1826 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001827#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 (char_u *)25L,
1829#else
1830 (char_u *)24L,
1831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1834#ifdef FEAT_GUI
1835 (char_u *)&p_linespace, PV_NONE,
1836#else
1837 (char_u *)NULL, PV_NONE,
1838#endif
1839#ifdef FEAT_GUI_W32
1840 {(char_u *)1L, (char_u *)0L}
1841#else
1842 {(char_u *)0L, (char_u *)0L}
1843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"lisp", NULL, P_BOOL|P_VI_DEF,
1846#ifdef FEAT_LISP
1847 (char_u *)&p_lisp, PV_LISP,
1848#else
1849 (char_u *)NULL, PV_NONE,
1850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001852 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001854 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1856#else
1857 (char_u *)NULL, PV_NONE,
1858 {(char_u *)"", (char_u *)0L}
1859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1862 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001864 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1868 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001870 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001871#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001872 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001873 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001874#else
1875 (char_u *)NULL, PV_NONE,
1876 {(char_u *)"", (char_u *)0L}
1877#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001878 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001879 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001880#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001881 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001882 {(char_u *)TRUE, (char_u *)0L}
1883#else
1884 (char_u *)NULL, PV_NONE,
1885 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001886#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001887 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"magic", NULL, P_BOOL|P_VI_DEF,
1889 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001891 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892#ifdef FEAT_QUICKFIX
1893 (char_u *)&p_mef, PV_NONE,
1894 {(char_u *)"", (char_u *)0L}
1895#else
1896 (char_u *)NULL, PV_NONE,
1897 {(char_u *)NULL, (char_u *)0L}
1898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001900 {"makeencoding","menc", P_STRING|P_VI_DEF,
1901#ifdef FEAT_MBYTE
1902 (char_u *)&p_menc, PV_MENC,
1903 {(char_u *)"", (char_u *)0L}
1904#else
1905 (char_u *)NULL, PV_NONE,
1906 {(char_u *)0L, (char_u *)0L}
1907#endif
1908 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1910#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001911 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912# ifdef VMS
1913 {(char_u *)"MMS", (char_u *)0L}
1914# else
1915 {(char_u *)"make", (char_u *)0L}
1916# endif
1917#else
1918 (char_u *)NULL, PV_NONE,
1919 {(char_u *)NULL, (char_u *)0L}
1920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001922 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1925 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"matchtime", "mat", P_NUM|P_VI_DEF,
1927 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001929 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001930#ifdef FEAT_MBYTE
1931 (char_u *)&p_mco, PV_NONE,
1932#else
1933 (char_u *)NULL, PV_NONE,
1934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1937#ifdef FEAT_EVAL
1938 (char_u *)&p_mfd, PV_NONE,
1939#else
1940 (char_u *)NULL, PV_NONE,
1941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001942 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1944 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001945 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001946 {"maxmem", "mm", P_NUM|P_VI_DEF,
1947 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001948 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1949 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001950 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1951 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1954 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1956 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 {"menuitems", "mis", P_NUM|P_VI_DEF,
1958#ifdef FEAT_MENU
1959 (char_u *)&p_mis, PV_NONE,
1960#else
1961 (char_u *)NULL, PV_NONE,
1962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"mesg", NULL, P_BOOL|P_VI_DEF,
1965 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001967 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001968#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001969 (char_u *)&p_msm, PV_NONE,
1970 {(char_u *)"460000,2000,500", (char_u *)0L}
1971#else
1972 (char_u *)NULL, PV_NONE,
1973 {(char_u *)0L, (char_u *)0L}
1974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 {"modeline", "ml", P_BOOL|P_VIM,
1977 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"modelines", "mls", P_NUM|P_VI_DEF,
1980 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1983 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1986 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"more", NULL, P_BOOL|P_VIM,
1989 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1992 (char_u *)&p_mouse, PV_NONE,
1993 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001994#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 (char_u *)"a",
1996#else
1997 (char_u *)"",
1998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001999 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2001#ifdef FEAT_GUI
2002 (char_u *)&p_mousef, PV_NONE,
2003#else
2004 (char_u *)NULL, PV_NONE,
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2008#ifdef FEAT_GUI
2009 (char_u *)&p_mh, PV_NONE,
2010#else
2011 (char_u *)NULL, PV_NONE,
2012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002014 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2015 (char_u *)&p_mousem, PV_NONE,
2016 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002017#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 (char_u *)"popup",
2019#else
2020# if defined(MACOS)
2021 (char_u *)"popup_setpos",
2022# else
2023 (char_u *)"extend",
2024# endif
2025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002026 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002027 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028#ifdef FEAT_MOUSESHAPE
2029 (char_u *)&p_mouseshape, PV_NONE,
2030 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2031#else
2032 (char_u *)NULL, PV_NONE,
2033 {(char_u *)NULL, (char_u *)0L}
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2037 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002038 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002039 {"mzquantum", "mzq", P_NUM,
2040#ifdef FEAT_MZSCHEME
2041 (char_u *)&p_mzq, PV_NONE,
2042#else
2043 (char_u *)NULL, PV_NONE,
2044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046 {"novice", NULL, P_BOOL|P_VI_DEF,
2047 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002048 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002049 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002051 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2054 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002055 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002056 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2057#ifdef FEAT_LINEBREAK
2058 (char_u *)VAR_WIN, PV_NUW,
2059#else
2060 (char_u *)NULL, PV_NONE,
2061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002062 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002063 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002064#ifdef FEAT_COMPL_FUNC
2065 (char_u *)&p_ofu, PV_OFU,
2066 {(char_u *)"", (char_u *)0L}
2067#else
2068 (char_u *)NULL, PV_NONE,
2069 {(char_u *)0L, (char_u *)0L}
2070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 {"open", NULL, P_BOOL|P_VI_DEF,
2073 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002075 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002076#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002077 (char_u *)&p_odev, PV_NONE,
2078#else
2079 (char_u *)NULL, PV_NONE,
2080#endif
2081 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002082 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002083 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2084 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"optimize", "opt", P_BOOL|P_VI_DEF,
2087 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002091 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002092 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2093 |P_SECURE,
2094 (char_u *)&p_pp, PV_NONE,
2095 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2096 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097 {"paragraphs", "para", P_STRING|P_VI_DEF,
2098 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002099 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002100 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002101 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2105 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002106 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2108#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2109 (char_u *)&p_pex, PV_NONE,
2110 {(char_u *)"", (char_u *)0L}
2111#else
2112 (char_u *)NULL, PV_NONE,
2113 {(char_u *)0L, (char_u *)0L}
2114#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002115 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002116 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002120 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002122#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)".,,",
2124#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002128 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002129#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002130 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002131 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002132#else
2133 (char_u *)NULL, PV_NONE,
2134 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002135#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002136 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2138 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002139 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002140 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2142 (char_u *)&p_pvh, PV_NONE,
2143#else
2144 (char_u *)NULL, PV_NONE,
2145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002146 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2148#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2149 (char_u *)VAR_WIN, PV_PVW,
2150#else
2151 (char_u *)NULL, PV_NONE,
2152#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002154 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155#ifdef FEAT_PRINTER
2156 (char_u *)&p_pdev, PV_NONE,
2157 {(char_u *)"", (char_u *)0L}
2158#else
2159 (char_u *)NULL, PV_NONE,
2160 {(char_u *)NULL, (char_u *)0L}
2161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002162 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002163 {"printencoding", "penc", P_STRING|P_VI_DEF,
2164#ifdef FEAT_POSTSCRIPT
2165 (char_u *)&p_penc, PV_NONE,
2166 {(char_u *)"", (char_u *)0L}
2167#else
2168 (char_u *)NULL, PV_NONE,
2169 {(char_u *)NULL, (char_u *)0L}
2170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002171 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002172 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173#ifdef FEAT_POSTSCRIPT
2174 (char_u *)&p_pexpr, PV_NONE,
2175 {(char_u *)"", (char_u *)0L}
2176#else
2177 (char_u *)NULL, PV_NONE,
2178 {(char_u *)NULL, (char_u *)0L}
2179#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002180 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 {"printfont", "pfn", P_STRING|P_VI_DEF,
2182#ifdef FEAT_PRINTER
2183 (char_u *)&p_pfn, PV_NONE,
2184 {
2185# ifdef MSWIN
2186 (char_u *)"Courier_New:h10",
2187# else
2188 (char_u *)"courier",
2189# endif
2190 (char_u *)0L}
2191#else
2192 (char_u *)NULL, PV_NONE,
2193 {(char_u *)NULL, (char_u *)0L}
2194#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002195 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002196 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2197#ifdef FEAT_PRINTER
2198 (char_u *)&p_header, PV_NONE,
2199 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002205 {"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 Moolenaara6e42502016-04-20 16:19:52 +02002242 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002243#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002244 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002245 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002246#else
2247 (char_u *)NULL, PV_NONE,
2248 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002249#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002251 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002252#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002253 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002254 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002255#else
2256 (char_u *)NULL, PV_NONE,
2257 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002258#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002259 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002260 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2261#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2262 (char_u *)&p_pyx, PV_NONE,
2263#else
2264 (char_u *)NULL, PV_NONE,
2265#endif
2266 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2267 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002268 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2269#ifdef FEAT_TEXTOBJ
2270 (char_u *)&p_qe, PV_QE,
2271 {(char_u *)"\\", (char_u *)0L}
2272#else
2273 (char_u *)NULL, PV_NONE,
2274 {(char_u *)NULL, (char_u *)0L}
2275#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2278 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"redraw", NULL, P_BOOL|P_VI_DEF,
2281 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002283 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2284#ifdef FEAT_RELTIME
2285 (char_u *)&p_rdt, PV_NONE,
2286#else
2287 (char_u *)NULL, PV_NONE,
2288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002290 {"regexpengine", "re", P_NUM|P_VI_DEF,
2291 (char_u *)&p_re, PV_NONE,
2292 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002293 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2294 (char_u *)VAR_WIN, PV_RNU,
2295 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"remap", NULL, P_BOOL|P_VI_DEF,
2297 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002298 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002299 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002300#ifdef FEAT_RENDER_OPTIONS
2301 (char_u *)&p_rop, PV_NONE,
2302 {(char_u *)"", (char_u *)0L}
2303#else
2304 (char_u *)NULL, PV_NONE,
2305 {(char_u *)NULL, (char_u *)0L}
2306#endif
2307 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"report", NULL, P_NUM|P_VI_DEF,
2309 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2312#ifdef WIN3264
2313 (char_u *)&p_rs, PV_NONE,
2314#else
2315 (char_u *)NULL, PV_NONE,
2316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2319#ifdef FEAT_RIGHTLEFT
2320 (char_u *)&p_ri, PV_NONE,
2321#else
2322 (char_u *)NULL, PV_NONE,
2323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2326#ifdef FEAT_RIGHTLEFT
2327 (char_u *)VAR_WIN, PV_RL,
2328#else
2329 (char_u *)NULL, PV_NONE,
2330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2333#ifdef FEAT_RIGHTLEFT
2334 (char_u *)VAR_WIN, PV_RLC,
2335 {(char_u *)"search", (char_u *)NULL}
2336#else
2337 (char_u *)NULL, PV_NONE,
2338 {(char_u *)NULL, (char_u *)0L}
2339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002341 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002342#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002343 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002344 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002345#else
2346 (char_u *)NULL, PV_NONE,
2347 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002348#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2351#ifdef FEAT_CMDL_INFO
2352 (char_u *)&p_ru, PV_NONE,
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 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2358#ifdef FEAT_STL_OPT
2359 (char_u *)&p_ruf, PV_NONE,
2360#else
2361 (char_u *)NULL, PV_NONE,
2362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002364 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2365 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2368 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2370 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2373#ifdef FEAT_SCROLLBIND
2374 (char_u *)VAR_WIN, PV_SCBIND,
2375#else
2376 (char_u *)NULL, PV_NONE,
2377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2380 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2383 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002385 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386#ifdef FEAT_SCROLLBIND
2387 (char_u *)&p_sbo, PV_NONE,
2388 {(char_u *)"ver,jump", (char_u *)0L}
2389#else
2390 (char_u *)NULL, PV_NONE,
2391 {(char_u *)0L, (char_u *)0L}
2392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"sections", "sect", P_STRING|P_VI_DEF,
2395 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2397 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2399 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)"inclusive", (char_u *)0L}
2404 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002405 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002408 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409#ifdef FEAT_SESSION
2410 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002411 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 (char_u *)0L}
2413#else
2414 (char_u *)NULL, PV_NONE,
2415 {(char_u *)0L, (char_u *)0L}
2416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002417 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2419 (char_u *)&p_sh, PV_NONE,
2420 {
2421#ifdef VMS
2422 (char_u *)"-",
2423#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002424# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002426# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428# endif
2429#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2432 (char_u *)&p_shcf, PV_NONE,
2433 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002434#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 (char_u *)"/c",
2436#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2441#ifdef FEAT_QUICKFIX
2442 (char_u *)&p_sp, PV_NONE,
2443 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002444#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446#else
2447 (char_u *)">",
2448#endif
2449 (char_u *)0L}
2450#else
2451 (char_u *)NULL, PV_NONE,
2452 {(char_u *)0L, (char_u *)0L}
2453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2456 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002457 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2459 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2462#ifdef BACKSLASH_IN_FILENAME
2463 (char_u *)&p_ssl, PV_NONE,
2464#else
2465 (char_u *)NULL, PV_NONE,
2466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002468 {"shelltemp", "stmp", P_BOOL,
2469 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"shelltype", "st", P_NUM|P_VI_DEF,
2472#ifdef AMIGA
2473 (char_u *)&p_st, PV_NONE,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2479 (char_u *)&p_sxq, PV_NONE,
2480 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002481#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 (char_u *)"\"",
2483#else
2484 (char_u *)"",
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002487 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2488 (char_u *)&p_sxe, PV_NONE,
2489 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002490#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002491 (char_u *)"\"&|<>()@^",
2492#else
2493 (char_u *)"",
2494#endif
2495 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2497 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2500 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2503 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)"", (char_u *)"filnxtToO"}
2505 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2510#ifdef FEAT_LINEBREAK
2511 (char_u *)&p_sbr, PV_NONE,
2512#else
2513 (char_u *)NULL, PV_NONE,
2514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"showcmd", "sc", P_BOOL|P_VIM,
2517#ifdef FEAT_CMDL_INFO
2518 (char_u *)&p_sc, PV_NONE,
2519#else
2520 (char_u *)NULL, PV_NONE,
2521#endif
2522 {(char_u *)FALSE,
2523#ifdef UNIX
2524 (char_u *)FALSE
2525#else
2526 (char_u *)TRUE
2527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2530 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2533 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"showmode", "smd", P_BOOL|P_VIM,
2536 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002538 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2539#ifdef FEAT_WINDOWS
2540 (char_u *)&p_stal, PV_NONE,
2541#else
2542 (char_u *)NULL, PV_NONE,
2543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2546 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2549 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002551 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2552#ifdef FEAT_SIGNS
2553 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002554 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002555#else
2556 (char_u *)NULL, PV_NONE,
2557 {(char_u *)NULL, (char_u *)0L}
2558#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002559 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2561 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2564 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2567#ifdef FEAT_SMARTINDENT
2568 (char_u *)&p_si, PV_SI,
2569#else
2570 (char_u *)NULL, PV_NONE,
2571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2574 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2577 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2580 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002582 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002583#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002584 (char_u *)VAR_WIN, PV_SPELL,
2585#else
2586 (char_u *)NULL, PV_NONE,
2587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002589 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002590#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002591 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002592 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002593#else
2594 (char_u *)NULL, PV_NONE,
2595 {(char_u *)0L, (char_u *)0L}
2596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002598 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2599 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002600#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002601 (char_u *)&p_spf, PV_SPF,
2602 {(char_u *)"", (char_u *)0L}
2603#else
2604 (char_u *)NULL, PV_NONE,
2605 {(char_u *)0L, (char_u *)0L}
2606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002608 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2609 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002610#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002611 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002612 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002613#else
2614 (char_u *)NULL, PV_NONE,
2615 {(char_u *)0L, (char_u *)0L}
2616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002618 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002619#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002620 (char_u *)&p_sps, PV_NONE,
2621 {(char_u *)"best", (char_u *)0L}
2622#else
2623 (char_u *)NULL, PV_NONE,
2624 {(char_u *)0L, (char_u *)0L}
2625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2628#ifdef FEAT_WINDOWS
2629 (char_u *)&p_sb, PV_NONE,
2630#else
2631 (char_u *)NULL, PV_NONE,
2632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002635#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 (char_u *)&p_spr, PV_NONE,
2637#else
2638 (char_u *)NULL, PV_NONE,
2639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002640 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2642 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002643 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2645#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002646 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647#else
2648 (char_u *)NULL, PV_NONE,
2649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002651 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 (char_u *)&p_su, PV_NONE,
2653 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002655 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002656#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657 (char_u *)&p_sua, PV_SUA,
2658 {(char_u *)"", (char_u *)0L}
2659#else
2660 (char_u *)NULL, PV_NONE,
2661 {(char_u *)0L, (char_u *)0L}
2662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2665 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"swapsync", "sws", P_STRING|P_VI_DEF,
2668 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002670 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002673 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2674#ifdef FEAT_SYN_HL
2675 (char_u *)&p_smc, PV_SMC,
2676 {(char_u *)3000L, (char_u *)0L}
2677#else
2678 (char_u *)NULL, PV_NONE,
2679 {(char_u *)0L, (char_u *)0L}
2680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002682 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683#ifdef FEAT_SYN_HL
2684 (char_u *)&p_syn, PV_SYN,
2685 {(char_u *)"", (char_u *)0L}
2686#else
2687 (char_u *)NULL, PV_NONE,
2688 {(char_u *)0L, (char_u *)0L}
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002691 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2692#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002693 (char_u *)&p_tal, PV_NONE,
2694#else
2695 (char_u *)NULL, PV_NONE,
2696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002698 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2699#ifdef FEAT_WINDOWS
2700 (char_u *)&p_tpm, PV_NONE,
2701#else
2702 (char_u *)NULL, PV_NONE,
2703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2706 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2709 (char_u *)&p_tbs, PV_NONE,
2710#ifdef VMS /* binary searching doesn't appear to work on VMS */
2711 {(char_u *)0L, (char_u *)0L}
2712#else
2713 {(char_u *)TRUE, (char_u *)0L}
2714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002716 {"tagcase", "tc", P_STRING|P_VIM,
2717 (char_u *)&p_tc, PV_TC,
2718 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"taglength", "tl", P_NUM|P_VI_DEF,
2720 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"tagrelative", "tr", P_BOOL|P_VIM,
2723 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002725 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002726 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002727 {
2728#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2729 (char_u *)"./tags,./TAGS,tags,TAGS",
2730#else
2731 (char_u *)"./tags,tags",
2732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002733 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2735 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002736 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002737 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002738#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002739 (char_u *)&p_tcldll, PV_NONE,
2740 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002741#else
2742 (char_u *)NULL, PV_NONE,
2743 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002744#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002745 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002746 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2747 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002748 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002749 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2750#ifdef FEAT_ARABIC
2751 (char_u *)&p_tbidi, PV_NONE,
2752#else
2753 (char_u *)NULL, PV_NONE,
2754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2757#ifdef FEAT_MBYTE
2758 (char_u *)&p_tenc, PV_NONE,
2759 {(char_u *)"", (char_u *)0L}
2760#else
2761 (char_u *)NULL, PV_NONE,
2762 {(char_u *)0L, (char_u *)0L}
2763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002765 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2766#ifdef FEAT_TERMGUICOLORS
2767 (char_u *)&p_tgc, PV_NONE,
2768 {(char_u *)FALSE, (char_u *)FALSE}
2769#else
2770 (char_u*)NULL, PV_NONE,
2771 {(char_u *)FALSE, (char_u *)FALSE}
2772#endif
2773 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002774 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2775#ifdef FEAT_TERMINAL
2776 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002777 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002778#else
2779 (char_u *)NULL, PV_NONE,
2780 {(char_u *)NULL, (char_u *)0L}
2781#endif
2782 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002783 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2784#ifdef FEAT_TERMINAL
2785 (char_u *)VAR_WIN, PV_TMS,
2786 {(char_u *)"", (char_u *)NULL}
2787#else
2788 (char_u *)NULL, PV_NONE,
2789 {(char_u *)NULL, (char_u *)0L}
2790#endif
2791 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"terse", NULL, P_BOOL|P_VI_DEF,
2793 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 {"textauto", "ta", P_BOOL|P_VIM,
2796 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2798 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2800 (char_u *)&p_tx, PV_TX,
2801 {
2802#ifdef USE_CRNL
2803 (char_u *)TRUE,
2804#else
2805 (char_u *)FALSE,
2806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002808 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002811 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002813 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814#else
2815 (char_u *)NULL, PV_NONE,
2816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2819 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"timeout", "to", P_BOOL|P_VI_DEF,
2822 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002823 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2825 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"title", NULL, P_BOOL|P_VI_DEF,
2828#ifdef FEAT_TITLE
2829 (char_u *)&p_title, PV_NONE,
2830#else
2831 (char_u *)NULL, PV_NONE,
2832#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"titlelen", NULL, P_NUM|P_VI_DEF,
2835#ifdef FEAT_TITLE
2836 (char_u *)&p_titlelen, PV_NONE,
2837#else
2838 (char_u *)NULL, PV_NONE,
2839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002841 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842#ifdef FEAT_TITLE
2843 (char_u *)&p_titleold, PV_NONE,
2844 {(char_u *)N_("Thanks for flying Vim"),
2845 (char_u *)0L}
2846#else
2847 (char_u *)NULL, PV_NONE,
2848 {(char_u *)0L, (char_u *)0L}
2849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"titlestring", NULL, P_STRING|P_VI_DEF,
2852#ifdef FEAT_TITLE
2853 (char_u *)&p_titlestring, PV_NONE,
2854#else
2855 (char_u *)NULL, PV_NONE,
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002858 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002859#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002861 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002862#else
2863 (char_u *)NULL, PV_NONE,
2864 {(char_u *)0L, (char_u *)0L}
2865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002868#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002870 {(char_u *)"small", (char_u *)0L}
2871#else
2872 (char_u *)NULL, PV_NONE,
2873 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2877 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2880 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2883 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002884 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2886 (char_u *)&p_tf, 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 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2889#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2890 (char_u *)&p_ttym, PV_NONE,
2891#else
2892 (char_u *)NULL, PV_NONE,
2893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002894 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2896 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2899 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002901 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2902 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002903#ifdef FEAT_PERSISTENT_UNDO
2904 (char_u *)&p_udir, PV_NONE,
2905 {(char_u *)".", (char_u *)0L}
2906#else
2907 (char_u *)NULL, PV_NONE,
2908 {(char_u *)0L, (char_u *)0L}
2909#endif
2910 SCRIPTID_INIT},
2911 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2912#ifdef FEAT_PERSISTENT_UNDO
2913 (char_u *)&p_udf, PV_UDF,
2914#else
2915 (char_u *)NULL, PV_NONE,
2916#endif
2917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002919 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002921#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 (char_u *)1000L,
2923#else
2924 (char_u *)100L,
2925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002927 {"undoreload", "ur", P_NUM|P_VI_DEF,
2928 (char_u *)&p_ur, PV_NONE,
2929 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"updatecount", "uc", P_NUM|P_VI_DEF,
2931 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002932 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 {"updatetime", "ut", P_NUM|P_VI_DEF,
2934 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"verbose", "vbs", P_NUM|P_VI_DEF,
2937 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002939 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2940 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002941 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2943#ifdef FEAT_SESSION
2944 (char_u *)&p_vdir, PV_NONE,
2945 {(char_u *)DFLT_VDIR, (char_u *)0L}
2946#else
2947 (char_u *)NULL, PV_NONE,
2948 {(char_u *)0L, (char_u *)0L}
2949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002951 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952#ifdef FEAT_SESSION
2953 (char_u *)&p_vop, PV_NONE,
2954 {(char_u *)"folds,options,cursor", (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 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961#ifdef FEAT_VIMINFO
2962 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002963#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002964 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965#else
2966# ifdef AMIGA
2967 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002968 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002970 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971# endif
2972#endif
2973#else
2974 (char_u *)NULL, PV_NONE,
2975 {(char_u *)0L, (char_u *)0L}
2976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002977 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002978 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2979#ifdef FEAT_VIMINFO
2980 (char_u *)&p_viminfofile, PV_NONE,
2981 {(char_u *)"", (char_u *)0L}
2982#else
2983 (char_u *)NULL, PV_NONE,
2984 {(char_u *)0L, (char_u *)0L}
2985#endif
2986 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002987 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2988 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989#ifdef FEAT_VIRTUALEDIT
2990 (char_u *)&p_ve, PV_NONE,
2991 {(char_u *)"", (char_u *)""}
2992#else
2993 (char_u *)NULL, PV_NONE,
2994 {(char_u *)0L, (char_u *)0L}
2995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2998 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 {"w300", NULL, P_NUM|P_VI_DEF,
3001 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003002 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 {"w1200", NULL, P_NUM|P_VI_DEF,
3004 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003005 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 {"w9600", NULL, P_NUM|P_VI_DEF,
3007 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003008 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 {"warn", NULL, P_BOOL|P_VI_DEF,
3010 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3013 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003014 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003015 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003017 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 {"wildchar", "wc", P_NUM|P_VIM,
3019 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3021 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003022 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003025 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026#ifdef FEAT_WILDIGN
3027 (char_u *)&p_wig, PV_NONE,
3028#else
3029 (char_u *)NULL, PV_NONE,
3030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003031 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003032 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3033 (char_u *)&p_wic, PV_NONE,
3034 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3036#ifdef FEAT_WILDMENU
3037 (char_u *)&p_wmnu, PV_NONE,
3038#else
3039 (char_u *)NULL, PV_NONE,
3040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003041 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003042 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003044 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003045 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3046#ifdef FEAT_CMDL_COMPL
3047 (char_u *)&p_wop, PV_NONE,
3048 {(char_u *)"", (char_u *)0L}
3049#else
3050 (char_u *)NULL, PV_NONE,
3051 {(char_u *)NULL, (char_u *)0L}
3052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003053 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3055#ifdef FEAT_WAK
3056 (char_u *)&p_wak, PV_NONE,
3057 {(char_u *)"menu", (char_u *)0L}
3058#else
3059 (char_u *)NULL, PV_NONE,
3060 {(char_u *)NULL, (char_u *)0L}
3061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003064 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"winheight", "wh", P_NUM|P_VI_DEF,
3067#ifdef FEAT_WINDOWS
3068 (char_u *)&p_wh, PV_NONE,
3069#else
3070 (char_u *)NULL, PV_NONE,
3071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003072 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003074#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 (char_u *)VAR_WIN, PV_WFH,
3076#else
3077 (char_u *)NULL, PV_NONE,
3078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003079 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003080 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003081#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003082 (char_u *)VAR_WIN, PV_WFW,
3083#else
3084 (char_u *)NULL, PV_NONE,
3085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3088#ifdef FEAT_WINDOWS
3089 (char_u *)&p_wmh, PV_NONE,
3090#else
3091 (char_u *)NULL, PV_NONE,
3092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003093 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003095#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 (char_u *)&p_wmw, PV_NONE,
3097#else
3098 (char_u *)NULL, PV_NONE,
3099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003100 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003102#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103 (char_u *)&p_wiw, PV_NONE,
3104#else
3105 (char_u *)NULL, PV_NONE,
3106#endif
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)
3146 p_term("t_cd", T_CD)
3147 p_term("t_ce", T_CE)
3148 p_term("t_cl", T_CL)
3149 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003150 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_Co", T_CCO)
3152 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003153 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003155#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_CV", T_CSV)
3157#endif
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 Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 p_term("t_fs", T_FS)
3164 p_term("t_IE", T_CIE)
3165 p_term("t_IS", T_CIS)
3166 p_term("t_ke", T_KE)
3167 p_term("t_ks", T_KS)
3168 p_term("t_le", T_LE)
3169 p_term("t_mb", T_MB)
3170 p_term("t_md", T_MD)
3171 p_term("t_me", T_ME)
3172 p_term("t_mr", T_MR)
3173 p_term("t_ms", T_MS)
3174 p_term("t_nd", T_ND)
3175 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_RI", T_CRI)
3178 p_term("t_RV", T_CRV)
3179 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003181 p_term("t_Sf", T_CSF)
3182 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003184 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186 p_term("t_te", T_TE)
3187 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003188 p_term("t_ts", T_TS)
3189 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190 p_term("t_ue", T_UE)
3191 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003192 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 p_term("t_vb", T_VB)
3194 p_term("t_ve", T_VE)
3195 p_term("t_vi", T_VI)
3196 p_term("t_vs", T_VS)
3197 p_term("t_WP", T_CWP)
Bram Moolenaar9f928862017-04-11 22:44:05 +02003198 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003200 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 p_term("t_xs", T_XS)
3202 p_term("t_ZH", T_CZH)
3203 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003204 p_term("t_8f", T_8F)
3205 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003206 p_term("t_BE", T_BE)
3207 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208
3209/* terminal key codes are not in here */
3210
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003211 /* end marker */
3212 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213};
3214
3215#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3216
3217#ifdef FEAT_MBYTE
3218static char *(p_ambw_values[]) = {"single", "double", NULL};
3219#endif
3220static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003221static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003223#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003224static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003225#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003226#ifdef FEAT_CMDL_COMPL
3227static char *(p_wop_values[]) = {"tagfile", NULL};
3228#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229#ifdef FEAT_WAK
3230static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3231#endif
3232static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3234static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236#ifdef FEAT_BROWSE
3237static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3238#endif
3239#ifdef FEAT_SCROLLBIND
3240static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3241#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003242static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003243#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3245#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003246#ifdef FEAT_AUTOCMD
3247static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3248#else
3249static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003251static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3253#ifdef FEAT_FOLDING
3254static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003255# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003257# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258 NULL};
3259static char *(p_fcl_values[]) = {"all", NULL};
3260#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003261#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003262static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003263#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003264#ifdef FEAT_SIGNS
3265static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3266#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static void set_option_default(int, int opt_flags, int compatible);
3269static void set_options_default(int opt_flags);
3270static char_u *term_bg_default(void);
3271static void did_set_option(int opt_idx, int opt_flags, int new_value);
3272static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275#endif
3276#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static char_u *option_expand(int opt_idx, char_u *val);
3280static void didset_options(void);
3281static void didset_options2(void);
3282static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003283#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003285#else
3286# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3287#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003288static void set_string_option_global(int opt_idx, char_u **varp);
3289static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3290static 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);
3291static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003292#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003298#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static char_u *did_set_spell_option(int is_spellfile);
3300static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003301#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003302#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003303static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003304#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3306static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3307static void check_redraw(long_u flags);
3308static int findoption(char_u *);
3309static int find_key_option(char_u *);
3310static void showoptions(int all, int opt_flags);
3311static int optval_default(struct vimoption *, char_u *varp);
3312static void showoneopt(struct vimoption *, int opt_flags);
3313static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3314static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3315static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3316static int istermoption(struct vimoption *);
3317static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3318static char_u *get_varp(struct vimoption *);
3319static void option_value2string(struct vimoption *, int opt_flags);
3320static void check_winopt(winopt_T *wop);
3321static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003323static void langmap_init(void);
3324static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003326static void paste_option_changed(void);
3327static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003329static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003331static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3332static int check_opt_strings(char_u *val, char **values, int);
3333static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003334#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003335static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337
3338/*
3339 * Initialize the options, first part.
3340 *
3341 * Called only once from main(), just after creating the first buffer.
3342 */
3343 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003344set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345{
3346 char_u *p;
3347 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003348 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349
3350#ifdef FEAT_LANGMAP
3351 langmap_init();
3352#endif
3353
3354 /* Be Vi compatible by default */
3355 p_cp = TRUE;
3356
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003357 /* Use POSIX compatibility when $VIM_POSIX is set. */
3358 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003359 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003360 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003361 set_string_default("shm", (char_u *)"A");
3362 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003363
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364 /*
3365 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003366 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003368 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003369#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003370 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003372 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373# endif
3374#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003375 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376 set_string_default("sh", p);
3377
3378#ifdef FEAT_WILDIGN
3379 /*
3380 * Set the default for 'backupskip' to include environment variables for
3381 * temp files.
3382 */
3383 {
3384# ifdef UNIX
3385 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3386# else
3387 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3388# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003389 int len;
3390 garray_T ga;
3391 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392
3393 ga_init2(&ga, 1, 100);
3394 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3395 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003396 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397# ifdef UNIX
3398 if (*names[n] == NUL)
3399 p = (char_u *)"/tmp";
3400 else
3401# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003402 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403 if (p != NULL && *p != NUL)
3404 {
3405 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003406 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407 if (ga_grow(&ga, len) == OK)
3408 {
3409 if (ga.ga_len > 0)
3410 STRCAT(ga.ga_data, ",");
3411 STRCAT(ga.ga_data, p);
3412 add_pathsep(ga.ga_data);
3413 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 ga.ga_len += len;
3415 }
3416 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003417 if (mustfree)
3418 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419 }
3420 if (ga.ga_data != NULL)
3421 {
3422 set_string_default("bsk", ga.ga_data);
3423 vim_free(ga.ga_data);
3424 }
3425 }
3426#endif
3427
3428 /*
3429 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3430 */
3431 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003432 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003434#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3435 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3436#endif
3437 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003439 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003440 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441#else
3442# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003443 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003444 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003446 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447# endif
3448#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003450 opt_idx = findoption((char_u *)"maxmem");
3451 if (opt_idx >= 0)
3452 {
3453#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003454 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3455 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003456#endif
3457 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3458 }
3459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460 }
3461
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462#ifdef FEAT_SEARCHPATH
3463 {
3464 char_u *cdpath;
3465 char_u *buf;
3466 int i;
3467 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003468 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469
3470 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003471 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 if (cdpath != NULL)
3473 {
3474 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3475 if (buf != NULL)
3476 {
3477 buf[0] = ','; /* start with ",", current dir first */
3478 j = 1;
3479 for (i = 0; cdpath[i] != NUL; ++i)
3480 {
3481 if (vim_ispathlistsep(cdpath[i]))
3482 buf[j++] = ',';
3483 else
3484 {
3485 if (cdpath[i] == ' ' || cdpath[i] == ',')
3486 buf[j++] = '\\';
3487 buf[j++] = cdpath[i];
3488 }
3489 }
3490 buf[j] = NUL;
3491 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003492 if (opt_idx >= 0)
3493 {
3494 options[opt_idx].def_val[VI_DEFAULT] = buf;
3495 options[opt_idx].flags |= P_DEF_ALLOCED;
3496 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003497 else
3498 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003500 if (mustfree)
3501 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502 }
3503 }
3504#endif
3505
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003506#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507 /* Set print encoding on platforms that don't default to latin1 */
3508 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003509# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510 (char_u *)"cp1252"
3511# else
3512# ifdef VMS
3513 (char_u *)"dec-mcs"
3514# else
3515# ifdef EBCDIC
3516 (char_u *)"ebcdic-uk"
3517# else
3518# ifdef MAC
3519 (char_u *)"mac-roman"
3520# else /* HPUX */
3521 (char_u *)"hp-roman8"
3522# endif
3523# endif
3524# endif
3525# endif
3526 );
3527#endif
3528
3529#ifdef FEAT_POSTSCRIPT
3530 /* 'printexpr' must be allocated to be able to evaluate it. */
3531 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003532# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003533 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003534# else
3535# ifdef VMS
3536 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3537
3538# else
3539 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3540# endif
3541# endif
3542 );
3543#endif
3544
3545 /*
3546 * Set all the options (except the terminal options) to their default
3547 * value. Also set the global value for local options.
3548 */
3549 set_options_default(0);
3550
3551#ifdef FEAT_GUI
3552 if (found_reverse_arg)
3553 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3554#endif
3555
3556 curbuf->b_p_initialized = TRUE;
3557 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003558 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559 check_buf_options(curbuf);
3560 check_win_options(curwin);
3561 check_options();
3562
3563 /* Must be before option_expand(), because that one needs vim_isIDc() */
3564 didset_options();
3565
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003566#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003567 /* Use the current chartab for the generic chartab. This is not in
3568 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003569 init_spell_chartab();
3570#endif
3571
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 /*
3573 * Expand environment variables and things like "~" for the defaults.
3574 * If option_expand() returns non-NULL the variable is expanded. This can
3575 * only happen for non-indirect options.
3576 * Also set the default to the expanded value, so ":set" does not list
3577 * them.
3578 * Don't set the P_ALLOCED flag, because we don't want to free the
3579 * default.
3580 */
3581 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3582 {
3583 if ((options[opt_idx].flags & P_GETTEXT)
3584 && options[opt_idx].var != NULL)
3585 p = (char_u *)_(*(char **)options[opt_idx].var);
3586 else
3587 p = option_expand(opt_idx, NULL);
3588 if (p != NULL && (p = vim_strsave(p)) != NULL)
3589 {
3590 *(char_u **)options[opt_idx].var = p;
3591 /* VIMEXP
3592 * Defaults for all expanded options are currently the same for Vi
3593 * and Vim. When this changes, add some code here! Also need to
3594 * split P_DEF_ALLOCED in two.
3595 */
3596 if (options[opt_idx].flags & P_DEF_ALLOCED)
3597 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3598 options[opt_idx].def_val[VI_DEFAULT] = p;
3599 options[opt_idx].flags |= P_DEF_ALLOCED;
3600 }
3601 }
3602
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 save_file_ff(curbuf); /* Buffer is unchanged */
3604
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605#if defined(FEAT_ARABIC)
3606 /* Detect use of mlterm.
3607 * Mlterm is a terminal emulator akin to xterm that has some special
3608 * abilities (bidi namely).
3609 * NOTE: mlterm's author is being asked to 'set' a variable
3610 * instead of an environment variable due to inheritance.
3611 */
3612 if (mch_getenv((char_u *)"MLTERM") != NULL)
3613 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3614#endif
3615
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003616 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617
3618#ifdef FEAT_MBYTE
3619# if defined(WIN3264) && defined(FEAT_GETTEXT)
3620 /*
3621 * If $LANG isn't set, try to get a good value for it. This makes the
3622 * right language be used automatically. Don't do this for English.
3623 */
3624 if (mch_getenv((char_u *)"LANG") == NULL)
3625 {
3626 char buf[20];
3627
3628 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3629 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3630 * only the first two. */
3631 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3632 (LPTSTR)buf, 20);
3633 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3634 {
3635 /* There are a few exceptions (probably more) */
3636 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3637 STRCPY(buf, "zh_TW");
3638 else if (STRNICMP(buf, "chs", 3) == 0
3639 || STRNICMP(buf, "zhc", 3) == 0)
3640 STRCPY(buf, "zh_CN");
3641 else if (STRNICMP(buf, "jp", 2) == 0)
3642 STRCPY(buf, "ja");
3643 else
3644 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003645 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 }
3647 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003648# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003649# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003650 /* Moved to os_mac_conv.c to avoid dependency problems. */
3651 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003652# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653# endif
3654
3655 /* enc_locale() will try to find the encoding of the current locale. */
3656 p = enc_locale();
3657 if (p != NULL)
3658 {
3659 char_u *save_enc;
3660
3661 /* Try setting 'encoding' and check if the value is valid.
3662 * If not, go back to the default "latin1". */
3663 save_enc = p_enc;
3664 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003665 if (STRCMP(p_enc, "gb18030") == 0)
3666 {
3667 /* We don't support "gb18030", but "cp936" is a good substitute
3668 * for practical purposes, thus use that. It's not an alias to
3669 * still support conversion between gb18030 and utf-8. */
3670 p_enc = vim_strsave((char_u *)"cp936");
3671 vim_free(p);
3672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003673 if (mb_init() == NULL)
3674 {
3675 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003676 if (opt_idx >= 0)
3677 {
3678 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3679 options[opt_idx].flags |= P_DEF_ALLOCED;
3680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003682#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003683 if (STRCMP(p_enc, "latin1") == 0
3684# ifdef FEAT_MBYTE
3685 || enc_utf8
3686# endif
3687 )
3688 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003689 /* Adjust the default for 'isprint' and 'iskeyword' to match
3690 * latin1. Also set the defaults for when 'nocompatible' is
3691 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003692 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003693 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003694 set_string_option_direct((char_u *)"isk", -1,
3695 ISK_LATIN1, OPT_FREE, SID_NONE);
3696 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003697 if (opt_idx >= 0)
3698 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003699 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (opt_idx >= 0)
3701 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003702 (void)init_chartab();
3703 }
3704#endif
3705
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706# if defined(WIN3264) && !defined(FEAT_GUI)
3707 /* Win32 console: When GetACP() returns a different value from
3708 * GetConsoleCP() set 'termencoding'. */
3709 if (GetACP() != GetConsoleCP())
3710 {
3711 char buf[50];
3712
3713 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3714 p_tenc = vim_strsave((char_u *)buf);
3715 if (p_tenc != NULL)
3716 {
3717 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003718 if (opt_idx >= 0)
3719 {
3720 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3721 options[opt_idx].flags |= P_DEF_ALLOCED;
3722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723 convert_setup(&input_conv, p_tenc, p_enc);
3724 convert_setup(&output_conv, p_enc, p_tenc);
3725 }
3726 else
3727 p_tenc = empty_option;
3728 }
3729# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003730# if defined(WIN3264) && defined(FEAT_MBYTE)
3731 /* $HOME may have characters in active code page. */
3732 init_homedir();
3733# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734 }
3735 else
3736 {
3737 vim_free(p_enc);
3738 p_enc = save_enc;
3739 }
3740 }
3741#endif
3742
3743#ifdef FEAT_MULTI_LANG
3744 /* Set the default for 'helplang'. */
3745 set_helplang_default(get_mess_lang());
3746#endif
3747}
3748
3749/*
3750 * Set an option to its default value.
3751 * This does not take care of side effects!
3752 */
3753 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003754set_option_default(
3755 int opt_idx,
3756 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3757 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758{
3759 char_u *varp; /* pointer to variable for current option */
3760 int dvi; /* index in def_val[] */
3761 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003762 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3764
3765 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3766 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003767 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 {
3769 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3770 if (flags & P_STRING)
3771 {
3772 /* Use set_string_option_direct() for local options to handle
3773 * freeing and allocating the value. */
3774 if (options[opt_idx].indir != PV_NONE)
3775 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003776 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 else
3778 {
3779 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3780 free_string_option(*(char_u **)(varp));
3781 *(char_u **)varp = options[opt_idx].def_val[dvi];
3782 options[opt_idx].flags &= ~P_ALLOCED;
3783 }
3784 }
3785 else if (flags & P_NUM)
3786 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003787 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 win_comp_scroll(curwin);
3789 else
3790 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003791 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 /* May also set global value for local option. */
3793 if (both)
3794 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3795 *(long *)varp;
3796 }
3797 }
3798 else /* P_BOOL */
3799 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003800 /* the cast to long is required for Manx C, long_i is needed for
3801 * MSVC */
3802 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003803#ifdef UNIX
3804 /* 'modeline' defaults to off for root */
3805 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3806 *(int *)varp = FALSE;
3807#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 /* May also set global value for local option. */
3809 if (both)
3810 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3811 *(int *)varp;
3812 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003813
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003814 /* The default value is not insecure. */
3815 flagsp = insecure_flag(opt_idx, opt_flags);
3816 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 }
3818
3819#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003820 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821#endif
3822}
3823
3824/*
3825 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003826 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003827 */
3828 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003829set_options_default(
3830 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831{
3832 int i;
3833#ifdef FEAT_WINDOWS
3834 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003835 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836#endif
3837
3838 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003839 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003840#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003841 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003842 || (TRUE
3843# if defined(FEAT_MBYTE)
3844 && options[i].var != (char_u *)&p_enc
3845# endif
3846# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003847 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003848 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003849# endif
3850 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003851#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003852 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853 set_option_default(i, opt_flags, p_cp);
3854
3855#ifdef FEAT_WINDOWS
3856 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003857 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 win_comp_scroll(wp);
3859#else
3860 win_comp_scroll(curwin);
3861#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003862#ifdef FEAT_CINDENT
3863 parse_cino(curbuf);
3864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865}
3866
3867/*
3868 * Set the Vi-default value of a string option.
3869 * Used for 'sh', 'backupskip' and 'term'.
3870 */
3871 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003872set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873{
3874 char_u *p;
3875 int opt_idx;
3876
3877 p = vim_strsave(val);
3878 if (p != NULL) /* we don't want a NULL */
3879 {
3880 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003881 if (opt_idx >= 0)
3882 {
3883 if (options[opt_idx].flags & P_DEF_ALLOCED)
3884 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3885 options[opt_idx].def_val[VI_DEFAULT] = p;
3886 options[opt_idx].flags |= P_DEF_ALLOCED;
3887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 }
3889}
3890
3891/*
3892 * Set the Vi-default value of a number option.
3893 * Used for 'lines' and 'columns'.
3894 */
3895 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003896set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003898 int opt_idx;
3899
3900 opt_idx = findoption((char_u *)name);
3901 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003902 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903}
3904
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003905#if defined(EXITFREE) || defined(PROTO)
3906/*
3907 * Free all options.
3908 */
3909 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003910free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003911{
3912 int i;
3913
3914 for (i = 0; !istermoption(&options[i]); i++)
3915 {
3916 if (options[i].indir == PV_NONE)
3917 {
3918 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003919 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003920 free_string_option(*(char_u **)options[i].var);
3921 if (options[i].flags & P_DEF_ALLOCED)
3922 free_string_option(options[i].def_val[VI_DEFAULT]);
3923 }
3924 else if (options[i].var != VAR_WIN
3925 && (options[i].flags & P_STRING))
3926 /* buffer-local option: free global value */
3927 free_string_option(*(char_u **)options[i].var);
3928 }
3929}
3930#endif
3931
3932
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933/*
3934 * Initialize the options, part two: After getting Rows and Columns and
3935 * setting 'term'.
3936 */
3937 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003938set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003940 int idx;
3941
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 /*
3943 * 'scroll' defaults to half the window height. Note that this default is
3944 * wrong when the window height changes.
3945 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003946 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003947 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003948 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003949 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 comp_col();
3951
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003952 /*
3953 * 'window' is only for backwards compatibility with Vi.
3954 * Default is Rows - 1.
3955 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003956 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003957 p_window = Rows - 1;
3958 set_number_default("window", Rows - 1);
3959
Bram Moolenaarf740b292006-02-16 22:11:02 +00003960 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003961#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003962 /*
3963 * If 'background' wasn't set by the user, try guessing the value,
3964 * depending on the terminal name. Only need to check for terminals
3965 * with a dark background, that can handle color.
3966 */
3967 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003968 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3969 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003971 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003972 /* don't mark it as set, when starting the GUI it may be
3973 * changed again */
3974 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 }
3976#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003977
3978#ifdef CURSOR_SHAPE
3979 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3980#endif
3981#ifdef FEAT_MOUSESHAPE
3982 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3983#endif
3984#ifdef FEAT_PRINTER
3985 (void)parse_printoptions(); /* parse 'printoptions' default value */
3986#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987}
3988
3989/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003990 * Return "dark" or "light" depending on the kind of terminal.
3991 * This is just guessing! Recognized are:
3992 * "linux" Linux console
3993 * "screen.linux" Linux console with screen
3994 * "cygwin" Cygwin shell
3995 * "putty" Putty program
3996 * We also check the COLORFGBG environment variable, which is set by
3997 * rxvt and derivatives. This variable contains either two or three
3998 * values separated by semicolons; we want the last value in either
3999 * case. If this value is 0-6 or 8, our background is dark.
4000 */
4001 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004002term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004003{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004004#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004005 /* DOS console nearly always black */
4006 return (char_u *)"dark";
4007#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004008 char_u *p;
4009
Bram Moolenaarf740b292006-02-16 22:11:02 +00004010 if (STRCMP(T_NAME, "linux") == 0
4011 || STRCMP(T_NAME, "screen.linux") == 0
4012 || STRCMP(T_NAME, "cygwin") == 0
4013 || STRCMP(T_NAME, "putty") == 0
4014 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4015 && (p = vim_strrchr(p, ';')) != NULL
4016 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4017 && p[2] == NUL))
4018 return (char_u *)"dark";
4019 return (char_u *)"light";
4020#endif
4021}
4022
4023/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004024 * Initialize the options, part three: After reading the .vimrc
4025 */
4026 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004027set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004029#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030/*
4031 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4032 * This is done after other initializations, where 'shell' might have been
4033 * set, but only if they have not been set before.
4034 */
4035 char_u *p;
4036 int idx_srr;
4037 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004038# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 int idx_sp;
4040 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004041# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042
4043 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004044 if (idx_srr < 0)
4045 do_srr = FALSE;
4046 else
4047 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004048# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004050 if (idx_sp < 0)
4051 do_sp = FALSE;
4052 else
4053 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004055 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 if (p != NULL)
4057 {
4058 /*
4059 * Default for p_sp is "| tee", for p_srr is ">".
4060 * For known shells it is changed here to include stderr.
4061 */
4062 if ( fnamecmp(p, "csh") == 0
4063 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004064# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 || fnamecmp(p, "csh.exe") == 0
4066 || fnamecmp(p, "tcsh.exe") == 0
4067# endif
4068 )
4069 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 if (do_sp)
4072 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004075# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004077# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4079 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 if (do_srr)
4082 {
4083 p_srr = (char_u *)">&";
4084 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4085 }
4086 }
4087 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 if ( fnamecmp(p, "sh") == 0
4090 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004091 || fnamecmp(p, "mksh") == 0
4092 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004094 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004096 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004097# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 || fnamecmp(p, "cmd") == 0
4099 || fnamecmp(p, "sh.exe") == 0
4100 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004101 || fnamecmp(p, "mksh.exe") == 0
4102 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004104 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 || fnamecmp(p, "bash.exe") == 0
4106 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004110# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 if (do_sp)
4112 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004113# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004115# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004117# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4119 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004120# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 if (do_srr)
4122 {
4123 p_srr = (char_u *)">%s 2>&1";
4124 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4125 }
4126 }
4127 vim_free(p);
4128 }
4129#endif
4130
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004131#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004133 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4134 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 * This is done after other initializations, where 'shell' might have been
4136 * set, but only if they have not been set before. Default for p_shcf is
4137 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004138 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004140 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 {
4142 int idx3;
4143
4144 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004145 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 {
4147 p_shcf = (char_u *)"-c";
4148 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4149 }
4150
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 /* Somehow Win32 requires the quotes around the redirection too */
4152 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004153 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 {
4155 p_sxq = (char_u *)"\"";
4156 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004159 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4160 {
4161 int idx3;
4162
4163 /*
4164 * cmd.exe on Windows will strip the first and last double quote given
4165 * on the command line, e.g. most of the time things like:
4166 * cmd /c "my path/to/echo" "my args to echo"
4167 * become:
4168 * my path/to/echo" "my args to echo
4169 * when executed.
4170 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004171 * To avoid this, set shellxquote to surround the command in
4172 * parenthesis. This appears to make most commands work, without
4173 * breaking commands that worked previously, such as
4174 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004175 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004176 idx3 = findoption((char_u *)"sxq");
4177 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4178 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004179 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004180 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4181 }
4182
Bram Moolenaara64ba222012-02-12 23:23:31 +01004183 idx3 = findoption((char_u *)"shcf");
4184 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4185 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004186 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004187 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4188 }
4189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190#endif
4191
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004192 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004193 {
4194 int idx_ffs = findoption((char_u *)"ffs");
4195
4196 /* Apply the first entry of 'fileformats' to the initial buffer. */
4197 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4198 set_fileformat(default_fileformat(), OPT_LOCAL);
4199 }
4200
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201#ifdef FEAT_TITLE
4202 set_title_defaults();
4203#endif
4204}
4205
4206#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4207/*
4208 * When 'helplang' is still at its default value, set it to "lang".
4209 * Only the first two characters of "lang" are used.
4210 */
4211 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004212set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004213{
4214 int idx;
4215
4216 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4217 return;
4218 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004219 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220 {
4221 if (options[idx].flags & P_ALLOCED)
4222 free_string_option(p_hlg);
4223 p_hlg = vim_strsave(lang);
4224 if (p_hlg == NULL)
4225 p_hlg = empty_option;
4226 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004227 {
4228 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4229 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4230 {
4231 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4232 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 options[idx].flags |= P_ALLOCED;
4237 }
4238}
4239#endif
4240
4241#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004242static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243
4244 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004245gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246{
4247 if (gui_get_lightness(gui.back_pixel) < 127)
4248 return (char_u *)"dark";
4249 return (char_u *)"light";
4250}
4251
4252/*
4253 * Option initializations that can only be done after opening the GUI window.
4254 */
4255 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004256init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004257{
4258 /* Set the 'background' option according to the lightness of the
4259 * background color, unless the user has set it already. */
4260 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4261 {
4262 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4263 highlight_changed();
4264 }
4265}
4266#endif
4267
4268#ifdef FEAT_TITLE
4269/*
4270 * 'title' and 'icon' only default to true if they have not been set or reset
4271 * in .vimrc and we can read the old value.
4272 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4273 * they can be reset. This reduces startup time when using X on a remote
4274 * machine.
4275 */
4276 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004277set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004278{
4279 int idx1;
4280 long val;
4281
4282 /*
4283 * If GUI is (going to be) used, we can always set the window title and
4284 * icon name. Saves a bit of time, because the X11 display server does
4285 * not need to be contacted.
4286 */
4287 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004288 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004289 {
4290#ifdef FEAT_GUI
4291 if (gui.starting || gui.in_use)
4292 val = TRUE;
4293 else
4294#endif
4295 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004296 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004297 p_title = val;
4298 }
4299 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004300 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004301 {
4302#ifdef FEAT_GUI
4303 if (gui.starting || gui.in_use)
4304 val = TRUE;
4305 else
4306#endif
4307 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004308 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309 p_icon = val;
4310 }
4311}
4312#endif
4313
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004314#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4315 static void
4316trigger_optionsset_string(
4317 int opt_idx,
4318 int opt_flags,
4319 char_u *oldval,
4320 char_u *newval)
4321{
4322 if (oldval != NULL && newval != NULL)
4323 {
4324 char_u buf_type[7];
4325
4326 sprintf((char *)buf_type, "%s",
4327 (opt_flags & OPT_LOCAL) ? "local" : "global");
4328 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4329 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4330 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4331 apply_autocmds(EVENT_OPTIONSET,
4332 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4333 reset_v_option_vars();
4334 }
4335 vim_free(oldval);
4336 vim_free(newval);
4337}
4338#endif
4339
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340/*
4341 * Parse 'arg' for option settings.
4342 *
4343 * 'arg' may be IObuff, but only when no errors can be present and option
4344 * does not need to be expanded with option_expand().
4345 * "opt_flags":
4346 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004347 * OPT_GLOBAL for ":setglobal"
4348 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004350 * OPT_WINONLY to only set window-local options
4351 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004352 *
4353 * returns FAIL if an error is detected, OK otherwise
4354 */
4355 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004356do_set(
4357 char_u *arg, /* option string (may be written to!) */
4358 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359{
4360 int opt_idx;
4361 char_u *errmsg;
4362 char_u errbuf[80];
4363 char_u *startarg;
4364 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4365 int nextchar; /* next non-white char after option name */
4366 int afterchar; /* character just after option name */
4367 int len;
4368 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004369 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 int key;
4371 long_u flags; /* flags for current option */
4372 char_u *varp = NULL; /* pointer to variable for current option */
4373 int did_show = FALSE; /* already showed one value */
4374 int adding; /* "opt+=arg" */
4375 int prepending; /* "opt^=arg" */
4376 int removing; /* "opt-=arg" */
4377 int cp_val = 0;
4378 char_u key_name[2];
4379
4380 if (*arg == NUL)
4381 {
4382 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004383 did_show = TRUE;
4384 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 }
4386
4387 while (*arg != NUL) /* loop to process all options */
4388 {
4389 errmsg = NULL;
4390 startarg = arg; /* remember for error message */
4391
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004392 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4393 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394 {
4395 /*
4396 * ":set all" show all options.
4397 * ":set all&" set all options to their default value.
4398 */
4399 arg += 3;
4400 if (*arg == '&')
4401 {
4402 ++arg;
4403 /* Only for :set command set global value of local options. */
4404 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004405 didset_options();
4406 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004407 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
4409 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004410 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004412 did_show = TRUE;
4413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004415 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004416 {
4417 showoptions(2, opt_flags);
4418 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004419 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 arg += 7;
4421 }
4422 else
4423 {
4424 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004425 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426 {
4427 prefix = 0;
4428 arg += 2;
4429 }
4430 else if (STRNCMP(arg, "inv", 3) == 0)
4431 {
4432 prefix = 2;
4433 arg += 3;
4434 }
4435
4436 /* find end of name */
4437 key = 0;
4438 if (*arg == '<')
4439 {
4440 nextchar = 0;
4441 opt_idx = -1;
4442 /* look out for <t_>;> */
4443 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4444 len = 5;
4445 else
4446 {
4447 len = 1;
4448 while (arg[len] != NUL && arg[len] != '>')
4449 ++len;
4450 }
4451 if (arg[len] != '>')
4452 {
4453 errmsg = e_invarg;
4454 goto skip;
4455 }
4456 arg[len] = NUL; /* put NUL after name */
4457 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4458 opt_idx = findoption(arg + 1);
4459 arg[len++] = '>'; /* restore '>' */
4460 if (opt_idx == -1)
4461 key = find_key_option(arg + 1);
4462 }
4463 else
4464 {
4465 len = 0;
4466 /*
4467 * The two characters after "t_" may not be alphanumeric.
4468 */
4469 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4470 len = 4;
4471 else
4472 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4473 ++len;
4474 nextchar = arg[len];
4475 arg[len] = NUL; /* put NUL after name */
4476 opt_idx = findoption(arg);
4477 arg[len] = nextchar; /* restore nextchar */
4478 if (opt_idx == -1)
4479 key = find_key_option(arg);
4480 }
4481
4482 /* remember character after option name */
4483 afterchar = arg[len];
4484
4485 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004486 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004487 ++len;
4488
4489 adding = FALSE;
4490 prepending = FALSE;
4491 removing = FALSE;
4492 if (arg[len] != NUL && arg[len + 1] == '=')
4493 {
4494 if (arg[len] == '+')
4495 {
4496 adding = TRUE; /* "+=" */
4497 ++len;
4498 }
4499 else if (arg[len] == '^')
4500 {
4501 prepending = TRUE; /* "^=" */
4502 ++len;
4503 }
4504 else if (arg[len] == '-')
4505 {
4506 removing = TRUE; /* "-=" */
4507 ++len;
4508 }
4509 }
4510 nextchar = arg[len];
4511
4512 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4513 {
4514 errmsg = (char_u *)N_("E518: Unknown option");
4515 goto skip;
4516 }
4517
4518 if (opt_idx >= 0)
4519 {
4520 if (options[opt_idx].var == NULL) /* hidden option: skip */
4521 {
4522 /* Only give an error message when requesting the value of
4523 * a hidden option, ignore setting it. */
4524 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4525 && (!(options[opt_idx].flags & P_BOOL)
4526 || nextchar == '?'))
4527 errmsg = (char_u *)N_("E519: Option not supported");
4528 goto skip;
4529 }
4530
4531 flags = options[opt_idx].flags;
4532 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4533 }
4534 else
4535 {
4536 flags = P_STRING;
4537 if (key < 0)
4538 {
4539 key_name[0] = KEY2TERMCAP0(key);
4540 key_name[1] = KEY2TERMCAP1(key);
4541 }
4542 else
4543 {
4544 key_name[0] = KS_KEY;
4545 key_name[1] = (key & 0xff);
4546 }
4547 }
4548
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004549 /* Skip all options that are not window-local (used when showing
4550 * an already loaded buffer in a window). */
4551 if ((opt_flags & OPT_WINONLY)
4552 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4553 goto skip;
4554
Bram Moolenaara3227e22006-03-08 21:32:40 +00004555 /* Skip all options that are window-local (used for :vimgrep). */
4556 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4557 && options[opt_idx].var == VAR_WIN)
4558 goto skip;
4559
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004560 /* Disallow changing some options from modelines. */
4561 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004563 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004564 {
4565 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4566 goto skip;
4567 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004568#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004569 /* In diff mode some options are overruled. This avoids that
4570 * 'foldmethod' becomes "marker" instead of "diff" and that
4571 * "wrap" gets set. */
4572 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004573 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004574 && (
4575#ifdef FEAT_FOLDING
4576 options[opt_idx].indir == PV_FDM ||
4577#endif
4578 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004579 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 }
4582
4583#ifdef HAVE_SANDBOX
4584 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004585 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 {
4587 errmsg = (char_u *)_(e_sandbox);
4588 goto skip;
4589 }
4590#endif
4591
4592 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4593 {
4594 arg += len;
4595 cp_val = p_cp;
4596 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4597 {
4598 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4599 {
4600 cp_val = FALSE;
4601 arg += 3;
4602 }
4603 else /* "opt&vi": set to Vi default */
4604 {
4605 cp_val = TRUE;
4606 arg += 2;
4607 }
4608 }
4609 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004610 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 {
4612 errmsg = e_trailing;
4613 goto skip;
4614 }
4615 }
4616
4617 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004618 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4619 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004620 */
4621 if (nextchar == '?'
4622 || (prefix == 1
4623 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4624 && !(flags & P_BOOL)))
4625 {
4626 /*
4627 * print value
4628 */
4629 if (did_show)
4630 msg_putchar('\n'); /* cursor below last one */
4631 else
4632 {
4633 gotocmdline(TRUE); /* cursor at status line */
4634 did_show = TRUE; /* remember that we did a line */
4635 }
4636 if (opt_idx >= 0)
4637 {
4638 showoneopt(&options[opt_idx], opt_flags);
4639#ifdef FEAT_EVAL
4640 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004641 {
4642 /* Mention where the option was last set. */
4643 if (varp == options[opt_idx].var)
4644 last_set_msg(options[opt_idx].scriptID);
4645 else if ((int)options[opt_idx].indir & PV_WIN)
4646 last_set_msg(curwin->w_p_scriptID[
4647 (int)options[opt_idx].indir & PV_MASK]);
4648 else if ((int)options[opt_idx].indir & PV_BUF)
4649 last_set_msg(curbuf->b_p_scriptID[
4650 (int)options[opt_idx].indir & PV_MASK]);
4651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652#endif
4653 }
4654 else
4655 {
4656 char_u *p;
4657
4658 p = find_termcode(key_name);
4659 if (p == NULL)
4660 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004661 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004662 goto skip;
4663 }
4664 else
4665 (void)show_one_termcode(key_name, p, TRUE);
4666 }
4667 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004668 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004669 errmsg = e_trailing;
4670 }
4671 else
4672 {
4673 if (flags & P_BOOL) /* boolean */
4674 {
4675 if (nextchar == '=' || nextchar == ':')
4676 {
4677 errmsg = e_invarg;
4678 goto skip;
4679 }
4680
4681 /*
4682 * ":set opt!": invert
4683 * ":set opt&": reset to default value
4684 * ":set opt<": reset to global value
4685 */
4686 if (nextchar == '!')
4687 value = *(int *)(varp) ^ 1;
4688 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004689 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004690 ((flags & P_VI_DEF) || cp_val)
4691 ? VI_DEFAULT : VIM_DEFAULT];
4692 else if (nextchar == '<')
4693 {
4694 /* For 'autoread' -1 means to use global value. */
4695 if ((int *)varp == &curbuf->b_p_ar
4696 && opt_flags == OPT_LOCAL)
4697 value = -1;
4698 else
4699 value = *(int *)get_varp_scope(&(options[opt_idx]),
4700 OPT_GLOBAL);
4701 }
4702 else
4703 {
4704 /*
4705 * ":set invopt": invert
4706 * ":set opt" or ":set noopt": set or reset
4707 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004708 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004709 {
4710 errmsg = e_trailing;
4711 goto skip;
4712 }
4713 if (prefix == 2) /* inv */
4714 value = *(int *)(varp) ^ 1;
4715 else
4716 value = prefix;
4717 }
4718
4719 errmsg = set_bool_option(opt_idx, varp, (int)value,
4720 opt_flags);
4721 }
4722 else /* numeric or string */
4723 {
4724 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4725 || prefix != 1)
4726 {
4727 errmsg = e_invarg;
4728 goto skip;
4729 }
4730
4731 if (flags & P_NUM) /* numeric */
4732 {
4733 /*
4734 * Different ways to set a number option:
4735 * & set to default value
4736 * < set to global value
4737 * <xx> accept special key codes for 'wildchar'
4738 * c accept any non-digit for 'wildchar'
4739 * [-]0-9 set number
4740 * other error
4741 */
4742 ++arg;
4743 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004744 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 ((flags & P_VI_DEF) || cp_val)
4746 ? VI_DEFAULT : VIM_DEFAULT];
4747 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004748 {
4749 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4750 * use the global value. */
4751 if ((long *)varp == &curbuf->b_p_ul
4752 && opt_flags == OPT_LOCAL)
4753 value = NO_LOCAL_UNDOLEVEL;
4754 else
4755 value = *(long *)get_varp_scope(
4756 &(options[opt_idx]), OPT_GLOBAL);
4757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004758 else if (((long *)varp == &p_wc
4759 || (long *)varp == &p_wcm)
4760 && (*arg == '<'
4761 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004762 || (*arg != NUL
4763 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004764 && !VIM_ISDIGIT(*arg))))
4765 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004766 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 if (value == 0 && (long *)varp != &p_wcm)
4768 {
4769 errmsg = e_invarg;
4770 goto skip;
4771 }
4772 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004773 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4774 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004775 /* Allow negative (for 'undolevels'), octal and
4776 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004777 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4778 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004779 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004780 {
4781 errmsg = e_invarg;
4782 goto skip;
4783 }
4784 }
4785 else
4786 {
4787 errmsg = (char_u *)N_("E521: Number required after =");
4788 goto skip;
4789 }
4790
4791 if (adding)
4792 value = *(long *)varp + value;
4793 if (prepending)
4794 value = *(long *)varp * value;
4795 if (removing)
4796 value = *(long *)varp - value;
4797 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004798 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 }
4800 else if (opt_idx >= 0) /* string */
4801 {
4802 char_u *save_arg = NULL;
4803 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004804 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004805 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004806 char_u *origval = NULL;
4807#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4808 char_u *saved_origval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004809 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004811 unsigned newlen;
4812 int comma;
4813 int bs;
4814 int new_value_alloced; /* new string option
4815 was allocated */
4816
4817 /* When using ":set opt=val" for a global option
4818 * with a local value the local value will be
4819 * reset, use the global value here. */
4820 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004821 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 varp = options[opt_idx].var;
4823
4824 /* The old value is kept until we are sure that the
4825 * new value is valid. */
4826 oldval = *(char_u **)varp;
4827 if (nextchar == '&') /* set to default val */
4828 {
4829 newval = options[opt_idx].def_val[
4830 ((flags & P_VI_DEF) || cp_val)
4831 ? VI_DEFAULT : VIM_DEFAULT];
4832 if ((char_u **)varp == &p_bg)
4833 {
4834 /* guess the value of 'background' */
4835#ifdef FEAT_GUI
4836 if (gui.in_use)
4837 newval = gui_bg_default();
4838 else
4839#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004840 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 }
4842
4843 /* expand environment variables and ~ (since the
4844 * default value was already expanded, only
4845 * required when an environment variable was set
4846 * later */
4847 if (newval == NULL)
4848 newval = empty_option;
4849 else
4850 {
4851 s = option_expand(opt_idx, newval);
4852 if (s == NULL)
4853 s = newval;
4854 newval = vim_strsave(s);
4855 }
4856 new_value_alloced = TRUE;
4857 }
4858 else if (nextchar == '<') /* set to global val */
4859 {
4860 newval = vim_strsave(*(char_u **)get_varp_scope(
4861 &(options[opt_idx]), OPT_GLOBAL));
4862 new_value_alloced = TRUE;
4863 }
4864 else
4865 {
4866 ++arg; /* jump to after the '=' or ':' */
4867
4868 /*
4869 * Set 'keywordprg' to ":help" if an empty
4870 * value was passed to :set by the user.
4871 * Misuse errbuf[] for the resulting string.
4872 */
4873 if (varp == (char_u *)&p_kp
4874 && (*arg == NUL || *arg == ' '))
4875 {
4876 STRCPY(errbuf, ":help");
4877 save_arg = arg;
4878 arg = errbuf;
4879 }
4880 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004881 * Convert 'backspace' number to string, for
4882 * adding, prepending and removing string.
4883 */
4884 else if (varp == (char_u *)&p_bs
4885 && VIM_ISDIGIT(**(char_u **)varp))
4886 {
4887 i = getdigits((char_u **)varp);
4888 switch (i)
4889 {
4890 case 0:
4891 *(char_u **)varp = empty_option;
4892 break;
4893 case 1:
4894 *(char_u **)varp = vim_strsave(
4895 (char_u *)"indent,eol");
4896 break;
4897 case 2:
4898 *(char_u **)varp = vim_strsave(
4899 (char_u *)"indent,eol,start");
4900 break;
4901 }
4902 vim_free(oldval);
4903 oldval = *(char_u **)varp;
4904 }
4905 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004906 * Convert 'whichwrap' number to string, for
4907 * backwards compatibility with Vim 3.0.
4908 * Misuse errbuf[] for the resulting string.
4909 */
4910 else if (varp == (char_u *)&p_ww
4911 && VIM_ISDIGIT(*arg))
4912 {
4913 *errbuf = NUL;
4914 i = getdigits(&arg);
4915 if (i & 1)
4916 STRCAT(errbuf, "b,");
4917 if (i & 2)
4918 STRCAT(errbuf, "s,");
4919 if (i & 4)
4920 STRCAT(errbuf, "h,l,");
4921 if (i & 8)
4922 STRCAT(errbuf, "<,>,");
4923 if (i & 16)
4924 STRCAT(errbuf, "[,],");
4925 if (*errbuf != NUL) /* remove trailing , */
4926 errbuf[STRLEN(errbuf) - 1] = NUL;
4927 save_arg = arg;
4928 arg = errbuf;
4929 }
4930 /*
4931 * Remove '>' before 'dir' and 'bdir', for
4932 * backwards compatibility with version 3.0
4933 */
4934 else if ( *arg == '>'
4935 && (varp == (char_u *)&p_dir
4936 || varp == (char_u *)&p_bdir))
4937 {
4938 ++arg;
4939 }
4940
4941 /* When setting the local value of a global
4942 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004943 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004944 && (opt_flags & OPT_LOCAL))
4945 origval = *(char_u **)get_varp(
4946 &options[opt_idx]);
4947 else
4948 origval = oldval;
4949
4950 /*
4951 * Copy the new string into allocated memory.
4952 * Can't use set_string_option_direct(), because
4953 * we need to remove the backslashes.
4954 */
4955 /* get a bit too much */
4956 newlen = (unsigned)STRLEN(arg) + 1;
4957 if (adding || prepending || removing)
4958 newlen += (unsigned)STRLEN(origval) + 1;
4959 newval = alloc(newlen);
4960 if (newval == NULL) /* out of mem, don't change */
4961 break;
4962 s = newval;
4963
4964 /*
4965 * Copy the string, skip over escaped chars.
4966 * For MS-DOS and WIN32 backslashes before normal
4967 * file name characters are not removed, and keep
4968 * backslash at start, for "\\machine\path", but
4969 * do remove it for "\\\\machine\\path".
4970 * The reverse is found in ExpandOldSetting().
4971 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004972 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004973 {
4974 if (*arg == '\\' && arg[1] != NUL
4975#ifdef BACKSLASH_IN_FILENAME
4976 && !((flags & P_EXPAND)
4977 && vim_isfilec(arg[1])
4978 && (arg[1] != '\\'
4979 || (s == newval
4980 && arg[2] != '\\')))
4981#endif
4982 )
4983 ++arg; /* remove backslash */
4984#ifdef FEAT_MBYTE
4985 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004986 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 {
4988 /* copy multibyte char */
4989 mch_memmove(s, arg, (size_t)i);
4990 arg += i;
4991 s += i;
4992 }
4993 else
4994#endif
4995 *s++ = *arg++;
4996 }
4997 *s = NUL;
4998
4999 /*
5000 * Expand environment variables and ~.
5001 * Don't do it when adding without inserting a
5002 * comma.
5003 */
5004 if (!(adding || prepending || removing)
5005 || (flags & P_COMMA))
5006 {
5007 s = option_expand(opt_idx, newval);
5008 if (s != NULL)
5009 {
5010 vim_free(newval);
5011 newlen = (unsigned)STRLEN(s) + 1;
5012 if (adding || prepending || removing)
5013 newlen += (unsigned)STRLEN(origval) + 1;
5014 newval = alloc(newlen);
5015 if (newval == NULL)
5016 break;
5017 STRCPY(newval, s);
5018 }
5019 }
5020
5021 /* locate newval[] in origval[] when removing it
5022 * and when adding to avoid duplicates */
5023 i = 0; /* init for GCC */
5024 if (removing || (flags & P_NODUP))
5025 {
5026 i = (int)STRLEN(newval);
5027 bs = 0;
5028 for (s = origval; *s; ++s)
5029 {
5030 if ((!(flags & P_COMMA)
5031 || s == origval
5032 || (s[-1] == ',' && !(bs & 1)))
5033 && STRNCMP(s, newval, i) == 0
5034 && (!(flags & P_COMMA)
5035 || s[i] == ','
5036 || s[i] == NUL))
5037 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005038 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005039 * even number of backslashes or a single
5040 * backslash preceded by a comma before it
5041 * is recognized as a separator */
5042 if ((s > origval + 1
5043 && s[-1] == '\\'
5044 && s[-2] != ',')
5045 || (s == origval + 1
5046 && s[-1] == '\\'))
5047
Bram Moolenaar071d4272004-06-13 20:20:40 +00005048 ++bs;
5049 else
5050 bs = 0;
5051 }
5052
5053 /* do not add if already there */
5054 if ((adding || prepending) && *s)
5055 {
5056 prepending = FALSE;
5057 adding = FALSE;
5058 STRCPY(newval, origval);
5059 }
5060 }
5061
5062 /* concatenate the two strings; add a ',' if
5063 * needed */
5064 if (adding || prepending)
5065 {
5066 comma = ((flags & P_COMMA) && *origval != NUL
5067 && *newval != NUL);
5068 if (adding)
5069 {
5070 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005071 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005072 if (comma && i > 1
5073 && (flags & P_ONECOMMA) == P_ONECOMMA
5074 && origval[i - 1] == ','
5075 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005076 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 mch_memmove(newval + i + comma, newval,
5078 STRLEN(newval) + 1);
5079 mch_memmove(newval, origval, (size_t)i);
5080 }
5081 else
5082 {
5083 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005084 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005085 }
5086 if (comma)
5087 newval[i] = ',';
5088 }
5089
5090 /* Remove newval[] from origval[]. (Note: "i" has
5091 * been set above and is used here). */
5092 if (removing)
5093 {
5094 STRCPY(newval, origval);
5095 if (*s)
5096 {
5097 /* may need to remove a comma */
5098 if (flags & P_COMMA)
5099 {
5100 if (s == origval)
5101 {
5102 /* include comma after string */
5103 if (s[i] == ',')
5104 ++i;
5105 }
5106 else
5107 {
5108 /* include comma before string */
5109 --s;
5110 ++i;
5111 }
5112 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005113 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005114 }
5115 }
5116
5117 if (flags & P_FLAGLIST)
5118 {
5119 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005120 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005121 {
5122 /* if options have P_FLAGLIST and
5123 * P_ONECOMMA such as 'whichwrap' */
5124 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005126 if (*s != ',' && *(s + 1) == ','
5127 && vim_strchr(s + 2, *s) != NULL)
5128 {
5129 /* Remove the duplicated value and
5130 * the next comma. */
5131 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005132 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005133 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005135 else
5136 {
5137 if ((!(flags & P_COMMA) || *s != ',')
5138 && vim_strchr(s + 1, *s) != NULL)
5139 {
5140 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005141 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005142 }
5143 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005144 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005145 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146 }
5147
5148 if (save_arg != NULL) /* number for 'whichwrap' */
5149 arg = save_arg;
5150 new_value_alloced = TRUE;
5151 }
5152
5153 /* Set the new value. */
5154 *(char_u **)(varp) = newval;
5155
Bram Moolenaar53744302015-07-17 17:38:22 +02005156#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005157 if (!starting
5158# ifdef FEAT_CRYPT
5159 && options[opt_idx].indir != PV_KEY
5160# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005161 && origval != NULL && newval != NULL)
5162 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005163 /* origval may be freed by
5164 * did_set_string_option(), make a copy. */
5165 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005166 /* newval (and varp) may become invalid if the
5167 * buffer is closed by autocommands. */
5168 saved_newval = vim_strsave(newval);
5169 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005170#endif
5171
Bram Moolenaar071d4272004-06-13 20:20:40 +00005172 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005173 * ":set" on local options. Note: when setting 'syntax'
5174 * or 'filetype' autocommands may be triggered that can
5175 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005176 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5177 new_value_alloced, oldval, errbuf, opt_flags);
5178
5179 /* If error detected, print the error message. */
5180 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005181 {
5182#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5183 vim_free(saved_origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005184 vim_free(saved_newval);
Bram Moolenaara9884962015-12-13 15:08:56 +01005185#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005187 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005188#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005189 trigger_optionsset_string(opt_idx, opt_flags,
5190 saved_origval, saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005191#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 }
5193 else /* key code option */
5194 {
5195 char_u *p;
5196
5197 if (nextchar == '&')
5198 {
5199 if (add_termcap_entry(key_name, TRUE) == FAIL)
5200 errmsg = (char_u *)N_("E522: Not found in termcap");
5201 }
5202 else
5203 {
5204 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005205 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 if (*p == '\\' && p[1] != NUL)
5207 ++p;
5208 nextchar = *p;
5209 *p = NUL;
5210 add_termcode(key_name, arg, FALSE);
5211 *p = nextchar;
5212 }
5213 if (full_screen)
5214 ttest(FALSE);
5215 redraw_all_later(CLEAR);
5216 }
5217 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005218
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005220 did_set_option(opt_idx, opt_flags,
5221 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005222 }
5223
5224skip:
5225 /*
5226 * Advance to next argument.
5227 * - skip until a blank found, taking care of backslashes
5228 * - skip blanks
5229 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5230 */
5231 for (i = 0; i < 2 ; ++i)
5232 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005233 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234 if (*arg++ == '\\' && *arg != NUL)
5235 ++arg;
5236 arg = skipwhite(arg);
5237 if (*arg != '=')
5238 break;
5239 }
5240 }
5241
5242 if (errmsg != NULL)
5243 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005244 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005245 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005246 if (i + (arg - startarg) < IOSIZE)
5247 {
5248 /* append the argument with the error */
5249 STRCAT(IObuff, ": ");
5250 mch_memmove(IObuff + i, startarg, (arg - startarg));
5251 IObuff[i + (arg - startarg)] = NUL;
5252 }
5253 /* make sure all characters are printable */
5254 trans_characters(IObuff, IOSIZE);
5255
5256 ++no_wait_return; /* wait_return done later */
5257 emsg(IObuff); /* show error highlighted */
5258 --no_wait_return;
5259
5260 return FAIL;
5261 }
5262
5263 arg = skipwhite(arg);
5264 }
5265
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005266theend:
5267 if (silent_mode && did_show)
5268 {
5269 /* After displaying option values in silent mode. */
5270 silent_mode = FALSE;
5271 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5272 msg_putchar('\n');
5273 cursor_on(); /* msg_start() switches it off */
5274 out_flush();
5275 silent_mode = TRUE;
5276 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5277 }
5278
Bram Moolenaar071d4272004-06-13 20:20:40 +00005279 return OK;
5280}
5281
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005282/*
5283 * Call this when an option has been given a new value through a user command.
5284 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5285 */
5286 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005287did_set_option(
5288 int opt_idx,
5289 int opt_flags, /* possibly with OPT_MODELINE */
5290 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005291{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005292 long_u *p;
5293
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005294 options[opt_idx].flags |= P_WAS_SET;
5295
5296 /* When an option is set in the sandbox, from a modeline or in secure mode
5297 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005298 * flag. */
5299 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005300 if (secure
5301#ifdef HAVE_SANDBOX
5302 || sandbox != 0
5303#endif
5304 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005305 *p = *p | P_INSECURE;
5306 else if (new_value)
5307 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005308}
5309
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005311illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312{
5313 if (errbuf == NULL)
5314 return (char_u *)"";
5315 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005316 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317 return errbuf;
5318}
5319
5320/*
5321 * Convert a key name or string into a key value.
5322 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005323 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005324 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005325 int
5326string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327{
5328 if (*arg == '<')
5329 return find_key_option(arg + 1);
5330 if (*arg == '^')
5331 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005332 if (multi_byte)
5333 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334 return *arg;
5335}
5336
5337#ifdef FEAT_CMDWIN
5338/*
5339 * Check value of 'cedit' and set cedit_key.
5340 * Returns NULL if value is OK, error message otherwise.
5341 */
5342 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005343check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005344{
5345 int n;
5346
5347 if (*p_cedit == NUL)
5348 cedit_key = -1;
5349 else
5350 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005351 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352 if (vim_isprintc(n))
5353 return e_invarg;
5354 cedit_key = n;
5355 }
5356 return NULL;
5357}
5358#endif
5359
5360#ifdef FEAT_TITLE
5361/*
5362 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5363 * maketitle() to create and display it.
5364 * When switching the title or icon off, call mch_restore_title() to get
5365 * the old value back.
5366 */
5367 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005368did_set_title(
5369 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005370{
5371 if (starting != NO_SCREEN
5372#ifdef FEAT_GUI
5373 && !gui.starting
5374#endif
5375 )
5376 {
5377 maketitle();
5378 if (icon)
5379 {
5380 if (!p_icon)
5381 mch_restore_title(2);
5382 }
5383 else
5384 {
5385 if (!p_title)
5386 mch_restore_title(1);
5387 }
5388 }
5389}
5390#endif
5391
5392/*
5393 * set_options_bin - called when 'bin' changes value.
5394 */
5395 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005396set_options_bin(
5397 int oldval,
5398 int newval,
5399 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400{
5401 /*
5402 * The option values that are changed when 'bin' changes are
5403 * copied when 'bin is set and restored when 'bin' is reset.
5404 */
5405 if (newval)
5406 {
5407 if (!oldval) /* switched on */
5408 {
5409 if (!(opt_flags & OPT_GLOBAL))
5410 {
5411 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5412 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5413 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5414 curbuf->b_p_et_nobin = curbuf->b_p_et;
5415 }
5416 if (!(opt_flags & OPT_LOCAL))
5417 {
5418 p_tw_nobin = p_tw;
5419 p_wm_nobin = p_wm;
5420 p_ml_nobin = p_ml;
5421 p_et_nobin = p_et;
5422 }
5423 }
5424
5425 if (!(opt_flags & OPT_GLOBAL))
5426 {
5427 curbuf->b_p_tw = 0; /* no automatic line wrap */
5428 curbuf->b_p_wm = 0; /* no automatic line wrap */
5429 curbuf->b_p_ml = 0; /* no modelines */
5430 curbuf->b_p_et = 0; /* no expandtab */
5431 }
5432 if (!(opt_flags & OPT_LOCAL))
5433 {
5434 p_tw = 0;
5435 p_wm = 0;
5436 p_ml = FALSE;
5437 p_et = FALSE;
5438 p_bin = TRUE; /* needed when called for the "-b" argument */
5439 }
5440 }
5441 else if (oldval) /* switched off */
5442 {
5443 if (!(opt_flags & OPT_GLOBAL))
5444 {
5445 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5446 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5447 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5448 curbuf->b_p_et = curbuf->b_p_et_nobin;
5449 }
5450 if (!(opt_flags & OPT_LOCAL))
5451 {
5452 p_tw = p_tw_nobin;
5453 p_wm = p_wm_nobin;
5454 p_ml = p_ml_nobin;
5455 p_et = p_et_nobin;
5456 }
5457 }
5458}
5459
5460#ifdef FEAT_VIMINFO
5461/*
5462 * Find the parameter represented by the given character (eg ', :, ", or /),
5463 * and return its associated value in the 'viminfo' string.
5464 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005465 * If the parameter is not specified in the string or there is no following
5466 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467 */
5468 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005469get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005470{
5471 char_u *p;
5472
5473 p = find_viminfo_parameter(type);
5474 if (p != NULL && VIM_ISDIGIT(*p))
5475 return atoi((char *)p);
5476 return -1;
5477}
5478
5479/*
5480 * Find the parameter represented by the given character (eg ''', ':', '"', or
5481 * '/') in the 'viminfo' option and return a pointer to the string after it.
5482 * Return NULL if the parameter is not specified in the string.
5483 */
5484 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005485find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005486{
5487 char_u *p;
5488
5489 for (p = p_viminfo; *p; ++p)
5490 {
5491 if (*p == type)
5492 return p + 1;
5493 if (*p == 'n') /* 'n' is always the last one */
5494 break;
5495 p = vim_strchr(p, ','); /* skip until next ',' */
5496 if (p == NULL) /* hit the end without finding parameter */
5497 break;
5498 }
5499 return NULL;
5500}
5501#endif
5502
5503/*
5504 * Expand environment variables for some string options.
5505 * These string options cannot be indirect!
5506 * If "val" is NULL expand the current value of the option.
5507 * Return pointer to NameBuff, or NULL when not expanded.
5508 */
5509 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005510option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511{
5512 /* if option doesn't need expansion nothing to do */
5513 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5514 return NULL;
5515
5516 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5517 * expand_env() would truncate the string. */
5518 if (val != NULL && STRLEN(val) > MAXPATHL)
5519 return NULL;
5520
5521 if (val == NULL)
5522 val = *(char_u **)options[opt_idx].var;
5523
5524 /*
5525 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5526 * Escape spaces when expanding 'tags', they are used to separate file
5527 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005528 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529 */
5530 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005531 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005532#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005533 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5534#endif
5535 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5537 return NULL;
5538
5539 return NameBuff;
5540}
5541
5542/*
5543 * After setting various option values: recompute variables that depend on
5544 * option values.
5545 */
5546 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005547didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005548{
5549 /* initialize the table for 'iskeyword' et.al. */
5550 (void)init_chartab();
5551
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005552#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005554#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005556 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557#ifdef FEAT_SESSION
5558 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5559 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5560#endif
5561#ifdef FEAT_FOLDING
5562 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5563#endif
5564 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005565 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566#ifdef FEAT_VIRTUALEDIT
5567 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5568#endif
5569#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5570 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5571#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005572#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005573 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005574 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005575 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005576 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5579 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5580#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005581#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5583#endif
5584#ifdef FEAT_CMDWIN
5585 /* set cedit_key */
5586 (void)check_cedit();
5587#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005588#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005589 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005590#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005591#ifdef FEAT_LINEBREAK
5592 /* initialize the table for 'breakat'. */
5593 fill_breakat_flags();
5594#endif
5595
5596}
5597
5598/*
5599 * More side effects of setting options.
5600 */
5601 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005602didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005603{
5604 /* Initialize the highlight_attr[] table. */
5605 (void)highlight_changed();
5606
5607 /* Parse default for 'wildmode' */
5608 check_opt_wim();
5609
5610 (void)set_chars_option(&p_lcs);
5611#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5612 /* Parse default for 'fillchars'. */
5613 (void)set_chars_option(&p_fcs);
5614#endif
5615
5616#ifdef FEAT_CLIPBOARD
5617 /* Parse default for 'clipboard' */
5618 (void)check_clipboard_option();
5619#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005620}
5621
5622/*
5623 * Check for string options that are NULL (normally only termcap options).
5624 */
5625 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005626check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627{
5628 int opt_idx;
5629
5630 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5631 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5632 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5633}
5634
5635/*
5636 * Check string options in a buffer for NULL value.
5637 */
5638 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005639check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005641 check_string_option(&buf->b_p_bh);
5642 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643#ifdef FEAT_MBYTE
5644 check_string_option(&buf->b_p_fenc);
5645#endif
5646 check_string_option(&buf->b_p_ff);
5647#ifdef FEAT_FIND_ID
5648 check_string_option(&buf->b_p_def);
5649 check_string_option(&buf->b_p_inc);
5650# ifdef FEAT_EVAL
5651 check_string_option(&buf->b_p_inex);
5652# endif
5653#endif
5654#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5655 check_string_option(&buf->b_p_inde);
5656 check_string_option(&buf->b_p_indk);
5657#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005658#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5659 check_string_option(&buf->b_p_bexpr);
5660#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005661#if defined(FEAT_CRYPT)
5662 check_string_option(&buf->b_p_cm);
5663#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005664 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005665#if defined(FEAT_EVAL)
5666 check_string_option(&buf->b_p_fex);
5667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668#ifdef FEAT_CRYPT
5669 check_string_option(&buf->b_p_key);
5670#endif
5671 check_string_option(&buf->b_p_kp);
5672 check_string_option(&buf->b_p_mps);
5673 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005674 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675 check_string_option(&buf->b_p_isk);
5676#ifdef FEAT_COMMENTS
5677 check_string_option(&buf->b_p_com);
5678#endif
5679#ifdef FEAT_FOLDING
5680 check_string_option(&buf->b_p_cms);
5681#endif
5682 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005683#ifdef FEAT_TEXTOBJ
5684 check_string_option(&buf->b_p_qe);
5685#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005686#ifdef FEAT_SYN_HL
5687 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005688 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005689#endif
5690#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005691 check_string_option(&buf->b_s.b_p_spc);
5692 check_string_option(&buf->b_s.b_p_spf);
5693 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694#endif
5695#ifdef FEAT_SEARCHPATH
5696 check_string_option(&buf->b_p_sua);
5697#endif
5698#ifdef FEAT_CINDENT
5699 check_string_option(&buf->b_p_cink);
5700 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005701 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702#endif
5703#ifdef FEAT_AUTOCMD
5704 check_string_option(&buf->b_p_ft);
5705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5707 check_string_option(&buf->b_p_cinw);
5708#endif
5709#ifdef FEAT_INS_EXPAND
5710 check_string_option(&buf->b_p_cpt);
5711#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005712#ifdef FEAT_COMPL_FUNC
5713 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005714 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716#ifdef FEAT_KEYMAP
5717 check_string_option(&buf->b_p_keymap);
5718#endif
5719#ifdef FEAT_QUICKFIX
5720 check_string_option(&buf->b_p_gp);
5721 check_string_option(&buf->b_p_mp);
5722 check_string_option(&buf->b_p_efm);
5723#endif
5724 check_string_option(&buf->b_p_ep);
5725 check_string_option(&buf->b_p_path);
5726 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005727 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728#ifdef FEAT_INS_EXPAND
5729 check_string_option(&buf->b_p_dict);
5730 check_string_option(&buf->b_p_tsr);
5731#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005732#ifdef FEAT_LISP
5733 check_string_option(&buf->b_p_lw);
5734#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005735 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005736#ifdef FEAT_MBYTE
5737 check_string_option(&buf->b_p_menc);
5738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739}
5740
5741/*
5742 * Free the string allocated for an option.
5743 * Checks for the string being empty_option. This may happen if we're out of
5744 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5745 * check_options().
5746 * Does NOT check for P_ALLOCED flag!
5747 */
5748 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005749free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005750{
5751 if (p != empty_option)
5752 vim_free(p);
5753}
5754
5755 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005756clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757{
5758 if (*pp != empty_option)
5759 vim_free(*pp);
5760 *pp = empty_option;
5761}
5762
5763 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005764check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765{
5766 if (*pp == NULL)
5767 *pp = empty_option;
5768}
5769
5770/*
5771 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5772 */
5773 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005774set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775{
5776 int opt_idx;
5777
5778 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5779 if (options[opt_idx].var == (char_u *)p)
5780 {
5781 options[opt_idx].flags |= P_ALLOCED;
5782 return;
5783 }
5784 return; /* cannot happen: didn't find it! */
5785}
5786
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005787#if defined(FEAT_EVAL) || defined(PROTO)
5788/*
5789 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5790 * Return FALSE when it wasn't.
5791 * Return -1 for an unknown option.
5792 */
5793 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005794was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005795{
5796 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005797 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005798
5799 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005800 {
5801 flagp = insecure_flag(idx, opt_flags);
5802 return (*flagp & P_INSECURE) != 0;
5803 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005804 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005805 return -1;
5806}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005807
5808/*
5809 * Get a pointer to the flags used for the P_INSECURE flag of option
5810 * "opt_idx". For some local options a local flags field is used.
5811 */
5812 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005813insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005814{
5815 if (opt_flags & OPT_LOCAL)
5816 switch ((int)options[opt_idx].indir)
5817 {
5818#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005819 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005820#endif
5821#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005822# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005823 case PV_FDE: return &curwin->w_p_fde_flags;
5824 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005825# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005826# ifdef FEAT_BEVAL
5827 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5828# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005829# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005830 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005831# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005832 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005834 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005835# endif
5836#endif
5837 }
5838
5839 /* Nothing special, return global flags field. */
5840 return &options[opt_idx].flags;
5841}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005842#endif
5843
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005844#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005845static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005846
5847/*
5848 * Redraw the window title and/or tab page text later.
5849 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005850static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005851{
5852 need_maketitle = TRUE;
5853# ifdef FEAT_WINDOWS
5854 redraw_tabline = TRUE;
5855# endif
5856}
5857#endif
5858
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859/*
5860 * Set a string option to a new value (without checking the effect).
5861 * The string is copied into allocated memory.
5862 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005863 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005864 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865 */
5866 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005867set_string_option_direct(
5868 char_u *name,
5869 int opt_idx,
5870 char_u *val,
5871 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5872 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873{
5874 char_u *s;
5875 char_u **varp;
5876 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005877 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878
Bram Moolenaar89d40322006-08-29 15:30:07 +00005879 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005881 idx = findoption(name);
5882 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005883 {
5884 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005885 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005888 }
5889
Bram Moolenaar89d40322006-08-29 15:30:07 +00005890 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891 return;
5892
5893 s = vim_strsave(val);
5894 if (s != NULL)
5895 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005896 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005898 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899 free_string_option(*varp);
5900 *varp = s;
5901
5902 /* For buffer/window local option may also set the global value. */
5903 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005904 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905
Bram Moolenaar89d40322006-08-29 15:30:07 +00005906 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907
5908 /* When setting both values of a global option with a local value,
5909 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005910 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911 {
5912 free_string_option(*varp);
5913 *varp = empty_option;
5914 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005915# ifdef FEAT_EVAL
5916 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005917 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005918 set_sid == 0 ? current_SID : set_sid);
5919# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920 }
5921}
5922
5923/*
5924 * Set global value for string option when it's a local option.
5925 */
5926 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005927set_string_option_global(
5928 int opt_idx, /* option index */
5929 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930{
5931 char_u **p, *s;
5932
5933 /* the global value is always allocated */
5934 if (options[opt_idx].var == VAR_WIN)
5935 p = (char_u **)GLOBAL_WO(varp);
5936 else
5937 p = (char_u **)options[opt_idx].var;
5938 if (options[opt_idx].indir != PV_NONE
5939 && p != varp
5940 && (s = vim_strsave(*varp)) != NULL)
5941 {
5942 free_string_option(*p);
5943 *p = s;
5944 }
5945}
5946
5947/*
5948 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005949 *
5950 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005951 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005952 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005953set_string_option(
5954 int opt_idx,
5955 char_u *value,
5956 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005957{
5958 char_u *s;
5959 char_u **varp;
5960 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005961#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5962 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005963 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005964#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005965 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966
5967 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005968 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969
5970 s = vim_strsave(value);
5971 if (s != NULL)
5972 {
5973 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5974 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005975 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976 ? OPT_GLOBAL : OPT_LOCAL)
5977 : opt_flags);
5978 oldval = *varp;
5979 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005980
5981#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005982 if (!starting
5983# ifdef FEAT_CRYPT
5984 && options[opt_idx].indir != PV_KEY
5985# endif
5986 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005988 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005989 saved_newval = vim_strsave(s);
5990 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005991#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005992 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5993 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005994 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005995
Bram Moolenaar53744302015-07-17 17:38:22 +02005996#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005997 /* call autocommand after handling side effects */
5998 trigger_optionsset_string(opt_idx, opt_flags,
5999 saved_oldval, saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006002 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006003}
6004
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006005#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006007 * Return TRUE if "val" is a valid 'filetype' name.
6008 * Also used for 'syntax' and 'keymap'.
6009 */
6010 static int
6011valid_filetype(char_u *val)
6012{
6013 char_u *s;
6014
6015 for (s = val; *s != NUL; ++s)
6016 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6017 return FALSE;
6018 return TRUE;
6019}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006020#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006021
6022/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006023 * Handle string options that need some action to perform when changed.
6024 * Returns NULL for success, or an error message for an error.
6025 */
6026 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006027did_set_string_option(
6028 int opt_idx, /* index in options[] table */
6029 char_u **varp, /* pointer to the option variable */
6030 int new_value_alloced, /* new value was allocated */
6031 char_u *oldval, /* previous value of the option */
6032 char_u *errbuf, /* buffer for errors, or NULL */
6033 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006034{
6035 char_u *errmsg = NULL;
6036 char_u *s, *p;
6037 int did_chartab = FALSE;
6038 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006039 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006040#ifdef FEAT_GUI
6041 /* set when changing an option that only requires a redraw in the GUI */
6042 int redraw_gui_only = FALSE;
6043#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006044#ifdef FEAT_AUTOCMD
6045 int ft_changed = FALSE;
6046#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047
6048 /* Get the global option to compare with, otherwise we would have to check
6049 * two values for all local options. */
6050 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6051
6052 /* Disallow changing some options from secure mode */
6053 if ((secure
6054#ifdef HAVE_SANDBOX
6055 || sandbox != 0
6056#endif
6057 ) && (options[opt_idx].flags & P_SECURE))
6058 {
6059 errmsg = e_secure;
6060 }
6061
Bram Moolenaar7554da42016-11-25 22:04:13 +01006062 /* Check for a "normal" directory or file name in some options. Disallow a
6063 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006064 * are often illegal in a file name. Be more permissive if "secure" is off.
6065 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006066 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006067 && vim_strpbrk(*varp, (char_u *)(secure
6068 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006069 || ((options[opt_idx].flags & P_NDNAME)
6070 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006071 {
6072 errmsg = e_invarg;
6073 }
6074
Bram Moolenaar071d4272004-06-13 20:20:40 +00006075 /* 'term' */
6076 else if (varp == &T_NAME)
6077 {
6078 if (T_NAME[0] == NUL)
6079 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6080#ifdef FEAT_GUI
6081 if (gui.in_use)
6082 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6083 else if (term_is_gui(T_NAME))
6084 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6085#endif
6086 else if (set_termname(T_NAME) == FAIL)
6087 errmsg = (char_u *)N_("E522: Not found in termcap");
6088 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006089 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090 /* Screen colors may have changed. */
6091 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006092
6093 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6094 * P_ALLOCED flag on 'term'. */
6095 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006096 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006097 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006098 }
6099
6100 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006101 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006103 char_u *bkc = p_bkc;
6104 unsigned int *flags = &bkc_flags;
6105
6106 if (opt_flags & OPT_LOCAL)
6107 {
6108 bkc = curbuf->b_p_bkc;
6109 flags = &curbuf->b_bkc_flags;
6110 }
6111
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006112 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6113 /* make the local value empty: use the global value */
6114 *flags = 0;
6115 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006117 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6118 errmsg = e_invarg;
6119 if ((((int)*flags & BKC_AUTO) != 0)
6120 + (((int)*flags & BKC_YES) != 0)
6121 + (((int)*flags & BKC_NO) != 0) != 1)
6122 {
6123 /* Must have exactly one of "auto", "yes" and "no". */
6124 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6125 errmsg = e_invarg;
6126 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127 }
6128 }
6129
6130 /* 'backupext' and 'patchmode' */
6131 else if (varp == &p_bex || varp == &p_pm)
6132 {
6133 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6134 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6135 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6136 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006137#ifdef FEAT_LINEBREAK
6138 /* 'breakindentopt' */
6139 else if (varp == &curwin->w_p_briopt)
6140 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006141 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006142 errmsg = e_invarg;
6143 }
6144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006145
6146 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006147 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006149 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150 */
6151 else if ( varp == &p_isi
6152 || varp == &(curbuf->b_p_isk)
6153 || varp == &p_isp
6154 || varp == &p_isf)
6155 {
6156 if (init_chartab() == FAIL)
6157 {
6158 did_chartab = TRUE; /* need to restore it below */
6159 errmsg = e_invarg; /* error in value */
6160 }
6161 }
6162
6163 /* 'helpfile' */
6164 else if (varp == &p_hf)
6165 {
6166 /* May compute new values for $VIM and $VIMRUNTIME */
6167 if (didset_vim)
6168 {
6169 vim_setenv((char_u *)"VIM", (char_u *)"");
6170 didset_vim = FALSE;
6171 }
6172 if (didset_vimruntime)
6173 {
6174 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6175 didset_vimruntime = FALSE;
6176 }
6177 }
6178
Bram Moolenaar1a384422010-07-14 19:53:30 +02006179#ifdef FEAT_SYN_HL
6180 /* 'colorcolumn' */
6181 else if (varp == &curwin->w_p_cc)
6182 errmsg = check_colorcolumn(curwin);
6183#endif
6184
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185#ifdef FEAT_MULTI_LANG
6186 /* 'helplang' */
6187 else if (varp == &p_hlg)
6188 {
6189 /* Check for "", "ab", "ab,cd", etc. */
6190 for (s = p_hlg; *s != NUL; s += 3)
6191 {
6192 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6193 {
6194 errmsg = e_invarg;
6195 break;
6196 }
6197 if (s[2] == NUL)
6198 break;
6199 }
6200 }
6201#endif
6202
6203 /* 'highlight' */
6204 else if (varp == &p_hl)
6205 {
6206 if (highlight_changed() == FAIL)
6207 errmsg = e_invarg; /* invalid flags */
6208 }
6209
6210 /* 'nrformats' */
6211 else if (gvarp == &p_nf)
6212 {
6213 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6214 errmsg = e_invarg;
6215 }
6216
6217#ifdef FEAT_SESSION
6218 /* 'sessionoptions' */
6219 else if (varp == &p_ssop)
6220 {
6221 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6222 errmsg = e_invarg;
6223 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6224 {
6225 /* Don't allow both "sesdir" and "curdir". */
6226 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6227 errmsg = e_invarg;
6228 }
6229 }
6230 /* 'viewoptions' */
6231 else if (varp == &p_vop)
6232 {
6233 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6234 errmsg = e_invarg;
6235 }
6236#endif
6237
6238 /* 'scrollopt' */
6239#ifdef FEAT_SCROLLBIND
6240 else if (varp == &p_sbo)
6241 {
6242 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6243 errmsg = e_invarg;
6244 }
6245#endif
6246
6247 /* 'ambiwidth' */
6248#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006249 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006250 {
6251 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6252 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006253 else if (set_chars_option(&p_lcs) != NULL)
6254 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6255# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6256 else if (set_chars_option(&p_fcs) != NULL)
6257 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6258# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006259 }
6260#endif
6261
6262 /* 'background' */
6263 else if (varp == &p_bg)
6264 {
6265 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6266 {
6267#ifdef FEAT_EVAL
6268 int dark = (*p_bg == 'd');
6269#endif
6270
6271 init_highlight(FALSE, FALSE);
6272
6273#ifdef FEAT_EVAL
6274 if (dark != (*p_bg == 'd')
6275 && get_var_value((char_u *)"g:colors_name") != NULL)
6276 {
6277 /* The color scheme must have set 'background' back to another
6278 * value, that's not what we want here. Disable the color
6279 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006280 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006281 free_string_option(p_bg);
6282 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6283 check_string_option(&p_bg);
6284 init_highlight(FALSE, FALSE);
6285 }
6286#endif
6287 }
6288 else
6289 errmsg = e_invarg;
6290 }
6291
6292 /* 'wildmode' */
6293 else if (varp == &p_wim)
6294 {
6295 if (check_opt_wim() == FAIL)
6296 errmsg = e_invarg;
6297 }
6298
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006299#ifdef FEAT_CMDL_COMPL
6300 /* 'wildoptions' */
6301 else if (varp == &p_wop)
6302 {
6303 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6304 errmsg = e_invarg;
6305 }
6306#endif
6307
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308#ifdef FEAT_WAK
6309 /* 'winaltkeys' */
6310 else if (varp == &p_wak)
6311 {
6312 if (*p_wak == NUL
6313 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6314 errmsg = e_invarg;
6315# ifdef FEAT_MENU
6316# ifdef FEAT_GUI_MOTIF
6317 else if (gui.in_use)
6318 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6319# else
6320# ifdef FEAT_GUI_GTK
6321 else if (gui.in_use)
6322 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6323# endif
6324# endif
6325# endif
6326 }
6327#endif
6328
6329#ifdef FEAT_AUTOCMD
6330 /* 'eventignore' */
6331 else if (varp == &p_ei)
6332 {
6333 if (check_ei() == FAIL)
6334 errmsg = e_invarg;
6335 }
6336#endif
6337
6338#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006339 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6340 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6341 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342 {
6343 if (gvarp == &p_fenc)
6344 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006345 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006346 errmsg = e_modifiable;
6347 else if (vim_strchr(*varp, ',') != NULL)
6348 /* No comma allowed in 'fileencoding'; catches confusing it
6349 * with 'fileencodings'. */
6350 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006352 {
6353# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006355 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006357 /* Add 'fileencoding' to the swap file. */
6358 ml_setflags(curbuf);
6359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006360 }
6361 if (errmsg == NULL)
6362 {
6363 /* canonize the value, so that STRCMP() can be used on it */
6364 p = enc_canonize(*varp);
6365 if (p != NULL)
6366 {
6367 vim_free(*varp);
6368 *varp = p;
6369 }
6370 if (varp == &p_enc)
6371 {
6372 errmsg = mb_init();
6373# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006374 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006375# endif
6376 }
6377 }
6378
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006379# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6381 {
6382 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6383 if (STRCMP(p_tenc, "utf-8") != 0)
6384 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6385 }
6386# endif
6387
6388 if (errmsg == NULL)
6389 {
6390# ifdef FEAT_KEYMAP
6391 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6392 * (with another encoding). */
6393 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6394 (void)keymap_init();
6395# endif
6396
6397 /* When 'termencoding' is not empty and 'encoding' changes or when
6398 * 'termencoding' changes, need to setup for keyboard input and
6399 * display output conversion. */
6400 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6401 {
6402 convert_setup(&input_conv, p_tenc, p_enc);
6403 convert_setup(&output_conv, p_enc, p_tenc);
6404 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006405
6406# if defined(WIN3264) && defined(FEAT_MBYTE)
6407 /* $HOME may have characters in active code page. */
6408 if (varp == &p_enc)
6409 init_homedir();
6410# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006411 }
6412 }
6413#endif
6414
6415#if defined(FEAT_POSTSCRIPT)
6416 else if (varp == &p_penc)
6417 {
6418 /* Canonize printencoding if VIM standard one */
6419 p = enc_canonize(p_penc);
6420 if (p != NULL)
6421 {
6422 vim_free(p_penc);
6423 p_penc = p;
6424 }
6425 else
6426 {
6427 /* Ensure lower case and '-' for '_' */
6428 for (s = p_penc; *s != NUL; s++)
6429 {
6430 if (*s == '_')
6431 *s = '-';
6432 else
6433 *s = TOLOWER_ASC(*s);
6434 }
6435 }
6436 }
6437#endif
6438
Bram Moolenaar9372a112005-12-06 19:59:18 +00006439#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440 else if (varp == &p_imak)
6441 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006442 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443 errmsg = e_invarg;
6444 }
6445#endif
6446
6447#ifdef FEAT_KEYMAP
6448 else if (varp == &curbuf->b_p_keymap)
6449 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006450 if (!valid_filetype(*varp))
6451 errmsg = e_invarg;
6452 else
6453 /* load or unload key mapping tables */
6454 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006455
Bram Moolenaarfab06232009-03-04 03:13:35 +00006456 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006457 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006458 if (*curbuf->b_p_keymap != NUL)
6459 {
6460 /* Installed a new keymap, switch on using it. */
6461 curbuf->b_p_iminsert = B_IMODE_LMAP;
6462 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6463 curbuf->b_p_imsearch = B_IMODE_LMAP;
6464 }
6465 else
6466 {
6467 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6468 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6469 curbuf->b_p_iminsert = B_IMODE_NONE;
6470 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6471 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6472 }
6473 if ((opt_flags & OPT_LOCAL) == 0)
6474 {
6475 set_iminsert_global();
6476 set_imsearch_global();
6477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006478# ifdef FEAT_WINDOWS
6479 status_redraw_curbuf();
6480# endif
6481 }
6482 }
6483#endif
6484
6485 /* 'fileformat' */
6486 else if (gvarp == &p_ff)
6487 {
6488 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6489 errmsg = e_modifiable;
6490 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6491 errmsg = e_invarg;
6492 else
6493 {
6494 /* may also change 'textmode' */
6495 if (get_fileformat(curbuf) == EOL_DOS)
6496 curbuf->b_p_tx = TRUE;
6497 else
6498 curbuf->b_p_tx = FALSE;
6499#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006500 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006501#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006502 /* update flag in swap file */
6503 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006504 /* Redraw needed when switching to/from "mac": a CR in the text
6505 * will be displayed differently. */
6506 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6507 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006508 }
6509 }
6510
6511 /* 'fileformats' */
6512 else if (varp == &p_ffs)
6513 {
6514 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6515 errmsg = e_invarg;
6516 else
6517 {
6518 /* also change 'textauto' */
6519 if (*p_ffs == NUL)
6520 p_ta = FALSE;
6521 else
6522 p_ta = TRUE;
6523 }
6524 }
6525
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006526#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006527 /* 'cryptkey' */
6528 else if (gvarp == &p_key)
6529 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006530# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006531 /* Make sure the ":set" command doesn't show the new value in the
6532 * history. */
6533 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006534# endif
6535 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6536 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006537 ml_set_crypt_key(curbuf, oldval,
6538 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006539 }
6540
6541 else if (gvarp == &p_cm)
6542 {
6543 if (opt_flags & OPT_LOCAL)
6544 p = curbuf->b_p_cm;
6545 else
6546 p = p_cm;
6547 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6548 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006549 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006550 errmsg = e_invarg;
6551 else
6552 {
6553 /* When setting the global value to empty, make it "zip". */
6554 if (*p_cm == NUL)
6555 {
6556 if (new_value_alloced)
6557 free_string_option(p_cm);
6558 p_cm = vim_strsave((char_u *)"zip");
6559 new_value_alloced = TRUE;
6560 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006561 /* When using ":set cm=name" the local value is going to be empty.
6562 * Do that here, otherwise the crypt functions will still use the
6563 * local value. */
6564 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6565 {
6566 free_string_option(curbuf->b_p_cm);
6567 curbuf->b_p_cm = empty_option;
6568 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006569
6570 /* Need to update the swapfile when the effective method changed.
6571 * Set "s" to the effective old value, "p" to the effective new
6572 * method and compare. */
6573 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6574 s = p_cm; /* was previously using the global value */
6575 else
6576 s = oldval;
6577 if (*curbuf->b_p_cm == NUL)
6578 p = p_cm; /* is now using the global value */
6579 else
6580 p = curbuf->b_p_cm;
6581 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006582 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006583
6584 /* If the global value changes need to update the swapfile for all
6585 * buffers using that value. */
6586 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6587 {
6588 buf_T *buf;
6589
Bram Moolenaar29323592016-07-24 22:04:11 +02006590 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006591 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006592 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006593 }
6594 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006595 }
6596#endif
6597
6598 /* 'matchpairs' */
6599 else if (gvarp == &p_mps)
6600 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006601#ifdef FEAT_MBYTE
6602 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006603 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006604 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006605 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006606 int x2 = -1;
6607 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006608
6609 if (*p != NUL)
6610 p += mb_ptr2len(p);
6611 if (*p != NUL)
6612 x2 = *p++;
6613 if (*p != NUL)
6614 {
6615 x3 = mb_ptr2char(p);
6616 p += mb_ptr2len(p);
6617 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006618 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006619 {
6620 errmsg = e_invarg;
6621 break;
6622 }
6623 if (*p == NUL)
6624 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006625 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006626 }
6627 else
6628#endif
6629 {
6630 /* Check for "x:y,x:y" */
6631 for (p = *varp; *p != NUL; p += 4)
6632 {
6633 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6634 {
6635 errmsg = e_invarg;
6636 break;
6637 }
6638 if (p[3] == NUL)
6639 break;
6640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006641 }
6642 }
6643
6644#ifdef FEAT_COMMENTS
6645 /* 'comments' */
6646 else if (gvarp == &p_com)
6647 {
6648 for (s = *varp; *s; )
6649 {
6650 while (*s && *s != ':')
6651 {
6652 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6653 && !VIM_ISDIGIT(*s) && *s != '-')
6654 {
6655 errmsg = illegal_char(errbuf, *s);
6656 break;
6657 }
6658 ++s;
6659 }
6660 if (*s++ == NUL)
6661 errmsg = (char_u *)N_("E524: Missing colon");
6662 else if (*s == ',' || *s == NUL)
6663 errmsg = (char_u *)N_("E525: Zero length string");
6664 if (errmsg != NULL)
6665 break;
6666 while (*s && *s != ',')
6667 {
6668 if (*s == '\\' && s[1] != NUL)
6669 ++s;
6670 ++s;
6671 }
6672 s = skip_to_option_part(s);
6673 }
6674 }
6675#endif
6676
6677 /* 'listchars' */
6678 else if (varp == &p_lcs)
6679 {
6680 errmsg = set_chars_option(varp);
6681 }
6682
6683#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6684 /* 'fillchars' */
6685 else if (varp == &p_fcs)
6686 {
6687 errmsg = set_chars_option(varp);
6688 }
6689#endif
6690
6691#ifdef FEAT_CMDWIN
6692 /* 'cedit' */
6693 else if (varp == &p_cedit)
6694 {
6695 errmsg = check_cedit();
6696 }
6697#endif
6698
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006699 /* 'verbosefile' */
6700 else if (varp == &p_vfile)
6701 {
6702 verbose_stop();
6703 if (*p_vfile != NUL && verbose_open() == FAIL)
6704 errmsg = e_invarg;
6705 }
6706
Bram Moolenaar071d4272004-06-13 20:20:40 +00006707#ifdef FEAT_VIMINFO
6708 /* 'viminfo' */
6709 else if (varp == &p_viminfo)
6710 {
6711 for (s = p_viminfo; *s;)
6712 {
6713 /* Check it's a valid character */
6714 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6715 {
6716 errmsg = illegal_char(errbuf, *s);
6717 break;
6718 }
6719 if (*s == 'n') /* name is always last one */
6720 {
6721 break;
6722 }
6723 else if (*s == 'r') /* skip until next ',' */
6724 {
6725 while (*++s && *s != ',')
6726 ;
6727 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006728 else if (*s == '%')
6729 {
6730 /* optional number */
6731 while (vim_isdigit(*++s))
6732 ;
6733 }
6734 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006735 ++s; /* no extra chars */
6736 else /* must have a number */
6737 {
6738 while (vim_isdigit(*++s))
6739 ;
6740
6741 if (!VIM_ISDIGIT(*(s - 1)))
6742 {
6743 if (errbuf != NULL)
6744 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006745 sprintf((char *)errbuf,
6746 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747 transchar_byte(*(s - 1)));
6748 errmsg = errbuf;
6749 }
6750 else
6751 errmsg = (char_u *)"";
6752 break;
6753 }
6754 }
6755 if (*s == ',')
6756 ++s;
6757 else if (*s)
6758 {
6759 if (errbuf != NULL)
6760 errmsg = (char_u *)N_("E527: Missing comma");
6761 else
6762 errmsg = (char_u *)"";
6763 break;
6764 }
6765 }
6766 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6767 errmsg = (char_u *)N_("E528: Must specify a ' value");
6768 }
6769#endif /* FEAT_VIMINFO */
6770
6771 /* terminal options */
6772 else if (istermoption(&options[opt_idx]) && full_screen)
6773 {
6774 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6775 if (varp == &T_CCO)
6776 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006777 int colors = atoi((char *)T_CCO);
6778
6779 /* Only reinitialize colors if t_Co value has really changed to
6780 * avoid expensive reload of colorscheme if t_Co is set to the
6781 * same value multiple times. */
6782 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006784 t_colors = colors;
6785 if (t_colors <= 1)
6786 {
6787 if (new_value_alloced)
6788 vim_free(T_CCO);
6789 T_CCO = empty_option;
6790 }
6791 /* We now have a different color setup, initialize it again. */
6792 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006794 }
6795 ttest(FALSE);
6796 if (varp == &T_ME)
6797 {
6798 out_str(T_ME);
6799 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006800#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 /* Since t_me has been set, this probably means that the user
6802 * wants to use this as default colors. Need to reset default
6803 * background/foreground colors. */
6804 mch_set_normal_colors();
6805#endif
6806 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006807 if (varp == &T_BE && termcap_active)
6808 {
6809 if (*T_BE == NUL)
6810 /* When clearing t_BE we assume the user no longer wants
6811 * bracketed paste, thus disable it by writing t_BD. */
6812 out_str(T_BD);
6813 else
6814 out_str(T_BE);
6815 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816 }
6817
6818#ifdef FEAT_LINEBREAK
6819 /* 'showbreak' */
6820 else if (varp == &p_sbr)
6821 {
6822 for (s = p_sbr; *s; )
6823 {
6824 if (ptr2cells(s) != 1)
6825 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006826 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006827 }
6828 }
6829#endif
6830
6831#ifdef FEAT_GUI
6832 /* 'guifont' */
6833 else if (varp == &p_guifont)
6834 {
6835 if (gui.in_use)
6836 {
6837 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006838# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839 /*
6840 * Put up a font dialog and let the user select a new value.
6841 * If this is cancelled go back to the old value but don't
6842 * give an error message.
6843 */
6844 if (STRCMP(p, "*") == 0)
6845 {
6846 p = gui_mch_font_dialog(oldval);
6847
6848 if (new_value_alloced)
6849 free_string_option(p_guifont);
6850
6851 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6852 new_value_alloced = TRUE;
6853 }
6854# endif
6855 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6856 {
6857# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6858 if (STRCMP(p_guifont, "*") == 0)
6859 {
6860 /* Dialog was cancelled: Keep the old value without giving
6861 * an error message. */
6862 if (new_value_alloced)
6863 free_string_option(p_guifont);
6864 p_guifont = vim_strsave(oldval);
6865 new_value_alloced = TRUE;
6866 }
6867 else
6868# endif
6869 errmsg = (char_u *)N_("E596: Invalid font(s)");
6870 }
6871 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006872 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 }
6874# ifdef FEAT_XFONTSET
6875 else if (varp == &p_guifontset)
6876 {
6877 if (STRCMP(p_guifontset, "*") == 0)
6878 errmsg = (char_u *)N_("E597: can't select fontset");
6879 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6880 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006881 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006882 }
6883# endif
6884# ifdef FEAT_MBYTE
6885 else if (varp == &p_guifontwide)
6886 {
6887 if (STRCMP(p_guifontwide, "*") == 0)
6888 errmsg = (char_u *)N_("E533: can't select wide font");
6889 else if (gui_get_wide_font() == FAIL)
6890 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006891 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006892 }
6893# endif
6894#endif
6895
6896#ifdef CURSOR_SHAPE
6897 /* 'guicursor' */
6898 else if (varp == &p_guicursor)
6899 errmsg = parse_shape_opt(SHAPE_CURSOR);
6900#endif
6901
6902#ifdef FEAT_MOUSESHAPE
6903 /* 'mouseshape' */
6904 else if (varp == &p_mouseshape)
6905 {
6906 errmsg = parse_shape_opt(SHAPE_MOUSE);
6907 update_mouseshape(-1);
6908 }
6909#endif
6910
6911#ifdef FEAT_PRINTER
6912 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006913 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006914# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006915 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006916 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006917# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918#endif
6919
6920#ifdef FEAT_LANGMAP
6921 /* 'langmap' */
6922 else if (varp == &p_langmap)
6923 langmap_set();
6924#endif
6925
6926#ifdef FEAT_LINEBREAK
6927 /* 'breakat' */
6928 else if (varp == &p_breakat)
6929 fill_breakat_flags();
6930#endif
6931
6932#ifdef FEAT_TITLE
6933 /* 'titlestring' and 'iconstring' */
6934 else if (varp == &p_titlestring || varp == &p_iconstring)
6935 {
6936# ifdef FEAT_STL_OPT
6937 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6938
6939 /* NULL => statusline syntax */
6940 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6941 stl_syntax |= flagval;
6942 else
6943 stl_syntax &= ~flagval;
6944# endif
6945 did_set_title(varp == &p_iconstring);
6946
6947 }
6948#endif
6949
6950#ifdef FEAT_GUI
6951 /* 'guioptions' */
6952 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006953 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006954 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006955 redraw_gui_only = TRUE;
6956 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957#endif
6958
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006959#if defined(FEAT_GUI_TABLINE)
6960 /* 'guitablabel' */
6961 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006962 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006963 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006964 redraw_gui_only = TRUE;
6965 }
6966 /* 'guitabtooltip' */
6967 else if (varp == &p_gtt)
6968 {
6969 redraw_gui_only = TRUE;
6970 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006971#endif
6972
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6974 /* 'ttymouse' */
6975 else if (varp == &p_ttym)
6976 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006977 /* Switch the mouse off before changing the escape sequences used for
6978 * that. */
6979 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6981 errmsg = e_invarg;
6982 else
6983 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006984 if (termcap_active)
6985 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006986 }
6987#endif
6988
Bram Moolenaar071d4272004-06-13 20:20:40 +00006989 /* 'selection' */
6990 else if (varp == &p_sel)
6991 {
6992 if (*p_sel == NUL
6993 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6994 errmsg = e_invarg;
6995 }
6996
6997 /* 'selectmode' */
6998 else if (varp == &p_slm)
6999 {
7000 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7001 errmsg = e_invarg;
7002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003
7004#ifdef FEAT_BROWSE
7005 /* 'browsedir' */
7006 else if (varp == &p_bsdir)
7007 {
7008 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7009 && !mch_isdir(p_bsdir))
7010 errmsg = e_invarg;
7011 }
7012#endif
7013
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 /* 'keymodel' */
7015 else if (varp == &p_km)
7016 {
7017 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7018 errmsg = e_invarg;
7019 else
7020 {
7021 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7022 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7023 }
7024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007025
7026 /* 'mousemodel' */
7027 else if (varp == &p_mousem)
7028 {
7029 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7030 errmsg = e_invarg;
7031#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7032 else if (*p_mousem != *oldval)
7033 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7034 * to create or delete the popup menus. */
7035 gui_motif_update_mousemodel(root_menu);
7036#endif
7037 }
7038
7039 /* 'switchbuf' */
7040 else if (varp == &p_swb)
7041 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007042 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043 errmsg = e_invarg;
7044 }
7045
7046 /* 'debug' */
7047 else if (varp == &p_debug)
7048 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007049 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 errmsg = e_invarg;
7051 }
7052
7053 /* 'display' */
7054 else if (varp == &p_dy)
7055 {
7056 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7057 errmsg = e_invarg;
7058 else
7059 (void)init_chartab();
7060
7061 }
7062
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007063#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007064 /* 'eadirection' */
7065 else if (varp == &p_ead)
7066 {
7067 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7068 errmsg = e_invarg;
7069 }
7070#endif
7071
7072#ifdef FEAT_CLIPBOARD
7073 /* 'clipboard' */
7074 else if (varp == &p_cb)
7075 errmsg = check_clipboard_option();
7076#endif
7077
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007078#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007079 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7080 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007081 else if (varp == &(curwin->w_s->b_p_spl)
7082 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007083 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007084 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007085 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007086 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007087 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007088 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007089 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007090 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007091 /* 'spellsuggest' */
7092 else if (varp == &p_sps)
7093 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007094 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007095 errmsg = e_invarg;
7096 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007097 /* 'mkspellmem' */
7098 else if (varp == &p_msm)
7099 {
7100 if (spell_check_msm() != OK)
7101 errmsg = e_invarg;
7102 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007103#endif
7104
Bram Moolenaar071d4272004-06-13 20:20:40 +00007105 /* When 'bufhidden' is set, check for valid value. */
7106 else if (gvarp == &p_bh)
7107 {
7108 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7109 errmsg = e_invarg;
7110 }
7111
7112 /* When 'buftype' is set, check for valid value. */
7113 else if (gvarp == &p_bt)
7114 {
7115 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7116 errmsg = e_invarg;
7117 else
7118 {
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007119#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 if (curwin->w_status_height)
7121 {
7122 curwin->w_redr_status = TRUE;
7123 redraw_later(VALID);
7124 }
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007125#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007126 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007127#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007128 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130 }
7131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007132
7133#ifdef FEAT_STL_OPT
7134 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007135 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007136 {
7137 int wid;
7138
7139 if (varp == &p_ruf) /* reset ru_wid first */
7140 ru_wid = 0;
7141 s = *varp;
7142 if (varp == &p_ruf && *s == '%')
7143 {
7144 /* set ru_wid if 'ruf' starts with "%99(" */
7145 if (*++s == '-') /* ignore a '-' */
7146 s++;
7147 wid = getdigits(&s);
7148 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7149 ru_wid = wid;
7150 else
7151 errmsg = check_stl_option(p_ruf);
7152 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007153 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007154 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007155 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007156 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157 comp_col();
7158 }
7159#endif
7160
7161#ifdef FEAT_INS_EXPAND
7162 /* check if it is a valid value for 'complete' -- Acevedo */
7163 else if (gvarp == &p_cpt)
7164 {
7165 for (s = *varp; *s;)
7166 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007167 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168 s++;
7169 if (!*s)
7170 break;
7171 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7172 {
7173 errmsg = illegal_char(errbuf, *s);
7174 break;
7175 }
7176 if (*++s != NUL && *s != ',' && *s != ' ')
7177 {
7178 if (s[-1] == 'k' || s[-1] == 's')
7179 {
7180 /* skip optional filename after 'k' and 's' */
7181 while (*s && *s != ',' && *s != ' ')
7182 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007183 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 ++s;
7185 ++s;
7186 }
7187 }
7188 else
7189 {
7190 if (errbuf != NULL)
7191 {
7192 sprintf((char *)errbuf,
7193 _("E535: Illegal character after <%c>"),
7194 *--s);
7195 errmsg = errbuf;
7196 }
7197 else
7198 errmsg = (char_u *)"";
7199 break;
7200 }
7201 }
7202 }
7203 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007204
7205 /* 'completeopt' */
7206 else if (varp == &p_cot)
7207 {
7208 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7209 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007210 else
7211 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007212 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213#endif /* FEAT_INS_EXPAND */
7214
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007215#ifdef FEAT_SIGNS
7216 /* 'signcolumn' */
7217 else if (varp == &curwin->w_p_scl)
7218 {
7219 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7220 errmsg = e_invarg;
7221 }
7222#endif
7223
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224
7225#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007226 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227 else if (varp == &p_toolbar)
7228 {
7229 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7230 &toolbar_flags, TRUE) != OK)
7231 errmsg = e_invarg;
7232 else
7233 {
7234 out_flush();
7235 gui_mch_show_toolbar((toolbar_flags &
7236 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7237 }
7238 }
7239#endif
7240
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007241#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242 /* 'toolbariconsize': GTK+ 2 only */
7243 else if (varp == &p_tbis)
7244 {
7245 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7246 errmsg = e_invarg;
7247 else
7248 {
7249 out_flush();
7250 gui_mch_show_toolbar((toolbar_flags &
7251 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7252 }
7253 }
7254#endif
7255
7256 /* 'pastetoggle': translate key codes like in a mapping */
7257 else if (varp == &p_pt)
7258 {
7259 if (*p_pt)
7260 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007261 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262 if (p != NULL)
7263 {
7264 if (new_value_alloced)
7265 free_string_option(p_pt);
7266 p_pt = p;
7267 new_value_alloced = TRUE;
7268 }
7269 }
7270 }
7271
7272 /* 'backspace' */
7273 else if (varp == &p_bs)
7274 {
7275 if (VIM_ISDIGIT(*p_bs))
7276 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007277 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007278 errmsg = e_invarg;
7279 }
7280 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7281 errmsg = e_invarg;
7282 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007283 else if (varp == &p_bo)
7284 {
7285 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7286 errmsg = e_invarg;
7287 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007288
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007289 /* 'tagcase' */
7290 else if (gvarp == &p_tc)
7291 {
7292 unsigned int *flags;
7293
7294 if (opt_flags & OPT_LOCAL)
7295 {
7296 p = curbuf->b_p_tc;
7297 flags = &curbuf->b_tc_flags;
7298 }
7299 else
7300 {
7301 p = p_tc;
7302 flags = &tc_flags;
7303 }
7304
7305 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7306 /* make the local value empty: use the global value */
7307 *flags = 0;
7308 else if (*p == NUL
7309 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7310 errmsg = e_invarg;
7311 }
7312
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007313#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007314 /* 'casemap' */
7315 else if (varp == &p_cmp)
7316 {
7317 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7318 errmsg = e_invarg;
7319 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007320#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007321
7322#ifdef FEAT_DIFF
7323 /* 'diffopt' */
7324 else if (varp == &p_dip)
7325 {
7326 if (diffopt_changed() == FAIL)
7327 errmsg = e_invarg;
7328 }
7329#endif
7330
7331#ifdef FEAT_FOLDING
7332 /* 'foldmethod' */
7333 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7334 {
7335 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7336 || *curwin->w_p_fdm == NUL)
7337 errmsg = e_invarg;
7338 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007339 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007340 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007341 if (foldmethodIsDiff(curwin))
7342 newFoldLevel();
7343 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344 }
7345# ifdef FEAT_EVAL
7346 /* 'foldexpr' */
7347 else if (varp == &curwin->w_p_fde)
7348 {
7349 if (foldmethodIsExpr(curwin))
7350 foldUpdateAll(curwin);
7351 }
7352# endif
7353 /* 'foldmarker' */
7354 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7355 {
7356 p = vim_strchr(*varp, ',');
7357 if (p == NULL)
7358 errmsg = (char_u *)N_("E536: comma required");
7359 else if (p == *varp || p[1] == NUL)
7360 errmsg = e_invarg;
7361 else if (foldmethodIsMarker(curwin))
7362 foldUpdateAll(curwin);
7363 }
7364 /* 'commentstring' */
7365 else if (gvarp == &p_cms)
7366 {
7367 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7368 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7369 }
7370 /* 'foldopen' */
7371 else if (varp == &p_fdo)
7372 {
7373 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7374 errmsg = e_invarg;
7375 }
7376 /* 'foldclose' */
7377 else if (varp == &p_fcl)
7378 {
7379 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7380 errmsg = e_invarg;
7381 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007382 /* 'foldignore' */
7383 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7384 {
7385 if (foldmethodIsIndent(curwin))
7386 foldUpdateAll(curwin);
7387 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007388#endif
7389
7390#ifdef FEAT_VIRTUALEDIT
7391 /* 'virtualedit' */
7392 else if (varp == &p_ve)
7393 {
7394 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7395 errmsg = e_invarg;
7396 else if (STRCMP(p_ve, oldval) != 0)
7397 {
7398 /* Recompute cursor position in case the new 've' setting
7399 * changes something. */
7400 validate_virtcol();
7401 coladvance(curwin->w_virtcol);
7402 }
7403 }
7404#endif
7405
7406#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7407 else if (varp == &p_csqf)
7408 {
7409 if (p_csqf != NULL)
7410 {
7411 p = p_csqf;
7412 while (*p != NUL)
7413 {
7414 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7415 || p[1] == NUL
7416 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7417 || (p[2] != NUL && p[2] != ','))
7418 {
7419 errmsg = e_invarg;
7420 break;
7421 }
7422 else if (p[2] == NUL)
7423 break;
7424 else
7425 p += 3;
7426 }
7427 }
7428 }
7429#endif
7430
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007431#ifdef FEAT_CINDENT
7432 /* 'cinoptions' */
7433 else if (gvarp == &p_cino)
7434 {
7435 /* TODO: recognize errors */
7436 parse_cino(curbuf);
7437 }
7438#endif
7439
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007440#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007441 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007442 else if (varp == &p_rop && gui.in_use)
7443 {
7444 if (!gui_mch_set_rendering_options(p_rop))
7445 errmsg = e_invarg;
7446 }
7447#endif
7448
Bram Moolenaard0b51382016-11-04 15:23:45 +01007449#ifdef FEAT_AUTOCMD
7450 else if (gvarp == &p_ft)
7451 {
7452 if (!valid_filetype(*varp))
7453 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007454 else
7455 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007456 }
7457#endif
7458
7459#ifdef FEAT_SYN_HL
7460 else if (gvarp == &p_syn)
7461 {
7462 if (!valid_filetype(*varp))
7463 errmsg = e_invarg;
7464 }
7465#endif
7466
Bram Moolenaar825680f2017-07-22 17:04:02 +02007467#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007468 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007469 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007470 {
7471 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7472 errmsg = e_invarg;
7473 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007474 /* 'termsize' */
7475 else if (varp == &curwin->w_p_tms)
7476 {
7477 if (*curwin->w_p_tms != NUL)
7478 {
7479 p = skipdigits(curwin->w_p_tms);
7480 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7481 errmsg = e_invarg;
7482 }
7483 }
7484#endif
7485
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 /* Options that are a list of flags. */
7487 else
7488 {
7489 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007490 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007492 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007493 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007494 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007495 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007496 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007497 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007498#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007499 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007500 p = (char_u *)COCU_ALL;
7501#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007502 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007503 {
7504#ifdef FEAT_MOUSE
7505 p = (char_u *)MOUSE_ALL;
7506#else
7507 if (*p_mouse != NUL)
7508 errmsg = (char_u *)N_("E538: No mouse support");
7509#endif
7510 }
7511#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007512 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 p = (char_u *)GO_ALL;
7514#endif
7515 if (p != NULL)
7516 {
7517 for (s = *varp; *s; ++s)
7518 if (vim_strchr(p, *s) == NULL)
7519 {
7520 errmsg = illegal_char(errbuf, *s);
7521 break;
7522 }
7523 }
7524 }
7525
7526 /*
7527 * If error detected, restore the previous value.
7528 */
7529 if (errmsg != NULL)
7530 {
7531 if (new_value_alloced)
7532 free_string_option(*varp);
7533 *varp = oldval;
7534 /*
7535 * When resetting some values, need to act on it.
7536 */
7537 if (did_chartab)
7538 (void)init_chartab();
7539 if (varp == &p_hl)
7540 (void)highlight_changed();
7541 }
7542 else
7543 {
7544#ifdef FEAT_EVAL
7545 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007546 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547#endif
7548 /*
7549 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007550 * Use "free_oldval", because recursiveness may change the flags under
7551 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007552 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007553 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007554 free_string_option(oldval);
7555 if (new_value_alloced)
7556 options[opt_idx].flags |= P_ALLOCED;
7557 else
7558 options[opt_idx].flags &= ~P_ALLOCED;
7559
7560 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007561 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007562 {
7563 /* global option with local value set to use global value; free
7564 * the local value and make it empty */
7565 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7566 free_string_option(*(char_u **)p);
7567 *(char_u **)p = empty_option;
7568 }
7569
7570 /* May set global value for local option. */
7571 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7572 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007573
7574#ifdef FEAT_AUTOCMD
7575 /*
7576 * Trigger the autocommand only after setting the flags.
7577 */
7578# ifdef FEAT_SYN_HL
7579 /* When 'syntax' is set, load the syntax of that name */
7580 if (varp == &(curbuf->b_p_syn))
7581 {
7582 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7583 curbuf->b_fname, TRUE, curbuf);
7584 }
7585# endif
7586 else if (varp == &(curbuf->b_p_ft))
7587 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007588 /* 'filetype' is set, trigger the FileType autocommand.
7589 * Skip this when called from a modeline and the filetype was
7590 * already set to this value. */
7591 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7592 {
7593 did_filetype = TRUE;
7594 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007595 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007596 /* Just in case the old "curbuf" is now invalid. */
7597 if (varp != &(curbuf->b_p_ft))
7598 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007599 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007600 }
7601#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007602#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007603 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007604 {
7605 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007606 char_u *q = curwin->w_s->b_p_spl;
7607
7608 /* Skip the first name if it is "cjk". */
7609 if (STRNCMP(q, "cjk,", 4) == 0)
7610 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007611
7612 /*
7613 * Source the spell/LANG.vim in 'runtimepath'.
7614 * They could set 'spellcapcheck' depending on the language.
7615 * Use the first name in 'spelllang' up to '_region' or
7616 * '.encoding'.
7617 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007618 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007619 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7620 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007621 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007622 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007623 }
7624#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007625 }
7626
7627#ifdef FEAT_MOUSE
7628 if (varp == &p_mouse)
7629 {
7630# ifdef FEAT_MOUSE_TTY
7631 if (*p_mouse == NUL)
7632 mch_setmouse(FALSE); /* switch mouse off */
7633 else
7634# endif
7635 setmouse(); /* in case 'mouse' changed */
7636 }
7637#endif
7638
Bram Moolenaar913077c2012-03-28 19:59:04 +02007639 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007640 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007641 curwin->w_set_curswant = TRUE;
7642
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007643#ifdef FEAT_GUI
7644 /* check redraw when it's not a GUI option or the GUI is active. */
7645 if (!redraw_gui_only || gui.in_use)
7646#endif
7647 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007648
7649 return errmsg;
7650}
7651
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007652#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007653/*
7654 * Simple int comparison function for use with qsort()
7655 */
7656 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007657int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007658{
7659 return *(const int *)a - *(const int *)b;
7660}
7661
7662/*
7663 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7664 * Returns error message, NULL if it's OK.
7665 */
7666 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007667check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007668{
7669 char_u *s;
7670 int col;
7671 int count = 0;
7672 int color_cols[256];
7673 int i;
7674 int j = 0;
7675
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007676 if (wp->w_buffer == NULL)
7677 return NULL; /* buffer was closed */
7678
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007679 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007680 {
7681 if (*s == '-' || *s == '+')
7682 {
7683 /* -N and +N: add to 'textwidth' */
7684 col = (*s == '-') ? -1 : 1;
7685 ++s;
7686 if (!VIM_ISDIGIT(*s))
7687 return e_invarg;
7688 col = col * getdigits(&s);
7689 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007690 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007691 col += wp->w_buffer->b_p_tw;
7692 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007693 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007694 }
7695 else if (VIM_ISDIGIT(*s))
7696 col = getdigits(&s);
7697 else
7698 return e_invarg;
7699 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007700skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007701 if (*s == NUL)
7702 break;
7703 if (*s != ',')
7704 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007705 if (*++s == NUL)
7706 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007707 }
7708
7709 vim_free(wp->w_p_cc_cols);
7710 if (count == 0)
7711 wp->w_p_cc_cols = NULL;
7712 else
7713 {
7714 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7715 if (wp->w_p_cc_cols != NULL)
7716 {
7717 /* sort the columns for faster usage on screen redraw inside
7718 * win_line() */
7719 qsort(color_cols, count, sizeof(int), int_cmp);
7720
7721 for (i = 0; i < count; ++i)
7722 /* skip duplicates */
7723 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7724 wp->w_p_cc_cols[j++] = color_cols[i];
7725 wp->w_p_cc_cols[j] = -1; /* end marker */
7726 }
7727 }
7728
7729 return NULL; /* no error */
7730}
7731#endif
7732
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733/*
7734 * Handle setting 'listchars' or 'fillchars'.
7735 * Returns error message, NULL if it's OK.
7736 */
7737 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007738set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739{
7740 int round, i, len, entries;
7741 char_u *p, *s;
7742 int c1, c2 = 0;
7743 struct charstab
7744 {
7745 int *cp;
7746 char *name;
7747 };
7748#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7749 static struct charstab filltab[] =
7750 {
7751 {&fill_stl, "stl"},
7752 {&fill_stlnc, "stlnc"},
7753 {&fill_vert, "vert"},
7754 {&fill_fold, "fold"},
7755 {&fill_diff, "diff"},
7756 };
7757#endif
7758 static struct charstab lcstab[] =
7759 {
7760 {&lcs_eol, "eol"},
7761 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007762 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007764 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765 {&lcs_tab2, "tab"},
7766 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007767#ifdef FEAT_CONCEAL
7768 {&lcs_conceal, "conceal"},
7769#else
7770 {NULL, "conceal"},
7771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007772 };
7773 struct charstab *tab;
7774
7775#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7776 if (varp == &p_lcs)
7777#endif
7778 {
7779 tab = lcstab;
7780 entries = sizeof(lcstab) / sizeof(struct charstab);
7781 }
7782#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7783 else
7784 {
7785 tab = filltab;
7786 entries = sizeof(filltab) / sizeof(struct charstab);
7787 }
7788#endif
7789
7790 /* first round: check for valid value, second round: assign values */
7791 for (round = 0; round <= 1; ++round)
7792 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007793 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007794 {
7795 /* After checking that the value is valid: set defaults: space for
7796 * 'fillchars', NUL for 'listchars' */
7797 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007798 if (tab[i].cp != NULL)
7799 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 if (varp == &p_lcs)
7801 lcs_tab1 = NUL;
7802#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7803 else
7804 fill_diff = '-';
7805#endif
7806 }
7807 p = *varp;
7808 while (*p)
7809 {
7810 for (i = 0; i < entries; ++i)
7811 {
7812 len = (int)STRLEN(tab[i].name);
7813 if (STRNCMP(p, tab[i].name, len) == 0
7814 && p[len] == ':'
7815 && p[len + 1] != NUL)
7816 {
7817 s = p + len + 1;
7818#ifdef FEAT_MBYTE
7819 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007820 if (mb_char2cells(c1) > 1)
7821 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007822#else
7823 c1 = *s++;
7824#endif
7825 if (tab[i].cp == &lcs_tab2)
7826 {
7827 if (*s == NUL)
7828 continue;
7829#ifdef FEAT_MBYTE
7830 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007831 if (mb_char2cells(c2) > 1)
7832 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007833#else
7834 c2 = *s++;
7835#endif
7836 }
7837 if (*s == ',' || *s == NUL)
7838 {
7839 if (round)
7840 {
7841 if (tab[i].cp == &lcs_tab2)
7842 {
7843 lcs_tab1 = c1;
7844 lcs_tab2 = c2;
7845 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007846 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007847 *(tab[i].cp) = c1;
7848
7849 }
7850 p = s;
7851 break;
7852 }
7853 }
7854 }
7855
7856 if (i == entries)
7857 return e_invarg;
7858 if (*p == ',')
7859 ++p;
7860 }
7861 }
7862
7863 return NULL; /* no error */
7864}
7865
7866#ifdef FEAT_STL_OPT
7867/*
7868 * Check validity of options with the 'statusline' format.
7869 * Return error message or NULL.
7870 */
7871 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007872check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873{
7874 int itemcnt = 0;
7875 int groupdepth = 0;
7876 static char_u errbuf[80];
7877
7878 while (*s && itemcnt < STL_MAX_ITEM)
7879 {
7880 /* Check for valid keys after % sequences */
7881 while (*s && *s != '%')
7882 s++;
7883 if (!*s)
7884 break;
7885 s++;
7886 if (*s != '%' && *s != ')')
7887 ++itemcnt;
7888 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7889 {
7890 s++;
7891 continue;
7892 }
7893 if (*s == ')')
7894 {
7895 s++;
7896 if (--groupdepth < 0)
7897 break;
7898 continue;
7899 }
7900 if (*s == '-')
7901 s++;
7902 while (VIM_ISDIGIT(*s))
7903 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007904 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905 continue;
7906 if (*s == '.')
7907 {
7908 s++;
7909 while (*s && VIM_ISDIGIT(*s))
7910 s++;
7911 }
7912 if (*s == '(')
7913 {
7914 groupdepth++;
7915 continue;
7916 }
7917 if (vim_strchr(STL_ALL, *s) == NULL)
7918 {
7919 return illegal_char(errbuf, *s);
7920 }
7921 if (*s == '{')
7922 {
7923 s++;
7924 while (*s != '}' && *s)
7925 s++;
7926 if (*s != '}')
7927 return (char_u *)N_("E540: Unclosed expression sequence");
7928 }
7929 }
7930 if (itemcnt >= STL_MAX_ITEM)
7931 return (char_u *)N_("E541: too many items");
7932 if (groupdepth != 0)
7933 return (char_u *)N_("E542: unbalanced groups");
7934 return NULL;
7935}
7936#endif
7937
7938#ifdef FEAT_CLIPBOARD
7939/*
7940 * Extract the items in the 'clipboard' option and set global values.
7941 */
7942 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007943check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007945 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007946 int new_autoselect_star = FALSE;
7947 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007948 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007949 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950 regprog_T *new_exclude_prog = NULL;
7951 char_u *errmsg = NULL;
7952 char_u *p;
7953
7954 for (p = p_cb; *p != NUL; )
7955 {
7956 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7957 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007958 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 p += 7;
7960 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007961 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007962 && (p[11] == ',' || p[11] == NUL))
7963 {
7964 new_unnamed |= CLIP_UNNAMED_PLUS;
7965 p += 11;
7966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007968 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007970 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007971 p += 10;
7972 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007973 else if (STRNCMP(p, "autoselectplus", 14) == 0
7974 && (p[14] == ',' || p[14] == NUL))
7975 {
7976 new_autoselect_plus = TRUE;
7977 p += 14;
7978 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007980 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 {
7982 new_autoselectml = TRUE;
7983 p += 12;
7984 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007985 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7986 {
7987 new_html = TRUE;
7988 p += 4;
7989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7991 {
7992 p += 8;
7993 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7994 if (new_exclude_prog == NULL)
7995 errmsg = e_invarg;
7996 break;
7997 }
7998 else
7999 {
8000 errmsg = e_invarg;
8001 break;
8002 }
8003 if (*p == ',')
8004 ++p;
8005 }
8006 if (errmsg == NULL)
8007 {
8008 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008009 clip_autoselect_star = new_autoselect_star;
8010 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008011 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008012 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008013 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008015#ifdef FEAT_GUI_GTK
8016 if (gui.in_use)
8017 {
8018 gui_gtk_set_selection_targets();
8019 gui_gtk_set_dnd_targets();
8020 }
8021#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008022 }
8023 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008024 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025
8026 return errmsg;
8027}
8028#endif
8029
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008030#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008031 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008032did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008033{
8034 char_u *errmsg = NULL;
8035 win_T *wp;
8036 int l;
8037
8038 if (is_spellfile)
8039 {
8040 l = (int)STRLEN(curwin->w_s->b_p_spf);
8041 if (l > 0 && (l < 4
8042 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8043 errmsg = e_invarg;
8044 }
8045
8046 if (errmsg == NULL)
8047 {
8048 FOR_ALL_WINDOWS(wp)
8049 if (wp->w_buffer == curbuf && wp->w_p_spell)
8050 {
8051 errmsg = did_set_spelllang(wp);
8052# ifdef FEAT_WINDOWS
8053 break;
8054# endif
8055 }
8056 }
8057 return errmsg;
8058}
8059
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008060/*
8061 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8062 * Return error message when failed, NULL when OK.
8063 */
8064 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008065compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008066{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008067 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008068 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008069
Bram Moolenaar860cae12010-06-05 23:22:07 +02008070 if (*synblock->b_p_spc == NUL)
8071 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008072 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008073 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008074 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008075 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008076 if (re != NULL)
8077 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008078 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008079 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008080 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008081 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008082 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008083 return e_invarg;
8084 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008085 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008086 }
8087
Bram Moolenaar473de612013-06-08 18:19:48 +02008088 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008089 return NULL;
8090}
8091#endif
8092
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008093#if defined(FEAT_EVAL) || defined(PROTO)
8094/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008095 * Set the scriptID for an option, taking care of setting the buffer- or
8096 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008097 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008098 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008099set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008100{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008101 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8102 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008103
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008104 /* Remember where the option was set. For local options need to do that
8105 * in the buffer or window structure. */
8106 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008107 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008108 if (both || (opt_flags & OPT_LOCAL))
8109 {
8110 if (indir & PV_BUF)
8111 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8112 else if (indir & PV_WIN)
8113 curwin->w_p_scriptID[indir & PV_MASK] = id;
8114 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008115}
8116#endif
8117
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118/*
8119 * Set the value of a boolean option, and take care of side effects.
8120 * Returns NULL for success, or an error message for an error.
8121 */
8122 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008123set_bool_option(
8124 int opt_idx, /* index in options[] table */
8125 char_u *varp, /* pointer to the option variable */
8126 int value, /* new value */
8127 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128{
8129 int old_value = *(int *)varp;
8130
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 /* Disallow changing some options from secure mode */
8132 if ((secure
8133#ifdef HAVE_SANDBOX
8134 || sandbox != 0
8135#endif
8136 ) && (options[opt_idx].flags & P_SECURE))
8137 return e_secure;
8138
8139 *(int *)varp = value; /* set the new value */
8140#ifdef FEAT_EVAL
8141 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008142 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143#endif
8144
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008145#ifdef FEAT_GUI
8146 need_mouse_correct = TRUE;
8147#endif
8148
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 /* May set global value for local option. */
8150 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8151 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8152
8153 /*
8154 * Handle side effects of changing a bool option.
8155 */
8156
8157 /* 'compatible' */
8158 if ((int *)varp == &p_cp)
8159 {
8160 compatible_set();
8161 }
8162
Bram Moolenaar920694c2016-08-21 17:45:02 +02008163#ifdef FEAT_LANGMAP
8164 if ((int *)varp == &p_lrm)
8165 /* 'langremap' -> !'langnoremap' */
8166 p_lnr = !p_lrm;
8167 else if ((int *)varp == &p_lnr)
8168 /* 'langnoremap' -> !'langremap' */
8169 p_lrm = !p_lnr;
8170#endif
8171
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008172#ifdef FEAT_PERSISTENT_UNDO
8173 /* 'undofile' */
8174 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8175 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008176 /* Only take action when the option was set. When reset we do not
8177 * delete the undo file, the option may be set again without making
8178 * any changes in between. */
8179 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008180 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008181 char_u hash[UNDO_HASH_SIZE];
8182 buf_T *save_curbuf = curbuf;
8183
Bram Moolenaar29323592016-07-24 22:04:11 +02008184 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008185 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008186 /* When 'undofile' is set globally: for every buffer, otherwise
8187 * only for the current buffer: Try to read in the undofile,
8188 * if one exists, the buffer wasn't changed and the buffer was
8189 * loaded */
8190 if ((curbuf == save_curbuf
8191 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8192 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8193 {
8194 u_compute_hash(hash);
8195 u_read_undo(NULL, hash, curbuf->b_fname);
8196 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008197 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008198 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008199 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008200 }
8201#endif
8202
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203 else if ((int *)varp == &curbuf->b_p_ro)
8204 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008205 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8207 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008208
8209 /* when 'readonly' is set may give W10 again */
8210 if (curbuf->b_p_ro)
8211 curbuf->b_did_warn = FALSE;
8212
Bram Moolenaar071d4272004-06-13 20:20:40 +00008213#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008214 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008215#endif
8216 }
8217
Bram Moolenaar9c449722010-07-20 18:44:27 +02008218#ifdef FEAT_GUI
8219 else if ((int *)varp == &p_mh)
8220 {
8221 if (!p_mh)
8222 gui_mch_mousehide(FALSE);
8223 }
8224#endif
8225
Bram Moolenaara539df02010-08-01 14:35:05 +02008226 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008227 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008228 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008229# ifdef FEAT_TERMINAL
8230 /* Cannot set 'modifiable' when in Terminal mode. */
8231 if (term_in_terminal_mode())
8232 {
8233 curbuf->b_p_ma = FALSE;
8234 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8235 }
8236# endif
8237# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008238 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008239# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008240 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008241#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008242 /* when 'endofline' is changed, redraw the window title */
8243 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008244 {
8245 redraw_titles();
8246 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008247 /* when 'fixeol' is changed, redraw the window title */
8248 else if ((int *)varp == &curbuf->b_p_fixeol)
8249 {
8250 redraw_titles();
8251 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008252# ifdef FEAT_MBYTE
8253 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008254 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008255 {
8256 redraw_titles();
8257 }
8258# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008259#endif
8260
8261 /* when 'bin' is set also set some other options */
8262 else if ((int *)varp == &curbuf->b_p_bin)
8263 {
8264 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8265#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008266 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008267#endif
8268 }
8269
8270#ifdef FEAT_AUTOCMD
8271 /* when 'buflisted' changes, trigger autocommands */
8272 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8273 {
8274 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8275 NULL, NULL, TRUE, curbuf);
8276 }
8277#endif
8278
8279 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8280 else if ((int *)varp == &curbuf->b_p_swf)
8281 {
8282 if (curbuf->b_p_swf && p_uc)
8283 ml_open_file(curbuf); /* create the swap file */
8284 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008285 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8286 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287 mf_close_file(curbuf, TRUE); /* remove the swap file */
8288 }
8289
8290 /* when 'terse' is set change 'shortmess' */
8291 else if ((int *)varp == &p_terse)
8292 {
8293 char_u *p;
8294
8295 p = vim_strchr(p_shm, SHM_SEARCH);
8296
8297 /* insert 's' in p_shm */
8298 if (p_terse && p == NULL)
8299 {
8300 STRCPY(IObuff, p_shm);
8301 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008302 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008303 }
8304 /* remove 's' from p_shm */
8305 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008306 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307 }
8308
8309 /* when 'paste' is set or reset also change other options */
8310 else if ((int *)varp == &p_paste)
8311 {
8312 paste_option_changed();
8313 }
8314
8315 /* when 'insertmode' is set from an autocommand need to do work here */
8316 else if ((int *)varp == &p_im)
8317 {
8318 if (p_im)
8319 {
8320 if ((State & INSERT) == 0)
8321 need_start_insertmode = TRUE;
8322 stop_insert_mode = FALSE;
8323 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008324 /* only reset if it was set previously */
8325 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 {
8327 need_start_insertmode = FALSE;
8328 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008329 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008330 clear_cmdline = TRUE; /* remove "(insert)" */
8331 restart_edit = 0;
8332 }
8333 }
8334
8335 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8336 else if ((int *)varp == &p_ic && p_hls)
8337 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008338 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 }
8340
8341#ifdef FEAT_SEARCH_EXTRA
8342 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8343 else if ((int *)varp == &p_hls)
8344 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008345 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008346 }
8347#endif
8348
8349#ifdef FEAT_SCROLLBIND
8350 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8351 * at the end of normal_cmd() */
8352 else if ((int *)varp == &curwin->w_p_scb)
8353 {
8354 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008355 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008357 curwin->w_scbind_pos = curwin->w_topline;
8358 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359 }
8360#endif
8361
8362#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8363 /* There can be only one window with 'previewwindow' set. */
8364 else if ((int *)varp == &curwin->w_p_pvw)
8365 {
8366 if (curwin->w_p_pvw)
8367 {
8368 win_T *win;
8369
Bram Moolenaar29323592016-07-24 22:04:11 +02008370 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008371 if (win->w_p_pvw && win != curwin)
8372 {
8373 curwin->w_p_pvw = FALSE;
8374 return (char_u *)N_("E590: A preview window already exists");
8375 }
8376 }
8377 }
8378#endif
8379
8380 /* when 'textmode' is set or reset also change 'fileformat' */
8381 else if ((int *)varp == &curbuf->b_p_tx)
8382 {
8383 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8384 }
8385
8386 /* when 'textauto' is set or reset also change 'fileformats' */
8387 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008388 set_string_option_direct((char_u *)"ffs", -1,
8389 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008390 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008391
8392 /*
8393 * When 'lisp' option changes include/exclude '-' in
8394 * keyword characters.
8395 */
8396#ifdef FEAT_LISP
8397 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8398 {
8399 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8400 }
8401#endif
8402
8403#ifdef FEAT_TITLE
8404 /* when 'title' changed, may need to change the title; same for 'icon' */
8405 else if ((int *)varp == &p_title)
8406 {
8407 did_set_title(FALSE);
8408 }
8409
8410 else if ((int *)varp == &p_icon)
8411 {
8412 did_set_title(TRUE);
8413 }
8414#endif
8415
8416 else if ((int *)varp == &curbuf->b_changed)
8417 {
8418 if (!value)
8419 save_file_ff(curbuf); /* Buffer is unchanged */
8420#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008421 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422#endif
8423#ifdef FEAT_AUTOCMD
8424 modified_was_set = value;
8425#endif
8426 }
8427
8428#ifdef BACKSLASH_IN_FILENAME
8429 else if ((int *)varp == &p_ssl)
8430 {
8431 if (p_ssl)
8432 {
8433 psepc = '/';
8434 psepcN = '\\';
8435 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 }
8437 else
8438 {
8439 psepc = '\\';
8440 psepcN = '/';
8441 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008442 }
8443
8444 /* need to adjust the file name arguments and buffer names. */
8445 buflist_slash_adjust();
8446 alist_slash_adjust();
8447# ifdef FEAT_EVAL
8448 scriptnames_slash_adjust();
8449# endif
8450 }
8451#endif
8452
8453 /* If 'wrap' is set, set w_leftcol to zero. */
8454 else if ((int *)varp == &curwin->w_p_wrap)
8455 {
8456 if (curwin->w_p_wrap)
8457 curwin->w_leftcol = 0;
8458 }
8459
8460#ifdef FEAT_WINDOWS
8461 else if ((int *)varp == &p_ea)
8462 {
8463 if (p_ea && !old_value)
8464 win_equal(curwin, FALSE, 0);
8465 }
8466#endif
8467
8468 else if ((int *)varp == &p_wiv)
8469 {
8470 /*
8471 * When 'weirdinvert' changed, set/reset 't_xs'.
8472 * Then set 'weirdinvert' according to value of 't_xs'.
8473 */
8474 if (p_wiv && !old_value)
8475 T_XS = (char_u *)"y";
8476 else if (!p_wiv && old_value)
8477 T_XS = empty_option;
8478 p_wiv = (*T_XS != NUL);
8479 }
8480
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008481#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008482 else if ((int *)varp == &p_beval)
8483 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008484 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008485 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008486 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008487 gui_mch_disable_beval_area(balloonEval);
8488 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008491#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492 else if ((int *)varp == &p_acd)
8493 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008494 /* Change directories when the 'acd' option is set now. */
8495 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008496 }
8497#endif
8498
8499#ifdef FEAT_DIFF
8500 /* 'diff' */
8501 else if ((int *)varp == &curwin->w_p_diff)
8502 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008503 /* May add or remove the buffer from the list of diff buffers. */
8504 diff_buf_adjust(curwin);
8505# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506 if (foldmethodIsDiff(curwin))
8507 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008508# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509 }
8510#endif
8511
8512#ifdef USE_IM_CONTROL
8513 /* 'imdisable' */
8514 else if ((int *)varp == &p_imdisable)
8515 {
8516 /* Only de-activate it here, it will be enabled when changing mode. */
8517 if (p_imdisable)
8518 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008519 else if (State & INSERT)
8520 /* When the option is set from an autocommand, it may need to take
8521 * effect right away. */
8522 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008523 }
8524#endif
8525
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008526#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008527 /* 'spell' */
8528 else if ((int *)varp == &curwin->w_p_spell)
8529 {
8530 if (curwin->w_p_spell)
8531 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008532 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008533 if (errmsg != NULL)
8534 EMSG(_(errmsg));
8535 }
8536 }
8537#endif
8538
Bram Moolenaar071d4272004-06-13 20:20:40 +00008539#ifdef FEAT_FKMAP
8540 else if ((int *)varp == &p_altkeymap)
8541 {
8542 if (old_value != p_altkeymap)
8543 {
8544 if (!p_altkeymap)
8545 {
8546 p_hkmap = p_fkmap;
8547 p_fkmap = 0;
8548 }
8549 else
8550 {
8551 p_fkmap = p_hkmap;
8552 p_hkmap = 0;
8553 }
8554 (void)init_chartab();
8555 }
8556 }
8557
8558 /*
8559 * In case some second language keymapping options have changed, check
8560 * and correct the setting in a consistent way.
8561 */
8562
8563 /*
8564 * If hkmap or fkmap are set, reset Arabic keymapping.
8565 */
8566 if ((p_hkmap || p_fkmap) && p_altkeymap)
8567 {
8568 p_altkeymap = p_fkmap;
8569# ifdef FEAT_ARABIC
8570 curwin->w_p_arab = FALSE;
8571# endif
8572 (void)init_chartab();
8573 }
8574
8575 /*
8576 * If hkmap set, reset Farsi keymapping.
8577 */
8578 if (p_hkmap && p_altkeymap)
8579 {
8580 p_altkeymap = 0;
8581 p_fkmap = 0;
8582# ifdef FEAT_ARABIC
8583 curwin->w_p_arab = FALSE;
8584# endif
8585 (void)init_chartab();
8586 }
8587
8588 /*
8589 * If fkmap set, reset Hebrew keymapping.
8590 */
8591 if (p_fkmap && !p_altkeymap)
8592 {
8593 p_altkeymap = 1;
8594 p_hkmap = 0;
8595# ifdef FEAT_ARABIC
8596 curwin->w_p_arab = FALSE;
8597# endif
8598 (void)init_chartab();
8599 }
8600#endif
8601
8602#ifdef FEAT_ARABIC
8603 if ((int *)varp == &curwin->w_p_arab)
8604 {
8605 if (curwin->w_p_arab)
8606 {
8607 /*
8608 * 'arabic' is set, handle various sub-settings.
8609 */
8610 if (!p_tbidi)
8611 {
8612 /* set rightleft mode */
8613 if (!curwin->w_p_rl)
8614 {
8615 curwin->w_p_rl = TRUE;
8616 changed_window_setting();
8617 }
8618
8619 /* Enable Arabic shaping (major part of what Arabic requires) */
8620 if (!p_arshape)
8621 {
8622 p_arshape = TRUE;
8623 redraw_later_clear();
8624 }
8625 }
8626
8627 /* Arabic requires a utf-8 encoding, inform the user if its not
8628 * set. */
8629 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008630 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008631 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8632
Bram Moolenaar8820b482017-03-16 17:23:31 +01008633 msg_source(HL_ATTR(HLF_W));
8634 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008635#ifdef FEAT_EVAL
8636 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8637#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008638 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639
8640# ifdef FEAT_MBYTE
8641 /* set 'delcombine' */
8642 p_deco = TRUE;
8643# endif
8644
8645# ifdef FEAT_KEYMAP
8646 /* Force-set the necessary keymap for arabic */
8647 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8648 OPT_LOCAL);
8649# endif
8650# ifdef FEAT_FKMAP
8651 p_altkeymap = 0;
8652 p_hkmap = 0;
8653 p_fkmap = 0;
8654 (void)init_chartab();
8655# endif
8656 }
8657 else
8658 {
8659 /*
8660 * 'arabic' is reset, handle various sub-settings.
8661 */
8662 if (!p_tbidi)
8663 {
8664 /* reset rightleft mode */
8665 if (curwin->w_p_rl)
8666 {
8667 curwin->w_p_rl = FALSE;
8668 changed_window_setting();
8669 }
8670
8671 /* 'arabicshape' isn't reset, it is a global option and
8672 * another window may still need it "on". */
8673 }
8674
8675 /* 'delcombine' isn't reset, it is a global option and another
8676 * window may still want it "on". */
8677
8678# ifdef FEAT_KEYMAP
8679 /* Revert to the default keymap */
8680 curbuf->b_p_iminsert = B_IMODE_NONE;
8681 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8682# endif
8683 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008684 }
8685
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008686#endif
8687
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008688#ifdef FEAT_TERMGUICOLORS
8689 /* 'termguicolors' */
8690 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008691 {
8692# ifdef FEAT_GUI
8693 if (!gui.in_use && !gui.starting)
8694# endif
8695 highlight_gui_started();
8696 }
8697#endif
8698
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699 /*
8700 * End of handling side effects for bool options.
8701 */
8702
Bram Moolenaar53744302015-07-17 17:38:22 +02008703 /* after handling side effects, call autocommand */
8704
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 options[opt_idx].flags |= P_WAS_SET;
8706
Bram Moolenaar53744302015-07-17 17:38:22 +02008707#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8708 if (!starting)
8709 {
8710 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008711 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8712 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8713 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008714 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8715 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8716 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8717 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8718 reset_v_option_vars();
8719 }
8720#endif
8721
Bram Moolenaar071d4272004-06-13 20:20:40 +00008722 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008723 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008724 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008725 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726 check_redraw(options[opt_idx].flags);
8727
8728 return NULL;
8729}
8730
8731/*
8732 * Set the value of a number option, and take care of side effects.
8733 * Returns NULL for success, or an error message for an error.
8734 */
8735 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008736set_num_option(
8737 int opt_idx, /* index in options[] table */
8738 char_u *varp, /* pointer to the option variable */
8739 long value, /* new value */
8740 char_u *errbuf, /* buffer for error messages */
8741 size_t errbuflen, /* length of "errbuf" */
8742 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008743 OPT_MODELINE */
8744{
8745 char_u *errmsg = NULL;
8746 long old_value = *(long *)varp;
8747 long old_Rows = Rows; /* remember old Rows */
8748 long old_Columns = Columns; /* remember old Columns */
8749 long *pp = (long *)varp;
8750
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008751 /* Disallow changing some options from secure mode. */
8752 if ((secure
8753#ifdef HAVE_SANDBOX
8754 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008756 ) && (options[opt_idx].flags & P_SECURE))
8757 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008758
8759 *pp = value;
8760#ifdef FEAT_EVAL
8761 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008762 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008764#ifdef FEAT_GUI
8765 need_mouse_correct = TRUE;
8766#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008767
Bram Moolenaar14f24742012-08-08 18:01:05 +02008768 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008769 {
8770 errmsg = e_positive;
8771 curbuf->b_p_sw = curbuf->b_p_ts;
8772 }
8773
8774 /*
8775 * Number options that need some action when changed
8776 */
8777#ifdef FEAT_WINDOWS
8778 if (pp == &p_wh || pp == &p_hh)
8779 {
8780 if (p_wh < 1)
8781 {
8782 errmsg = e_positive;
8783 p_wh = 1;
8784 }
8785 if (p_wmh > p_wh)
8786 {
8787 errmsg = e_winheight;
8788 p_wh = p_wmh;
8789 }
8790 if (p_hh < 0)
8791 {
8792 errmsg = e_positive;
8793 p_hh = 0;
8794 }
8795
8796 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008797 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798 {
8799 if (pp == &p_wh && curwin->w_height < p_wh)
8800 win_setheight((int)p_wh);
8801 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8802 win_setheight((int)p_hh);
8803 }
8804 }
8805
8806 /* 'winminheight' */
8807 else if (pp == &p_wmh)
8808 {
8809 if (p_wmh < 0)
8810 {
8811 errmsg = e_positive;
8812 p_wmh = 0;
8813 }
8814 if (p_wmh > p_wh)
8815 {
8816 errmsg = e_winheight;
8817 p_wmh = p_wh;
8818 }
8819 win_setminheight();
8820 }
8821
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008822# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008823 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008824 {
8825 if (p_wiw < 1)
8826 {
8827 errmsg = e_positive;
8828 p_wiw = 1;
8829 }
8830 if (p_wmw > p_wiw)
8831 {
8832 errmsg = e_winwidth;
8833 p_wiw = p_wmw;
8834 }
8835
8836 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008837 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 win_setwidth((int)p_wiw);
8839 }
8840
8841 /* 'winminwidth' */
8842 else if (pp == &p_wmw)
8843 {
8844 if (p_wmw < 0)
8845 {
8846 errmsg = e_positive;
8847 p_wmw = 0;
8848 }
8849 if (p_wmw > p_wiw)
8850 {
8851 errmsg = e_winwidth;
8852 p_wmw = p_wiw;
8853 }
8854 win_setminheight();
8855 }
8856# endif
8857
8858#endif
8859
8860#ifdef FEAT_WINDOWS
8861 /* (re)set last window status line */
8862 else if (pp == &p_ls)
8863 {
8864 last_status(FALSE);
8865 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008866
8867 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008868 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008869 {
8870 shell_new_rows(); /* recompute window positions and heights */
8871 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872#endif
8873
8874#ifdef FEAT_GUI
8875 else if (pp == &p_linespace)
8876 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008877 /* Recompute gui.char_height and resize the Vim window to keep the
8878 * same number of lines. */
8879 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008880 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 }
8882#endif
8883
8884#ifdef FEAT_FOLDING
8885 /* 'foldlevel' */
8886 else if (pp == &curwin->w_p_fdl)
8887 {
8888 if (curwin->w_p_fdl < 0)
8889 curwin->w_p_fdl = 0;
8890 newFoldLevel();
8891 }
8892
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008893 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008894 else if (pp == &curwin->w_p_fml)
8895 {
8896 foldUpdateAll(curwin);
8897 }
8898
8899 /* 'foldnestmax' */
8900 else if (pp == &curwin->w_p_fdn)
8901 {
8902 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8903 foldUpdateAll(curwin);
8904 }
8905
8906 /* 'foldcolumn' */
8907 else if (pp == &curwin->w_p_fdc)
8908 {
8909 if (curwin->w_p_fdc < 0)
8910 {
8911 errmsg = e_positive;
8912 curwin->w_p_fdc = 0;
8913 }
8914 else if (curwin->w_p_fdc > 12)
8915 {
8916 errmsg = e_invarg;
8917 curwin->w_p_fdc = 12;
8918 }
8919 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008920#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008922#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 /* 'shiftwidth' or 'tabstop' */
8924 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8925 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008926# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008927 if (foldmethodIsIndent(curwin))
8928 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008929# endif
8930# ifdef FEAT_CINDENT
8931 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8932 * parse 'cinoptions'. */
8933 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8934 parse_cino(curbuf);
8935# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008937#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008938
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008939#ifdef FEAT_MBYTE
8940 /* 'maxcombine' */
8941 else if (pp == &p_mco)
8942 {
8943 if (p_mco > MAX_MCO)
8944 p_mco = MAX_MCO;
8945 else if (p_mco < 0)
8946 p_mco = 0;
8947 screenclear(); /* will re-allocate the screen */
8948 }
8949#endif
8950
Bram Moolenaar071d4272004-06-13 20:20:40 +00008951 else if (pp == &curbuf->b_p_iminsert)
8952 {
8953 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8954 {
8955 errmsg = e_invarg;
8956 curbuf->b_p_iminsert = B_IMODE_NONE;
8957 }
8958 p_iminsert = curbuf->b_p_iminsert;
8959 if (termcap_active) /* don't do this in the alternate screen */
8960 showmode();
8961#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8962 /* Show/unshow value of 'keymap' in status lines. */
8963 status_redraw_curbuf();
8964#endif
8965 }
8966
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008967 else if (pp == &p_window)
8968 {
8969 if (p_window < 1)
8970 p_window = 1;
8971 else if (p_window >= Rows)
8972 p_window = Rows - 1;
8973 }
8974
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975 else if (pp == &curbuf->b_p_imsearch)
8976 {
8977 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8978 {
8979 errmsg = e_invarg;
8980 curbuf->b_p_imsearch = B_IMODE_NONE;
8981 }
8982 p_imsearch = curbuf->b_p_imsearch;
8983 }
8984
8985#ifdef FEAT_TITLE
8986 /* if 'titlelen' has changed, redraw the title */
8987 else if (pp == &p_titlelen)
8988 {
8989 if (p_titlelen < 0)
8990 {
8991 errmsg = e_positive;
8992 p_titlelen = 85;
8993 }
8994 if (starting != NO_SCREEN && old_value != p_titlelen)
8995 need_maketitle = TRUE;
8996 }
8997#endif
8998
8999 /* if p_ch changed value, change the command line height */
9000 else if (pp == &p_ch)
9001 {
9002 if (p_ch < 1)
9003 {
9004 errmsg = e_positive;
9005 p_ch = 1;
9006 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009007 if (p_ch > Rows - min_rows() + 1)
9008 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009
9010 /* Only compute the new window layout when startup has been
9011 * completed. Otherwise the frame sizes may be wrong. */
9012 if (p_ch != old_value && full_screen
9013#ifdef FEAT_GUI
9014 && !gui.starting
9015#endif
9016 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009017 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009018 }
9019
9020 /* when 'updatecount' changes from zero to non-zero, open swap files */
9021 else if (pp == &p_uc)
9022 {
9023 if (p_uc < 0)
9024 {
9025 errmsg = e_positive;
9026 p_uc = 100;
9027 }
9028 if (p_uc && !old_value)
9029 ml_open_files();
9030 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009031#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009032 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009033 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009034 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009035 {
9036 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009037 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009038 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009039 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009040 {
9041 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009042 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009043 }
9044 }
9045#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009046#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009047 else if (pp == &p_mzq)
9048 mzvim_reset_timer();
9049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009051#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9052 /* 'pyxversion' */
9053 else if (pp == &p_pyx)
9054 {
9055 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9056 errmsg = e_invarg;
9057 }
9058#endif
9059
Bram Moolenaar071d4272004-06-13 20:20:40 +00009060 /* sync undo before 'undolevels' changes */
9061 else if (pp == &p_ul)
9062 {
9063 /* use the old value, otherwise u_sync() may not work properly */
9064 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009065 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066 p_ul = value;
9067 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009068 else if (pp == &curbuf->b_p_ul)
9069 {
9070 /* use the old value, otherwise u_sync() may not work properly */
9071 curbuf->b_p_ul = old_value;
9072 u_sync(TRUE);
9073 curbuf->b_p_ul = value;
9074 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009076#ifdef FEAT_LINEBREAK
9077 /* 'numberwidth' must be positive */
9078 else if (pp == &curwin->w_p_nuw)
9079 {
9080 if (curwin->w_p_nuw < 1)
9081 {
9082 errmsg = e_positive;
9083 curwin->w_p_nuw = 1;
9084 }
9085 if (curwin->w_p_nuw > 10)
9086 {
9087 errmsg = e_invarg;
9088 curwin->w_p_nuw = 10;
9089 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009090 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009091 }
9092#endif
9093
Bram Moolenaar1a384422010-07-14 19:53:30 +02009094 else if (pp == &curbuf->b_p_tw)
9095 {
9096 if (curbuf->b_p_tw < 0)
9097 {
9098 errmsg = e_positive;
9099 curbuf->b_p_tw = 0;
9100 }
9101#ifdef FEAT_SYN_HL
9102# ifdef FEAT_WINDOWS
9103 {
9104 win_T *wp;
9105 tabpage_T *tp;
9106
9107 FOR_ALL_TAB_WINDOWS(tp, wp)
9108 check_colorcolumn(wp);
9109 }
9110# else
9111 check_colorcolumn(curwin);
9112# endif
9113#endif
9114 }
9115
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 /*
9117 * Check the bounds for numeric options here
9118 */
9119 if (Rows < min_rows() && full_screen)
9120 {
9121 if (errbuf != NULL)
9122 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009123 vim_snprintf((char *)errbuf, errbuflen,
9124 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009125 errmsg = errbuf;
9126 }
9127 Rows = min_rows();
9128 }
9129 if (Columns < MIN_COLUMNS && full_screen)
9130 {
9131 if (errbuf != NULL)
9132 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009133 vim_snprintf((char *)errbuf, errbuflen,
9134 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009135 errmsg = errbuf;
9136 }
9137 Columns = MIN_COLUMNS;
9138 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009139 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009140
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141 /*
9142 * If the screen (shell) height has been changed, assume it is the
9143 * physical screenheight.
9144 */
9145 if (old_Rows != Rows || old_Columns != Columns)
9146 {
9147 /* Changing the screen size is not allowed while updating the screen. */
9148 if (updating_screen)
9149 *pp = old_value;
9150 else if (full_screen
9151#ifdef FEAT_GUI
9152 && !gui.starting
9153#endif
9154 )
9155 set_shellsize((int)Columns, (int)Rows, TRUE);
9156 else
9157 {
9158 /* Postpone the resizing; check the size and cmdline position for
9159 * messages. */
9160 check_shellsize();
9161 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9162 cmdline_row = Rows - p_ch;
9163 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009164 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009165 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009166 }
9167
Bram Moolenaar071d4272004-06-13 20:20:40 +00009168 if (curbuf->b_p_ts <= 0)
9169 {
9170 errmsg = e_positive;
9171 curbuf->b_p_ts = 8;
9172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009173 if (p_tm < 0)
9174 {
9175 errmsg = e_positive;
9176 p_tm = 0;
9177 }
9178 if ((curwin->w_p_scr <= 0
9179 || (curwin->w_p_scr > curwin->w_height
9180 && curwin->w_height > 0))
9181 && full_screen)
9182 {
9183 if (pp == &(curwin->w_p_scr))
9184 {
9185 if (curwin->w_p_scr != 0)
9186 errmsg = e_scroll;
9187 win_comp_scroll(curwin);
9188 }
9189 /* If 'scroll' became invalid because of a side effect silently adjust
9190 * it. */
9191 else if (curwin->w_p_scr <= 0)
9192 curwin->w_p_scr = 1;
9193 else /* curwin->w_p_scr > curwin->w_height */
9194 curwin->w_p_scr = curwin->w_height;
9195 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009196 if (p_hi < 0)
9197 {
9198 errmsg = e_positive;
9199 p_hi = 0;
9200 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009201 else if (p_hi > 10000)
9202 {
9203 errmsg = e_invarg;
9204 p_hi = 10000;
9205 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009206 if (p_re < 0 || p_re > 2)
9207 {
9208 errmsg = e_invarg;
9209 p_re = 0;
9210 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009211 if (p_report < 0)
9212 {
9213 errmsg = e_positive;
9214 p_report = 1;
9215 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009216 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217 {
9218 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9219 p_sj = Rows / 2;
9220 else
9221 {
9222 errmsg = e_scroll;
9223 p_sj = 1;
9224 }
9225 }
9226 if (p_so < 0 && full_screen)
9227 {
9228 errmsg = e_scroll;
9229 p_so = 0;
9230 }
9231 if (p_siso < 0 && full_screen)
9232 {
9233 errmsg = e_positive;
9234 p_siso = 0;
9235 }
9236#ifdef FEAT_CMDWIN
9237 if (p_cwh < 1)
9238 {
9239 errmsg = e_positive;
9240 p_cwh = 1;
9241 }
9242#endif
9243 if (p_ut < 0)
9244 {
9245 errmsg = e_positive;
9246 p_ut = 2000;
9247 }
9248 if (p_ss < 0)
9249 {
9250 errmsg = e_positive;
9251 p_ss = 0;
9252 }
9253
9254 /* May set global value for local option. */
9255 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9256 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9257
9258 options[opt_idx].flags |= P_WAS_SET;
9259
Bram Moolenaar53744302015-07-17 17:38:22 +02009260#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9261 if (!starting && errmsg == NULL)
9262 {
9263 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009264 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9265 vim_snprintf((char *)buf_new, 10, "%ld", value);
9266 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009267 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9268 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9269 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9270 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9271 reset_v_option_vars();
9272 }
9273#endif
9274
Bram Moolenaar071d4272004-06-13 20:20:40 +00009275 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009276 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009277 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009278 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279 check_redraw(options[opt_idx].flags);
9280
9281 return errmsg;
9282}
9283
9284/*
9285 * Called after an option changed: check if something needs to be redrawn.
9286 */
9287 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009288check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009289{
9290 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009291 int doclear = (flags & P_RCLR) == P_RCLR;
9292 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009293
9294#ifdef FEAT_WINDOWS
9295 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9296 status_redraw_all();
9297#endif
9298
9299 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9300 changed_window_setting();
9301 if (flags & P_RBUF)
9302 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009303 if (flags & P_RWINONLY)
9304 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009305 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306 redraw_all_later(CLEAR);
9307 else if (all)
9308 redraw_all_later(NOT_VALID);
9309}
9310
9311/*
9312 * Find index for option 'arg'.
9313 * Return -1 if not found.
9314 */
9315 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009316findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009317{
9318 int opt_idx;
9319 char *s, *p;
9320 static short quick_tab[27] = {0, 0}; /* quick access table */
9321 int is_term_opt;
9322
9323 /*
9324 * For first call: Initialize the quick-access table.
9325 * It contains the index for the first option that starts with a certain
9326 * letter. There are 26 letters, plus the first "t_" option.
9327 */
9328 if (quick_tab[1] == 0)
9329 {
9330 p = options[0].fullname;
9331 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9332 {
9333 if (s[0] != p[0])
9334 {
9335 if (s[0] == 't' && s[1] == '_')
9336 quick_tab[26] = opt_idx;
9337 else
9338 quick_tab[CharOrdLow(s[0])] = opt_idx;
9339 }
9340 p = s;
9341 }
9342 }
9343
9344 /*
9345 * Check for name starting with an illegal character.
9346 */
9347#ifdef EBCDIC
9348 if (!islower(arg[0]))
9349#else
9350 if (arg[0] < 'a' || arg[0] > 'z')
9351#endif
9352 return -1;
9353
9354 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9355 if (is_term_opt)
9356 opt_idx = quick_tab[26];
9357 else
9358 opt_idx = quick_tab[CharOrdLow(arg[0])];
9359 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9360 {
9361 if (STRCMP(arg, s) == 0) /* match full name */
9362 break;
9363 }
9364 if (s == NULL && !is_term_opt)
9365 {
9366 opt_idx = quick_tab[CharOrdLow(arg[0])];
9367 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9368 {
9369 s = options[opt_idx].shortname;
9370 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9371 break;
9372 s = NULL;
9373 }
9374 }
9375 if (s == NULL)
9376 opt_idx = -1;
9377 return opt_idx;
9378}
9379
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009380#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009381/*
9382 * Get the value for an option.
9383 *
9384 * Returns:
9385 * Number or Toggle option: 1, *numval gets value.
9386 * String option: 0, *stringval gets allocated string.
9387 * Hidden Number or Toggle option: -1.
9388 * hidden String option: -2.
9389 * unknown option: -3.
9390 */
9391 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009392get_option_value(
9393 char_u *name,
9394 long *numval,
9395 char_u **stringval, /* NULL when only checking existence */
9396 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009397{
9398 int opt_idx;
9399 char_u *varp;
9400
9401 opt_idx = findoption(name);
9402 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009403 {
9404 int key;
9405
9406 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9407 && (key = find_key_option(name)) != 0)
9408 {
9409 char_u key_name[2];
9410 char_u *p;
9411
9412 if (key < 0)
9413 {
9414 key_name[0] = KEY2TERMCAP0(key);
9415 key_name[1] = KEY2TERMCAP1(key);
9416 }
9417 else
9418 {
9419 key_name[0] = KS_KEY;
9420 key_name[1] = (key & 0xff);
9421 }
9422 p = find_termcode(key_name);
9423 if (p != NULL)
9424 {
9425 if (stringval != NULL)
9426 *stringval = vim_strsave(p);
9427 return 0;
9428 }
9429 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009430 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009431 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432
9433 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9434
9435 if (options[opt_idx].flags & P_STRING)
9436 {
9437 if (varp == NULL) /* hidden option */
9438 return -2;
9439 if (stringval != NULL)
9440 {
9441#ifdef FEAT_CRYPT
9442 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009443 if ((char_u **)varp == &curbuf->b_p_key
9444 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009445 *stringval = vim_strsave((char_u *)"*****");
9446 else
9447#endif
9448 *stringval = vim_strsave(*(char_u **)(varp));
9449 }
9450 return 0;
9451 }
9452
9453 if (varp == NULL) /* hidden option */
9454 return -1;
9455 if (options[opt_idx].flags & P_NUM)
9456 *numval = *(long *)varp;
9457 else
9458 {
9459 /* Special case: 'modified' is b_changed, but we also want to consider
9460 * it set when 'ff' or 'fenc' changed. */
9461 if ((int *)varp == &curbuf->b_changed)
9462 *numval = curbufIsChanged();
9463 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009464 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009465 }
9466 return 1;
9467}
9468#endif
9469
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009470#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009471/*
9472 * Returns the option attributes and its value. Unlike the above function it
9473 * will return either global value or local value of the option depending on
9474 * what was requested, but it will never return global value if it was
9475 * requested to return local one and vice versa. Neither it will return
9476 * buffer-local value if it was requested to return window-local one.
9477 *
9478 * Pretends that option is absent if it is not present in the requested scope
9479 * (i.e. has no global, window-local or buffer-local value depending on
9480 * opt_type). Uses
9481 *
9482 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009483 * 0 hidden or unknown option, also option that does not have requested
9484 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009485 * see SOPT_* in vim.h for other flags
9486 *
9487 * Possible opt_type values: see SREQ_* in vim.h
9488 */
9489 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009490get_option_value_strict(
9491 char_u *name,
9492 long *numval,
9493 char_u **stringval, /* NULL when only obtaining attributes */
9494 int opt_type,
9495 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009496{
9497 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009498 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009499 struct vimoption *p;
9500 int r = 0;
9501
9502 opt_idx = findoption(name);
9503 if (opt_idx < 0)
9504 return 0;
9505
9506 p = &(options[opt_idx]);
9507
9508 /* Hidden option */
9509 if (p->var == NULL)
9510 return 0;
9511
9512 if (p->flags & P_BOOL)
9513 r |= SOPT_BOOL;
9514 else if (p->flags & P_NUM)
9515 r |= SOPT_NUM;
9516 else if (p->flags & P_STRING)
9517 r |= SOPT_STRING;
9518
9519 if (p->indir == PV_NONE)
9520 {
9521 if (opt_type == SREQ_GLOBAL)
9522 r |= SOPT_GLOBAL;
9523 else
9524 return 0; /* Did not request global-only option */
9525 }
9526 else
9527 {
9528 if (p->indir & PV_BOTH)
9529 r |= SOPT_GLOBAL;
9530 else if (opt_type == SREQ_GLOBAL)
9531 return 0; /* Requested global option */
9532
9533 if (p->indir & PV_WIN)
9534 {
9535 if (opt_type == SREQ_BUF)
9536 return 0; /* Did not request window-local option */
9537 else
9538 r |= SOPT_WIN;
9539 }
9540 else if (p->indir & PV_BUF)
9541 {
9542 if (opt_type == SREQ_WIN)
9543 return 0; /* Did not request buffer-local option */
9544 else
9545 r |= SOPT_BUF;
9546 }
9547 }
9548
9549 if (stringval == NULL)
9550 return r;
9551
9552 if (opt_type == SREQ_GLOBAL)
9553 varp = p->var;
9554 else
9555 {
9556 if (opt_type == SREQ_BUF)
9557 {
9558 /* Special case: 'modified' is b_changed, but we also want to
9559 * consider it set when 'ff' or 'fenc' changed. */
9560 if (p->indir == PV_MOD)
9561 {
9562 *numval = bufIsChanged((buf_T *) from);
9563 varp = NULL;
9564 }
9565#ifdef FEAT_CRYPT
9566 else if (p->indir == PV_KEY)
9567 {
9568 /* never return the value of the crypt key */
9569 *stringval = NULL;
9570 varp = NULL;
9571 }
9572#endif
9573 else
9574 {
9575 aco_save_T aco;
9576 aucmd_prepbuf(&aco, (buf_T *) from);
9577 varp = get_varp(p);
9578 aucmd_restbuf(&aco);
9579 }
9580 }
9581 else if (opt_type == SREQ_WIN)
9582 {
9583 win_T *save_curwin;
9584 save_curwin = curwin;
9585 curwin = (win_T *) from;
9586 curbuf = curwin->w_buffer;
9587 varp = get_varp(p);
9588 curwin = save_curwin;
9589 curbuf = curwin->w_buffer;
9590 }
9591 if (varp == p->var)
9592 return (r | SOPT_UNSET);
9593 }
9594
9595 if (varp != NULL)
9596 {
9597 if (p->flags & P_STRING)
9598 *stringval = vim_strsave(*(char_u **)(varp));
9599 else if (p->flags & P_NUM)
9600 *numval = *(long *) varp;
9601 else
9602 *numval = *(int *)varp;
9603 }
9604
9605 return r;
9606}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009607
9608/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009609 * Iterate over options. First argument is a pointer to a pointer to a
9610 * structure inside options[] array, second is option type like in the above
9611 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009612 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009613 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009614 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009615 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009616 * first argument to NULL.
9617 *
9618 * Returns full option name for current option on each call.
9619 */
9620 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009621option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009622{
9623 struct vimoption *ret = NULL;
9624 do
9625 {
9626 if (*option == NULL)
9627 *option = (void *) options;
9628 else if (((struct vimoption *) (*option))->fullname == NULL)
9629 {
9630 *option = NULL;
9631 return NULL;
9632 }
9633 else
9634 *option = (void *) (((struct vimoption *) (*option)) + 1);
9635
9636 ret = ((struct vimoption *) (*option));
9637
9638 /* Hidden option */
9639 if (ret->var == NULL)
9640 {
9641 ret = NULL;
9642 continue;
9643 }
9644
9645 switch (opt_type)
9646 {
9647 case SREQ_GLOBAL:
9648 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9649 ret = NULL;
9650 break;
9651 case SREQ_BUF:
9652 if (!(ret->indir & PV_BUF))
9653 ret = NULL;
9654 break;
9655 case SREQ_WIN:
9656 if (!(ret->indir & PV_WIN))
9657 ret = NULL;
9658 break;
9659 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009660 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009661 return NULL;
9662 }
9663 }
9664 while (ret == NULL);
9665
9666 return (char_u *)ret->fullname;
9667}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009668#endif
9669
Bram Moolenaar071d4272004-06-13 20:20:40 +00009670/*
9671 * Set the value of option "name".
9672 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009673 *
9674 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009675 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009676 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009677set_option_value(
9678 char_u *name,
9679 long number,
9680 char_u *string,
9681 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009682{
9683 int opt_idx;
9684 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009685 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009686
9687 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009688 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009689 {
9690 int key;
9691
9692 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9693 && (key = find_key_option(name)) != 0)
9694 {
9695 char_u key_name[2];
9696
9697 if (key < 0)
9698 {
9699 key_name[0] = KEY2TERMCAP0(key);
9700 key_name[1] = KEY2TERMCAP1(key);
9701 }
9702 else
9703 {
9704 key_name[0] = KS_KEY;
9705 key_name[1] = (key & 0xff);
9706 }
9707 add_termcode(key_name, string, FALSE);
9708 if (full_screen)
9709 ttest(FALSE);
9710 redraw_all_later(CLEAR);
9711 return NULL;
9712 }
9713
Bram Moolenaar071d4272004-06-13 20:20:40 +00009714 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009715 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716 else
9717 {
9718 flags = options[opt_idx].flags;
9719#ifdef HAVE_SANDBOX
9720 /* Disallow changing some options in the sandbox */
9721 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009722 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009724 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009725 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009727 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009728 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009729 else
9730 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009731 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009732 if (varp != NULL) /* hidden option is not changed */
9733 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009734 if (number == 0 && string != NULL)
9735 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009736 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009737
9738 /* Either we are given a string or we are setting option
9739 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009740 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009741 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009742 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009743 {
9744 /* There's another character after zeros or the string
9745 * is empty. In both cases, we are trying to set a
9746 * num option using a string. */
9747 EMSG3(_("E521: Number required: &%s = '%s'"),
9748 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009749 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009750
9751 }
9752 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009753 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009754 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009755 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009757 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009758 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759 }
9760 }
9761 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009762 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009763}
9764
9765/*
9766 * Get the terminal code for a terminal option.
9767 * Returns NULL when not found.
9768 */
9769 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009770get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009771{
9772 int opt_idx;
9773 char_u *varp;
9774
9775 if (tname[0] != 't' || tname[1] != '_' ||
9776 tname[2] == NUL || tname[3] == NUL)
9777 return NULL;
9778 if ((opt_idx = findoption(tname)) >= 0)
9779 {
9780 varp = get_varp(&(options[opt_idx]));
9781 if (varp != NULL)
9782 varp = *(char_u **)(varp);
9783 return varp;
9784 }
9785 return find_termcode(tname + 2);
9786}
9787
9788 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009789get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790{
9791 int i;
9792
9793 i = findoption((char_u *)"hl");
9794 if (i >= 0)
9795 return options[i].def_val[VI_DEFAULT];
9796 return (char_u *)NULL;
9797}
9798
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009799#if defined(FEAT_MBYTE) || defined(PROTO)
9800 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009801get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009802{
9803 int i;
9804
9805 i = findoption((char_u *)"enc");
9806 if (i >= 0)
9807 return options[i].def_val[VI_DEFAULT];
9808 return (char_u *)NULL;
9809}
9810#endif
9811
Bram Moolenaar071d4272004-06-13 20:20:40 +00009812/*
9813 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9814 */
9815 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009816find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009817{
9818 int key;
9819 int modifiers;
9820
9821 /*
9822 * Don't use get_special_key_code() for t_xx, we don't want it to call
9823 * add_termcap_entry().
9824 */
9825 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9826 key = TERMCAP2KEY(arg[2], arg[3]);
9827 else
9828 {
9829 --arg; /* put arg at the '<' */
9830 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009831 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832 if (modifiers) /* can't handle modifiers here */
9833 key = 0;
9834 }
9835 return key;
9836}
9837
9838/*
9839 * if 'all' == 0: show changed options
9840 * if 'all' == 1: show all normal options
9841 * if 'all' == 2: show all terminal options
9842 */
9843 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009844showoptions(
9845 int all,
9846 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009847{
9848 struct vimoption *p;
9849 int col;
9850 int isterm;
9851 char_u *varp;
9852 struct vimoption **items;
9853 int item_count;
9854 int run;
9855 int row, rows;
9856 int cols;
9857 int i;
9858 int len;
9859
9860#define INC 20
9861#define GAP 3
9862
9863 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9864 PARAM_COUNT));
9865 if (items == NULL)
9866 return;
9867
9868 /* Highlight title */
9869 if (all == 2)
9870 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9871 else if (opt_flags & OPT_GLOBAL)
9872 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9873 else if (opt_flags & OPT_LOCAL)
9874 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9875 else
9876 MSG_PUTS_TITLE(_("\n--- Options ---"));
9877
9878 /*
9879 * do the loop two times:
9880 * 1. display the short items
9881 * 2. display the long items (only strings and numbers)
9882 */
9883 for (run = 1; run <= 2 && !got_int; ++run)
9884 {
9885 /*
9886 * collect the items in items[]
9887 */
9888 item_count = 0;
9889 for (p = &options[0]; p->fullname != NULL; p++)
9890 {
9891 varp = NULL;
9892 isterm = istermoption(p);
9893 if (opt_flags != 0)
9894 {
9895 if (p->indir != PV_NONE && !isterm)
9896 varp = get_varp_scope(p, opt_flags);
9897 }
9898 else
9899 varp = get_varp(p);
9900 if (varp != NULL
9901 && ((all == 2 && isterm)
9902 || (all == 1 && !isterm)
9903 || (all == 0 && !optval_default(p, varp))))
9904 {
9905 if (p->flags & P_BOOL)
9906 len = 1; /* a toggle option fits always */
9907 else
9908 {
9909 option_value2string(p, opt_flags);
9910 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9911 }
9912 if ((len <= INC - GAP && run == 1) ||
9913 (len > INC - GAP && run == 2))
9914 items[item_count++] = p;
9915 }
9916 }
9917
9918 /*
9919 * display the items
9920 */
9921 if (run == 1)
9922 {
9923 cols = (Columns + GAP - 3) / INC;
9924 if (cols == 0)
9925 cols = 1;
9926 rows = (item_count + cols - 1) / cols;
9927 }
9928 else /* run == 2 */
9929 rows = item_count;
9930 for (row = 0; row < rows && !got_int; ++row)
9931 {
9932 msg_putchar('\n'); /* go to next line */
9933 if (got_int) /* 'q' typed in more */
9934 break;
9935 col = 0;
9936 for (i = row; i < item_count; i += rows)
9937 {
9938 msg_col = col; /* make columns */
9939 showoneopt(items[i], opt_flags);
9940 col += INC;
9941 }
9942 out_flush();
9943 ui_breakcheck();
9944 }
9945 }
9946 vim_free(items);
9947}
9948
9949/*
9950 * Return TRUE if option "p" has its default value.
9951 */
9952 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009953optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009954{
9955 int dvi;
9956
9957 if (varp == NULL)
9958 return TRUE; /* hidden option is always at default */
9959 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9960 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009961 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009963 /* the cast to long is required for Manx C, long_i is
9964 * needed for MSVC */
9965 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966 /* P_STRING */
9967 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9968}
9969
9970/*
9971 * showoneopt: show the value of one option
9972 * must not be called with a hidden option!
9973 */
9974 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009975showoneopt(
9976 struct vimoption *p,
9977 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009979 char_u *varp;
9980 int save_silent = silent_mode;
9981
9982 silent_mode = FALSE;
9983 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984
9985 varp = get_varp_scope(p, opt_flags);
9986
9987 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9988 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9989 ? !curbufIsChanged() : !*(int *)varp))
9990 MSG_PUTS("no");
9991 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9992 MSG_PUTS("--");
9993 else
9994 MSG_PUTS(" ");
9995 MSG_PUTS(p->fullname);
9996 if (!(p->flags & P_BOOL))
9997 {
9998 msg_putchar('=');
9999 /* put value string in NameBuff */
10000 option_value2string(p, opt_flags);
10001 msg_outtrans(NameBuff);
10002 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010003
10004 silent_mode = save_silent;
10005 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006}
10007
10008/*
10009 * Write modified options as ":set" commands to a file.
10010 *
10011 * There are three values for "opt_flags":
10012 * OPT_GLOBAL: Write global option values and fresh values of
10013 * buffer-local options (used for start of a session
10014 * file).
10015 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10016 * curwin (used for a vimrc file).
10017 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10018 * and local values for window-local options of
10019 * curwin. Local values are also written when at the
10020 * default value, because a modeline or autocommand
10021 * may have set them when doing ":edit file" and the
10022 * user has set them back at the default or fresh
10023 * value.
10024 * When "local_only" is TRUE, don't write fresh
10025 * values, only local values (for ":mkview").
10026 * (fresh value = value used for a new buffer or window for a local option).
10027 *
10028 * Return FAIL on error, OK otherwise.
10029 */
10030 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010031makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032{
10033 struct vimoption *p;
10034 char_u *varp; /* currently used value */
10035 char_u *varp_fresh; /* local value */
10036 char_u *varp_local = NULL; /* fresh value */
10037 char *cmd;
10038 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010039 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040
10041 /*
10042 * The options that don't have a default (terminal name, columns, lines)
10043 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010044 * Do the loop over "options[]" twice: once for options with the
10045 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010047 for (pri = 1; pri >= 0; --pri)
10048 {
10049 for (p = &options[0]; !istermoption(p); p++)
10050 if (!(p->flags & P_NO_MKRC)
10051 && !istermoption(p)
10052 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010053 {
10054 /* skip global option when only doing locals */
10055 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10056 continue;
10057
10058 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10059 * file, they are always buffer-specific. */
10060 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10061 continue;
10062
10063 /* Global values are only written when not at the default value. */
10064 varp = get_varp_scope(p, opt_flags);
10065 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10066 continue;
10067
10068 round = 2;
10069 if (p->indir != PV_NONE)
10070 {
10071 if (p->var == VAR_WIN)
10072 {
10073 /* skip window-local option when only doing globals */
10074 if (!(opt_flags & OPT_LOCAL))
10075 continue;
10076 /* When fresh value of window-local option is not at the
10077 * default, need to write it too. */
10078 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10079 {
10080 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10081 if (!optval_default(p, varp_fresh))
10082 {
10083 round = 1;
10084 varp_local = varp;
10085 varp = varp_fresh;
10086 }
10087 }
10088 }
10089 }
10090
10091 /* Round 1: fresh value for window-local options.
10092 * Round 2: other values */
10093 for ( ; round <= 2; varp = varp_local, ++round)
10094 {
10095 if (round == 1 || (opt_flags & OPT_GLOBAL))
10096 cmd = "set";
10097 else
10098 cmd = "setlocal";
10099
10100 if (p->flags & P_BOOL)
10101 {
10102 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10103 return FAIL;
10104 }
10105 else if (p->flags & P_NUM)
10106 {
10107 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10108 return FAIL;
10109 }
10110 else /* P_STRING */
10111 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010112#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10113 int do_endif = FALSE;
10114
Bram Moolenaar071d4272004-06-13 20:20:40 +000010115 /* Don't set 'syntax' and 'filetype' again if the value is
10116 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010117 if (
10118# if defined(FEAT_SYN_HL)
10119 p->indir == PV_SYN
10120# if defined(FEAT_AUTOCMD)
10121 ||
10122# endif
10123# endif
10124# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010125 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010126# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010127 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128 {
10129 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10130 *(char_u **)(varp)) < 0
10131 || put_eol(fd) < 0)
10132 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010133 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010134 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010135#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010136 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10137 (p->flags & P_EXPAND) != 0) == FAIL)
10138 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010139#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10140 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141 {
10142 if (put_line(fd, "endif") == FAIL)
10143 return FAIL;
10144 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010145#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146 }
10147 }
10148 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010150 return OK;
10151}
10152
10153#if defined(FEAT_FOLDING) || defined(PROTO)
10154/*
10155 * Generate set commands for the local fold options only. Used when
10156 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10157 */
10158 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010159makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160{
10161 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10162# ifdef FEAT_EVAL
10163 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10164 == FAIL
10165# endif
10166 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10167 == FAIL
10168 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10169 == FAIL
10170 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10171 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10172 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10173 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10174 )
10175 return FAIL;
10176
10177 return OK;
10178}
10179#endif
10180
10181 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010182put_setstring(
10183 FILE *fd,
10184 char *cmd,
10185 char *name,
10186 char_u **valuep,
10187 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188{
10189 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010190 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191
10192 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10193 return FAIL;
10194 if (*valuep != NULL)
10195 {
10196 /* Output 'pastetoggle' as key names. For other
10197 * options some characters have to be escaped with
10198 * CTRL-V or backslash */
10199 if (valuep == &p_pt)
10200 {
10201 s = *valuep;
10202 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010203 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204 return FAIL;
10205 }
10206 else if (expand)
10207 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010208 buf = alloc(MAXPATHL);
10209 if (buf == NULL)
10210 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10212 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010213 {
10214 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010216 }
10217 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 }
10219 else if (put_escstr(fd, *valuep, 2) == FAIL)
10220 return FAIL;
10221 }
10222 if (put_eol(fd) < 0)
10223 return FAIL;
10224 return OK;
10225}
10226
10227 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010228put_setnum(
10229 FILE *fd,
10230 char *cmd,
10231 char *name,
10232 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233{
10234 long wc;
10235
10236 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10237 return FAIL;
10238 if (wc_use_keyname((char_u *)valuep, &wc))
10239 {
10240 /* print 'wildchar' and 'wildcharm' as a key name */
10241 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10242 return FAIL;
10243 }
10244 else if (fprintf(fd, "%ld", *valuep) < 0)
10245 return FAIL;
10246 if (put_eol(fd) < 0)
10247 return FAIL;
10248 return OK;
10249}
10250
10251 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010252put_setbool(
10253 FILE *fd,
10254 char *cmd,
10255 char *name,
10256 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257{
Bram Moolenaar893de922007-10-02 18:40:57 +000010258 if (value < 0) /* global/local option using global value */
10259 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10261 || put_eol(fd) < 0)
10262 return FAIL;
10263 return OK;
10264}
10265
10266/*
10267 * Clear all the terminal options.
10268 * If the option has been allocated, free the memory.
10269 * Terminal options are never hidden or indirect.
10270 */
10271 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010272clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274 /*
10275 * Reset a few things before clearing the old options. This may cause
10276 * outputting a few things that the terminal doesn't understand, but the
10277 * screen will be cleared later, so this is OK.
10278 */
10279#ifdef FEAT_MOUSE_TTY
10280 mch_setmouse(FALSE); /* switch mouse off */
10281#endif
10282#ifdef FEAT_TITLE
10283 mch_restore_title(3); /* restore window titles */
10284#endif
10285#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10286 /* When starting the GUI close the display opened for the clipboard.
10287 * After restoring the title, because that will need the display. */
10288 if (gui.starting)
10289 clear_xterm_clip();
10290#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010291 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010293 free_termoptions();
10294}
10295
10296 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010297free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010298{
10299 struct vimoption *p;
10300
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301 for (p = &options[0]; p->fullname != NULL; p++)
10302 if (istermoption(p))
10303 {
10304 if (p->flags & P_ALLOCED)
10305 free_string_option(*(char_u **)(p->var));
10306 if (p->flags & P_DEF_ALLOCED)
10307 free_string_option(p->def_val[VI_DEFAULT]);
10308 *(char_u **)(p->var) = empty_option;
10309 p->def_val[VI_DEFAULT] = empty_option;
10310 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10311 }
10312 clear_termcodes();
10313}
10314
10315/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010316 * Free the string for one term option, if it was allocated.
10317 * Set the string to empty_option and clear allocated flag.
10318 * "var" points to the option value.
10319 */
10320 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010321free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010322{
10323 struct vimoption *p;
10324
10325 for (p = &options[0]; p->fullname != NULL; p++)
10326 if (p->var == var)
10327 {
10328 if (p->flags & P_ALLOCED)
10329 free_string_option(*(char_u **)(p->var));
10330 *(char_u **)(p->var) = empty_option;
10331 p->flags &= ~P_ALLOCED;
10332 break;
10333 }
10334}
10335
10336/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337 * Set the terminal option defaults to the current value.
10338 * Used after setting the terminal name.
10339 */
10340 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010341set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342{
10343 struct vimoption *p;
10344
10345 for (p = &options[0]; p->fullname != NULL; p++)
10346 {
10347 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10348 {
10349 if (p->flags & P_DEF_ALLOCED)
10350 {
10351 free_string_option(p->def_val[VI_DEFAULT]);
10352 p->flags &= ~P_DEF_ALLOCED;
10353 }
10354 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10355 if (p->flags & P_ALLOCED)
10356 {
10357 p->flags |= P_DEF_ALLOCED;
10358 p->flags &= ~P_ALLOCED; /* don't free the value now */
10359 }
10360 }
10361 }
10362}
10363
10364/*
10365 * return TRUE if 'p' starts with 't_'
10366 */
10367 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010368istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369{
10370 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10371}
10372
10373/*
10374 * Compute columns for ruler and shown command. 'sc_col' is also used to
10375 * decide what the maximum length of a message on the status line can be.
10376 * If there is a status line for the last window, 'sc_col' is independent
10377 * of 'ru_col'.
10378 */
10379
10380#define COL_RULER 17 /* columns needed by standard ruler */
10381
10382 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010383comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384{
10385#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010386 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387
10388 sc_col = 0;
10389 ru_col = 0;
10390 if (p_ru)
10391 {
10392#ifdef FEAT_STL_OPT
10393 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10394#else
10395 ru_col = COL_RULER + 1;
10396#endif
10397 /* no last status line, adjust sc_col */
10398 if (!last_has_status)
10399 sc_col = ru_col;
10400 }
10401 if (p_sc)
10402 {
10403 sc_col += SHOWCMD_COLS;
10404 if (!p_ru || last_has_status) /* no need for separating space */
10405 ++sc_col;
10406 }
10407 sc_col = Columns - sc_col;
10408 ru_col = Columns - ru_col;
10409 if (sc_col <= 0) /* screen too narrow, will become a mess */
10410 sc_col = 1;
10411 if (ru_col <= 0)
10412 ru_col = 1;
10413#else
10414 sc_col = Columns;
10415 ru_col = Columns;
10416#endif
10417}
10418
10419/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010420 * Unset local option value, similar to ":set opt<".
10421 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010422 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010423unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010424{
10425 struct vimoption *p;
10426 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010427 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010428
10429 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010430 if (opt_idx < 0)
10431 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010432 p = &(options[opt_idx]);
10433
10434 switch ((int)p->indir)
10435 {
10436 /* global option with local value: use local value if it's been set */
10437 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010438 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010439 break;
10440 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010441 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010442 break;
10443 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010444 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010445 break;
10446 case PV_AR:
10447 buf->b_p_ar = -1;
10448 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010449 case PV_BKC:
10450 clear_string_option(&buf->b_p_bkc);
10451 buf->b_bkc_flags = 0;
10452 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010453 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010454 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010455 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010456 case PV_TC:
10457 clear_string_option(&buf->b_p_tc);
10458 buf->b_tc_flags = 0;
10459 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010460#ifdef FEAT_FIND_ID
10461 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010462 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010463 break;
10464 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010465 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466 break;
10467#endif
10468#ifdef FEAT_INS_EXPAND
10469 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010470 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010471 break;
10472 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010473 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010474 break;
10475#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010476 case PV_FP:
10477 clear_string_option(&buf->b_p_fp);
10478 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010479#ifdef FEAT_QUICKFIX
10480 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010481 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010482 break;
10483 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010484 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010485 break;
10486 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010487 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010488 break;
10489#endif
10490#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10491 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010492 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010493 break;
10494#endif
10495#if defined(FEAT_CRYPT)
10496 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010497 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010498 break;
10499#endif
10500#ifdef FEAT_STL_OPT
10501 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010502 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010503 break;
10504#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010505 case PV_UL:
10506 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10507 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010508#ifdef FEAT_LISP
10509 case PV_LW:
10510 clear_string_option(&buf->b_p_lw);
10511 break;
10512#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010513#ifdef FEAT_MBYTE
10514 case PV_MENC:
10515 clear_string_option(&buf->b_p_menc);
10516 break;
10517#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010518 }
10519}
10520
10521/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522 * Get pointer to option variable, depending on local or global scope.
10523 */
10524 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010525get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526{
10527 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10528 {
10529 if (p->var == VAR_WIN)
10530 return (char_u *)GLOBAL_WO(get_varp(p));
10531 return p->var;
10532 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010533 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534 {
10535 switch ((int)p->indir)
10536 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010537 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010539 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10540 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10541 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010543 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10544 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10545 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010546 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010547 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010548 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010550 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10551 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552#endif
10553#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010554 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10555 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010557#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10558 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10559#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010560#if defined(FEAT_CRYPT)
10561 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10562#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010563#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010564 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010565#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010566 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010567#ifdef FEAT_LISP
10568 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10569#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010570 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010571#ifdef FEAT_MBYTE
10572 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10573#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574 }
10575 return NULL; /* "cannot happen" */
10576 }
10577 return get_varp(p);
10578}
10579
10580/*
10581 * Get pointer to option variable.
10582 */
10583 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010584get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585{
10586 /* hidden option, always return NULL */
10587 if (p->var == NULL)
10588 return NULL;
10589
10590 switch ((int)p->indir)
10591 {
10592 case PV_NONE: return p->var;
10593
10594 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010595 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010597 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010599 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010601 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010603 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010605 case PV_TC: return *curbuf->b_p_tc != NUL
10606 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010607 case PV_BKC: return *curbuf->b_p_bkc != NUL
10608 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010609#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010610 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010612 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10614#endif
10615#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010616 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010618 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10620#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010621 case PV_FP: return *curbuf->b_p_fp != NUL
10622 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010623#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010624 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010626 case PV_GP: return *curbuf->b_p_gp != NUL
10627 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10628 case PV_MP: return *curbuf->b_p_mp != NUL
10629 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010631#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10632 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10633 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10634#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010635#if defined(FEAT_CRYPT)
10636 case PV_CM: return *curbuf->b_p_cm != NUL
10637 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10638#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010639#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010640 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010641 ? (char_u *)&(curwin->w_p_stl) : p->var;
10642#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010643 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10644 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010645#ifdef FEAT_LISP
10646 case PV_LW: return *curbuf->b_p_lw != NUL
10647 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10648#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010649#ifdef FEAT_MBYTE
10650 case PV_MENC: return *curbuf->b_p_menc != NUL
10651 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653
10654#ifdef FEAT_ARABIC
10655 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10656#endif
10657 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010658#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010659 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10660#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010661#ifdef FEAT_SYN_HL
10662 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10663 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010664 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010665#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010666#ifdef FEAT_DIFF
10667 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10668#endif
10669#ifdef FEAT_FOLDING
10670 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10671 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10672 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10673 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10674 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10675 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10676 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10677# ifdef FEAT_EVAL
10678 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10679 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10680# endif
10681 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10682#endif
10683 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010684 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010685#ifdef FEAT_LINEBREAK
10686 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10687#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010688#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010690 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10691#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010692#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10693 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10694#endif
10695#ifdef FEAT_RIGHTLEFT
10696 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10697 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10698#endif
10699 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10700 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10701#ifdef FEAT_LINEBREAK
10702 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010703 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10704 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705#endif
10706#ifdef FEAT_SCROLLBIND
10707 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10708#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010709#ifdef FEAT_CURSORBIND
10710 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10711#endif
10712#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010713 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10714 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10715#endif
10716#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010717 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010718 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720
10721 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10722 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10723#ifdef FEAT_MBYTE
10724 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10727 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010728 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10729 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10730#ifdef FEAT_CINDENT
10731 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10732 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10733 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10734#endif
10735#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10736 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10737#endif
10738#ifdef FEAT_COMMENTS
10739 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10740#endif
10741#ifdef FEAT_FOLDING
10742 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10743#endif
10744#ifdef FEAT_INS_EXPAND
10745 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10746#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010747#ifdef FEAT_COMPL_FUNC
10748 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010749 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010752 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10754#ifdef FEAT_MBYTE
10755 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10756#endif
10757 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10758#ifdef FEAT_AUTOCMD
10759 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10760#endif
10761 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010762 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10764 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10765 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10766 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10767#ifdef FEAT_FIND_ID
10768# ifdef FEAT_EVAL
10769 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10770# endif
10771#endif
10772#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10773 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10774 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10775#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010776#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010777 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779#ifdef FEAT_CRYPT
10780 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10781#endif
10782#ifdef FEAT_LISP
10783 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10784#endif
10785 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10786 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10787 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10788 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10789 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010790 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010791#ifdef FEAT_TEXTOBJ
10792 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10793#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010794 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10795#ifdef FEAT_SMARTINDENT
10796 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10800#ifdef FEAT_SEARCHPATH
10801 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10802#endif
10803 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10804#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010805 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010806 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10807#endif
10808#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010809 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10810 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10811 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010812#endif
10813 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10814 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10815 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10816 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010817#ifdef FEAT_PERSISTENT_UNDO
10818 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10819#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10821#ifdef FEAT_KEYMAP
10822 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10823#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010824#ifdef FEAT_SIGNS
10825 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10826#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010827 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828 }
10829 /* always return a valid pointer to avoid a crash! */
10830 return (char_u *)&(curbuf->b_p_wm);
10831}
10832
10833/*
10834 * Get the value of 'equalprg', either the buffer-local one or the global one.
10835 */
10836 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010837get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838{
10839 if (*curbuf->b_p_ep == NUL)
10840 return p_ep;
10841 return curbuf->b_p_ep;
10842}
10843
10844#if defined(FEAT_WINDOWS) || defined(PROTO)
10845/*
10846 * Copy options from one window to another.
10847 * Used when splitting a window.
10848 */
10849 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010850win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851{
10852 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10853 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10854# ifdef FEAT_RIGHTLEFT
10855# ifdef FEAT_FKMAP
10856 /* Is this right? */
10857 wp_to->w_farsi = wp_from->w_farsi;
10858# endif
10859# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010860#if defined(FEAT_LINEBREAK)
10861 briopt_check(wp_to);
10862#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863}
10864#endif
10865
10866/*
10867 * Copy the options from one winopt_T to another.
10868 * Doesn't free the old option values in "to", use clear_winopt() for that.
10869 * The 'scroll' option is not copied, because it depends on the window height.
10870 * The 'previewwindow' option is reset, there can be only one preview window.
10871 */
10872 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010873copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874{
10875#ifdef FEAT_ARABIC
10876 to->wo_arab = from->wo_arab;
10877#endif
10878 to->wo_list = from->wo_list;
10879 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010880 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010881#ifdef FEAT_LINEBREAK
10882 to->wo_nuw = from->wo_nuw;
10883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884#ifdef FEAT_RIGHTLEFT
10885 to->wo_rl = from->wo_rl;
10886 to->wo_rlc = vim_strsave(from->wo_rlc);
10887#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010888#ifdef FEAT_STL_OPT
10889 to->wo_stl = vim_strsave(from->wo_stl);
10890#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010892#ifdef FEAT_DIFF
10893 to->wo_wrap_save = from->wo_wrap_save;
10894#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895#ifdef FEAT_LINEBREAK
10896 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010897 to->wo_bri = from->wo_bri;
10898 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899#endif
10900#ifdef FEAT_SCROLLBIND
10901 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010902 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010903#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010904#ifdef FEAT_CURSORBIND
10905 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010906 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010907#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010908#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010909 to->wo_spell = from->wo_spell;
10910#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010911#ifdef FEAT_SYN_HL
10912 to->wo_cuc = from->wo_cuc;
10913 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010914 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010915#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916#ifdef FEAT_DIFF
10917 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010918 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010919#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010920#ifdef FEAT_CONCEAL
10921 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010922 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010923#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010924#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010925 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010926 to->wo_tms = vim_strsave(from->wo_tms);
10927#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928#ifdef FEAT_FOLDING
10929 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010930 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010932 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933 to->wo_fdi = vim_strsave(from->wo_fdi);
10934 to->wo_fml = from->wo_fml;
10935 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010936 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010937 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010938 to->wo_fdm_save = from->wo_diff_saved
10939 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 to->wo_fdn = from->wo_fdn;
10941# ifdef FEAT_EVAL
10942 to->wo_fde = vim_strsave(from->wo_fde);
10943 to->wo_fdt = vim_strsave(from->wo_fdt);
10944# endif
10945 to->wo_fmr = vim_strsave(from->wo_fmr);
10946#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010947#ifdef FEAT_SIGNS
10948 to->wo_scl = vim_strsave(from->wo_scl);
10949#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010950 check_winopt(to); /* don't want NULL pointers */
10951}
10952
10953/*
10954 * Check string options in a window for a NULL value.
10955 */
10956 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010957check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010958{
10959 check_winopt(&win->w_onebuf_opt);
10960 check_winopt(&win->w_allbuf_opt);
10961}
10962
10963/*
10964 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10965 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010966 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010967check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010968{
10969#ifdef FEAT_FOLDING
10970 check_string_option(&wop->wo_fdi);
10971 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010972 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010973# ifdef FEAT_EVAL
10974 check_string_option(&wop->wo_fde);
10975 check_string_option(&wop->wo_fdt);
10976# endif
10977 check_string_option(&wop->wo_fmr);
10978#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010979#ifdef FEAT_SIGNS
10980 check_string_option(&wop->wo_scl);
10981#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982#ifdef FEAT_RIGHTLEFT
10983 check_string_option(&wop->wo_rlc);
10984#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010985#ifdef FEAT_STL_OPT
10986 check_string_option(&wop->wo_stl);
10987#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010988#ifdef FEAT_SYN_HL
10989 check_string_option(&wop->wo_cc);
10990#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010991#ifdef FEAT_CONCEAL
10992 check_string_option(&wop->wo_cocu);
10993#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010994#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010995 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010996 check_string_option(&wop->wo_tms);
10997#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010998#ifdef FEAT_LINEBREAK
10999 check_string_option(&wop->wo_briopt);
11000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011001}
11002
11003/*
11004 * Free the allocated memory inside a winopt_T.
11005 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011006 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011007clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011008{
11009#ifdef FEAT_FOLDING
11010 clear_string_option(&wop->wo_fdi);
11011 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011012 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013# ifdef FEAT_EVAL
11014 clear_string_option(&wop->wo_fde);
11015 clear_string_option(&wop->wo_fdt);
11016# endif
11017 clear_string_option(&wop->wo_fmr);
11018#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011019#ifdef FEAT_SIGNS
11020 clear_string_option(&wop->wo_scl);
11021#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011022#ifdef FEAT_LINEBREAK
11023 clear_string_option(&wop->wo_briopt);
11024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025#ifdef FEAT_RIGHTLEFT
11026 clear_string_option(&wop->wo_rlc);
11027#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011028#ifdef FEAT_STL_OPT
11029 clear_string_option(&wop->wo_stl);
11030#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011031#ifdef FEAT_SYN_HL
11032 clear_string_option(&wop->wo_cc);
11033#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011034#ifdef FEAT_CONCEAL
11035 clear_string_option(&wop->wo_cocu);
11036#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011037#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011038 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011039 clear_string_option(&wop->wo_tms);
11040#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011041}
11042
11043/*
11044 * Copy global option values to local options for one buffer.
11045 * Used when creating a new buffer and sometimes when entering a buffer.
11046 * flags:
11047 * BCO_ENTER We will enter the buf buffer.
11048 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11049 * appropriate.
11050 * BCO_NOHELP Don't copy the values to a help buffer.
11051 */
11052 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011053buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054{
11055 int should_copy = TRUE;
11056 char_u *save_p_isk = NULL; /* init for GCC */
11057 int dont_do_help;
11058 int did_isk = FALSE;
11059
11060 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011061 * Skip this when the option defaults have not been set yet. Happens when
11062 * main() allocates the first buffer.
11063 */
11064 if (p_cpo != NULL)
11065 {
11066 /*
11067 * Always copy when entering and 'cpo' contains 'S'.
11068 * Don't copy when already initialized.
11069 * Don't copy when 'cpo' contains 's' and not entering.
11070 * 'S' BCO_ENTER initialized 's' should_copy
11071 * yes yes X X TRUE
11072 * yes no yes X FALSE
11073 * no X yes X FALSE
11074 * X no no yes FALSE
11075 * X no no no TRUE
11076 * no yes no X TRUE
11077 */
11078 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11079 && (buf->b_p_initialized
11080 || (!(flags & BCO_ENTER)
11081 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11082 should_copy = FALSE;
11083
11084 if (should_copy || (flags & BCO_ALWAYS))
11085 {
11086 /* Don't copy the options specific to a help buffer when
11087 * BCO_NOHELP is given or the options were initialized already
11088 * (jumping back to a help file with CTRL-T or CTRL-O) */
11089 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11090 || buf->b_p_initialized;
11091 if (dont_do_help) /* don't free b_p_isk */
11092 {
11093 save_p_isk = buf->b_p_isk;
11094 buf->b_p_isk = NULL;
11095 }
11096 /*
11097 * Always free the allocated strings.
11098 * If not already initialized, set 'readonly' and copy 'fileformat'.
11099 */
11100 if (!buf->b_p_initialized)
11101 {
11102 free_buf_options(buf, TRUE);
11103 buf->b_p_ro = FALSE; /* don't copy readonly */
11104 buf->b_p_tx = p_tx;
11105#ifdef FEAT_MBYTE
11106 buf->b_p_fenc = vim_strsave(p_fenc);
11107#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011108 switch (*p_ffs)
11109 {
11110 case 'm':
11111 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11112 case 'd':
11113 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11114 case 'u':
11115 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11116 default:
11117 buf->b_p_ff = vim_strsave(p_ff);
11118 }
11119 if (buf->b_p_ff != NULL)
11120 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121 buf->b_p_bh = empty_option;
11122 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011123 }
11124 else
11125 free_buf_options(buf, FALSE);
11126
11127 buf->b_p_ai = p_ai;
11128 buf->b_p_ai_nopaste = p_ai_nopaste;
11129 buf->b_p_sw = p_sw;
11130 buf->b_p_tw = p_tw;
11131 buf->b_p_tw_nopaste = p_tw_nopaste;
11132 buf->b_p_tw_nobin = p_tw_nobin;
11133 buf->b_p_wm = p_wm;
11134 buf->b_p_wm_nopaste = p_wm_nopaste;
11135 buf->b_p_wm_nobin = p_wm_nobin;
11136 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011137#ifdef FEAT_MBYTE
11138 buf->b_p_bomb = p_bomb;
11139#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011140 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011141 buf->b_p_et = p_et;
11142 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011143 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011144 buf->b_p_ml = p_ml;
11145 buf->b_p_ml_nobin = p_ml_nobin;
11146 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011147 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148#ifdef FEAT_INS_EXPAND
11149 buf->b_p_cpt = vim_strsave(p_cpt);
11150#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011151#ifdef FEAT_COMPL_FUNC
11152 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011153 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155 buf->b_p_sts = p_sts;
11156 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011157 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011158#ifdef FEAT_COMMENTS
11159 buf->b_p_com = vim_strsave(p_com);
11160#endif
11161#ifdef FEAT_FOLDING
11162 buf->b_p_cms = vim_strsave(p_cms);
11163#endif
11164 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011165 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166 buf->b_p_nf = vim_strsave(p_nf);
11167 buf->b_p_mps = vim_strsave(p_mps);
11168#ifdef FEAT_SMARTINDENT
11169 buf->b_p_si = p_si;
11170#endif
11171 buf->b_p_ci = p_ci;
11172#ifdef FEAT_CINDENT
11173 buf->b_p_cin = p_cin;
11174 buf->b_p_cink = vim_strsave(p_cink);
11175 buf->b_p_cino = vim_strsave(p_cino);
11176#endif
11177#ifdef FEAT_AUTOCMD
11178 /* Don't copy 'filetype', it must be detected */
11179 buf->b_p_ft = empty_option;
11180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181 buf->b_p_pi = p_pi;
11182#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11183 buf->b_p_cinw = vim_strsave(p_cinw);
11184#endif
11185#ifdef FEAT_LISP
11186 buf->b_p_lisp = p_lisp;
11187#endif
11188#ifdef FEAT_SYN_HL
11189 /* Don't copy 'syntax', it must be set */
11190 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011191 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011192 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011193#endif
11194#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011195 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011196 (void)compile_cap_prog(&buf->b_s);
11197 buf->b_s.b_p_spf = vim_strsave(p_spf);
11198 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011199#endif
11200#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11201 buf->b_p_inde = vim_strsave(p_inde);
11202 buf->b_p_indk = vim_strsave(p_indk);
11203#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011204 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011205#if defined(FEAT_EVAL)
11206 buf->b_p_fex = vim_strsave(p_fex);
11207#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208#ifdef FEAT_CRYPT
11209 buf->b_p_key = vim_strsave(p_key);
11210#endif
11211#ifdef FEAT_SEARCHPATH
11212 buf->b_p_sua = vim_strsave(p_sua);
11213#endif
11214#ifdef FEAT_KEYMAP
11215 buf->b_p_keymap = vim_strsave(p_keymap);
11216 buf->b_kmap_state |= KEYMAP_INIT;
11217#endif
11218 /* This isn't really an option, but copying the langmap and IME
11219 * state from the current buffer is better than resetting it. */
11220 buf->b_p_iminsert = p_iminsert;
11221 buf->b_p_imsearch = p_imsearch;
11222
11223 /* options that are normally global but also have a local value
11224 * are not copied, start using the global value */
11225 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011226 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011227 buf->b_p_bkc = empty_option;
11228 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229#ifdef FEAT_QUICKFIX
11230 buf->b_p_gp = empty_option;
11231 buf->b_p_mp = empty_option;
11232 buf->b_p_efm = empty_option;
11233#endif
11234 buf->b_p_ep = empty_option;
11235 buf->b_p_kp = empty_option;
11236 buf->b_p_path = empty_option;
11237 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011238 buf->b_p_tc = empty_option;
11239 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240#ifdef FEAT_FIND_ID
11241 buf->b_p_def = empty_option;
11242 buf->b_p_inc = empty_option;
11243# ifdef FEAT_EVAL
11244 buf->b_p_inex = vim_strsave(p_inex);
11245# endif
11246#endif
11247#ifdef FEAT_INS_EXPAND
11248 buf->b_p_dict = empty_option;
11249 buf->b_p_tsr = empty_option;
11250#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011251#ifdef FEAT_TEXTOBJ
11252 buf->b_p_qe = vim_strsave(p_qe);
11253#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011254#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11255 buf->b_p_bexpr = empty_option;
11256#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011257#if defined(FEAT_CRYPT)
11258 buf->b_p_cm = empty_option;
11259#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011260#ifdef FEAT_PERSISTENT_UNDO
11261 buf->b_p_udf = p_udf;
11262#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011263#ifdef FEAT_LISP
11264 buf->b_p_lw = empty_option;
11265#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011266#ifdef FEAT_MBYTE
11267 buf->b_p_menc = empty_option;
11268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269
11270 /*
11271 * Don't copy the options set by ex_help(), use the saved values,
11272 * when going from a help buffer to a non-help buffer.
11273 * Don't touch these at all when BCO_NOHELP is used and going from
11274 * or to a help buffer.
11275 */
11276 if (dont_do_help)
11277 buf->b_p_isk = save_p_isk;
11278 else
11279 {
11280 buf->b_p_isk = vim_strsave(p_isk);
11281 did_isk = TRUE;
11282 buf->b_p_ts = p_ts;
11283 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284 if (buf->b_p_bt[0] == 'h')
11285 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286 buf->b_p_ma = p_ma;
11287 }
11288 }
11289
11290 /*
11291 * When the options should be copied (ignoring BCO_ALWAYS), set the
11292 * flag that indicates that the options have been initialized.
11293 */
11294 if (should_copy)
11295 buf->b_p_initialized = TRUE;
11296 }
11297
11298 check_buf_options(buf); /* make sure we don't have NULLs */
11299 if (did_isk)
11300 (void)buf_init_chartab(buf, FALSE);
11301}
11302
11303/*
11304 * Reset the 'modifiable' option and its default value.
11305 */
11306 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011307reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308{
11309 int opt_idx;
11310
11311 curbuf->b_p_ma = FALSE;
11312 p_ma = FALSE;
11313 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011314 if (opt_idx >= 0)
11315 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316}
11317
11318/*
11319 * Set the global value for 'iminsert' to the local value.
11320 */
11321 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011322set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323{
11324 p_iminsert = curbuf->b_p_iminsert;
11325}
11326
11327/*
11328 * Set the global value for 'imsearch' to the local value.
11329 */
11330 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011331set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332{
11333 p_imsearch = curbuf->b_p_imsearch;
11334}
11335
11336#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11337static int expand_option_idx = -1;
11338static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11339static int expand_option_flags = 0;
11340
11341 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011342set_context_in_set_cmd(
11343 expand_T *xp,
11344 char_u *arg,
11345 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011346{
11347 int nextchar;
11348 long_u flags = 0; /* init for GCC */
11349 int opt_idx = 0; /* init for GCC */
11350 char_u *p;
11351 char_u *s;
11352 int is_term_option = FALSE;
11353 int key;
11354
11355 expand_option_flags = opt_flags;
11356
11357 xp->xp_context = EXPAND_SETTINGS;
11358 if (*arg == NUL)
11359 {
11360 xp->xp_pattern = arg;
11361 return;
11362 }
11363 p = arg + STRLEN(arg) - 1;
11364 if (*p == ' ' && *(p - 1) != '\\')
11365 {
11366 xp->xp_pattern = p + 1;
11367 return;
11368 }
11369 while (p > arg)
11370 {
11371 s = p;
11372 /* count number of backslashes before ' ' or ',' */
11373 if (*p == ' ' || *p == ',')
11374 {
11375 while (s > arg && *(s - 1) == '\\')
11376 --s;
11377 }
11378 /* break at a space with an even number of backslashes */
11379 if (*p == ' ' && ((p - s) & 1) == 0)
11380 {
11381 ++p;
11382 break;
11383 }
11384 --p;
11385 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011386 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387 {
11388 xp->xp_context = EXPAND_BOOL_SETTINGS;
11389 p += 2;
11390 }
11391 if (STRNCMP(p, "inv", 3) == 0)
11392 {
11393 xp->xp_context = EXPAND_BOOL_SETTINGS;
11394 p += 3;
11395 }
11396 xp->xp_pattern = arg = p;
11397 if (*arg == '<')
11398 {
11399 while (*p != '>')
11400 if (*p++ == NUL) /* expand terminal option name */
11401 return;
11402 key = get_special_key_code(arg + 1);
11403 if (key == 0) /* unknown name */
11404 {
11405 xp->xp_context = EXPAND_NOTHING;
11406 return;
11407 }
11408 nextchar = *++p;
11409 is_term_option = TRUE;
11410 expand_option_name[2] = KEY2TERMCAP0(key);
11411 expand_option_name[3] = KEY2TERMCAP1(key);
11412 }
11413 else
11414 {
11415 if (p[0] == 't' && p[1] == '_')
11416 {
11417 p += 2;
11418 if (*p != NUL)
11419 ++p;
11420 if (*p == NUL)
11421 return; /* expand option name */
11422 nextchar = *++p;
11423 is_term_option = TRUE;
11424 expand_option_name[2] = p[-2];
11425 expand_option_name[3] = p[-1];
11426 }
11427 else
11428 {
11429 /* Allow * wildcard */
11430 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11431 p++;
11432 if (*p == NUL)
11433 return;
11434 nextchar = *p;
11435 *p = NUL;
11436 opt_idx = findoption(arg);
11437 *p = nextchar;
11438 if (opt_idx == -1 || options[opt_idx].var == NULL)
11439 {
11440 xp->xp_context = EXPAND_NOTHING;
11441 return;
11442 }
11443 flags = options[opt_idx].flags;
11444 if (flags & P_BOOL)
11445 {
11446 xp->xp_context = EXPAND_NOTHING;
11447 return;
11448 }
11449 }
11450 }
11451 /* handle "-=" and "+=" */
11452 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11453 {
11454 ++p;
11455 nextchar = '=';
11456 }
11457 if ((nextchar != '=' && nextchar != ':')
11458 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11459 {
11460 xp->xp_context = EXPAND_UNSUCCESSFUL;
11461 return;
11462 }
11463 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11464 {
11465 xp->xp_context = EXPAND_OLD_SETTING;
11466 if (is_term_option)
11467 expand_option_idx = -1;
11468 else
11469 expand_option_idx = opt_idx;
11470 xp->xp_pattern = p + 1;
11471 return;
11472 }
11473 xp->xp_context = EXPAND_NOTHING;
11474 if (is_term_option || (flags & P_NUM))
11475 return;
11476
11477 xp->xp_pattern = p + 1;
11478
11479 if (flags & P_EXPAND)
11480 {
11481 p = options[opt_idx].var;
11482 if (p == (char_u *)&p_bdir
11483 || p == (char_u *)&p_dir
11484 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011485 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486 || p == (char_u *)&p_rtp
11487#ifdef FEAT_SEARCHPATH
11488 || p == (char_u *)&p_cdpath
11489#endif
11490#ifdef FEAT_SESSION
11491 || p == (char_u *)&p_vdir
11492#endif
11493 )
11494 {
11495 xp->xp_context = EXPAND_DIRECTORIES;
11496 if (p == (char_u *)&p_path
11497#ifdef FEAT_SEARCHPATH
11498 || p == (char_u *)&p_cdpath
11499#endif
11500 )
11501 xp->xp_backslash = XP_BS_THREE;
11502 else
11503 xp->xp_backslash = XP_BS_ONE;
11504 }
11505 else
11506 {
11507 xp->xp_context = EXPAND_FILES;
11508 /* for 'tags' need three backslashes for a space */
11509 if (p == (char_u *)&p_tags)
11510 xp->xp_backslash = XP_BS_THREE;
11511 else
11512 xp->xp_backslash = XP_BS_ONE;
11513 }
11514 }
11515
11516 /* For an option that is a list of file names, find the start of the
11517 * last file name. */
11518 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11519 {
11520 /* count number of backslashes before ' ' or ',' */
11521 if (*p == ' ' || *p == ',')
11522 {
11523 s = p;
11524 while (s > xp->xp_pattern && *(s - 1) == '\\')
11525 --s;
11526 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11527 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11528 {
11529 xp->xp_pattern = p + 1;
11530 break;
11531 }
11532 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011533
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011534#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011535 /* for 'spellsuggest' start at "file:" */
11536 if (options[opt_idx].var == (char_u *)&p_sps
11537 && STRNCMP(p, "file:", 5) == 0)
11538 {
11539 xp->xp_pattern = p + 5;
11540 break;
11541 }
11542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011543 }
11544
11545 return;
11546}
11547
11548 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011549ExpandSettings(
11550 expand_T *xp,
11551 regmatch_T *regmatch,
11552 int *num_file,
11553 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011554{
11555 int num_normal = 0; /* Nr of matching non-term-code settings */
11556 int num_term = 0; /* Nr of matching terminal code settings */
11557 int opt_idx;
11558 int match;
11559 int count = 0;
11560 char_u *str;
11561 int loop;
11562 int is_term_opt;
11563 char_u name_buf[MAX_KEY_NAME_LEN];
11564 static char *(names[]) = {"all", "termcap"};
11565 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11566
11567 /* do this loop twice:
11568 * loop == 0: count the number of matching options
11569 * loop == 1: copy the matching options into allocated memory
11570 */
11571 for (loop = 0; loop <= 1; ++loop)
11572 {
11573 regmatch->rm_ic = ic;
11574 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11575 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011576 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11577 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11579 {
11580 if (loop == 0)
11581 num_normal++;
11582 else
11583 (*file)[count++] = vim_strsave((char_u *)names[match]);
11584 }
11585 }
11586 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11587 opt_idx++)
11588 {
11589 if (options[opt_idx].var == NULL)
11590 continue;
11591 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11592 && !(options[opt_idx].flags & P_BOOL))
11593 continue;
11594 is_term_opt = istermoption(&options[opt_idx]);
11595 if (is_term_opt && num_normal > 0)
11596 continue;
11597 match = FALSE;
11598 if (vim_regexec(regmatch, str, (colnr_T)0)
11599 || (options[opt_idx].shortname != NULL
11600 && vim_regexec(regmatch,
11601 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11602 match = TRUE;
11603 else if (is_term_opt)
11604 {
11605 name_buf[0] = '<';
11606 name_buf[1] = 't';
11607 name_buf[2] = '_';
11608 name_buf[3] = str[2];
11609 name_buf[4] = str[3];
11610 name_buf[5] = '>';
11611 name_buf[6] = NUL;
11612 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11613 {
11614 match = TRUE;
11615 str = name_buf;
11616 }
11617 }
11618 if (match)
11619 {
11620 if (loop == 0)
11621 {
11622 if (is_term_opt)
11623 num_term++;
11624 else
11625 num_normal++;
11626 }
11627 else
11628 (*file)[count++] = vim_strsave(str);
11629 }
11630 }
11631 /*
11632 * Check terminal key codes, these are not in the option table
11633 */
11634 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11635 {
11636 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11637 {
11638 if (!isprint(str[0]) || !isprint(str[1]))
11639 continue;
11640
11641 name_buf[0] = 't';
11642 name_buf[1] = '_';
11643 name_buf[2] = str[0];
11644 name_buf[3] = str[1];
11645 name_buf[4] = NUL;
11646
11647 match = FALSE;
11648 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11649 match = TRUE;
11650 else
11651 {
11652 name_buf[0] = '<';
11653 name_buf[1] = 't';
11654 name_buf[2] = '_';
11655 name_buf[3] = str[0];
11656 name_buf[4] = str[1];
11657 name_buf[5] = '>';
11658 name_buf[6] = NUL;
11659
11660 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11661 match = TRUE;
11662 }
11663 if (match)
11664 {
11665 if (loop == 0)
11666 num_term++;
11667 else
11668 (*file)[count++] = vim_strsave(name_buf);
11669 }
11670 }
11671
11672 /*
11673 * Check special key names.
11674 */
11675 regmatch->rm_ic = TRUE; /* ignore case here */
11676 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11677 {
11678 name_buf[0] = '<';
11679 STRCPY(name_buf + 1, str);
11680 STRCAT(name_buf, ">");
11681
11682 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11683 {
11684 if (loop == 0)
11685 num_term++;
11686 else
11687 (*file)[count++] = vim_strsave(name_buf);
11688 }
11689 }
11690 }
11691 if (loop == 0)
11692 {
11693 if (num_normal > 0)
11694 *num_file = num_normal;
11695 else if (num_term > 0)
11696 *num_file = num_term;
11697 else
11698 return OK;
11699 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11700 if (*file == NULL)
11701 {
11702 *file = (char_u **)"";
11703 return FAIL;
11704 }
11705 }
11706 }
11707 return OK;
11708}
11709
11710 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011711ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011712{
11713 char_u *var = NULL; /* init for GCC */
11714 char_u *buf;
11715
11716 *num_file = 0;
11717 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11718 if (*file == NULL)
11719 return FAIL;
11720
11721 /*
11722 * For a terminal key code expand_option_idx is < 0.
11723 */
11724 if (expand_option_idx < 0)
11725 {
11726 var = find_termcode(expand_option_name + 2);
11727 if (var == NULL)
11728 expand_option_idx = findoption(expand_option_name);
11729 }
11730
11731 if (expand_option_idx >= 0)
11732 {
11733 /* put string of option value in NameBuff */
11734 option_value2string(&options[expand_option_idx], expand_option_flags);
11735 var = NameBuff;
11736 }
11737 else if (var == NULL)
11738 var = (char_u *)"";
11739
11740 /* A backslash is required before some characters. This is the reverse of
11741 * what happens in do_set(). */
11742 buf = vim_strsave_escaped(var, escape_chars);
11743
11744 if (buf == NULL)
11745 {
11746 vim_free(*file);
11747 *file = NULL;
11748 return FAIL;
11749 }
11750
11751#ifdef BACKSLASH_IN_FILENAME
11752 /* For MS-Windows et al. we don't double backslashes at the start and
11753 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011754 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011755 if (var[0] == '\\' && var[1] == '\\'
11756 && expand_option_idx >= 0
11757 && (options[expand_option_idx].flags & P_EXPAND)
11758 && vim_isfilec(var[2])
11759 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011760 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761#endif
11762
11763 *file[0] = buf;
11764 *num_file = 1;
11765 return OK;
11766}
11767#endif
11768
11769/*
11770 * Get the value for the numeric or string option *opp in a nice format into
11771 * NameBuff[]. Must not be called with a hidden option!
11772 */
11773 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011774option_value2string(
11775 struct vimoption *opp,
11776 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777{
11778 char_u *varp;
11779
11780 varp = get_varp_scope(opp, opt_flags);
11781
11782 if (opp->flags & P_NUM)
11783 {
11784 long wc = 0;
11785
11786 if (wc_use_keyname(varp, &wc))
11787 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11788 else if (wc != 0)
11789 STRCPY(NameBuff, transchar((int)wc));
11790 else
11791 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11792 }
11793 else /* P_STRING */
11794 {
11795 varp = *(char_u **)(varp);
11796 if (varp == NULL) /* just in case */
11797 NameBuff[0] = NUL;
11798#ifdef FEAT_CRYPT
11799 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011800 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011801 STRCPY(NameBuff, "*****");
11802#endif
11803 else if (opp->flags & P_EXPAND)
11804 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11805 /* Translate 'pastetoggle' into special key names */
11806 else if ((char_u **)opp->var == &p_pt)
11807 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11808 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011809 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011810 }
11811}
11812
11813/*
11814 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11815 * printed as a keyname.
11816 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11817 */
11818 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011819wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820{
11821 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11822 {
11823 *wcp = *(long *)varp;
11824 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11825 return TRUE;
11826 }
11827 return FALSE;
11828}
11829
Bram Moolenaar01615492015-02-03 13:00:38 +010011830#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011832 * Any character has an equivalent 'langmap' character. This is used for
11833 * keyboards that have a special language mode that sends characters above
11834 * 128 (although other characters can be translated too). The "to" field is a
11835 * Vim command character. This avoids having to switch the keyboard back to
11836 * ASCII mode when leaving Insert mode.
11837 *
11838 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11839 * commands.
11840 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11841 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11842 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011843 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011844# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011845/*
11846 * With multi-byte support use growarray for 'langmap' chars >= 256
11847 */
11848typedef struct
11849{
11850 int from;
11851 int to;
11852} langmap_entry_T;
11853
11854static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011855static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856
11857/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011858 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11859 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011860 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011861 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011862langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011863{
11864 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011865 int a = 0;
11866 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011867
11868 /* Do a binary search for an existing entry. */
11869 while (a != b)
11870 {
11871 int i = (a + b) / 2;
11872 int d = entries[i].from - from;
11873
11874 if (d == 0)
11875 {
11876 entries[i].to = to;
11877 return;
11878 }
11879 if (d < 0)
11880 a = i + 1;
11881 else
11882 b = i;
11883 }
11884
11885 if (ga_grow(&langmap_mapga, 1) != OK)
11886 return; /* out of memory */
11887
11888 /* insert new entry at position "a" */
11889 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11890 mch_memmove(entries + 1, entries,
11891 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11892 ++langmap_mapga.ga_len;
11893 entries[0].from = from;
11894 entries[0].to = to;
11895}
11896
11897/*
11898 * Apply 'langmap' to multi-byte character "c" and return the result.
11899 */
11900 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011901langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011902{
11903 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11904 int a = 0;
11905 int b = langmap_mapga.ga_len;
11906
11907 while (a != b)
11908 {
11909 int i = (a + b) / 2;
11910 int d = entries[i].from - c;
11911
11912 if (d == 0)
11913 return entries[i].to; /* found matching entry */
11914 if (d < 0)
11915 a = i + 1;
11916 else
11917 b = i;
11918 }
11919 return c; /* no entry found, return "c" unmodified */
11920}
11921# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922
11923 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011924langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925{
11926 int i;
11927
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011928 for (i = 0; i < 256; i++)
11929 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11930# ifdef FEAT_MBYTE
11931 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11932# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933}
11934
11935/*
11936 * Called when langmap option is set; the language map can be
11937 * changed at any time!
11938 */
11939 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011940langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011941{
11942 char_u *p;
11943 char_u *p2;
11944 int from, to;
11945
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011946#ifdef FEAT_MBYTE
11947 ga_clear(&langmap_mapga); /* clear the previous map first */
11948#endif
11949 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011950
11951 for (p = p_langmap; p[0] != NUL; )
11952 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011953 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011954 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 {
11956 if (p2[0] == '\\' && p2[1] != NUL)
11957 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011958 }
11959 if (p2[0] == ';')
11960 ++p2; /* abcd;ABCD form, p2 points to A */
11961 else
11962 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11963 while (p[0])
11964 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011965 if (p[0] == ',')
11966 {
11967 ++p;
11968 break;
11969 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970 if (p[0] == '\\' && p[1] != NUL)
11971 ++p;
11972#ifdef FEAT_MBYTE
11973 from = (*mb_ptr2char)(p);
11974#else
11975 from = p[0];
11976#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011977 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978 if (p2 == NULL)
11979 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011980 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011981 if (p[0] != ',')
11982 {
11983 if (p[0] == '\\')
11984 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011986 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011987#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011988 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011989#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011991 }
11992 else
11993 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011994 if (p2[0] != ',')
11995 {
11996 if (p2[0] == '\\')
11997 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011999 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012000#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012001 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012003 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012004 }
12005 if (to == NUL)
12006 {
12007 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12008 transchar(from));
12009 return;
12010 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012011
12012#ifdef FEAT_MBYTE
12013 if (from >= 256)
12014 langmap_set_entry(from, to);
12015 else
12016#endif
12017 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012018
12019 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012020 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012021 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012022 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012023 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012024 if (*p == ';')
12025 {
12026 p = p2;
12027 if (p[0] != NUL)
12028 {
12029 if (p[0] != ',')
12030 {
12031 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12032 return;
12033 }
12034 ++p;
12035 }
12036 break;
12037 }
12038 }
12039 }
12040 }
12041}
12042#endif
12043
12044/*
12045 * Return TRUE if format option 'x' is in effect.
12046 * Take care of no formatting when 'paste' is set.
12047 */
12048 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012049has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050{
12051 if (p_paste)
12052 return FALSE;
12053 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12054}
12055
12056/*
12057 * Return TRUE if "x" is present in 'shortmess' option, or
12058 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12059 */
12060 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012061shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012062{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012063 return p_shm != NULL &&
12064 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012065 || (vim_strchr(p_shm, 'a') != NULL
12066 && vim_strchr((char_u *)SHM_A, x) != NULL));
12067}
12068
12069/*
12070 * paste_option_changed() - Called after p_paste was set or reset.
12071 */
12072 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012073paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012074{
12075 static int old_p_paste = FALSE;
12076 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012077 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078#ifdef FEAT_CMDL_INFO
12079 static int save_ru = 0;
12080#endif
12081#ifdef FEAT_RIGHTLEFT
12082 static int save_ri = 0;
12083 static int save_hkmap = 0;
12084#endif
12085 buf_T *buf;
12086
12087 if (p_paste)
12088 {
12089 /*
12090 * Paste switched from off to on.
12091 * Save the current values, so they can be restored later.
12092 */
12093 if (!old_p_paste)
12094 {
12095 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012096 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097 {
12098 buf->b_p_tw_nopaste = buf->b_p_tw;
12099 buf->b_p_wm_nopaste = buf->b_p_wm;
12100 buf->b_p_sts_nopaste = buf->b_p_sts;
12101 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012102 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 }
12104
12105 /* save global options */
12106 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012107 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108#ifdef FEAT_CMDL_INFO
12109 save_ru = p_ru;
12110#endif
12111#ifdef FEAT_RIGHTLEFT
12112 save_ri = p_ri;
12113 save_hkmap = p_hkmap;
12114#endif
12115 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012116 p_ai_nopaste = p_ai;
12117 p_et_nopaste = p_et;
12118 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119 p_tw_nopaste = p_tw;
12120 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 }
12122
12123 /*
12124 * Always set the option values, also when 'paste' is set when it is
12125 * already on.
12126 */
12127 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012128 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129 {
12130 buf->b_p_tw = 0; /* textwidth is 0 */
12131 buf->b_p_wm = 0; /* wrapmargin is 0 */
12132 buf->b_p_sts = 0; /* softtabstop is 0 */
12133 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012134 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012135 }
12136
12137 /* set global options */
12138 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012139 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140#ifdef FEAT_CMDL_INFO
12141# ifdef FEAT_WINDOWS
12142 if (p_ru)
12143 status_redraw_all(); /* redraw to remove the ruler */
12144# endif
12145 p_ru = 0; /* no ruler */
12146#endif
12147#ifdef FEAT_RIGHTLEFT
12148 p_ri = 0; /* no reverse insert */
12149 p_hkmap = 0; /* no Hebrew keyboard */
12150#endif
12151 /* set global values for local buffer options */
12152 p_tw = 0;
12153 p_wm = 0;
12154 p_sts = 0;
12155 p_ai = 0;
12156 }
12157
12158 /*
12159 * Paste switched from on to off: Restore saved values.
12160 */
12161 else if (old_p_paste)
12162 {
12163 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012164 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 {
12166 buf->b_p_tw = buf->b_p_tw_nopaste;
12167 buf->b_p_wm = buf->b_p_wm_nopaste;
12168 buf->b_p_sts = buf->b_p_sts_nopaste;
12169 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012170 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012171 }
12172
12173 /* restore global options */
12174 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012175 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176#ifdef FEAT_CMDL_INFO
12177# ifdef FEAT_WINDOWS
12178 if (p_ru != save_ru)
12179 status_redraw_all(); /* redraw to draw the ruler */
12180# endif
12181 p_ru = save_ru;
12182#endif
12183#ifdef FEAT_RIGHTLEFT
12184 p_ri = save_ri;
12185 p_hkmap = save_hkmap;
12186#endif
12187 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012188 p_ai = p_ai_nopaste;
12189 p_et = p_et_nopaste;
12190 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012191 p_tw = p_tw_nopaste;
12192 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193 }
12194
12195 old_p_paste = p_paste;
12196}
12197
12198/*
12199 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12200 *
12201 * Reset 'compatible' and set the values for options that didn't get set yet
12202 * to the Vim defaults.
12203 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012204 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012205 */
12206 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012207vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012208{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012209 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012210 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012211 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012212
12213 if (!option_was_set((char_u *)"cp"))
12214 {
12215 p_cp = FALSE;
12216 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12217 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12218 set_option_default(opt_idx, OPT_FREE, FALSE);
12219 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012220 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012222
12223 if (fname != NULL)
12224 {
12225 p = vim_getenv(envname, &dofree);
12226 if (p == NULL)
12227 {
12228 /* Set $MYVIMRC to the first vimrc file found. */
12229 p = FullName_save(fname, FALSE);
12230 if (p != NULL)
12231 {
12232 vim_setenv(envname, p);
12233 vim_free(p);
12234 }
12235 }
12236 else if (dofree)
12237 vim_free(p);
12238 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012239}
12240
12241/*
12242 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12243 */
12244 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012245change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012247 int opt_idx;
12248
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249 if (p_cp != on)
12250 {
12251 p_cp = on;
12252 compatible_set();
12253 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012254 opt_idx = findoption((char_u *)"cp");
12255 if (opt_idx >= 0)
12256 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257}
12258
12259/*
12260 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012261 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012262 */
12263 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012264option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265{
12266 int idx;
12267
12268 idx = findoption(name);
12269 if (idx < 0) /* unknown option */
12270 return FALSE;
12271 if (options[idx].flags & P_WAS_SET)
12272 return TRUE;
12273 return FALSE;
12274}
12275
12276/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012277 * Reset the flag indicating option "name" was set.
12278 */
12279 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012280reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012281{
12282 int idx = findoption(name);
12283
12284 if (idx >= 0)
12285 options[idx].flags &= ~P_WAS_SET;
12286}
12287
12288/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012289 * compatible_set() - Called when 'compatible' has been set or unset.
12290 *
12291 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12292 * flag) to a Vi compatible value.
12293 * When 'compatible' is unset: Set all options that have a different default
12294 * for Vim (without the P_VI_DEF flag) to that default.
12295 */
12296 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012297compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012298{
12299 int opt_idx;
12300
12301 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12302 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12303 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12304 set_option_default(opt_idx, OPT_FREE, p_cp);
12305 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012306 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012307}
12308
12309#ifdef FEAT_LINEBREAK
12310
12311# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12312 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012313 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012314# endif
12315
12316/*
12317 * fill_breakat_flags() -- called when 'breakat' changes value.
12318 */
12319 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012320fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012321{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012322 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012323 int i;
12324
12325 for (i = 0; i < 256; i++)
12326 breakat_flags[i] = FALSE;
12327
12328 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012329 for (p = p_breakat; *p; p++)
12330 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012331}
12332
12333# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012334 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012335# endif
12336
12337#endif
12338
12339/*
12340 * Check an option that can be a range of string values.
12341 *
12342 * Return OK for correct value, FAIL otherwise.
12343 * Empty is always OK.
12344 */
12345 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012346check_opt_strings(
12347 char_u *val,
12348 char **values,
12349 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012350{
12351 return opt_strings_flags(val, values, NULL, list);
12352}
12353
12354/*
12355 * Handle an option that can be a range of string values.
12356 * Set a flag in "*flagp" for each string present.
12357 *
12358 * Return OK for correct value, FAIL otherwise.
12359 * Empty is always OK.
12360 */
12361 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012362opt_strings_flags(
12363 char_u *val, /* new value */
12364 char **values, /* array of valid string values */
12365 unsigned *flagp,
12366 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012367{
12368 int i;
12369 int len;
12370 unsigned new_flags = 0;
12371
12372 while (*val)
12373 {
12374 for (i = 0; ; ++i)
12375 {
12376 if (values[i] == NULL) /* val not found in values[] */
12377 return FAIL;
12378
12379 len = (int)STRLEN(values[i]);
12380 if (STRNCMP(values[i], val, len) == 0
12381 && ((list && val[len] == ',') || val[len] == NUL))
12382 {
12383 val += len + (val[len] == ',');
12384 new_flags |= (1 << i);
12385 break; /* check next item in val list */
12386 }
12387 }
12388 }
12389 if (flagp != NULL)
12390 *flagp = new_flags;
12391
12392 return OK;
12393}
12394
12395/*
12396 * Read the 'wildmode' option, fill wim_flags[].
12397 */
12398 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012399check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012400{
12401 char_u new_wim_flags[4];
12402 char_u *p;
12403 int i;
12404 int idx = 0;
12405
12406 for (i = 0; i < 4; ++i)
12407 new_wim_flags[i] = 0;
12408
12409 for (p = p_wim; *p; ++p)
12410 {
12411 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12412 ;
12413 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12414 return FAIL;
12415 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12416 new_wim_flags[idx] |= WIM_LONGEST;
12417 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12418 new_wim_flags[idx] |= WIM_FULL;
12419 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12420 new_wim_flags[idx] |= WIM_LIST;
12421 else
12422 return FAIL;
12423 p += i;
12424 if (*p == NUL)
12425 break;
12426 if (*p == ',')
12427 {
12428 if (idx == 3)
12429 return FAIL;
12430 ++idx;
12431 }
12432 }
12433
12434 /* fill remaining entries with last flag */
12435 while (idx < 3)
12436 {
12437 new_wim_flags[idx + 1] = new_wim_flags[idx];
12438 ++idx;
12439 }
12440
12441 /* only when there are no errors, wim_flags[] is changed */
12442 for (i = 0; i < 4; ++i)
12443 wim_flags[i] = new_wim_flags[i];
12444 return OK;
12445}
12446
12447/*
12448 * Check if backspacing over something is allowed.
12449 */
12450 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012451can_bs(
12452 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012453{
12454 switch (*p_bs)
12455 {
12456 case '2': return TRUE;
12457 case '1': return (what != BS_START);
12458 case '0': return FALSE;
12459 }
12460 return vim_strchr(p_bs, what) != NULL;
12461}
12462
12463/*
12464 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12465 * the file must be considered changed when the value is different.
12466 */
12467 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012468save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012469{
12470 buf->b_start_ffc = *buf->b_p_ff;
12471 buf->b_start_eol = buf->b_p_eol;
12472#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012473 buf->b_start_bomb = buf->b_p_bomb;
12474
Bram Moolenaar071d4272004-06-13 20:20:40 +000012475 /* Only use free/alloc when necessary, they take time. */
12476 if (buf->b_start_fenc == NULL
12477 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12478 {
12479 vim_free(buf->b_start_fenc);
12480 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12481 }
12482#endif
12483}
12484
12485/*
12486 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12487 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012488 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12489 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012490 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012491 * When "ignore_empty" is true don't consider a new, empty buffer to be
12492 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012493 */
12494 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012495file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012496{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012497 /* In a buffer that was never loaded the options are not valid. */
12498 if (buf->b_flags & BF_NEVERLOADED)
12499 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012500 if (ignore_empty
12501 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012502 && buf->b_ml.ml_line_count == 1
12503 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12504 return FALSE;
12505 if (buf->b_start_ffc != *buf->b_p_ff)
12506 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012507 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012508 return TRUE;
12509#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012510 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12511 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012512 if (buf->b_start_fenc == NULL)
12513 return (*buf->b_p_fenc != NUL);
12514 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12515#else
12516 return FALSE;
12517#endif
12518}
12519
12520/*
12521 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12522 */
12523 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012524check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012525{
12526 return check_opt_strings(p, p_ff_values, FALSE);
12527}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012528
12529/*
12530 * Return the effective shiftwidth value for current buffer, using the
12531 * 'tabstop' value when 'shiftwidth' is zero.
12532 */
12533 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012534get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012535{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012536 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012537}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012538
12539/*
12540 * Return the effective softtabstop value for the current buffer, using the
12541 * 'tabstop' value when 'softtabstop' is negative.
12542 */
12543 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012544get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012545{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012546 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012547}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012548
12549/*
12550 * Check matchpairs option for "*initc".
12551 * If there is a match set "*initc" to the matching character and "*findc" to
12552 * the opposite character. Set "*backwards" to the direction.
12553 * When "switchit" is TRUE swap the direction.
12554 */
12555 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012556find_mps_values(
12557 int *initc,
12558 int *findc,
12559 int *backwards,
12560 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012561{
12562 char_u *ptr;
12563
12564 ptr = curbuf->b_p_mps;
12565 while (*ptr != NUL)
12566 {
12567#ifdef FEAT_MBYTE
12568 if (has_mbyte)
12569 {
12570 char_u *prev;
12571
12572 if (mb_ptr2char(ptr) == *initc)
12573 {
12574 if (switchit)
12575 {
12576 *findc = *initc;
12577 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12578 *backwards = TRUE;
12579 }
12580 else
12581 {
12582 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12583 *backwards = FALSE;
12584 }
12585 return;
12586 }
12587 prev = ptr;
12588 ptr += mb_ptr2len(ptr) + 1;
12589 if (mb_ptr2char(ptr) == *initc)
12590 {
12591 if (switchit)
12592 {
12593 *findc = *initc;
12594 *initc = mb_ptr2char(prev);
12595 *backwards = FALSE;
12596 }
12597 else
12598 {
12599 *findc = mb_ptr2char(prev);
12600 *backwards = TRUE;
12601 }
12602 return;
12603 }
12604 ptr += mb_ptr2len(ptr);
12605 }
12606 else
12607#endif
12608 {
12609 if (*ptr == *initc)
12610 {
12611 if (switchit)
12612 {
12613 *backwards = TRUE;
12614 *findc = *initc;
12615 *initc = ptr[2];
12616 }
12617 else
12618 {
12619 *backwards = FALSE;
12620 *findc = ptr[2];
12621 }
12622 return;
12623 }
12624 ptr += 2;
12625 if (*ptr == *initc)
12626 {
12627 if (switchit)
12628 {
12629 *backwards = FALSE;
12630 *findc = *initc;
12631 *initc = ptr[-2];
12632 }
12633 else
12634 {
12635 *backwards = TRUE;
12636 *findc = ptr[-2];
12637 }
12638 return;
12639 }
12640 ++ptr;
12641 }
12642 if (*ptr == ',')
12643 ++ptr;
12644 }
12645}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012646
12647#if defined(FEAT_LINEBREAK) || defined(PROTO)
12648/*
12649 * This is called when 'breakindentopt' is changed and when a window is
12650 * initialized.
12651 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012652 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012653briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012654{
12655 char_u *p;
12656 int bri_shift = 0;
12657 long bri_min = 20;
12658 int bri_sbr = FALSE;
12659
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012660 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012661 while (*p != NUL)
12662 {
12663 if (STRNCMP(p, "shift:", 6) == 0
12664 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12665 {
12666 p += 6;
12667 bri_shift = getdigits(&p);
12668 }
12669 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12670 {
12671 p += 4;
12672 bri_min = getdigits(&p);
12673 }
12674 else if (STRNCMP(p, "sbr", 3) == 0)
12675 {
12676 p += 3;
12677 bri_sbr = TRUE;
12678 }
12679 if (*p != ',' && *p != NUL)
12680 return FAIL;
12681 if (*p == ',')
12682 ++p;
12683 }
12684
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012685 wp->w_p_brishift = bri_shift;
12686 wp->w_p_brimin = bri_min;
12687 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012688
12689 return OK;
12690}
12691#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012692
12693/*
12694 * Get the local or global value of 'backupcopy'.
12695 */
12696 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012697get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012698{
12699 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12700}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012701
12702#if defined(FEAT_SIGNS) || defined(PROTO)
12703/*
12704 * Return TRUE when window "wp" has a column to draw signs in.
12705 */
12706 int
12707signcolumn_on(win_T *wp)
12708{
12709 if (*wp->w_p_scl == 'n')
12710 return FALSE;
12711 if (*wp->w_p_scl == 'y')
12712 return TRUE;
12713 return (wp->w_buffer->b_signlist != NULL
12714# ifdef FEAT_NETBEANS_INTG
12715 || wp->w_buffer->b_has_sign_column
12716# endif
12717 );
12718}
12719#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012720
12721#if defined(FEAT_EVAL) || defined(PROTO)
12722/*
12723 * Get window or buffer local options.
12724 */
12725 dict_T *
12726get_winbuf_options(int bufopt)
12727{
12728 dict_T *d;
12729 int opt_idx;
12730
12731 d = dict_alloc();
12732 if (d == NULL)
12733 return NULL;
12734
12735 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12736 {
12737 struct vimoption *opt = &options[opt_idx];
12738
12739 if ((bufopt && (opt->indir & PV_BUF))
12740 || (!bufopt && (opt->indir & PV_WIN)))
12741 {
12742 char_u *varp = get_varp(opt);
12743
12744 if (varp != NULL)
12745 {
12746 if (opt->flags & P_STRING)
12747 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012748 else if (opt->flags & P_NUM)
12749 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012750 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012751 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012752 }
12753 }
12754 }
12755
12756 return d;
12757}
12758#endif