blob: f89c4730bba2170db94022de149898be3f45fcf7 [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)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100117#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000118#define PV_IMI OPT_BUF(BV_IMI)
119#define PV_IMS OPT_BUF(BV_IMS)
120#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
121# define PV_INDE OPT_BUF(BV_INDE)
122# define PV_INDK OPT_BUF(BV_INDK)
123#endif
124#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
125# define PV_INEX OPT_BUF(BV_INEX)
126#endif
127#define PV_INF OPT_BUF(BV_INF)
128#define PV_ISK OPT_BUF(BV_ISK)
129#ifdef FEAT_CRYPT
130# define PV_KEY OPT_BUF(BV_KEY)
131#endif
132#ifdef FEAT_KEYMAP
133# define PV_KMAP OPT_BUF(BV_KMAP)
134#endif
135#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
136#ifdef FEAT_LISP
137# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100138# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000139#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100140#ifdef FEAT_MBYTE
141# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
142#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#define PV_MA OPT_BUF(BV_MA)
144#define PV_ML OPT_BUF(BV_ML)
145#define PV_MOD OPT_BUF(BV_MOD)
146#define PV_MPS OPT_BUF(BV_MPS)
147#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000148#ifdef FEAT_COMPL_FUNC
149# define PV_OFU OPT_BUF(BV_OFU)
150#endif
151#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
152#define PV_PI OPT_BUF(BV_PI)
153#ifdef FEAT_TEXTOBJ
154# define PV_QE OPT_BUF(BV_QE)
155#endif
156#define PV_RO OPT_BUF(BV_RO)
157#ifdef FEAT_SMARTINDENT
158# define PV_SI OPT_BUF(BV_SI)
159#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100160#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100177#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_TS OPT_BUF(BV_TS)
179#define PV_TW OPT_BUF(BV_TW)
180#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200181#ifdef FEAT_PERSISTENT_UNDO
182# define PV_UDF OPT_BUF(BV_UDF)
183#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200185#ifdef FEAT_VARTABS
186# define PV_VSTS OPT_BUF(BV_VSTS)
187# define PV_VTS OPT_BUF(BV_VTS)
188#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189
190/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000191 * Definition of the PV_ values for window-local options.
192 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000193 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000194#define PV_LIST OPT_WIN(WV_LIST)
195#ifdef FEAT_ARABIC
196# define PV_ARAB OPT_WIN(WV_ARAB)
197#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200198#ifdef FEAT_LINEBREAK
199# define PV_BRI OPT_WIN(WV_BRI)
200# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
201#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000202#ifdef FEAT_DIFF
203# define PV_DIFF OPT_WIN(WV_DIFF)
204#endif
205#ifdef FEAT_FOLDING
206# define PV_FDC OPT_WIN(WV_FDC)
207# define PV_FEN OPT_WIN(WV_FEN)
208# define PV_FDI OPT_WIN(WV_FDI)
209# define PV_FDL OPT_WIN(WV_FDL)
210# define PV_FDM OPT_WIN(WV_FDM)
211# define PV_FML OPT_WIN(WV_FML)
212# define PV_FDN OPT_WIN(WV_FDN)
213# ifdef FEAT_EVAL
214# define PV_FDE OPT_WIN(WV_FDE)
215# define PV_FDT OPT_WIN(WV_FDT)
216# endif
217# define PV_FMR OPT_WIN(WV_FMR)
218#endif
219#ifdef FEAT_LINEBREAK
220# define PV_LBR OPT_WIN(WV_LBR)
221#endif
222#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200223#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000224#ifdef FEAT_LINEBREAK
225# define PV_NUW OPT_WIN(WV_NUW)
226#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200227#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000228# define PV_PVW OPT_WIN(WV_PVW)
229#endif
230#ifdef FEAT_RIGHTLEFT
231# define PV_RL OPT_WIN(WV_RL)
232# define PV_RLC OPT_WIN(WV_RLC)
233#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100234#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100251#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200252#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200253# define PV_COCU OPT_WIN(WV_COCU)
254# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200255#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200256#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200257# define PV_TWK OPT_WIN(WV_TWK)
258# define PV_TWS OPT_WIN(WV_TWS)
259# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200261#ifdef FEAT_SIGNS
262# define PV_SCL OPT_WIN(WV_SCL)
263#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000264
265/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266typedef enum
267{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000268 PV_NONE = 0,
269 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000270} idopt_T;
271
272/*
273 * Options local to a window have a value local to a buffer and global to all
274 * buffers. Indicate this by setting "var" to VAR_WIN.
275 */
276#define VAR_WIN ((char_u *)-1)
277
278/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000279 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280 * Only to be used in option.c!
281 */
282static int p_ai;
283static int p_bin;
284#ifdef FEAT_MBYTE
285static int p_bomb;
286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287static char_u *p_bh;
288static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000289static int p_bl;
290static int p_ci;
291#ifdef FEAT_CINDENT
292static int p_cin;
293static char_u *p_cink;
294static char_u *p_cino;
295#endif
296#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
297static char_u *p_cinw;
298#endif
299#ifdef FEAT_COMMENTS
300static char_u *p_com;
301#endif
302#ifdef FEAT_FOLDING
303static char_u *p_cms;
304#endif
305#ifdef FEAT_INS_EXPAND
306static char_u *p_cpt;
307#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000308#ifdef FEAT_COMPL_FUNC
309static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000310static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200313static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static int p_et;
315#ifdef FEAT_MBYTE
316static char_u *p_fenc;
317#endif
318static char_u *p_ff;
319static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000320static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322static long p_iminsert;
323static long p_imsearch;
324#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
325static char_u *p_inex;
326#endif
327#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
328static char_u *p_inde;
329static char_u *p_indk;
330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000331#if defined(FEAT_EVAL)
332static char_u *p_fex;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_inf;
335static char_u *p_isk;
336#ifdef FEAT_CRYPT
337static char_u *p_key;
338#endif
339#ifdef FEAT_LISP
340static int p_lisp;
341#endif
342static int p_ml;
343static int p_ma;
344static int p_mod;
345static char_u *p_mps;
346static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000348#ifdef FEAT_TEXTOBJ
349static char_u *p_qe;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_ro;
352#ifdef FEAT_SMARTINDENT
353static int p_si;
354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static long p_sts;
357#if defined(FEAT_SEARCHPATH)
358static char_u *p_sua;
359#endif
360static long p_sw;
361static int p_swf;
362#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000363static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000365#endif
366#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000367static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000368static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000369static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370#endif
371static long p_ts;
372static long p_tw;
373static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200374#ifdef FEAT_PERSISTENT_UNDO
375static int p_udf;
376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200378#ifdef FEAT_VARTABS
379static char_u *p_vsts;
380static char_u *p_vts;
381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382#ifdef FEAT_KEYMAP
383static char_u *p_keymap;
384#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200385#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200386static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388
389/* Saved values for when 'bin' is set. */
390static int p_et_nobin;
391static int p_ml_nobin;
392static long p_tw_nobin;
393static long p_wm_nobin;
394
395/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200396static int p_ai_nopaste;
397static int p_et_nopaste;
398static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399static long p_tw_nopaste;
400static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200401#ifdef FEAT_VARTABS
402static char_u *p_vsts_nopaste;
403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404
405struct vimoption
406{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200407 char *fullname; // full option name
408 char *shortname; // permissible abbreviation
409 long_u flags; // see below
410 char_u *var; // global option: pointer to variable;
411 // window-local option: VAR_WIN;
412 // buffer-local option: global value
413 idopt_T indir; // global option: PV_NONE;
414 // local option: indirect option index
415 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200417 sctx_T script_ctx; // script context where the option was last set
418# define SCTX_INIT , {0, 0}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000419#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200420# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000421#endif
422};
423
424#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
425#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
426
427/*
428 * Flags
429 */
430#define P_BOOL 0x01 /* the option is boolean */
431#define P_NUM 0x02 /* the option is numeric */
432#define P_STRING 0x04 /* the option is a string */
433#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000434 must use free_string_option() when
435 assigning new value. Not set if default is
436 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
438 never be used for local or hidden options! */
439#define P_NODEFAULT 0x40 /* don't set to default value */
440#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
441 use vim_free() when assigning new value */
442#define P_WAS_SET 0x100 /* option has been set/reset */
443#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
444#define P_VI_DEF 0x400 /* Use Vi default for Vim */
445#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
446
447 /* when option changed, what to display: */
448#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100449#define P_RWIN 0x2000 /* redraw current window and recompute text */
450#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451#define P_RALL 0x6000 /* redraw all windows */
452#define P_RCLR 0x7000 /* clear and redraw all */
453
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200454#define P_COMMA 0x8000 /* comma separated list */
455#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
456 * commas */
457#define P_NODUP 0x20000L /* don't allow duplicate strings */
458#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
461#define P_GETTEXT 0x100000L /* expand default value with _() */
462#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
463#define P_NFNAME 0x400000L /* only normal file name chars allowed */
464#define P_INSECURE 0x800000L /* option was set from a modeline */
465#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100466 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200467#define P_NO_ML 0x2000000L /* not allowed in modeline */
468#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200469 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100470#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100471#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000472
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000473#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
474
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000475/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
476 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100477#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000478# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000479#else
480# define ISP_LATIN1 (char_u *)"@,161-255"
481#endif
482
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200483# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000484
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100485/* Default python version for pyx* commands */
486#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
487# define DEFAULT_PYTHON_VER 0
488#elif defined(FEAT_PYTHON3)
489# define DEFAULT_PYTHON_VER 3
490#elif defined(FEAT_PYTHON)
491# define DEFAULT_PYTHON_VER 2
492#else
493# define DEFAULT_PYTHON_VER 0
494#endif
495
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496/*
497 * options[] is initialized here.
498 * The order of the options MUST be alphabetic for ":set all" and findoption().
499 * All option names MUST start with a lowercase letter (for findoption()).
500 * Exception: "t_" options are at the end.
501 * The options with a NULL variable are 'hidden': a set command for them is
502 * ignored and they are not printed.
503 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100504static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200506 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507#ifdef FEAT_RIGHTLEFT
508 (char_u *)&p_aleph, PV_NONE,
509#else
510 (char_u *)NULL, PV_NONE,
511#endif
512 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100513#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)128L,
515#else
516 (char_u *)224L,
517#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200518 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200520#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521 (char_u *)&p_antialias, PV_NONE,
522 {(char_u *)FALSE, (char_u *)FALSE}
523#else
524 (char_u *)NULL, PV_NONE,
525 {(char_u *)FALSE, (char_u *)FALSE}
526#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200527 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200528 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529#ifdef FEAT_ARABIC
530 (char_u *)VAR_WIN, PV_ARAB,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200534 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
536#ifdef FEAT_ARABIC
537 (char_u *)&p_arshape, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200541 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
543#ifdef FEAT_RIGHTLEFT
544 (char_u *)&p_ari, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200548 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
550#ifdef FEAT_FKMAP
551 (char_u *)&p_altkeymap, PV_NONE,
552#else
553 (char_u *)NULL, PV_NONE,
554#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200555 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
557#if defined(FEAT_MBYTE)
558 (char_u *)&p_ambw, PV_NONE,
559 {(char_u *)"single", (char_u *)0L}
560#else
561 (char_u *)NULL, PV_NONE,
562 {(char_u *)0L, (char_u *)0L}
563#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200564 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100568 {(char_u *)FALSE, (char_u *)0L}
569#else
570 (char_u *)NULL, PV_NONE,
571 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200573 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autoindent", "ai", P_BOOL|P_VI_DEF,
575 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autoprint", "ap", P_BOOL|P_VI_DEF,
578 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200579 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000581 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200582 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"autowrite", "aw", P_BOOL|P_VI_DEF,
584 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200585 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"autowriteall","awa", P_BOOL|P_VI_DEF,
587 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200588 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
590 (char_u *)&p_bg, PV_NONE,
591 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100592#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)"dark",
594#else
595 (char_u *)"light",
596#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200597 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200598 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200600 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
602 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200603 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200604 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200605 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606#ifdef UNIX
607 {(char_u *)"yes", (char_u *)"auto"}
608#else
609 {(char_u *)"auto", (char_u *)"auto"}
610#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200611 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200612 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
613 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200615 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000616 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 (char_u *)&p_bex, PV_NONE,
618 {
619#ifdef VMS
620 (char_u *)"_",
621#else
622 (char_u *)"~",
623#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200624 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200625 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#ifdef FEAT_WILDIGN
627 (char_u *)&p_bsk, PV_NONE,
628 {(char_u *)"", (char_u *)0L}
629#else
630 (char_u *)NULL, PV_NONE,
631 {(char_u *)0L, (char_u *)0L}
632#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200633 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100637 {(char_u *)600L, (char_u *)0L}
638#else
639 (char_u *)NULL, PV_NONE,
640 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200642 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100643 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100644#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100645 (char_u *)&p_beval, PV_NONE,
646 {(char_u *)FALSE, (char_u *)0L}
647#else
648 (char_u *)NULL, PV_NONE,
649 {(char_u *)0L, (char_u *)0L}
650#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200651 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100652 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100653#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100654 (char_u *)&p_bevalterm, PV_NONE,
655 {(char_u *)FALSE, (char_u *)0L}
656#else
657 (char_u *)NULL, PV_NONE,
658 {(char_u *)0L, (char_u *)0L}
659#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200660 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100661 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
662#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
663 (char_u *)&p_bexpr, PV_BEXPR,
664 {(char_u *)"", (char_u *)0L}
665#else
666 (char_u *)NULL, PV_NONE,
667 {(char_u *)0L, (char_u *)0L}
668#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200669 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"beautify", "bf", P_BOOL|P_VI_DEF,
671 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200672 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200673 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
674 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200675 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
677 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200678 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000679 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200681 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
683#ifdef FEAT_MBYTE
684 (char_u *)&p_bomb, PV_BOMB,
685#else
686 (char_u *)NULL, PV_NONE,
687#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200688 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000689 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
690#ifdef FEAT_LINEBREAK
691 (char_u *)&p_breakat, PV_NONE,
692 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200697 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200698 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
699#ifdef FEAT_LINEBREAK
700 (char_u *)VAR_WIN, PV_BRI,
701 {(char_u *)FALSE, (char_u *)0L}
702#else
703 (char_u *)NULL, PV_NONE,
704 {(char_u *)0L, (char_u *)0L}
705#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200706 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200707 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
708 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200709#ifdef FEAT_LINEBREAK
710 (char_u *)VAR_WIN, PV_BRIOPT,
711 {(char_u *)"", (char_u *)NULL}
712#else
713 (char_u *)NULL, PV_NONE,
714 {(char_u *)"", (char_u *)NULL}
715#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200716 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
718#ifdef FEAT_BROWSE
719 (char_u *)&p_bsdir, PV_NONE,
720 {(char_u *)"last", (char_u *)0L}
721#else
722 (char_u *)NULL, PV_NONE,
723 {(char_u *)0L, (char_u *)0L}
724#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200725 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 (char_u *)&p_bh, PV_BH,
728 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200729 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
731 (char_u *)&p_bl, PV_BL,
732 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200733 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735 (char_u *)&p_bt, PV_BT,
736 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200737 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200738 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000739#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 (char_u *)&p_cmp, PV_NONE,
741 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000742#else
743 (char_u *)NULL, PV_NONE,
744 {(char_u *)0L, (char_u *)0L}
745#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200746 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
748#ifdef FEAT_SEARCHPATH
749 (char_u *)&p_cdpath, PV_NONE,
750 {(char_u *)",,", (char_u *)0L}
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)0L, (char_u *)0L}
754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200755 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756 {"cedit", NULL, P_STRING,
757#ifdef FEAT_CMDWIN
758 (char_u *)&p_cedit, PV_NONE,
759 {(char_u *)"", (char_u *)CTRL_F_STR}
760#else
761 (char_u *)NULL, PV_NONE,
762 {(char_u *)0L, (char_u *)0L}
763#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200764 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
766#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
767 (char_u *)&p_ccv, PV_NONE,
768 {(char_u *)"", (char_u *)0L}
769#else
770 (char_u *)NULL, PV_NONE,
771 {(char_u *)0L, (char_u *)0L}
772#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200773 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
775#ifdef FEAT_CINDENT
776 (char_u *)&p_cin, PV_CIN,
777#else
778 (char_u *)NULL, PV_NONE,
779#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200780 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200781 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782#ifdef FEAT_CINDENT
783 (char_u *)&p_cink, PV_CINK,
784 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
785#else
786 (char_u *)NULL, PV_NONE,
787 {(char_u *)0L, (char_u *)0L}
788#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200789 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200790 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791#ifdef FEAT_CINDENT
792 (char_u *)&p_cino, PV_CINO,
793#else
794 (char_u *)NULL, PV_NONE,
795#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200796 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200797 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000798#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
799 (char_u *)&p_cinw, PV_CINW,
800 {(char_u *)"if,else,while,do,for,switch",
801 (char_u *)0L}
802#else
803 (char_u *)NULL, PV_NONE,
804 {(char_u *)0L, (char_u *)0L}
805#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200806 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200807 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808#ifdef FEAT_CLIPBOARD
809 (char_u *)&p_cb, PV_NONE,
810# ifdef FEAT_XCLIPBOARD
811 {(char_u *)"autoselect,exclude:cons\\|linux",
812 (char_u *)0L}
813# else
814 {(char_u *)"", (char_u *)0L}
815# endif
816#else
817 (char_u *)NULL, PV_NONE,
818 {(char_u *)"", (char_u *)0L}
819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200820 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000821 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
822 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200823 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000824 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
825#ifdef FEAT_CMDWIN
826 (char_u *)&p_cwh, PV_NONE,
827#else
828 (char_u *)NULL, PV_NONE,
829#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200830 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200831 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200832#ifdef FEAT_SYN_HL
833 (char_u *)VAR_WIN, PV_CC,
834#else
835 (char_u *)NULL, PV_NONE,
836#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200837 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
839 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200840 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200841 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
842 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843#ifdef FEAT_COMMENTS
844 (char_u *)&p_com, PV_COM,
845 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
846 (char_u *)0L}
847#else
848 (char_u *)NULL, PV_NONE,
849 {(char_u *)0L, (char_u *)0L}
850#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200851 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200852 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853#ifdef FEAT_FOLDING
854 (char_u *)&p_cms, PV_CMS,
855 {(char_u *)"/*%s*/", (char_u *)0L}
856#else
857 (char_u *)NULL, PV_NONE,
858 {(char_u *)0L, (char_u *)0L}
859#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200860 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000861 /* P_PRI_MKRC isn't needed here, optval_default()
862 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000863 {"compatible", "cp", P_BOOL|P_RALL,
864 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200865 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200866 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867#ifdef FEAT_INS_EXPAND
868 (char_u *)&p_cpt, PV_CPT,
869 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
870#else
871 (char_u *)NULL, PV_NONE,
872 {(char_u *)0L, (char_u *)0L}
873#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200874 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200875 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200876#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200877 (char_u *)VAR_WIN, PV_COCU,
878 {(char_u *)"", (char_u *)NULL}
879#else
880 (char_u *)NULL, PV_NONE,
881 {(char_u *)NULL, (char_u *)0L}
882#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200883 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200884 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
885#ifdef FEAT_CONCEAL
886 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200887#else
888 (char_u *)NULL, PV_NONE,
889#endif
890 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200891 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000892 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
893#ifdef FEAT_COMPL_FUNC
894 (char_u *)&p_cfu, PV_CFU,
895 {(char_u *)"", (char_u *)0L}
896#else
897 (char_u *)NULL, PV_NONE,
898 {(char_u *)0L, (char_u *)0L}
899#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200900 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200901 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000902#ifdef FEAT_INS_EXPAND
903 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000904 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000905#else
906 (char_u *)NULL, PV_NONE,
907 {(char_u *)0L, (char_u *)0L}
908#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200909 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 {"confirm", "cf", P_BOOL|P_VI_DEF,
911#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
912 (char_u *)&p_confirm, PV_NONE,
913#else
914 (char_u *)NULL, PV_NONE,
915#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200916 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200919 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
921 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200922 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000923 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
924 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000925 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200926 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200927 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200928#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200929 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200930 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200931#else
932 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200933 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200934#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200935 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000936 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
937#ifdef FEAT_CSCOPE
938 (char_u *)&p_cspc, PV_NONE,
939#else
940 (char_u *)NULL, PV_NONE,
941#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200942 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000943 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
944#ifdef FEAT_CSCOPE
945 (char_u *)&p_csprg, PV_NONE,
946 {(char_u *)"cscope", (char_u *)0L}
947#else
948 (char_u *)NULL, PV_NONE,
949 {(char_u *)0L, (char_u *)0L}
950#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200951 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200952 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
954 (char_u *)&p_csqf, PV_NONE,
955 {(char_u *)"", (char_u *)0L}
956#else
957 (char_u *)NULL, PV_NONE,
958 {(char_u *)0L, (char_u *)0L}
959#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200960 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200961 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
962#ifdef FEAT_CSCOPE
963 (char_u *)&p_csre, PV_NONE,
964#else
965 (char_u *)NULL, PV_NONE,
966#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200967 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
969#ifdef FEAT_CSCOPE
970 (char_u *)&p_cst, PV_NONE,
971#else
972 (char_u *)NULL, PV_NONE,
973#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200974 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
976#ifdef FEAT_CSCOPE
977 (char_u *)&p_csto, PV_NONE,
978#else
979 (char_u *)NULL, PV_NONE,
980#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200981 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000982 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
983#ifdef FEAT_CSCOPE
984 (char_u *)&p_csverbose, PV_NONE,
985#else
986 (char_u *)NULL, PV_NONE,
987#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200988 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200989 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200990 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200991 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000992 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
993#ifdef FEAT_SYN_HL
994 (char_u *)VAR_WIN, PV_CUC,
995#else
996 (char_u *)NULL, PV_NONE,
997#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200998 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100999 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001000#ifdef FEAT_SYN_HL
1001 (char_u *)VAR_WIN, PV_CUL,
1002#else
1003 (char_u *)NULL, PV_NONE,
1004#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001005 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"debug", NULL, P_STRING|P_VI_DEF,
1007 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001008 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001009 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001011 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001012 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#else
1014 (char_u *)NULL, PV_NONE,
1015 {(char_u *)NULL, (char_u *)0L}
1016#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001017 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1019#ifdef FEAT_MBYTE
1020 (char_u *)&p_deco, PV_NONE,
1021#else
1022 (char_u *)NULL, PV_NONE,
1023#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001024 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001025 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001027 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#else
1029 (char_u *)NULL, PV_NONE,
1030#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001031 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1033#ifdef FEAT_DIFF
1034 (char_u *)VAR_WIN, PV_DIFF,
1035#else
1036 (char_u *)NULL, PV_NONE,
1037#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001038 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001039 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1041 (char_u *)&p_dex, PV_NONE,
1042 {(char_u *)"", (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)0L, (char_u *)0L}
1046#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001047 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001048 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1049 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050#ifdef FEAT_DIFF
1051 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001052 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053#else
1054 (char_u *)NULL, PV_NONE,
1055 {(char_u *)"", (char_u *)NULL}
1056#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001057 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1059#ifdef FEAT_DIGRAPHS
1060 (char_u *)&p_dg, PV_NONE,
1061#else
1062 (char_u *)NULL, PV_NONE,
1063#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001064 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001065 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1066 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001068 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001069 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001071 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 (char_u *)&p_ead, PV_NONE,
1074 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001075 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1077 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001078 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001079 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1080#if defined(FEAT_MBYTE)
1081 (char_u *)&p_emoji, PV_NONE,
1082 {(char_u *)TRUE, (char_u *)0L}
1083#else
1084 (char_u *)NULL, PV_NONE,
1085 {(char_u *)0L, (char_u *)0L}
1086#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001087 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001088 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089#ifdef FEAT_MBYTE
1090 (char_u *)&p_enc, PV_NONE,
1091 {(char_u *)ENC_DFLT, (char_u *)0L}
1092#else
1093 (char_u *)NULL, PV_NONE,
1094 {(char_u *)0L, (char_u *)0L}
1095#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001096 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1098 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001099 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1101 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001102 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001104 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001105 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1107 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001108 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1110#ifdef FEAT_QUICKFIX
1111 (char_u *)&p_ef, PV_NONE,
1112 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1113#else
1114 (char_u *)NULL, PV_NONE,
1115 {(char_u *)NULL, (char_u *)0L}
1116#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001117 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001120 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122#else
1123 (char_u *)NULL, PV_NONE,
1124 {(char_u *)NULL, (char_u *)0L}
1125#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001126 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127 {"esckeys", "ek", P_BOOL|P_VIM,
1128 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001129 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001130 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001132 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1134 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001135 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1137 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001138 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001139 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1140 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141#ifdef FEAT_MBYTE
1142 (char_u *)&p_fenc, PV_FENC,
1143 {(char_u *)"", (char_u *)0L}
1144#else
1145 (char_u *)NULL, PV_NONE,
1146 {(char_u *)0L, (char_u *)0L}
1147#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001148 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001149 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150#ifdef FEAT_MBYTE
1151 (char_u *)&p_fencs, PV_NONE,
1152 {(char_u *)"ucs-bom", (char_u *)0L}
1153#else
1154 (char_u *)NULL, PV_NONE,
1155 {(char_u *)0L, (char_u *)0L}
1156#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001157 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001158 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1159 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001161 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001162 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001163 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001164 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001165 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001166 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1167 (char_u *)&p_fic, PV_NONE,
1168 {
1169#ifdef CASE_INSENSITIVE_FILENAME
1170 (char_u *)TRUE,
1171#else
1172 (char_u *)FALSE,
1173#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001174 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001175 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 (char_u *)&p_ft, PV_FT,
1177 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001178 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001179 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001180 (char_u *)&p_fcs, PV_NONE,
1181 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001182 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001183 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1184 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001185 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1187#ifdef FEAT_FKMAP
1188 (char_u *)&p_fkmap, PV_NONE,
1189#else
1190 (char_u *)NULL, PV_NONE,
1191#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001192 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193 {"flash", "fl", P_BOOL|P_VI_DEF,
1194 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001195 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001196 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001197#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001199 {(char_u *)"", (char_u *)0L}
1200#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)NULL, PV_NONE,
1202 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001203#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001204 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001205 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1206#ifdef FEAT_FOLDING
1207 (char_u *)VAR_WIN, PV_FDC,
1208 {(char_u *)FALSE, (char_u *)0L}
1209#else
1210 (char_u *)NULL, PV_NONE,
1211 {(char_u *)NULL, (char_u *)0L}
1212#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001213 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001214 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1215#ifdef FEAT_FOLDING
1216 (char_u *)VAR_WIN, PV_FEN,
1217 {(char_u *)TRUE, (char_u *)0L}
1218#else
1219 (char_u *)NULL, PV_NONE,
1220 {(char_u *)NULL, (char_u *)0L}
1221#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001222 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001223 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1224#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1225 (char_u *)VAR_WIN, PV_FDE,
1226 {(char_u *)"0", (char_u *)NULL}
1227#else
1228 (char_u *)NULL, PV_NONE,
1229 {(char_u *)NULL, (char_u *)0L}
1230#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001231 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001233#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001235 {(char_u *)"#", (char_u *)NULL}
1236#else
1237 (char_u *)NULL, PV_NONE,
1238 {(char_u *)NULL, (char_u *)0L}
1239#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001240 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001242#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001244 {(char_u *)0L, (char_u *)0L}
1245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)NULL, (char_u *)0L}
1248#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001249 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001250 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001251#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 {(char_u *)-1L, (char_u *)0L}
1254#else
1255 (char_u *)NULL, PV_NONE,
1256 {(char_u *)NULL, (char_u *)0L}
1257#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001258 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001260 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001261#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001264#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 (char_u *)NULL, PV_NONE,
1266 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001268 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001269 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1270#ifdef FEAT_FOLDING
1271 (char_u *)VAR_WIN, PV_FDM,
1272 {(char_u *)"manual", (char_u *)NULL}
1273#else
1274 (char_u *)NULL, PV_NONE,
1275 {(char_u *)NULL, (char_u *)0L}
1276#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001277 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001278 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1279#ifdef FEAT_FOLDING
1280 (char_u *)VAR_WIN, PV_FML,
1281 {(char_u *)1L, (char_u *)0L}
1282#else
1283 (char_u *)NULL, PV_NONE,
1284 {(char_u *)NULL, (char_u *)0L}
1285#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001286 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001287 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1288#ifdef FEAT_FOLDING
1289 (char_u *)VAR_WIN, PV_FDN,
1290 {(char_u *)20L, (char_u *)0L}
1291#else
1292 (char_u *)NULL, PV_NONE,
1293 {(char_u *)NULL, (char_u *)0L}
1294#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001295 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001296 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1297#ifdef FEAT_FOLDING
1298 (char_u *)&p_fdo, PV_NONE,
1299 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1300 (char_u *)0L}
1301#else
1302 (char_u *)NULL, PV_NONE,
1303 {(char_u *)NULL, (char_u *)0L}
1304#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001305 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001306 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1307#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1308 (char_u *)VAR_WIN, PV_FDT,
1309 {(char_u *)"foldtext()", (char_u *)NULL}
1310#else
1311 (char_u *)NULL, PV_NONE,
1312 {(char_u *)NULL, (char_u *)0L}
1313#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001314 SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001315 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001316#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001317 (char_u *)&p_fex, PV_FEX,
1318 {(char_u *)"", (char_u *)0L}
1319#else
1320 (char_u *)NULL, PV_NONE,
1321 {(char_u *)0L, (char_u *)0L}
1322#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001323 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1325 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001326 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001327 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001328 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1329 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001331 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001333 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001334 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001335 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1336#ifdef HAVE_FSYNC
1337 (char_u *)&p_fs, PV_NONE,
1338 {(char_u *)TRUE, (char_u *)0L}
1339#else
1340 (char_u *)NULL, PV_NONE,
1341 {(char_u *)FALSE, (char_u *)0L}
1342#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001343 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1345 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001346 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {"graphic", "gr", P_BOOL|P_VI_DEF,
1348 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001349 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001350 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351#ifdef FEAT_QUICKFIX
1352 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001353 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354#else
1355 (char_u *)NULL, PV_NONE,
1356 {(char_u *)NULL, (char_u *)0L}
1357#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001358 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1360#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001361 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {
1363# ifdef WIN3264
1364 /* may be changed to "grep -n" in os_win32.c */
1365 (char_u *)"findstr /n",
1366# else
1367# ifdef UNIX
1368 /* Add an extra file name so that grep will always
1369 * insert a file name in the match line. */
1370 (char_u *)"grep -n $* /dev/null",
1371# else
1372# ifdef VMS
1373 (char_u *)"SEARCH/NUMBERS ",
1374# else
1375 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376# endif
1377# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001384 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001385 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#ifdef CURSOR_SHAPE
1387 (char_u *)&p_guicursor, PV_NONE,
1388 {
1389# ifdef FEAT_GUI
1390 (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 +01001391# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1393# endif
1394 (char_u *)0L}
1395#else
1396 (char_u *)NULL, PV_NONE,
1397 {(char_u *)NULL, (char_u *)0L}
1398#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001399 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001400 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401#ifdef FEAT_GUI
1402 (char_u *)&p_guifont, PV_NONE,
1403 {(char_u *)"", (char_u *)0L}
1404#else
1405 (char_u *)NULL, PV_NONE,
1406 {(char_u *)NULL, (char_u *)0L}
1407#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001408 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001409 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1411 (char_u *)&p_guifontset, PV_NONE,
1412 {(char_u *)"", (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)NULL, (char_u *)0L}
1416#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001417 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001418 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1420 (char_u *)&p_guifontwide, 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 Moolenaarf29c1c62018-09-10 21:05:02 +02001426 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001428#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 (char_u *)&p_ghr, PV_NONE,
1430#else
1431 (char_u *)NULL, PV_NONE,
1432#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001433 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001435#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001437# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001438 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001439# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001440 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441# endif
1442#else
1443 (char_u *)NULL, PV_NONE,
1444 {(char_u *)NULL, (char_u *)0L}
1445#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001446 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 {"guipty", NULL, P_BOOL|P_VI_DEF,
1448#if defined(FEAT_GUI)
1449 (char_u *)&p_guipty, PV_NONE,
1450#else
1451 (char_u *)NULL, PV_NONE,
1452#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001453 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001454 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001455#if defined(FEAT_GUI_TABLINE)
1456 (char_u *)&p_gtl, PV_NONE,
1457 {(char_u *)"", (char_u *)0L}
1458#else
1459 (char_u *)NULL, PV_NONE,
1460 {(char_u *)NULL, (char_u *)0L}
1461#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001462 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001463 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001464#if defined(FEAT_GUI_TABLINE)
1465 (char_u *)&p_gtt, PV_NONE,
1466 {(char_u *)"", (char_u *)0L}
1467#else
1468 (char_u *)NULL, PV_NONE,
1469 {(char_u *)NULL, (char_u *)0L}
1470#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001471 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1473 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001474 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001475 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1476 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001478 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001481 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001482 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483#ifdef FEAT_MULTI_LANG
1484 (char_u *)&p_hlg, PV_NONE,
1485 {(char_u *)"", (char_u *)0L}
1486#else
1487 (char_u *)NULL, PV_NONE,
1488 {(char_u *)0L, (char_u *)0L}
1489#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001490 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"hidden", "hid", P_BOOL|P_VI_DEF,
1492 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001493 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001494 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001497 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {"history", "hi", P_NUM|P_VIM,
1499 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001500 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1502#ifdef FEAT_RIGHTLEFT
1503 (char_u *)&p_hkmap, PV_NONE,
1504#else
1505 (char_u *)NULL, PV_NONE,
1506#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001507 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1509#ifdef FEAT_RIGHTLEFT
1510 (char_u *)&p_hkmapp, PV_NONE,
1511#else
1512 (char_u *)NULL, PV_NONE,
1513#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001514 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1516 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001517 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 {"icon", NULL, P_BOOL|P_VI_DEF,
1519#ifdef FEAT_TITLE
1520 (char_u *)&p_icon, PV_NONE,
1521#else
1522 (char_u *)NULL, PV_NONE,
1523#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001524 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {"iconstring", NULL, P_STRING|P_VI_DEF,
1526#ifdef FEAT_TITLE
1527 (char_u *)&p_iconstring, PV_NONE,
1528#else
1529 (char_u *)NULL, PV_NONE,
1530#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001531 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1533 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001534 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001535 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001536#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001537 (char_u *)&p_imaf, PV_NONE,
1538 {(char_u *)"", (char_u *)NULL}
1539# else
1540 (char_u *)NULL, PV_NONE,
1541 {(char_u *)NULL, (char_u *)0L}
1542# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001543 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001545#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 (char_u *)&p_imak, PV_NONE,
1547#else
1548 (char_u *)NULL, PV_NONE,
1549#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001550 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001552#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 (char_u *)&p_imcmdline, PV_NONE,
1554#else
1555 (char_u *)NULL, PV_NONE,
1556#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001557 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001559#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001560 (char_u *)&p_imdisable, PV_NONE,
1561#else
1562 (char_u *)NULL, PV_NONE,
1563#endif
1564#ifdef __sgi
1565 {(char_u *)TRUE, (char_u *)0L}
1566#else
1567 {(char_u *)FALSE, (char_u *)0L}
1568#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001569 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 {"iminsert", "imi", P_NUM|P_VI_DEF,
1571 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001573 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 {"imsearch", "ims", P_NUM|P_VI_DEF,
1575 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001576 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001577 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001578 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001579#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001580 (char_u *)&p_imsf, PV_NONE,
1581 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001582#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001583 (char_u *)NULL, PV_NONE,
1584 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001585#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001586 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001587 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1588#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1589 (char_u *)&p_imst, PV_NONE,
1590 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1591#else
1592 (char_u *)NULL, PV_NONE,
1593 {(char_u *)0L, (char_u *)0L}
1594#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001595 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1597#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001598 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1600#else
1601 (char_u *)NULL, PV_NONE,
1602 {(char_u *)0L, (char_u *)0L}
1603#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001604 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1606#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1607 (char_u *)&p_inex, PV_INEX,
1608 {(char_u *)"", (char_u *)0L}
1609#else
1610 (char_u *)NULL, PV_NONE,
1611 {(char_u *)0L, (char_u *)0L}
1612#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001613 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1615 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001616 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1618#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1619 (char_u *)&p_inde, PV_INDE,
1620 {(char_u *)"", (char_u *)0L}
1621#else
1622 (char_u *)NULL, PV_NONE,
1623 {(char_u *)0L, (char_u *)0L}
1624#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001625 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001626 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1628 (char_u *)&p_indk, PV_INDK,
1629 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1630#else
1631 (char_u *)NULL, PV_NONE,
1632 {(char_u *)0L, (char_u *)0L}
1633#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001634 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"infercase", "inf", P_BOOL|P_VI_DEF,
1636 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001637 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1639 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001640 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1642 (char_u *)&p_isf, PV_NONE,
1643 {
1644#ifdef BACKSLASH_IN_FILENAME
1645 /* Excluded are: & and ^ are special in cmd.exe
1646 * ( and ) are used in text separating fnames */
1647 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1648#else
1649# ifdef AMIGA
1650 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1651# else
1652# ifdef VMS
1653 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1654# else /* UNIX et al. */
1655# ifdef EBCDIC
1656 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1657# else
1658 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1659# endif
1660# endif
1661# endif
1662#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001663 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1665 (char_u *)&p_isi, PV_NONE,
1666 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001667#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 (char_u *)"@,48-57,_,128-167,224-235",
1669#else
1670# ifdef EBCDIC
1671 /* TODO: EBCDIC Check this! @ == isalpha()*/
1672 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1673 "112-120,128,140-142,156,158,172,"
1674 "174,186,191,203-207,219-225,235-239,"
1675 "251-254",
1676# else
1677 (char_u *)"@,48-57,_,192-255",
1678# endif
1679#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001680 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1682 (char_u *)&p_isk, PV_ISK,
1683 {
1684#ifdef EBCDIC
1685 (char_u *)"@,240-249,_",
1686 /* TODO: EBCDIC Check this! @ == isalpha()*/
1687 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1688 "112-120,128,140-142,156,158,172,"
1689 "174,186,191,203-207,219-225,235-239,"
1690 "251-254",
1691#else
1692 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001693# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 (char_u *)"@,48-57,_,128-167,224-235"
1695# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001696 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697# endif
1698#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001699 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1701 (char_u *)&p_isp, PV_NONE,
1702 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001703#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704 (char_u *)"@,~-255",
1705#else
1706# ifdef EBCDIC
1707 /* all chars above 63 are printable */
1708 (char_u *)"63-255",
1709# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001710 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711# endif
1712#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001713 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1715 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001716 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1718#ifdef FEAT_CRYPT
1719 (char_u *)&p_key, PV_KEY,
1720 {(char_u *)"", (char_u *)0L}
1721#else
1722 (char_u *)NULL, PV_NONE,
1723 {(char_u *)0L, (char_u *)0L}
1724#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001725 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001726 {"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 +00001727#ifdef FEAT_KEYMAP
1728 (char_u *)&p_keymap, PV_KMAP,
1729 {(char_u *)"", (char_u *)0L}
1730#else
1731 (char_u *)NULL, PV_NONE,
1732 {(char_u *)"", (char_u *)0L}
1733#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001734 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001735 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001737 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001739 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001741#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 (char_u *)":help",
1743#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001744# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001746# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001747# ifdef USEMAN_S
1748 (char_u *)"man -s",
1749# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001751# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001752# endif
1753#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001754 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001755 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756#ifdef FEAT_LANGMAP
1757 (char_u *)&p_langmap, PV_NONE,
1758 {(char_u *)"", /* unmatched } */
1759#else
1760 (char_u *)NULL, PV_NONE,
1761 {(char_u *)NULL,
1762#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001763 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001764 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1766 (char_u *)&p_lm, PV_NONE,
1767#else
1768 (char_u *)NULL, PV_NONE,
1769#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001770 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001771 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1772#ifdef FEAT_LANGMAP
1773 (char_u *)&p_lnr, PV_NONE,
1774#else
1775 (char_u *)NULL, PV_NONE,
1776#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001777 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001778 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1779#ifdef FEAT_LANGMAP
1780 (char_u *)&p_lrm, PV_NONE,
1781#else
1782 (char_u *)NULL, PV_NONE,
1783#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001784 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001787 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1789 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001790 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1792#ifdef FEAT_LINEBREAK
1793 (char_u *)VAR_WIN, PV_LBR,
1794#else
1795 (char_u *)NULL, PV_NONE,
1796#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001797 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1799 (char_u *)&Rows, PV_NONE,
1800 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001801#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802 (char_u *)25L,
1803#else
1804 (char_u *)24L,
1805#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001806 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1808#ifdef FEAT_GUI
1809 (char_u *)&p_linespace, PV_NONE,
1810#else
1811 (char_u *)NULL, PV_NONE,
1812#endif
1813#ifdef FEAT_GUI_W32
1814 {(char_u *)1L, (char_u *)0L}
1815#else
1816 {(char_u *)0L, (char_u *)0L}
1817#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001818 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 {"lisp", NULL, P_BOOL|P_VI_DEF,
1820#ifdef FEAT_LISP
1821 (char_u *)&p_lisp, PV_LISP,
1822#else
1823 (char_u *)NULL, PV_NONE,
1824#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001825 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001826 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001828 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1830#else
1831 (char_u *)NULL, PV_NONE,
1832 {(char_u *)"", (char_u *)0L}
1833#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001834 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1836 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001837 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001838 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001840 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1842 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001843 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001844 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001845#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001846 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001847 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001848#else
1849 (char_u *)NULL, PV_NONE,
1850 {(char_u *)"", (char_u *)0L}
1851#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001852 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001853 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001854#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001855 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001856 {(char_u *)TRUE, (char_u *)0L}
1857#else
1858 (char_u *)NULL, PV_NONE,
1859 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001860#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001861 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {"magic", NULL, P_BOOL|P_VI_DEF,
1863 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001864 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001865 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866#ifdef FEAT_QUICKFIX
1867 (char_u *)&p_mef, PV_NONE,
1868 {(char_u *)"", (char_u *)0L}
1869#else
1870 (char_u *)NULL, PV_NONE,
1871 {(char_u *)NULL, (char_u *)0L}
1872#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001873 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001874 {"makeencoding","menc", P_STRING|P_VI_DEF,
1875#ifdef FEAT_MBYTE
1876 (char_u *)&p_menc, PV_MENC,
1877 {(char_u *)"", (char_u *)0L}
1878#else
1879 (char_u *)NULL, PV_NONE,
1880 {(char_u *)0L, (char_u *)0L}
1881#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001882 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1884#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001885 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886# ifdef VMS
1887 {(char_u *)"MMS", (char_u *)0L}
1888# else
1889 {(char_u *)"make", (char_u *)0L}
1890# endif
1891#else
1892 (char_u *)NULL, PV_NONE,
1893 {(char_u *)NULL, (char_u *)0L}
1894#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001895 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001896 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"matchtime", "mat", P_NUM|P_VI_DEF,
1901 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001902 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001903 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001904#ifdef FEAT_MBYTE
1905 (char_u *)&p_mco, PV_NONE,
1906#else
1907 (char_u *)NULL, PV_NONE,
1908#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001909 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1911#ifdef FEAT_EVAL
1912 (char_u *)&p_mfd, PV_NONE,
1913#else
1914 (char_u *)NULL, PV_NONE,
1915#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001916 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1918 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001919 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"maxmem", "mm", P_NUM|P_VI_DEF,
1921 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001923 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001924 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1925 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001926 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1928 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001929 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001930 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"menuitems", "mis", P_NUM|P_VI_DEF,
1932#ifdef FEAT_MENU
1933 (char_u *)&p_mis, PV_NONE,
1934#else
1935 (char_u *)NULL, PV_NONE,
1936#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001937 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"mesg", NULL, P_BOOL|P_VI_DEF,
1939 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001940 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001941 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001942#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001943 (char_u *)&p_msm, PV_NONE,
1944 {(char_u *)"460000,2000,500", (char_u *)0L}
1945#else
1946 (char_u *)NULL, PV_NONE,
1947 {(char_u *)0L, (char_u *)0L}
1948#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001949 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"modeline", "ml", P_BOOL|P_VIM,
1951 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001952 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"modelines", "mls", P_NUM|P_VI_DEF,
1954 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001955 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1957 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001958 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1960 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001961 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"more", NULL, P_BOOL|P_VIM,
1963 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001964 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1966 (char_u *)&p_mouse, PV_NONE,
1967 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001968#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001969 (char_u *)"a",
1970#else
1971 (char_u *)"",
1972#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001973 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1975#ifdef FEAT_GUI
1976 (char_u *)&p_mousef, PV_NONE,
1977#else
1978 (char_u *)NULL, PV_NONE,
1979#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001980 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1982#ifdef FEAT_GUI
1983 (char_u *)&p_mh, PV_NONE,
1984#else
1985 (char_u *)NULL, PV_NONE,
1986#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001987 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1989 (char_u *)&p_mousem, PV_NONE,
1990 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001991#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 (char_u *)"popup",
1993#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001994# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 (char_u *)"popup_setpos",
1996# else
1997 (char_u *)"extend",
1998# endif
1999#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002000 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002001 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002#ifdef FEAT_MOUSESHAPE
2003 (char_u *)&p_mouseshape, PV_NONE,
2004 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2005#else
2006 (char_u *)NULL, PV_NONE,
2007 {(char_u *)NULL, (char_u *)0L}
2008#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002009 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2011 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002012 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002013 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2014#if defined(DYNAMIC_MZSCHEME)
2015 (char_u *)&p_mzschemedll, PV_NONE,
2016 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2017#else
2018 (char_u *)NULL, PV_NONE,
2019 {(char_u *)"", (char_u *)0L}
2020#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002021 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002022 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2023#if defined(DYNAMIC_MZSCHEME)
2024 (char_u *)&p_mzschemegcdll, PV_NONE,
2025 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2026#else
2027 (char_u *)NULL, PV_NONE,
2028 {(char_u *)"", (char_u *)0L}
2029#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002030 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002031 {"mzquantum", "mzq", P_NUM,
2032#ifdef FEAT_MZSCHEME
2033 (char_u *)&p_mzq, PV_NONE,
2034#else
2035 (char_u *)NULL, PV_NONE,
2036#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002037 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038 {"novice", NULL, P_BOOL|P_VI_DEF,
2039 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002040 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002041 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002043 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002044 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2046 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002047 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002048 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2049#ifdef FEAT_LINEBREAK
2050 (char_u *)VAR_WIN, PV_NUW,
2051#else
2052 (char_u *)NULL, PV_NONE,
2053#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002054 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002055 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002056#ifdef FEAT_COMPL_FUNC
2057 (char_u *)&p_ofu, PV_OFU,
2058 {(char_u *)"", (char_u *)0L}
2059#else
2060 (char_u *)NULL, PV_NONE,
2061 {(char_u *)0L, (char_u *)0L}
2062#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002063 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"open", NULL, P_BOOL|P_VI_DEF,
2065 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002066 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002067 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002068#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002069 (char_u *)&p_odev, PV_NONE,
2070#else
2071 (char_u *)NULL, PV_NONE,
2072#endif
2073 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002074 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002075 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2076 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002077 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"optimize", "opt", P_BOOL|P_VI_DEF,
2079 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002080 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002083 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002084 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2085 |P_SECURE,
2086 (char_u *)&p_pp, PV_NONE,
2087 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002088 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 {"paragraphs", "para", P_STRING|P_VI_DEF,
2090 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002091 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002092 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002093 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002095 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2097 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002098 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2100#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2101 (char_u *)&p_pex, PV_NONE,
2102 {(char_u *)"", (char_u *)0L}
2103#else
2104 (char_u *)NULL, PV_NONE,
2105 {(char_u *)0L, (char_u *)0L}
2106#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002107 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002108 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002110 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002112 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002114#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 (char_u *)".,,",
2116#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002119 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002120 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002121#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002122 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002123 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002124#else
2125 (char_u *)NULL, PV_NONE,
2126 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002127#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002128 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2130 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002131 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002132 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002133#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 (char_u *)&p_pvh, PV_NONE,
2135#else
2136 (char_u *)NULL, PV_NONE,
2137#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002138 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002140#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 (char_u *)VAR_WIN, PV_PVW,
2142#else
2143 (char_u *)NULL, PV_NONE,
2144#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002145 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002146 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147#ifdef FEAT_PRINTER
2148 (char_u *)&p_pdev, PV_NONE,
2149 {(char_u *)"", (char_u *)0L}
2150#else
2151 (char_u *)NULL, PV_NONE,
2152 {(char_u *)NULL, (char_u *)0L}
2153#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002154 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 {"printencoding", "penc", P_STRING|P_VI_DEF,
2156#ifdef FEAT_POSTSCRIPT
2157 (char_u *)&p_penc, PV_NONE,
2158 {(char_u *)"", (char_u *)0L}
2159#else
2160 (char_u *)NULL, PV_NONE,
2161 {(char_u *)NULL, (char_u *)0L}
2162#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002163 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002164 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165#ifdef FEAT_POSTSCRIPT
2166 (char_u *)&p_pexpr, PV_NONE,
2167 {(char_u *)"", (char_u *)0L}
2168#else
2169 (char_u *)NULL, PV_NONE,
2170 {(char_u *)NULL, (char_u *)0L}
2171#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002172 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 {"printfont", "pfn", P_STRING|P_VI_DEF,
2174#ifdef FEAT_PRINTER
2175 (char_u *)&p_pfn, PV_NONE,
2176 {
2177# ifdef MSWIN
2178 (char_u *)"Courier_New:h10",
2179# else
2180 (char_u *)"courier",
2181# endif
2182 (char_u *)0L}
2183#else
2184 (char_u *)NULL, PV_NONE,
2185 {(char_u *)NULL, (char_u *)0L}
2186#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002187 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2189#ifdef FEAT_PRINTER
2190 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002191 /* untranslated to avoid problems when 'encoding'
2192 * is changed */
2193 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194#else
2195 (char_u *)NULL, PV_NONE,
2196 {(char_u *)NULL, (char_u *)0L}
2197#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002198 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002199 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2200#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2201 (char_u *)&p_pmcs, PV_NONE,
2202 {(char_u *)"", (char_u *)0L}
2203#else
2204 (char_u *)NULL, PV_NONE,
2205 {(char_u *)NULL, (char_u *)0L}
2206#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002207 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002208 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2209#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2210 (char_u *)&p_pmfn, PV_NONE,
2211 {(char_u *)"", (char_u *)0L}
2212#else
2213 (char_u *)NULL, PV_NONE,
2214 {(char_u *)NULL, (char_u *)0L}
2215#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002216 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002217 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218#ifdef FEAT_PRINTER
2219 (char_u *)&p_popt, PV_NONE,
2220 {(char_u *)"", (char_u *)0L}
2221#else
2222 (char_u *)NULL, PV_NONE,
2223 {(char_u *)NULL, (char_u *)0L}
2224#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002225 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002227 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002228 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002229 {"pumheight", "ph", P_NUM|P_VI_DEF,
2230#ifdef FEAT_INS_EXPAND
2231 (char_u *)&p_ph, PV_NONE,
2232#else
2233 (char_u *)NULL, PV_NONE,
2234#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002235 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002236 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2237#ifdef FEAT_INS_EXPAND
2238 (char_u *)&p_pw, PV_NONE,
2239#else
2240 (char_u *)NULL, PV_NONE,
2241#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002242 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002243 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002244#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002245 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002246 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002247#else
2248 (char_u *)NULL, PV_NONE,
2249 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002250#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002251 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002252 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2253#if defined(FEAT_PYTHON3)
2254 (char_u *)&p_py3home, PV_NONE,
2255 {(char_u *)"", (char_u *)0L}
2256#else
2257 (char_u *)NULL, PV_NONE,
2258 {(char_u *)NULL, (char_u *)0L}
2259#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002260 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002261 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002262#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002263 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002264 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002265#else
2266 (char_u *)NULL, PV_NONE,
2267 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002268#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002269 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002270 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2271#if defined(FEAT_PYTHON)
2272 (char_u *)&p_pyhome, PV_NONE,
2273 {(char_u *)"", (char_u *)0L}
2274#else
2275 (char_u *)NULL, PV_NONE,
2276 {(char_u *)NULL, (char_u *)0L}
2277#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002278 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002279 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2280#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2281 (char_u *)&p_pyx, PV_NONE,
2282#else
2283 (char_u *)NULL, PV_NONE,
2284#endif
2285 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002286 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002287 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2288#ifdef FEAT_TEXTOBJ
2289 (char_u *)&p_qe, PV_QE,
2290 {(char_u *)"\\", (char_u *)0L}
2291#else
2292 (char_u *)NULL, PV_NONE,
2293 {(char_u *)NULL, (char_u *)0L}
2294#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002295 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2297 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002298 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"redraw", NULL, P_BOOL|P_VI_DEF,
2300 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002301 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002302 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2303#ifdef FEAT_RELTIME
2304 (char_u *)&p_rdt, PV_NONE,
2305#else
2306 (char_u *)NULL, PV_NONE,
2307#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002308 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002309 {"regexpengine", "re", P_NUM|P_VI_DEF,
2310 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002311 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002312 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2313 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002314 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"remap", NULL, P_BOOL|P_VI_DEF,
2316 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002317 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002318 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002319#ifdef FEAT_RENDER_OPTIONS
2320 (char_u *)&p_rop, PV_NONE,
2321 {(char_u *)"", (char_u *)0L}
2322#else
2323 (char_u *)NULL, PV_NONE,
2324 {(char_u *)NULL, (char_u *)0L}
2325#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002326 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"report", NULL, P_NUM|P_VI_DEF,
2328 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002329 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2331#ifdef WIN3264
2332 (char_u *)&p_rs, PV_NONE,
2333#else
2334 (char_u *)NULL, PV_NONE,
2335#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002336 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2338#ifdef FEAT_RIGHTLEFT
2339 (char_u *)&p_ri, PV_NONE,
2340#else
2341 (char_u *)NULL, PV_NONE,
2342#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002343 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2345#ifdef FEAT_RIGHTLEFT
2346 (char_u *)VAR_WIN, PV_RL,
2347#else
2348 (char_u *)NULL, PV_NONE,
2349#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002350 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2352#ifdef FEAT_RIGHTLEFT
2353 (char_u *)VAR_WIN, PV_RLC,
2354 {(char_u *)"search", (char_u *)NULL}
2355#else
2356 (char_u *)NULL, PV_NONE,
2357 {(char_u *)NULL, (char_u *)0L}
2358#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002359 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002360 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002361#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002362 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002363 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002364#else
2365 (char_u *)NULL, PV_NONE,
2366 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002367#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002368 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2370#ifdef FEAT_CMDL_INFO
2371 (char_u *)&p_ru, PV_NONE,
2372#else
2373 (char_u *)NULL, PV_NONE,
2374#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002375 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2377#ifdef FEAT_STL_OPT
2378 (char_u *)&p_ruf, PV_NONE,
2379#else
2380 (char_u *)NULL, PV_NONE,
2381#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002382 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002383 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2384 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002386 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002387 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2389 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002390 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002393 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2395 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002396 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2398 (char_u *)&p_so, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002399 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002400 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)&p_sbo, PV_NONE,
2402 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002403 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"sections", "sect", P_STRING|P_VI_DEF,
2405 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002407 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2409 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002410 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002414 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002415 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002417 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002418 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419#ifdef FEAT_SESSION
2420 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002421 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 (char_u *)0L}
2423#else
2424 (char_u *)NULL, PV_NONE,
2425 {(char_u *)0L, (char_u *)0L}
2426#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002427 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2429 (char_u *)&p_sh, PV_NONE,
2430 {
2431#ifdef VMS
2432 (char_u *)"-",
2433#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002434# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002436# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438# endif
2439#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002440 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2442 (char_u *)&p_shcf, PV_NONE,
2443 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002444#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 (char_u *)"/c",
2446#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002449 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2451#ifdef FEAT_QUICKFIX
2452 (char_u *)&p_sp, PV_NONE,
2453 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002454#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456#else
2457 (char_u *)">",
2458#endif
2459 (char_u *)0L}
2460#else
2461 (char_u *)NULL, PV_NONE,
2462 {(char_u *)0L, (char_u *)0L}
2463#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002464 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2466 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002467 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2469 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002470 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2472#ifdef BACKSLASH_IN_FILENAME
2473 (char_u *)&p_ssl, PV_NONE,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002477 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002478 {"shelltemp", "stmp", P_BOOL,
2479 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002480 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 {"shelltype", "st", P_NUM|P_VI_DEF,
2482#ifdef AMIGA
2483 (char_u *)&p_st, PV_NONE,
2484#else
2485 (char_u *)NULL, PV_NONE,
2486#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002487 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2489 (char_u *)&p_sxq, PV_NONE,
2490 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002491#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 (char_u *)"\"",
2493#else
2494 (char_u *)"",
2495#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002496 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002497 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2498 (char_u *)&p_sxe, PV_NONE,
2499 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002500#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002501 (char_u *)"\"&|<>()@^",
2502#else
2503 (char_u *)"",
2504#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002505 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2507 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002508 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2510 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002511 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2513 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)"", (char_u *)"filnxtToO"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002515 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002518 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2520#ifdef FEAT_LINEBREAK
2521 (char_u *)&p_sbr, PV_NONE,
2522#else
2523 (char_u *)NULL, PV_NONE,
2524#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002525 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"showcmd", "sc", P_BOOL|P_VIM,
2527#ifdef FEAT_CMDL_INFO
2528 (char_u *)&p_sc, PV_NONE,
2529#else
2530 (char_u *)NULL, PV_NONE,
2531#endif
2532 {(char_u *)FALSE,
2533#ifdef UNIX
2534 (char_u *)FALSE
2535#else
2536 (char_u *)TRUE
2537#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002538 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2540 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002541 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2543 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002544 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 {"showmode", "smd", P_BOOL|P_VIM,
2546 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002547 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002548 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002549 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002550 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2552 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002553 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2555 (char_u *)&p_siso, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002556 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002557 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2558#ifdef FEAT_SIGNS
2559 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002560 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)NULL, (char_u *)0L}
2564#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002565 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2567 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002568 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2570 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002571 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2573#ifdef FEAT_SMARTINDENT
2574 (char_u *)&p_si, PV_SI,
2575#else
2576 (char_u *)NULL, PV_NONE,
2577#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002578 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2580 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002581 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2583 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002584 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2586 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002587 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002588 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002589#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002590 (char_u *)VAR_WIN, PV_SPELL,
2591#else
2592 (char_u *)NULL, PV_NONE,
2593#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002594 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002595 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002596#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002597 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002598 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002603 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002604 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2605 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002606#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002607 (char_u *)&p_spf, PV_SPF,
2608 {(char_u *)"", (char_u *)0L}
2609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002613 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002614 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2615 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002616#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002617 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002618 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002619#else
2620 (char_u *)NULL, PV_NONE,
2621 {(char_u *)0L, (char_u *)0L}
2622#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002623 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002624 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002625#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002626 (char_u *)&p_sps, PV_NONE,
2627 {(char_u *)"best", (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002632 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002635 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002638 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2640 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2643#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002644 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645#else
2646 (char_u *)NULL, PV_NONE,
2647#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002648 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002649 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 (char_u *)&p_su, PV_NONE,
2651 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002652 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002653 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002654#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 (char_u *)&p_sua, PV_SUA,
2656 {(char_u *)"", (char_u *)0L}
2657#else
2658 (char_u *)NULL, PV_NONE,
2659 {(char_u *)0L, (char_u *)0L}
2660#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002661 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2663 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002664 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"swapsync", "sws", P_STRING|P_VI_DEF,
2666 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002667 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002668 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002670 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002671 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2672#ifdef FEAT_SYN_HL
2673 (char_u *)&p_smc, PV_SMC,
2674 {(char_u *)3000L, (char_u *)0L}
2675#else
2676 (char_u *)NULL, PV_NONE,
2677 {(char_u *)0L, (char_u *)0L}
2678#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002679 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002680 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681#ifdef FEAT_SYN_HL
2682 (char_u *)&p_syn, PV_SYN,
2683 {(char_u *)"", (char_u *)0L}
2684#else
2685 (char_u *)NULL, PV_NONE,
2686 {(char_u *)0L, (char_u *)0L}
2687#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002688 SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002689 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2690#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002691 (char_u *)&p_tal, PV_NONE,
2692#else
2693 (char_u *)NULL, PV_NONE,
2694#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002695 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002696 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002697 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002698 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2700 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002701 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2703 (char_u *)&p_tbs, PV_NONE,
2704#ifdef VMS /* binary searching doesn't appear to work on VMS */
2705 {(char_u *)0L, (char_u *)0L}
2706#else
2707 {(char_u *)TRUE, (char_u *)0L}
2708#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002709 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002710 {"tagcase", "tc", P_STRING|P_VIM,
2711 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002712 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"taglength", "tl", P_NUM|P_VI_DEF,
2714 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002715 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"tagrelative", "tr", P_BOOL|P_VIM,
2717 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002718 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002719 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002720 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {
2722#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2723 (char_u *)"./tags,./TAGS,tags,TAGS",
2724#else
2725 (char_u *)"./tags,tags",
2726#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002727 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2729 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002730 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002731 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002732#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002733 (char_u *)&p_tcldll, PV_NONE,
2734 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002735#else
2736 (char_u *)NULL, PV_NONE,
2737 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002738#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002739 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2741 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002742 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2744#ifdef FEAT_ARABIC
2745 (char_u *)&p_tbidi, PV_NONE,
2746#else
2747 (char_u *)NULL, PV_NONE,
2748#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002749 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2751#ifdef FEAT_MBYTE
2752 (char_u *)&p_tenc, PV_NONE,
2753 {(char_u *)"", (char_u *)0L}
2754#else
2755 (char_u *)NULL, PV_NONE,
2756 {(char_u *)0L, (char_u *)0L}
2757#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002758 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002759 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2760#ifdef FEAT_TERMGUICOLORS
2761 (char_u *)&p_tgc, PV_NONE,
2762 {(char_u *)FALSE, (char_u *)FALSE}
2763#else
2764 (char_u*)NULL, PV_NONE,
2765 {(char_u *)FALSE, (char_u *)FALSE}
2766#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002767 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002768 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2769#ifdef FEAT_TERMINAL
2770 (char_u *)VAR_WIN, PV_TWK,
2771 {(char_u *)"", (char_u *)NULL}
2772#else
2773 (char_u *)NULL, PV_NONE,
2774 {(char_u *)NULL, (char_u *)0L}
2775#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002776 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002777 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2778#ifdef FEAT_TERMINAL
2779 (char_u *)&p_twsl, PV_TWSL,
2780 {(char_u *)10000L, (char_u *)10000L}
2781#else
2782 (char_u *)NULL, PV_NONE,
2783 {(char_u *)NULL, (char_u *)0L}
2784#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002785 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002786 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2787#ifdef FEAT_TERMINAL
2788 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002789 {(char_u *)"", (char_u *)NULL}
2790#else
2791 (char_u *)NULL, PV_NONE,
2792 {(char_u *)NULL, (char_u *)0L}
2793#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002794 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 {"terse", NULL, P_BOOL|P_VI_DEF,
2796 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002797 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"textauto", "ta", P_BOOL|P_VIM,
2799 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002801 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2803 (char_u *)&p_tx, PV_TX,
2804 {
2805#ifdef USE_CRNL
2806 (char_u *)TRUE,
2807#else
2808 (char_u *)FALSE,
2809#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002810 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002811 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002813 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002814 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002816 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817#else
2818 (char_u *)NULL, PV_NONE,
2819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002820 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2822 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002823 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"timeout", "to", P_BOOL|P_VI_DEF,
2825 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002826 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2828 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002829 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"title", NULL, P_BOOL|P_VI_DEF,
2831#ifdef FEAT_TITLE
2832 (char_u *)&p_title, PV_NONE,
2833#else
2834 (char_u *)NULL, PV_NONE,
2835#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002836 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"titlelen", NULL, P_NUM|P_VI_DEF,
2838#ifdef FEAT_TITLE
2839 (char_u *)&p_titlelen, PV_NONE,
2840#else
2841 (char_u *)NULL, PV_NONE,
2842#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002843 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002844 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845#ifdef FEAT_TITLE
2846 (char_u *)&p_titleold, PV_NONE,
2847 {(char_u *)N_("Thanks for flying Vim"),
2848 (char_u *)0L}
2849#else
2850 (char_u *)NULL, PV_NONE,
2851 {(char_u *)0L, (char_u *)0L}
2852#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002853 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"titlestring", NULL, P_STRING|P_VI_DEF,
2855#ifdef FEAT_TITLE
2856 (char_u *)&p_titlestring, PV_NONE,
2857#else
2858 (char_u *)NULL, PV_NONE,
2859#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002860 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002861 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002862#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002865#else
2866 (char_u *)NULL, PV_NONE,
2867 {(char_u *)0L, (char_u *)0L}
2868#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002869 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002871#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002873 {(char_u *)"small", (char_u *)0L}
2874#else
2875 (char_u *)NULL, PV_NONE,
2876 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002878 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2880 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002881 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2883 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002884 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2886 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002887 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2889 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002890 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2892#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2893 (char_u *)&p_ttym, PV_NONE,
2894#else
2895 (char_u *)NULL, PV_NONE,
2896#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002897 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2899 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002900 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2902 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002903 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002904 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2905 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002906#ifdef FEAT_PERSISTENT_UNDO
2907 (char_u *)&p_udir, PV_NONE,
2908 {(char_u *)".", (char_u *)0L}
2909#else
2910 (char_u *)NULL, PV_NONE,
2911 {(char_u *)0L, (char_u *)0L}
2912#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002913 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002914 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2915#ifdef FEAT_PERSISTENT_UNDO
2916 (char_u *)&p_udf, PV_UDF,
2917#else
2918 (char_u *)NULL, PV_NONE,
2919#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002920 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002922 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002924#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 (char_u *)1000L,
2926#else
2927 (char_u *)100L,
2928#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002929 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002930 {"undoreload", "ur", P_NUM|P_VI_DEF,
2931 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002932 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 {"updatecount", "uc", P_NUM|P_VI_DEF,
2934 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002935 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"updatetime", "ut", P_NUM|P_VI_DEF,
2937 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002938 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002939 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2940#ifdef FEAT_VARTABS
2941 (char_u *)&p_vsts, PV_VSTS,
2942 {(char_u *)"", (char_u *)0L}
2943#else
2944 (char_u *)NULL, PV_NONE,
2945 {(char_u *)"", (char_u *)NULL}
2946#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002947 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002948 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2949#ifdef FEAT_VARTABS
2950 (char_u *)&p_vts, PV_VTS,
2951 {(char_u *)"", (char_u *)0L}
2952#else
2953 (char_u *)NULL, PV_NONE,
2954 {(char_u *)"", (char_u *)NULL}
2955#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002956 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 {"verbose", "vbs", P_NUM|P_VI_DEF,
2958 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002959 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002960 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2961 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002962 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2964#ifdef FEAT_SESSION
2965 (char_u *)&p_vdir, PV_NONE,
2966 {(char_u *)DFLT_VDIR, (char_u *)0L}
2967#else
2968 (char_u *)NULL, PV_NONE,
2969 {(char_u *)0L, (char_u *)0L}
2970#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002971 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002972 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973#ifdef FEAT_SESSION
2974 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002975 {(char_u *)"folds,options,cursor,curdir",
2976 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977#else
2978 (char_u *)NULL, PV_NONE,
2979 {(char_u *)0L, (char_u *)0L}
2980#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002981 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002982 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983#ifdef FEAT_VIMINFO
2984 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002985#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002986 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987#else
2988# ifdef AMIGA
2989 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002990 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002992 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993# endif
2994#endif
2995#else
2996 (char_u *)NULL, PV_NONE,
2997 {(char_u *)0L, (char_u *)0L}
2998#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002999 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02003000 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
3001 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02003002#ifdef FEAT_VIMINFO
3003 (char_u *)&p_viminfofile, PV_NONE,
3004 {(char_u *)"", (char_u *)0L}
3005#else
3006 (char_u *)NULL, PV_NONE,
3007 {(char_u *)0L, (char_u *)0L}
3008#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003009 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003010 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
3011 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012#ifdef FEAT_VIRTUALEDIT
3013 (char_u *)&p_ve, PV_NONE,
3014 {(char_u *)"", (char_u *)""}
3015#else
3016 (char_u *)NULL, PV_NONE,
3017 {(char_u *)0L, (char_u *)0L}
3018#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003019 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3021 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003022 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"w300", NULL, P_NUM|P_VI_DEF,
3024 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003025 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 {"w1200", NULL, P_NUM|P_VI_DEF,
3027 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003028 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"w9600", NULL, P_NUM|P_VI_DEF,
3030 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003031 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 {"warn", NULL, P_BOOL|P_VI_DEF,
3033 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003034 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3036 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003037 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003038 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003040 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 {"wildchar", "wc", P_NUM|P_VIM,
3042 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003043 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003044 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003045 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003047 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003048 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049#ifdef FEAT_WILDIGN
3050 (char_u *)&p_wig, PV_NONE,
3051#else
3052 (char_u *)NULL, PV_NONE,
3053#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003054 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003055 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3056 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003057 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3059#ifdef FEAT_WILDMENU
3060 (char_u *)&p_wmnu, PV_NONE,
3061#else
3062 (char_u *)NULL, PV_NONE,
3063#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003064 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003065 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003067 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003068 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3069#ifdef FEAT_CMDL_COMPL
3070 (char_u *)&p_wop, PV_NONE,
3071 {(char_u *)"", (char_u *)0L}
3072#else
3073 (char_u *)NULL, PV_NONE,
3074 {(char_u *)NULL, (char_u *)0L}
3075#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003076 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3078#ifdef FEAT_WAK
3079 (char_u *)&p_wak, PV_NONE,
3080 {(char_u *)"menu", (char_u *)0L}
3081#else
3082 (char_u *)NULL, PV_NONE,
3083 {(char_u *)NULL, (char_u *)0L}
3084#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003085 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003087 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003088 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003091 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003094 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003095 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003096 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003097 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003100 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003103 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003104 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003105#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003106 (char_u *)&p_winptydll, PV_NONE, {
3107# ifdef _WIN64
3108 (char_u *)"winpty64.dll",
3109# else
3110 (char_u *)"winpty32.dll",
3111# endif
3112 (char_u *)0L}
3113#else
3114 (char_u *)NULL, PV_NONE,
3115 {(char_u *)0L, (char_u *)0L}
3116#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003117 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003120 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3122 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003123 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3125 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003126 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3128 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003129 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 {"write", NULL, P_BOOL|P_VI_DEF,
3131 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003132 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 {"writeany", "wa", P_BOOL|P_VI_DEF,
3134 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003135 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3137 (char_u *)&p_wb, PV_NONE,
3138 {
3139#ifdef FEAT_WRITEBACKUP
3140 (char_u *)TRUE,
3141#else
3142 (char_u *)FALSE,
3143#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003144 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 {"writedelay", "wd", P_NUM|P_VI_DEF,
3146 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003147 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148
3149/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003150#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003152 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153
3154 p_term("t_AB", T_CAB)
3155 p_term("t_AF", T_CAF)
3156 p_term("t_AL", T_CAL)
3157 p_term("t_al", T_AL)
3158 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003159 p_term("t_BE", T_BE)
3160 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 p_term("t_cd", T_CD)
3162 p_term("t_ce", T_CE)
3163 p_term("t_cl", T_CL)
3164 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003165 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_Co", T_CCO)
3167 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003168 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_da", T_DA)
3172 p_term("t_db", T_DB)
3173 p_term("t_DL", T_CDL)
3174 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003175 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003178 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_IE", T_CIE)
3180 p_term("t_IS", T_CIS)
3181 p_term("t_ke", T_KE)
3182 p_term("t_ks", T_KS)
3183 p_term("t_le", T_LE)
3184 p_term("t_mb", T_MB)
3185 p_term("t_md", T_MD)
3186 p_term("t_me", T_ME)
3187 p_term("t_mr", T_MR)
3188 p_term("t_ms", T_MS)
3189 p_term("t_nd", T_ND)
3190 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003191 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003192 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003193 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003195 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003196 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003197 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198 p_term("t_RV", T_CRV)
3199 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003200 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003202 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003203 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003204 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003205 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003207 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003209 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003210 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211 p_term("t_te", T_TE)
3212 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003213 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003214 p_term("t_ts", T_TS)
3215 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 p_term("t_ue", T_UE)
3217 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003218 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 p_term("t_vb", T_VB)
3220 p_term("t_ve", T_VE)
3221 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003222 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 p_term("t_vs", T_VS)
3224 p_term("t_WP", T_CWP)
3225 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003226 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 p_term("t_xs", T_XS)
3228 p_term("t_ZH", T_CZH)
3229 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003230 p_term("t_8f", T_8F)
3231 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232
3233/* terminal key codes are not in here */
3234
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003235 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003236 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237};
3238
3239#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3240
3241#ifdef FEAT_MBYTE
3242static char *(p_ambw_values[]) = {"single", "double", NULL};
3243#endif
3244static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003245static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003247#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003248static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003249#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003250#ifdef FEAT_CMDL_COMPL
3251static char *(p_wop_values[]) = {"tagfile", NULL};
3252#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253#ifdef FEAT_WAK
3254static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3255#endif
3256static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3258static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260#ifdef FEAT_BROWSE
3261static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3262#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003264static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003266static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003267static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3269#ifdef FEAT_FOLDING
3270static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003271# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003273# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274 NULL};
3275static char *(p_fcl_values[]) = {"all", NULL};
3276#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003277#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003278static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003279#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003280#ifdef FEAT_SIGNS
3281static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static void set_option_default(int, int opt_flags, int compatible);
3285static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003286static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static char_u *term_bg_default(void);
3288static void did_set_option(int opt_idx, int opt_flags, int new_value);
3289static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003290#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003291static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static char_u *option_expand(int opt_idx, char_u *val);
3294static void didset_options(void);
3295static void didset_options2(void);
3296static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003297#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003298static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003299#else
3300# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3301#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static void set_string_option_global(int opt_idx, char_u **varp);
3303static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3304static 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);
3305static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003306#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003307static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003310static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003312#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003313static char_u *did_set_spell_option(int is_spellfile);
3314static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003315#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003316#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003317static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003318#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003319static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3320static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3321static void check_redraw(long_u flags);
3322static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003323static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003324static void showoptions(int all, int opt_flags);
3325static int optval_default(struct vimoption *, char_u *varp);
3326static void showoneopt(struct vimoption *, int opt_flags);
3327static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3328static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3329static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3330static int istermoption(struct vimoption *);
3331static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3332static char_u *get_varp(struct vimoption *);
3333static void option_value2string(struct vimoption *, int opt_flags);
3334static void check_winopt(winopt_T *wop);
3335static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003337static void langmap_init(void);
3338static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003340static void paste_option_changed(void);
3341static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003343static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003345static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3346static int check_opt_strings(char_u *val, char **values, int);
3347static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003348#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003349static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351
3352/*
3353 * Initialize the options, first part.
3354 *
3355 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003356 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 */
3358 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003359set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360{
3361 char_u *p;
3362 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003363 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364
3365#ifdef FEAT_LANGMAP
3366 langmap_init();
3367#endif
3368
3369 /* Be Vi compatible by default */
3370 p_cp = TRUE;
3371
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003372 /* Use POSIX compatibility when $VIM_POSIX is set. */
3373 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003374 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003375 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003376 set_string_default("shm", (char_u *)"A");
3377 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003378
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379 /*
3380 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003381 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003383 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003384#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003385 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003387 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388# endif
3389#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003390 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003391 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392
3393#ifdef FEAT_WILDIGN
3394 /*
3395 * Set the default for 'backupskip' to include environment variables for
3396 * temp files.
3397 */
3398 {
3399# ifdef UNIX
3400 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3401# else
3402 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3403# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003404 int len;
3405 garray_T ga;
3406 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407
3408 ga_init2(&ga, 1, 100);
3409 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3410 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003411 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412# ifdef UNIX
3413 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003414# ifdef MACOS_X
3415 p = (char_u *)"/private/tmp";
3416# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003418# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419 else
3420# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003421 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422 if (p != NULL && *p != NUL)
3423 {
3424 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003425 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426 if (ga_grow(&ga, len) == OK)
3427 {
3428 if (ga.ga_len > 0)
3429 STRCAT(ga.ga_data, ",");
3430 STRCAT(ga.ga_data, p);
3431 add_pathsep(ga.ga_data);
3432 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 ga.ga_len += len;
3434 }
3435 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003436 if (mustfree)
3437 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438 }
3439 if (ga.ga_data != NULL)
3440 {
3441 set_string_default("bsk", ga.ga_data);
3442 vim_free(ga.ga_data);
3443 }
3444 }
3445#endif
3446
3447 /*
3448 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3449 */
3450 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003451 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003453#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3454 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3455#endif
3456 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003458 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003459 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460#else
3461# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003462 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003463 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003465 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466# endif
3467#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003469 opt_idx = findoption((char_u *)"maxmem");
3470 if (opt_idx >= 0)
3471 {
3472#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003473 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3474 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003475#endif
3476 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3477 }
3478 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 }
3480
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481#ifdef FEAT_SEARCHPATH
3482 {
3483 char_u *cdpath;
3484 char_u *buf;
3485 int i;
3486 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003487 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488
3489 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003490 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 if (cdpath != NULL)
3492 {
3493 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3494 if (buf != NULL)
3495 {
3496 buf[0] = ','; /* start with ",", current dir first */
3497 j = 1;
3498 for (i = 0; cdpath[i] != NUL; ++i)
3499 {
3500 if (vim_ispathlistsep(cdpath[i]))
3501 buf[j++] = ',';
3502 else
3503 {
3504 if (cdpath[i] == ' ' || cdpath[i] == ',')
3505 buf[j++] = '\\';
3506 buf[j++] = cdpath[i];
3507 }
3508 }
3509 buf[j] = NUL;
3510 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003511 if (opt_idx >= 0)
3512 {
3513 options[opt_idx].def_val[VI_DEFAULT] = buf;
3514 options[opt_idx].flags |= P_DEF_ALLOCED;
3515 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003516 else
3517 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003519 if (mustfree)
3520 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521 }
3522 }
3523#endif
3524
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003525#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526 /* Set print encoding on platforms that don't default to latin1 */
3527 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003528# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 (char_u *)"cp1252"
3530# else
3531# ifdef VMS
3532 (char_u *)"dec-mcs"
3533# else
3534# ifdef EBCDIC
3535 (char_u *)"ebcdic-uk"
3536# else
3537# ifdef MAC
3538 (char_u *)"mac-roman"
3539# else /* HPUX */
3540 (char_u *)"hp-roman8"
3541# endif
3542# endif
3543# endif
3544# endif
3545 );
3546#endif
3547
3548#ifdef FEAT_POSTSCRIPT
3549 /* 'printexpr' must be allocated to be able to evaluate it. */
3550 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003551# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003552 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553# else
3554# ifdef VMS
3555 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3556
3557# else
3558 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3559# endif
3560# endif
3561 );
3562#endif
3563
3564 /*
3565 * Set all the options (except the terminal options) to their default
3566 * value. Also set the global value for local options.
3567 */
3568 set_options_default(0);
3569
Bram Moolenaar07268702018-03-01 21:57:32 +01003570#ifdef CLEAN_RUNTIMEPATH
3571 if (clean_arg)
3572 {
3573 opt_idx = findoption((char_u *)"runtimepath");
3574 if (opt_idx >= 0)
3575 {
3576 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3577 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3578 }
3579 opt_idx = findoption((char_u *)"packpath");
3580 if (opt_idx >= 0)
3581 {
3582 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3583 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3584 }
3585 }
3586#endif
3587
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588#ifdef FEAT_GUI
3589 if (found_reverse_arg)
3590 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3591#endif
3592
3593 curbuf->b_p_initialized = TRUE;
3594 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003595 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 check_buf_options(curbuf);
3597 check_win_options(curwin);
3598 check_options();
3599
3600 /* Must be before option_expand(), because that one needs vim_isIDc() */
3601 didset_options();
3602
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003603#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003604 /* Use the current chartab for the generic chartab. This is not in
3605 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003606 init_spell_chartab();
3607#endif
3608
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 /*
3610 * Expand environment variables and things like "~" for the defaults.
3611 * If option_expand() returns non-NULL the variable is expanded. This can
3612 * only happen for non-indirect options.
3613 * Also set the default to the expanded value, so ":set" does not list
3614 * them.
3615 * Don't set the P_ALLOCED flag, because we don't want to free the
3616 * default.
3617 */
3618 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3619 {
3620 if ((options[opt_idx].flags & P_GETTEXT)
3621 && options[opt_idx].var != NULL)
3622 p = (char_u *)_(*(char **)options[opt_idx].var);
3623 else
3624 p = option_expand(opt_idx, NULL);
3625 if (p != NULL && (p = vim_strsave(p)) != NULL)
3626 {
3627 *(char_u **)options[opt_idx].var = p;
3628 /* VIMEXP
3629 * Defaults for all expanded options are currently the same for Vi
3630 * and Vim. When this changes, add some code here! Also need to
3631 * split P_DEF_ALLOCED in two.
3632 */
3633 if (options[opt_idx].flags & P_DEF_ALLOCED)
3634 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3635 options[opt_idx].def_val[VI_DEFAULT] = p;
3636 options[opt_idx].flags |= P_DEF_ALLOCED;
3637 }
3638 }
3639
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640 save_file_ff(curbuf); /* Buffer is unchanged */
3641
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642#if defined(FEAT_ARABIC)
3643 /* Detect use of mlterm.
3644 * Mlterm is a terminal emulator akin to xterm that has some special
3645 * abilities (bidi namely).
3646 * NOTE: mlterm's author is being asked to 'set' a variable
3647 * instead of an environment variable due to inheritance.
3648 */
3649 if (mch_getenv((char_u *)"MLTERM") != NULL)
3650 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3651#endif
3652
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003653 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654
3655#ifdef FEAT_MBYTE
3656# if defined(WIN3264) && defined(FEAT_GETTEXT)
3657 /*
3658 * If $LANG isn't set, try to get a good value for it. This makes the
3659 * right language be used automatically. Don't do this for English.
3660 */
3661 if (mch_getenv((char_u *)"LANG") == NULL)
3662 {
3663 char buf[20];
3664
3665 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3666 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3667 * only the first two. */
3668 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3669 (LPTSTR)buf, 20);
3670 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3671 {
3672 /* There are a few exceptions (probably more) */
3673 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3674 STRCPY(buf, "zh_TW");
3675 else if (STRNICMP(buf, "chs", 3) == 0
3676 || STRNICMP(buf, "zhc", 3) == 0)
3677 STRCPY(buf, "zh_CN");
3678 else if (STRNICMP(buf, "jp", 2) == 0)
3679 STRCPY(buf, "ja");
3680 else
3681 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003682 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 }
3684 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003685# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003686# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003687 /* Moved to os_mac_conv.c to avoid dependency problems. */
3688 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003689# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690# endif
3691
3692 /* enc_locale() will try to find the encoding of the current locale. */
3693 p = enc_locale();
3694 if (p != NULL)
3695 {
3696 char_u *save_enc;
3697
3698 /* Try setting 'encoding' and check if the value is valid.
3699 * If not, go back to the default "latin1". */
3700 save_enc = p_enc;
3701 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003702 if (STRCMP(p_enc, "gb18030") == 0)
3703 {
3704 /* We don't support "gb18030", but "cp936" is a good substitute
3705 * for practical purposes, thus use that. It's not an alias to
3706 * still support conversion between gb18030 and utf-8. */
3707 p_enc = vim_strsave((char_u *)"cp936");
3708 vim_free(p);
3709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710 if (mb_init() == NULL)
3711 {
3712 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003713 if (opt_idx >= 0)
3714 {
3715 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3716 options[opt_idx].flags |= P_DEF_ALLOCED;
3717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718
Bram Moolenaard0573012017-10-28 21:11:06 +02003719#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003720 if (STRCMP(p_enc, "latin1") == 0
3721# ifdef FEAT_MBYTE
3722 || enc_utf8
3723# endif
3724 )
3725 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003726 /* Adjust the default for 'isprint' and 'iskeyword' to match
3727 * latin1. Also set the defaults for when 'nocompatible' is
3728 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003729 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003730 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003731 set_string_option_direct((char_u *)"isk", -1,
3732 ISK_LATIN1, OPT_FREE, SID_NONE);
3733 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003734 if (opt_idx >= 0)
3735 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003736 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003737 if (opt_idx >= 0)
3738 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003739 (void)init_chartab();
3740 }
3741#endif
3742
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743# if defined(WIN3264) && !defined(FEAT_GUI)
3744 /* Win32 console: When GetACP() returns a different value from
3745 * GetConsoleCP() set 'termencoding'. */
3746 if (GetACP() != GetConsoleCP())
3747 {
3748 char buf[50];
3749
3750 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3751 p_tenc = vim_strsave((char_u *)buf);
3752 if (p_tenc != NULL)
3753 {
3754 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003755 if (opt_idx >= 0)
3756 {
3757 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3758 options[opt_idx].flags |= P_DEF_ALLOCED;
3759 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760 convert_setup(&input_conv, p_tenc, p_enc);
3761 convert_setup(&output_conv, p_enc, p_tenc);
3762 }
3763 else
3764 p_tenc = empty_option;
3765 }
3766# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003767# if defined(WIN3264) && defined(FEAT_MBYTE)
3768 /* $HOME may have characters in active code page. */
3769 init_homedir();
3770# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 }
3772 else
3773 {
3774 vim_free(p_enc);
3775 p_enc = save_enc;
3776 }
3777 }
3778#endif
3779
3780#ifdef FEAT_MULTI_LANG
3781 /* Set the default for 'helplang'. */
3782 set_helplang_default(get_mess_lang());
3783#endif
3784}
3785
3786/*
3787 * Set an option to its default value.
3788 * This does not take care of side effects!
3789 */
3790 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003791set_option_default(
3792 int opt_idx,
3793 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3794 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795{
3796 char_u *varp; /* pointer to variable for current option */
3797 int dvi; /* index in def_val[] */
3798 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003799 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3801
3802 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3803 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003804 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805 {
3806 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3807 if (flags & P_STRING)
3808 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003809 /* Use set_string_option_direct() for local options to handle
3810 * freeing and allocating the value. */
3811 if (options[opt_idx].indir != PV_NONE)
3812 set_string_option_direct(NULL, opt_idx,
3813 options[opt_idx].def_val[dvi], opt_flags, 0);
3814 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003816 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3817 free_string_option(*(char_u **)(varp));
3818 *(char_u **)varp = options[opt_idx].def_val[dvi];
3819 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 }
3821 }
3822 else if (flags & P_NUM)
3823 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003824 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 win_comp_scroll(curwin);
3826 else
3827 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003828 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 /* May also set global value for local option. */
3830 if (both)
3831 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3832 *(long *)varp;
3833 }
3834 }
3835 else /* P_BOOL */
3836 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003837 /* the cast to long is required for Manx C, long_i is needed for
3838 * MSVC */
3839 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003840#ifdef UNIX
3841 /* 'modeline' defaults to off for root */
3842 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3843 *(int *)varp = FALSE;
3844#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003845 /* May also set global value for local option. */
3846 if (both)
3847 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3848 *(int *)varp;
3849 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003850
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003851 /* The default value is not insecure. */
3852 flagsp = insecure_flag(opt_idx, opt_flags);
3853 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 }
3855
3856#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003857 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858#endif
3859}
3860
3861/*
3862 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003863 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 */
3865 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003866set_options_default(
3867 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868{
3869 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003871 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872
3873 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003874 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003875#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003876 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003877 || (TRUE
3878# if defined(FEAT_MBYTE)
3879 && options[i].var != (char_u *)&p_enc
3880# endif
3881# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003882 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003883 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003884# endif
3885 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003886#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003887 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 set_option_default(i, opt_flags, p_cp);
3889
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003891 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003893#ifdef FEAT_CINDENT
3894 parse_cino(curbuf);
3895#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896}
3897
3898/*
3899 * Set the Vi-default value of a string option.
3900 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003901 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003903 static void
3904set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905{
3906 char_u *p;
3907 int opt_idx;
3908
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003909 if (escape && vim_strchr(val, ' ') != NULL)
3910 p = vim_strsave_escaped(val, (char_u *)" ");
3911 else
3912 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 if (p != NULL) /* we don't want a NULL */
3914 {
3915 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003916 if (opt_idx >= 0)
3917 {
3918 if (options[opt_idx].flags & P_DEF_ALLOCED)
3919 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3920 options[opt_idx].def_val[VI_DEFAULT] = p;
3921 options[opt_idx].flags |= P_DEF_ALLOCED;
3922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 }
3924}
3925
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003926 void
3927set_string_default(char *name, char_u *val)
3928{
3929 set_string_default_esc(name, val, FALSE);
3930}
3931
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932/*
3933 * Set the Vi-default value of a number option.
3934 * Used for 'lines' and 'columns'.
3935 */
3936 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003937set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003939 int opt_idx;
3940
3941 opt_idx = findoption((char_u *)name);
3942 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003943 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944}
3945
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003946#if defined(EXITFREE) || defined(PROTO)
3947/*
3948 * Free all options.
3949 */
3950 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003951free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003952{
3953 int i;
3954
3955 for (i = 0; !istermoption(&options[i]); i++)
3956 {
3957 if (options[i].indir == PV_NONE)
3958 {
3959 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003960 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003961 free_string_option(*(char_u **)options[i].var);
3962 if (options[i].flags & P_DEF_ALLOCED)
3963 free_string_option(options[i].def_val[VI_DEFAULT]);
3964 }
3965 else if (options[i].var != VAR_WIN
3966 && (options[i].flags & P_STRING))
3967 /* buffer-local option: free global value */
3968 free_string_option(*(char_u **)options[i].var);
3969 }
3970}
3971#endif
3972
3973
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974/*
3975 * Initialize the options, part two: After getting Rows and Columns and
3976 * setting 'term'.
3977 */
3978 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003979set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003980{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003981 int idx;
3982
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003984 * 'scroll' defaults to half the window height. The stored default is zero,
3985 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003987 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003988 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003989 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 comp_col();
3991
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003992 /*
3993 * 'window' is only for backwards compatibility with Vi.
3994 * Default is Rows - 1.
3995 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003996 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003997 p_window = Rows - 1;
3998 set_number_default("window", Rows - 1);
3999
Bram Moolenaarf740b292006-02-16 22:11:02 +00004000 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004001#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00004002 /*
4003 * If 'background' wasn't set by the user, try guessing the value,
4004 * depending on the terminal name. Only need to check for terminals
4005 * with a dark background, that can handle color.
4006 */
4007 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004008 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4009 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004010 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004011 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004012 /* don't mark it as set, when starting the GUI it may be
4013 * changed again */
4014 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 }
4016#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004017
4018#ifdef CURSOR_SHAPE
4019 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4020#endif
4021#ifdef FEAT_MOUSESHAPE
4022 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4023#endif
4024#ifdef FEAT_PRINTER
4025 (void)parse_printoptions(); /* parse 'printoptions' default value */
4026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004027}
4028
4029/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004030 * Return "dark" or "light" depending on the kind of terminal.
4031 * This is just guessing! Recognized are:
4032 * "linux" Linux console
4033 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004034 * "cygwin.*" Cygwin shell
4035 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004036 * We also check the COLORFGBG environment variable, which is set by
4037 * rxvt and derivatives. This variable contains either two or three
4038 * values separated by semicolons; we want the last value in either
4039 * case. If this value is 0-6 or 8, our background is dark.
4040 */
4041 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004042term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004043{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004044#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004045 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004046 return (char_u *)"dark";
4047#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004048 char_u *p;
4049
Bram Moolenaarf740b292006-02-16 22:11:02 +00004050 if (STRCMP(T_NAME, "linux") == 0
4051 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004052 || STRNCMP(T_NAME, "cygwin", 6) == 0
4053 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004054 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4055 && (p = vim_strrchr(p, ';')) != NULL
4056 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4057 && p[2] == NUL))
4058 return (char_u *)"dark";
4059 return (char_u *)"light";
4060#endif
4061}
4062
4063/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 * Initialize the options, part three: After reading the .vimrc
4065 */
4066 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004067set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070/*
4071 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4072 * This is done after other initializations, where 'shell' might have been
4073 * set, but only if they have not been set before.
4074 */
4075 char_u *p;
4076 int idx_srr;
4077 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 int idx_sp;
4080 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082
4083 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004084 if (idx_srr < 0)
4085 do_srr = FALSE;
4086 else
4087 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004090 if (idx_sp < 0)
4091 do_sp = FALSE;
4092 else
4093 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004094# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004095 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 if (p != NULL)
4097 {
4098 /*
4099 * Default for p_sp is "| tee", for p_srr is ">".
4100 * For known shells it is changed here to include stderr.
4101 */
4102 if ( fnamecmp(p, "csh") == 0
4103 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004104# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 || fnamecmp(p, "csh.exe") == 0
4106 || fnamecmp(p, "tcsh.exe") == 0
4107# endif
4108 )
4109 {
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 *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004115# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 p_sp = (char_u *)"|& 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 *)">&";
4124 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4125 }
4126 }
4127 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004128 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 if ( fnamecmp(p, "sh") == 0
4130 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004131 || fnamecmp(p, "mksh") == 0
4132 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004134 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004136 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004137# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 || fnamecmp(p, "cmd") == 0
4139 || fnamecmp(p, "sh.exe") == 0
4140 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004141 || fnamecmp(p, "mksh.exe") == 0
4142 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004144 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 || fnamecmp(p, "bash.exe") == 0
4146 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004148 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004150# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 if (do_sp)
4152 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004153# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004155# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004157# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4159 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004160# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 if (do_srr)
4162 {
4163 p_srr = (char_u *)">%s 2>&1";
4164 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4165 }
4166 }
4167 vim_free(p);
4168 }
4169#endif
4170
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004171#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004173 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4174 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004175 * This is done after other initializations, where 'shell' might have been
4176 * set, but only if they have not been set before. Default for p_shcf is
4177 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004178 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004180 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004181 {
4182 int idx3;
4183
4184 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004185 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186 {
4187 p_shcf = (char_u *)"-c";
4188 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4189 }
4190
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 /* Somehow Win32 requires the quotes around the redirection too */
4192 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004193 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 {
4195 p_sxq = (char_u *)"\"";
4196 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4197 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004199 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4200 {
4201 int idx3;
4202
4203 /*
4204 * cmd.exe on Windows will strip the first and last double quote given
4205 * on the command line, e.g. most of the time things like:
4206 * cmd /c "my path/to/echo" "my args to echo"
4207 * become:
4208 * my path/to/echo" "my args to echo
4209 * when executed.
4210 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004211 * To avoid this, set shellxquote to surround the command in
4212 * parenthesis. This appears to make most commands work, without
4213 * breaking commands that worked previously, such as
4214 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004215 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004216 idx3 = findoption((char_u *)"sxq");
4217 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4218 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004219 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004220 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4221 }
4222
Bram Moolenaara64ba222012-02-12 23:23:31 +01004223 idx3 = findoption((char_u *)"shcf");
4224 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4225 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004226 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004227 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4228 }
4229 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004230#endif
4231
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004232 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004233 {
4234 int idx_ffs = findoption((char_u *)"ffs");
4235
4236 /* Apply the first entry of 'fileformats' to the initial buffer. */
4237 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4238 set_fileformat(default_fileformat(), OPT_LOCAL);
4239 }
4240
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241#ifdef FEAT_TITLE
4242 set_title_defaults();
4243#endif
4244}
4245
4246#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4247/*
4248 * When 'helplang' is still at its default value, set it to "lang".
4249 * Only the first two characters of "lang" are used.
4250 */
4251 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004252set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253{
4254 int idx;
4255
4256 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4257 return;
4258 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004259 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260 {
4261 if (options[idx].flags & P_ALLOCED)
4262 free_string_option(p_hlg);
4263 p_hlg = vim_strsave(lang);
4264 if (p_hlg == NULL)
4265 p_hlg = empty_option;
4266 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004267 {
4268 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4269 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4270 {
4271 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4272 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4273 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004275 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004276 options[idx].flags |= P_ALLOCED;
4277 }
4278}
4279#endif
4280
4281#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004282static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004283
4284 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004285gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004286{
4287 if (gui_get_lightness(gui.back_pixel) < 127)
4288 return (char_u *)"dark";
4289 return (char_u *)"light";
4290}
4291
4292/*
4293 * Option initializations that can only be done after opening the GUI window.
4294 */
4295 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004296init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004297{
4298 /* Set the 'background' option according to the lightness of the
4299 * background color, unless the user has set it already. */
4300 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4301 {
4302 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4303 highlight_changed();
4304 }
4305}
4306#endif
4307
4308#ifdef FEAT_TITLE
4309/*
4310 * 'title' and 'icon' only default to true if they have not been set or reset
4311 * in .vimrc and we can read the old value.
4312 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4313 * they can be reset. This reduces startup time when using X on a remote
4314 * machine.
4315 */
4316 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004317set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004318{
4319 int idx1;
4320 long val;
4321
4322 /*
4323 * If GUI is (going to be) used, we can always set the window title and
4324 * icon name. Saves a bit of time, because the X11 display server does
4325 * not need to be contacted.
4326 */
4327 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004328 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329 {
4330#ifdef FEAT_GUI
4331 if (gui.starting || gui.in_use)
4332 val = TRUE;
4333 else
4334#endif
4335 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004336 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004337 p_title = val;
4338 }
4339 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004340 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004341 {
4342#ifdef FEAT_GUI
4343 if (gui.starting || gui.in_use)
4344 val = TRUE;
4345 else
4346#endif
4347 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004348 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 p_icon = val;
4350 }
4351}
4352#endif
4353
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004354#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004355 static void
4356trigger_optionsset_string(
4357 int opt_idx,
4358 int opt_flags,
4359 char_u *oldval,
4360 char_u *newval)
4361{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004362 // Don't do this recursively.
4363 if (oldval != NULL && newval != NULL
4364 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004365 {
4366 char_u buf_type[7];
4367
4368 sprintf((char *)buf_type, "%s",
4369 (opt_flags & OPT_LOCAL) ? "local" : "global");
4370 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4371 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4372 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4373 apply_autocmds(EVENT_OPTIONSET,
4374 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4375 reset_v_option_vars();
4376 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004377}
4378#endif
4379
Bram Moolenaar071d4272004-06-13 20:20:40 +00004380/*
4381 * Parse 'arg' for option settings.
4382 *
4383 * 'arg' may be IObuff, but only when no errors can be present and option
4384 * does not need to be expanded with option_expand().
4385 * "opt_flags":
4386 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004387 * OPT_GLOBAL for ":setglobal"
4388 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004390 * OPT_WINONLY to only set window-local options
4391 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392 *
4393 * returns FAIL if an error is detected, OK otherwise
4394 */
4395 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004396do_set(
4397 char_u *arg, /* option string (may be written to!) */
4398 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399{
4400 int opt_idx;
4401 char_u *errmsg;
4402 char_u errbuf[80];
4403 char_u *startarg;
4404 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4405 int nextchar; /* next non-white char after option name */
4406 int afterchar; /* character just after option name */
4407 int len;
4408 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004409 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 int key;
4411 long_u flags; /* flags for current option */
4412 char_u *varp = NULL; /* pointer to variable for current option */
4413 int did_show = FALSE; /* already showed one value */
4414 int adding; /* "opt+=arg" */
4415 int prepending; /* "opt^=arg" */
4416 int removing; /* "opt-=arg" */
4417 int cp_val = 0;
4418 char_u key_name[2];
4419
4420 if (*arg == NUL)
4421 {
4422 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004423 did_show = TRUE;
4424 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 }
4426
4427 while (*arg != NUL) /* loop to process all options */
4428 {
4429 errmsg = NULL;
4430 startarg = arg; /* remember for error message */
4431
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004432 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4433 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004434 {
4435 /*
4436 * ":set all" show all options.
4437 * ":set all&" set all options to their default value.
4438 */
4439 arg += 3;
4440 if (*arg == '&')
4441 {
4442 ++arg;
4443 /* Only for :set command set global value of local options. */
4444 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004445 didset_options();
4446 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004447 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004448 }
4449 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004450 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004451 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004452 did_show = TRUE;
4453 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004454 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004455 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004456 {
4457 showoptions(2, opt_flags);
4458 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004459 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004460 arg += 7;
4461 }
4462 else
4463 {
4464 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004465 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004466 {
4467 prefix = 0;
4468 arg += 2;
4469 }
4470 else if (STRNCMP(arg, "inv", 3) == 0)
4471 {
4472 prefix = 2;
4473 arg += 3;
4474 }
4475
4476 /* find end of name */
4477 key = 0;
4478 if (*arg == '<')
4479 {
4480 nextchar = 0;
4481 opt_idx = -1;
4482 /* look out for <t_>;> */
4483 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4484 len = 5;
4485 else
4486 {
4487 len = 1;
4488 while (arg[len] != NUL && arg[len] != '>')
4489 ++len;
4490 }
4491 if (arg[len] != '>')
4492 {
4493 errmsg = e_invarg;
4494 goto skip;
4495 }
4496 arg[len] = NUL; /* put NUL after name */
4497 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4498 opt_idx = findoption(arg + 1);
4499 arg[len++] = '>'; /* restore '>' */
4500 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004501 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004502 }
4503 else
4504 {
4505 len = 0;
4506 /*
4507 * The two characters after "t_" may not be alphanumeric.
4508 */
4509 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4510 len = 4;
4511 else
4512 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4513 ++len;
4514 nextchar = arg[len];
4515 arg[len] = NUL; /* put NUL after name */
4516 opt_idx = findoption(arg);
4517 arg[len] = nextchar; /* restore nextchar */
4518 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004519 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004520 }
4521
4522 /* remember character after option name */
4523 afterchar = arg[len];
4524
4525 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004526 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004527 ++len;
4528
4529 adding = FALSE;
4530 prepending = FALSE;
4531 removing = FALSE;
4532 if (arg[len] != NUL && arg[len + 1] == '=')
4533 {
4534 if (arg[len] == '+')
4535 {
4536 adding = TRUE; /* "+=" */
4537 ++len;
4538 }
4539 else if (arg[len] == '^')
4540 {
4541 prepending = TRUE; /* "^=" */
4542 ++len;
4543 }
4544 else if (arg[len] == '-')
4545 {
4546 removing = TRUE; /* "-=" */
4547 ++len;
4548 }
4549 }
4550 nextchar = arg[len];
4551
4552 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4553 {
4554 errmsg = (char_u *)N_("E518: Unknown option");
4555 goto skip;
4556 }
4557
4558 if (opt_idx >= 0)
4559 {
4560 if (options[opt_idx].var == NULL) /* hidden option: skip */
4561 {
4562 /* Only give an error message when requesting the value of
4563 * a hidden option, ignore setting it. */
4564 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4565 && (!(options[opt_idx].flags & P_BOOL)
4566 || nextchar == '?'))
4567 errmsg = (char_u *)N_("E519: Option not supported");
4568 goto skip;
4569 }
4570
4571 flags = options[opt_idx].flags;
4572 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4573 }
4574 else
4575 {
4576 flags = P_STRING;
4577 if (key < 0)
4578 {
4579 key_name[0] = KEY2TERMCAP0(key);
4580 key_name[1] = KEY2TERMCAP1(key);
4581 }
4582 else
4583 {
4584 key_name[0] = KS_KEY;
4585 key_name[1] = (key & 0xff);
4586 }
4587 }
4588
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004589 /* Skip all options that are not window-local (used when showing
4590 * an already loaded buffer in a window). */
4591 if ((opt_flags & OPT_WINONLY)
4592 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4593 goto skip;
4594
Bram Moolenaara3227e22006-03-08 21:32:40 +00004595 /* Skip all options that are window-local (used for :vimgrep). */
4596 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4597 && options[opt_idx].var == VAR_WIN)
4598 goto skip;
4599
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004600 /* Disallow changing some options from modelines. */
4601 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004602 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004603 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004604 {
4605 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4606 goto skip;
4607 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004608#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004609 /* In diff mode some options are overruled. This avoids that
4610 * 'foldmethod' becomes "marker" instead of "diff" and that
4611 * "wrap" gets set. */
4612 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004613 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004614 && (
4615#ifdef FEAT_FOLDING
4616 options[opt_idx].indir == PV_FDM ||
4617#endif
4618 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004619 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004621 }
4622
4623#ifdef HAVE_SANDBOX
4624 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004625 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004626 {
4627 errmsg = (char_u *)_(e_sandbox);
4628 goto skip;
4629 }
4630#endif
4631
4632 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4633 {
4634 arg += len;
4635 cp_val = p_cp;
4636 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4637 {
4638 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4639 {
4640 cp_val = FALSE;
4641 arg += 3;
4642 }
4643 else /* "opt&vi": set to Vi default */
4644 {
4645 cp_val = TRUE;
4646 arg += 2;
4647 }
4648 }
4649 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004650 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 {
4652 errmsg = e_trailing;
4653 goto skip;
4654 }
4655 }
4656
4657 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004658 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4659 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004660 */
4661 if (nextchar == '?'
4662 || (prefix == 1
4663 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4664 && !(flags & P_BOOL)))
4665 {
4666 /*
4667 * print value
4668 */
4669 if (did_show)
4670 msg_putchar('\n'); /* cursor below last one */
4671 else
4672 {
4673 gotocmdline(TRUE); /* cursor at status line */
4674 did_show = TRUE; /* remember that we did a line */
4675 }
4676 if (opt_idx >= 0)
4677 {
4678 showoneopt(&options[opt_idx], opt_flags);
4679#ifdef FEAT_EVAL
4680 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004681 {
4682 /* Mention where the option was last set. */
4683 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004684 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004685 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004686 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004687 (int)options[opt_idx].indir & PV_MASK]);
4688 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004689 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004690 (int)options[opt_idx].indir & PV_MASK]);
4691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004692#endif
4693 }
4694 else
4695 {
4696 char_u *p;
4697
4698 p = find_termcode(key_name);
4699 if (p == NULL)
4700 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004701 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004702 goto skip;
4703 }
4704 else
4705 (void)show_one_termcode(key_name, p, TRUE);
4706 }
4707 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004708 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004709 errmsg = e_trailing;
4710 }
4711 else
4712 {
4713 if (flags & P_BOOL) /* boolean */
4714 {
4715 if (nextchar == '=' || nextchar == ':')
4716 {
4717 errmsg = e_invarg;
4718 goto skip;
4719 }
4720
4721 /*
4722 * ":set opt!": invert
4723 * ":set opt&": reset to default value
4724 * ":set opt<": reset to global value
4725 */
4726 if (nextchar == '!')
4727 value = *(int *)(varp) ^ 1;
4728 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004729 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004730 ((flags & P_VI_DEF) || cp_val)
4731 ? VI_DEFAULT : VIM_DEFAULT];
4732 else if (nextchar == '<')
4733 {
4734 /* For 'autoread' -1 means to use global value. */
4735 if ((int *)varp == &curbuf->b_p_ar
4736 && opt_flags == OPT_LOCAL)
4737 value = -1;
4738 else
4739 value = *(int *)get_varp_scope(&(options[opt_idx]),
4740 OPT_GLOBAL);
4741 }
4742 else
4743 {
4744 /*
4745 * ":set invopt": invert
4746 * ":set opt" or ":set noopt": set or reset
4747 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004748 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004749 {
4750 errmsg = e_trailing;
4751 goto skip;
4752 }
4753 if (prefix == 2) /* inv */
4754 value = *(int *)(varp) ^ 1;
4755 else
4756 value = prefix;
4757 }
4758
4759 errmsg = set_bool_option(opt_idx, varp, (int)value,
4760 opt_flags);
4761 }
4762 else /* numeric or string */
4763 {
4764 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4765 || prefix != 1)
4766 {
4767 errmsg = e_invarg;
4768 goto skip;
4769 }
4770
4771 if (flags & P_NUM) /* numeric */
4772 {
4773 /*
4774 * Different ways to set a number option:
4775 * & set to default value
4776 * < set to global value
4777 * <xx> accept special key codes for 'wildchar'
4778 * c accept any non-digit for 'wildchar'
4779 * [-]0-9 set number
4780 * other error
4781 */
4782 ++arg;
4783 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004784 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004785 ((flags & P_VI_DEF) || cp_val)
4786 ? VI_DEFAULT : VIM_DEFAULT];
4787 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004788 {
4789 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4790 * use the global value. */
4791 if ((long *)varp == &curbuf->b_p_ul
4792 && opt_flags == OPT_LOCAL)
4793 value = NO_LOCAL_UNDOLEVEL;
4794 else
4795 value = *(long *)get_varp_scope(
4796 &(options[opt_idx]), OPT_GLOBAL);
4797 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 else if (((long *)varp == &p_wc
4799 || (long *)varp == &p_wcm)
4800 && (*arg == '<'
4801 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004802 || (*arg != NUL
4803 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 && !VIM_ISDIGIT(*arg))))
4805 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004806 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 if (value == 0 && (long *)varp != &p_wcm)
4808 {
4809 errmsg = e_invarg;
4810 goto skip;
4811 }
4812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004813 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4814 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004815 /* Allow negative (for 'undolevels'), octal and
4816 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004817 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4818 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004819 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004820 {
4821 errmsg = e_invarg;
4822 goto skip;
4823 }
4824 }
4825 else
4826 {
4827 errmsg = (char_u *)N_("E521: Number required after =");
4828 goto skip;
4829 }
4830
4831 if (adding)
4832 value = *(long *)varp + value;
4833 if (prepending)
4834 value = *(long *)varp * value;
4835 if (removing)
4836 value = *(long *)varp - value;
4837 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004838 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004839 }
4840 else if (opt_idx >= 0) /* string */
4841 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004842 char_u *save_arg = NULL;
4843 char_u *s = NULL;
4844 char_u *oldval = NULL; /* previous value if *varp */
4845 char_u *newval;
4846 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004847#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004848 char_u *saved_origval = NULL;
4849 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004850#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004851 unsigned newlen;
4852 int comma;
4853 int bs;
4854 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004855 was allocated */
4856
4857 /* When using ":set opt=val" for a global option
4858 * with a local value the local value will be
4859 * reset, use the global value here. */
4860 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004861 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004862 varp = options[opt_idx].var;
4863
4864 /* The old value is kept until we are sure that the
4865 * new value is valid. */
4866 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004867
4868 /* When setting the local value of a global
4869 * option, the old value may be the global value. */
4870 if (((int)options[opt_idx].indir & PV_BOTH)
4871 && (opt_flags & OPT_LOCAL))
4872 origval = *(char_u **)get_varp(
4873 &options[opt_idx]);
4874 else
4875 origval = oldval;
4876
Bram Moolenaar071d4272004-06-13 20:20:40 +00004877 if (nextchar == '&') /* set to default val */
4878 {
4879 newval = options[opt_idx].def_val[
4880 ((flags & P_VI_DEF) || cp_val)
4881 ? VI_DEFAULT : VIM_DEFAULT];
4882 if ((char_u **)varp == &p_bg)
4883 {
4884 /* guess the value of 'background' */
4885#ifdef FEAT_GUI
4886 if (gui.in_use)
4887 newval = gui_bg_default();
4888 else
4889#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004890 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004891 }
4892
4893 /* expand environment variables and ~ (since the
4894 * default value was already expanded, only
4895 * required when an environment variable was set
4896 * later */
4897 if (newval == NULL)
4898 newval = empty_option;
4899 else
4900 {
4901 s = option_expand(opt_idx, newval);
4902 if (s == NULL)
4903 s = newval;
4904 newval = vim_strsave(s);
4905 }
4906 new_value_alloced = TRUE;
4907 }
4908 else if (nextchar == '<') /* set to global val */
4909 {
4910 newval = vim_strsave(*(char_u **)get_varp_scope(
4911 &(options[opt_idx]), OPT_GLOBAL));
4912 new_value_alloced = TRUE;
4913 }
4914 else
4915 {
4916 ++arg; /* jump to after the '=' or ':' */
4917
4918 /*
4919 * Set 'keywordprg' to ":help" if an empty
4920 * value was passed to :set by the user.
4921 * Misuse errbuf[] for the resulting string.
4922 */
4923 if (varp == (char_u *)&p_kp
4924 && (*arg == NUL || *arg == ' '))
4925 {
4926 STRCPY(errbuf, ":help");
4927 save_arg = arg;
4928 arg = errbuf;
4929 }
4930 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004931 * Convert 'backspace' number to string, for
4932 * adding, prepending and removing string.
4933 */
4934 else if (varp == (char_u *)&p_bs
4935 && VIM_ISDIGIT(**(char_u **)varp))
4936 {
4937 i = getdigits((char_u **)varp);
4938 switch (i)
4939 {
4940 case 0:
4941 *(char_u **)varp = empty_option;
4942 break;
4943 case 1:
4944 *(char_u **)varp = vim_strsave(
4945 (char_u *)"indent,eol");
4946 break;
4947 case 2:
4948 *(char_u **)varp = vim_strsave(
4949 (char_u *)"indent,eol,start");
4950 break;
4951 }
4952 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004953 if (origval == oldval)
4954 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004955 oldval = *(char_u **)varp;
4956 }
4957 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004958 * Convert 'whichwrap' number to string, for
4959 * backwards compatibility with Vim 3.0.
4960 * Misuse errbuf[] for the resulting string.
4961 */
4962 else if (varp == (char_u *)&p_ww
4963 && VIM_ISDIGIT(*arg))
4964 {
4965 *errbuf = NUL;
4966 i = getdigits(&arg);
4967 if (i & 1)
4968 STRCAT(errbuf, "b,");
4969 if (i & 2)
4970 STRCAT(errbuf, "s,");
4971 if (i & 4)
4972 STRCAT(errbuf, "h,l,");
4973 if (i & 8)
4974 STRCAT(errbuf, "<,>,");
4975 if (i & 16)
4976 STRCAT(errbuf, "[,],");
4977 if (*errbuf != NUL) /* remove trailing , */
4978 errbuf[STRLEN(errbuf) - 1] = NUL;
4979 save_arg = arg;
4980 arg = errbuf;
4981 }
4982 /*
4983 * Remove '>' before 'dir' and 'bdir', for
4984 * backwards compatibility with version 3.0
4985 */
4986 else if ( *arg == '>'
4987 && (varp == (char_u *)&p_dir
4988 || varp == (char_u *)&p_bdir))
4989 {
4990 ++arg;
4991 }
4992
Bram Moolenaar071d4272004-06-13 20:20:40 +00004993 /*
4994 * Copy the new string into allocated memory.
4995 * Can't use set_string_option_direct(), because
4996 * we need to remove the backslashes.
4997 */
4998 /* get a bit too much */
4999 newlen = (unsigned)STRLEN(arg) + 1;
5000 if (adding || prepending || removing)
5001 newlen += (unsigned)STRLEN(origval) + 1;
5002 newval = alloc(newlen);
5003 if (newval == NULL) /* out of mem, don't change */
5004 break;
5005 s = newval;
5006
5007 /*
5008 * Copy the string, skip over escaped chars.
5009 * For MS-DOS and WIN32 backslashes before normal
5010 * file name characters are not removed, and keep
5011 * backslash at start, for "\\machine\path", but
5012 * do remove it for "\\\\machine\\path".
5013 * The reverse is found in ExpandOldSetting().
5014 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005015 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 {
5017 if (*arg == '\\' && arg[1] != NUL
5018#ifdef BACKSLASH_IN_FILENAME
5019 && !((flags & P_EXPAND)
5020 && vim_isfilec(arg[1])
5021 && (arg[1] != '\\'
5022 || (s == newval
5023 && arg[2] != '\\')))
5024#endif
5025 )
5026 ++arg; /* remove backslash */
5027#ifdef FEAT_MBYTE
5028 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005029 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005030 {
5031 /* copy multibyte char */
5032 mch_memmove(s, arg, (size_t)i);
5033 arg += i;
5034 s += i;
5035 }
5036 else
5037#endif
5038 *s++ = *arg++;
5039 }
5040 *s = NUL;
5041
5042 /*
5043 * Expand environment variables and ~.
5044 * Don't do it when adding without inserting a
5045 * comma.
5046 */
5047 if (!(adding || prepending || removing)
5048 || (flags & P_COMMA))
5049 {
5050 s = option_expand(opt_idx, newval);
5051 if (s != NULL)
5052 {
5053 vim_free(newval);
5054 newlen = (unsigned)STRLEN(s) + 1;
5055 if (adding || prepending || removing)
5056 newlen += (unsigned)STRLEN(origval) + 1;
5057 newval = alloc(newlen);
5058 if (newval == NULL)
5059 break;
5060 STRCPY(newval, s);
5061 }
5062 }
5063
5064 /* locate newval[] in origval[] when removing it
5065 * and when adding to avoid duplicates */
5066 i = 0; /* init for GCC */
5067 if (removing || (flags & P_NODUP))
5068 {
5069 i = (int)STRLEN(newval);
5070 bs = 0;
5071 for (s = origval; *s; ++s)
5072 {
5073 if ((!(flags & P_COMMA)
5074 || s == origval
5075 || (s[-1] == ',' && !(bs & 1)))
5076 && STRNCMP(s, newval, i) == 0
5077 && (!(flags & P_COMMA)
5078 || s[i] == ','
5079 || s[i] == NUL))
5080 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005081 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005082 * even number of backslashes or a single
5083 * backslash preceded by a comma before it
5084 * is recognized as a separator */
5085 if ((s > origval + 1
5086 && s[-1] == '\\'
5087 && s[-2] != ',')
5088 || (s == origval + 1
5089 && s[-1] == '\\'))
5090
Bram Moolenaar071d4272004-06-13 20:20:40 +00005091 ++bs;
5092 else
5093 bs = 0;
5094 }
5095
5096 /* do not add if already there */
5097 if ((adding || prepending) && *s)
5098 {
5099 prepending = FALSE;
5100 adding = FALSE;
5101 STRCPY(newval, origval);
5102 }
5103 }
5104
5105 /* concatenate the two strings; add a ',' if
5106 * needed */
5107 if (adding || prepending)
5108 {
5109 comma = ((flags & P_COMMA) && *origval != NUL
5110 && *newval != NUL);
5111 if (adding)
5112 {
5113 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005114 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005115 if (comma && i > 1
5116 && (flags & P_ONECOMMA) == P_ONECOMMA
5117 && origval[i - 1] == ','
5118 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005119 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 mch_memmove(newval + i + comma, newval,
5121 STRLEN(newval) + 1);
5122 mch_memmove(newval, origval, (size_t)i);
5123 }
5124 else
5125 {
5126 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005127 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005128 }
5129 if (comma)
5130 newval[i] = ',';
5131 }
5132
5133 /* Remove newval[] from origval[]. (Note: "i" has
5134 * been set above and is used here). */
5135 if (removing)
5136 {
5137 STRCPY(newval, origval);
5138 if (*s)
5139 {
5140 /* may need to remove a comma */
5141 if (flags & P_COMMA)
5142 {
5143 if (s == origval)
5144 {
5145 /* include comma after string */
5146 if (s[i] == ',')
5147 ++i;
5148 }
5149 else
5150 {
5151 /* include comma before string */
5152 --s;
5153 ++i;
5154 }
5155 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005156 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005157 }
5158 }
5159
5160 if (flags & P_FLAGLIST)
5161 {
5162 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005163 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005164 {
5165 /* if options have P_FLAGLIST and
5166 * P_ONECOMMA such as 'whichwrap' */
5167 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005168 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005169 if (*s != ',' && *(s + 1) == ','
5170 && vim_strchr(s + 2, *s) != NULL)
5171 {
5172 /* Remove the duplicated value and
5173 * the next comma. */
5174 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005175 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005176 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005177 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005178 else
5179 {
5180 if ((!(flags & P_COMMA) || *s != ',')
5181 && vim_strchr(s + 1, *s) != NULL)
5182 {
5183 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005184 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005185 }
5186 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005187 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189 }
5190
5191 if (save_arg != NULL) /* number for 'whichwrap' */
5192 arg = save_arg;
5193 new_value_alloced = TRUE;
5194 }
5195
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005196 /*
5197 * Set the new value.
5198 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005199 *(char_u **)(varp) = newval;
5200
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005201#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005202 if (!starting
5203# ifdef FEAT_CRYPT
5204 && options[opt_idx].indir != PV_KEY
5205# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005206 && origval != NULL && newval != NULL)
5207 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005208 /* origval may be freed by
5209 * did_set_string_option(), make a copy. */
5210 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005211 /* newval (and varp) may become invalid if the
5212 * buffer is closed by autocommands. */
5213 saved_newval = vim_strsave(newval);
5214 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005215#endif
5216
Bram Moolenaar071d4272004-06-13 20:20:40 +00005217 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005218 * ":set" on local options. Note: when setting 'syntax'
5219 * or 'filetype' autocommands may be triggered that can
5220 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5222 new_value_alloced, oldval, errbuf, opt_flags);
5223
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005224#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005225 if (errmsg == NULL)
5226 trigger_optionsset_string(opt_idx, opt_flags,
5227 saved_origval, saved_newval);
5228 vim_free(saved_origval);
5229 vim_free(saved_newval);
5230#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005231 /* If error detected, print the error message. */
5232 if (errmsg != NULL)
5233 goto skip;
5234 }
5235 else /* key code option */
5236 {
5237 char_u *p;
5238
5239 if (nextchar == '&')
5240 {
5241 if (add_termcap_entry(key_name, TRUE) == FAIL)
5242 errmsg = (char_u *)N_("E522: Not found in termcap");
5243 }
5244 else
5245 {
5246 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005247 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 if (*p == '\\' && p[1] != NUL)
5249 ++p;
5250 nextchar = *p;
5251 *p = NUL;
5252 add_termcode(key_name, arg, FALSE);
5253 *p = nextchar;
5254 }
5255 if (full_screen)
5256 ttest(FALSE);
5257 redraw_all_later(CLEAR);
5258 }
5259 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005260
Bram Moolenaar071d4272004-06-13 20:20:40 +00005261 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005262 did_set_option(opt_idx, opt_flags,
5263 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 }
5265
5266skip:
5267 /*
5268 * Advance to next argument.
5269 * - skip until a blank found, taking care of backslashes
5270 * - skip blanks
5271 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5272 */
5273 for (i = 0; i < 2 ; ++i)
5274 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005275 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005276 if (*arg++ == '\\' && *arg != NUL)
5277 ++arg;
5278 arg = skipwhite(arg);
5279 if (*arg != '=')
5280 break;
5281 }
5282 }
5283
5284 if (errmsg != NULL)
5285 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005286 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005287 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288 if (i + (arg - startarg) < IOSIZE)
5289 {
5290 /* append the argument with the error */
5291 STRCAT(IObuff, ": ");
5292 mch_memmove(IObuff + i, startarg, (arg - startarg));
5293 IObuff[i + (arg - startarg)] = NUL;
5294 }
5295 /* make sure all characters are printable */
5296 trans_characters(IObuff, IOSIZE);
5297
5298 ++no_wait_return; /* wait_return done later */
5299 emsg(IObuff); /* show error highlighted */
5300 --no_wait_return;
5301
5302 return FAIL;
5303 }
5304
5305 arg = skipwhite(arg);
5306 }
5307
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005308theend:
5309 if (silent_mode && did_show)
5310 {
5311 /* After displaying option values in silent mode. */
5312 silent_mode = FALSE;
5313 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5314 msg_putchar('\n');
5315 cursor_on(); /* msg_start() switches it off */
5316 out_flush();
5317 silent_mode = TRUE;
5318 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5319 }
5320
Bram Moolenaar071d4272004-06-13 20:20:40 +00005321 return OK;
5322}
5323
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005324/*
5325 * Call this when an option has been given a new value through a user command.
5326 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5327 */
5328 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005329did_set_option(
5330 int opt_idx,
5331 int opt_flags, /* possibly with OPT_MODELINE */
5332 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005333{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005334 long_u *p;
5335
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005336 options[opt_idx].flags |= P_WAS_SET;
5337
5338 /* When an option is set in the sandbox, from a modeline or in secure mode
5339 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005340 * flag. */
5341 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005342 if (secure
5343#ifdef HAVE_SANDBOX
5344 || sandbox != 0
5345#endif
5346 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005347 *p = *p | P_INSECURE;
5348 else if (new_value)
5349 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005350}
5351
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005353illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354{
5355 if (errbuf == NULL)
5356 return (char_u *)"";
5357 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005358 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359 return errbuf;
5360}
5361
5362/*
5363 * Convert a key name or string into a key value.
5364 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005365 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005366 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005367 int
5368string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369{
5370 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005371 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372 if (*arg == '^')
5373 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005374 if (multi_byte)
5375 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376 return *arg;
5377}
5378
5379#ifdef FEAT_CMDWIN
5380/*
5381 * Check value of 'cedit' and set cedit_key.
5382 * Returns NULL if value is OK, error message otherwise.
5383 */
5384 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005385check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005386{
5387 int n;
5388
5389 if (*p_cedit == NUL)
5390 cedit_key = -1;
5391 else
5392 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005393 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005394 if (vim_isprintc(n))
5395 return e_invarg;
5396 cedit_key = n;
5397 }
5398 return NULL;
5399}
5400#endif
5401
5402#ifdef FEAT_TITLE
5403/*
5404 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5405 * maketitle() to create and display it.
5406 * When switching the title or icon off, call mch_restore_title() to get
5407 * the old value back.
5408 */
5409 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005410did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005411{
5412 if (starting != NO_SCREEN
5413#ifdef FEAT_GUI
5414 && !gui.starting
5415#endif
5416 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005417 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005418}
5419#endif
5420
5421/*
5422 * set_options_bin - called when 'bin' changes value.
5423 */
5424 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005425set_options_bin(
5426 int oldval,
5427 int newval,
5428 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005429{
5430 /*
5431 * The option values that are changed when 'bin' changes are
5432 * copied when 'bin is set and restored when 'bin' is reset.
5433 */
5434 if (newval)
5435 {
5436 if (!oldval) /* switched on */
5437 {
5438 if (!(opt_flags & OPT_GLOBAL))
5439 {
5440 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5441 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5442 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5443 curbuf->b_p_et_nobin = curbuf->b_p_et;
5444 }
5445 if (!(opt_flags & OPT_LOCAL))
5446 {
5447 p_tw_nobin = p_tw;
5448 p_wm_nobin = p_wm;
5449 p_ml_nobin = p_ml;
5450 p_et_nobin = p_et;
5451 }
5452 }
5453
5454 if (!(opt_flags & OPT_GLOBAL))
5455 {
5456 curbuf->b_p_tw = 0; /* no automatic line wrap */
5457 curbuf->b_p_wm = 0; /* no automatic line wrap */
5458 curbuf->b_p_ml = 0; /* no modelines */
5459 curbuf->b_p_et = 0; /* no expandtab */
5460 }
5461 if (!(opt_flags & OPT_LOCAL))
5462 {
5463 p_tw = 0;
5464 p_wm = 0;
5465 p_ml = FALSE;
5466 p_et = FALSE;
5467 p_bin = TRUE; /* needed when called for the "-b" argument */
5468 }
5469 }
5470 else if (oldval) /* switched off */
5471 {
5472 if (!(opt_flags & OPT_GLOBAL))
5473 {
5474 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5475 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5476 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5477 curbuf->b_p_et = curbuf->b_p_et_nobin;
5478 }
5479 if (!(opt_flags & OPT_LOCAL))
5480 {
5481 p_tw = p_tw_nobin;
5482 p_wm = p_wm_nobin;
5483 p_ml = p_ml_nobin;
5484 p_et = p_et_nobin;
5485 }
5486 }
5487}
5488
5489#ifdef FEAT_VIMINFO
5490/*
5491 * Find the parameter represented by the given character (eg ', :, ", or /),
5492 * and return its associated value in the 'viminfo' string.
5493 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005494 * If the parameter is not specified in the string or there is no following
5495 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496 */
5497 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005498get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499{
5500 char_u *p;
5501
5502 p = find_viminfo_parameter(type);
5503 if (p != NULL && VIM_ISDIGIT(*p))
5504 return atoi((char *)p);
5505 return -1;
5506}
5507
5508/*
5509 * Find the parameter represented by the given character (eg ''', ':', '"', or
5510 * '/') in the 'viminfo' option and return a pointer to the string after it.
5511 * Return NULL if the parameter is not specified in the string.
5512 */
5513 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005514find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005515{
5516 char_u *p;
5517
5518 for (p = p_viminfo; *p; ++p)
5519 {
5520 if (*p == type)
5521 return p + 1;
5522 if (*p == 'n') /* 'n' is always the last one */
5523 break;
5524 p = vim_strchr(p, ','); /* skip until next ',' */
5525 if (p == NULL) /* hit the end without finding parameter */
5526 break;
5527 }
5528 return NULL;
5529}
5530#endif
5531
5532/*
5533 * Expand environment variables for some string options.
5534 * These string options cannot be indirect!
5535 * If "val" is NULL expand the current value of the option.
5536 * Return pointer to NameBuff, or NULL when not expanded.
5537 */
5538 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005539option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540{
5541 /* if option doesn't need expansion nothing to do */
5542 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5543 return NULL;
5544
5545 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5546 * expand_env() would truncate the string. */
5547 if (val != NULL && STRLEN(val) > MAXPATHL)
5548 return NULL;
5549
5550 if (val == NULL)
5551 val = *(char_u **)options[opt_idx].var;
5552
5553 /*
5554 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5555 * Escape spaces when expanding 'tags', they are used to separate file
5556 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005557 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558 */
5559 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005560 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005561#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005562 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5563#endif
5564 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5566 return NULL;
5567
5568 return NameBuff;
5569}
5570
5571/*
5572 * After setting various option values: recompute variables that depend on
5573 * option values.
5574 */
5575 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005576didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577{
5578 /* initialize the table for 'iskeyword' et.al. */
5579 (void)init_chartab();
5580
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005581#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005585 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005586#ifdef FEAT_SESSION
5587 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5588 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5589#endif
5590#ifdef FEAT_FOLDING
5591 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5592#endif
5593 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005594 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005595#ifdef FEAT_VIRTUALEDIT
5596 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5597#endif
5598#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5599 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5600#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005601#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005602 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005603 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005604 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005605 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005606#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5608 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5609#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005610#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5612#endif
5613#ifdef FEAT_CMDWIN
5614 /* set cedit_key */
5615 (void)check_cedit();
5616#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005617#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005618 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005619#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005620#ifdef FEAT_LINEBREAK
5621 /* initialize the table for 'breakat'. */
5622 fill_breakat_flags();
5623#endif
5624
5625}
5626
5627/*
5628 * More side effects of setting options.
5629 */
5630 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005631didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005632{
5633 /* Initialize the highlight_attr[] table. */
5634 (void)highlight_changed();
5635
5636 /* Parse default for 'wildmode' */
5637 check_opt_wim();
5638
5639 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005640 /* Parse default for 'fillchars'. */
5641 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005642
5643#ifdef FEAT_CLIPBOARD
5644 /* Parse default for 'clipboard' */
5645 (void)check_clipboard_option();
5646#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005647#ifdef FEAT_VARTABS
5648 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5649 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651}
5652
5653/*
5654 * Check for string options that are NULL (normally only termcap options).
5655 */
5656 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005657check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658{
5659 int opt_idx;
5660
5661 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5662 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5663 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5664}
5665
5666/*
5667 * Check string options in a buffer for NULL value.
5668 */
5669 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005670check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672 check_string_option(&buf->b_p_bh);
5673 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005674#ifdef FEAT_MBYTE
5675 check_string_option(&buf->b_p_fenc);
5676#endif
5677 check_string_option(&buf->b_p_ff);
5678#ifdef FEAT_FIND_ID
5679 check_string_option(&buf->b_p_def);
5680 check_string_option(&buf->b_p_inc);
5681# ifdef FEAT_EVAL
5682 check_string_option(&buf->b_p_inex);
5683# endif
5684#endif
5685#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5686 check_string_option(&buf->b_p_inde);
5687 check_string_option(&buf->b_p_indk);
5688#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005689#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5690 check_string_option(&buf->b_p_bexpr);
5691#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005692#if defined(FEAT_CRYPT)
5693 check_string_option(&buf->b_p_cm);
5694#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005695 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005696#if defined(FEAT_EVAL)
5697 check_string_option(&buf->b_p_fex);
5698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699#ifdef FEAT_CRYPT
5700 check_string_option(&buf->b_p_key);
5701#endif
5702 check_string_option(&buf->b_p_kp);
5703 check_string_option(&buf->b_p_mps);
5704 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005705 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706 check_string_option(&buf->b_p_isk);
5707#ifdef FEAT_COMMENTS
5708 check_string_option(&buf->b_p_com);
5709#endif
5710#ifdef FEAT_FOLDING
5711 check_string_option(&buf->b_p_cms);
5712#endif
5713 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005714#ifdef FEAT_TEXTOBJ
5715 check_string_option(&buf->b_p_qe);
5716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717#ifdef FEAT_SYN_HL
5718 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005719 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005720#endif
5721#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005722 check_string_option(&buf->b_s.b_p_spc);
5723 check_string_option(&buf->b_s.b_p_spf);
5724 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725#endif
5726#ifdef FEAT_SEARCHPATH
5727 check_string_option(&buf->b_p_sua);
5728#endif
5729#ifdef FEAT_CINDENT
5730 check_string_option(&buf->b_p_cink);
5731 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005732 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5736 check_string_option(&buf->b_p_cinw);
5737#endif
5738#ifdef FEAT_INS_EXPAND
5739 check_string_option(&buf->b_p_cpt);
5740#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005741#ifdef FEAT_COMPL_FUNC
5742 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005743 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005744#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745#ifdef FEAT_KEYMAP
5746 check_string_option(&buf->b_p_keymap);
5747#endif
5748#ifdef FEAT_QUICKFIX
5749 check_string_option(&buf->b_p_gp);
5750 check_string_option(&buf->b_p_mp);
5751 check_string_option(&buf->b_p_efm);
5752#endif
5753 check_string_option(&buf->b_p_ep);
5754 check_string_option(&buf->b_p_path);
5755 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005756 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757#ifdef FEAT_INS_EXPAND
5758 check_string_option(&buf->b_p_dict);
5759 check_string_option(&buf->b_p_tsr);
5760#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005761#ifdef FEAT_LISP
5762 check_string_option(&buf->b_p_lw);
5763#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005764 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005765#ifdef FEAT_MBYTE
5766 check_string_option(&buf->b_p_menc);
5767#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005768#ifdef FEAT_VARTABS
5769 check_string_option(&buf->b_p_vsts);
5770 check_string_option(&buf->b_p_vts);
5771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772}
5773
5774/*
5775 * Free the string allocated for an option.
5776 * Checks for the string being empty_option. This may happen if we're out of
5777 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5778 * check_options().
5779 * Does NOT check for P_ALLOCED flag!
5780 */
5781 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005782free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783{
5784 if (p != empty_option)
5785 vim_free(p);
5786}
5787
5788 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005789clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005790{
5791 if (*pp != empty_option)
5792 vim_free(*pp);
5793 *pp = empty_option;
5794}
5795
5796 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005797check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798{
5799 if (*pp == NULL)
5800 *pp = empty_option;
5801}
5802
5803/*
5804 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5805 */
5806 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005807set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005808{
5809 int opt_idx;
5810
5811 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5812 if (options[opt_idx].var == (char_u *)p)
5813 {
5814 options[opt_idx].flags |= P_ALLOCED;
5815 return;
5816 }
5817 return; /* cannot happen: didn't find it! */
5818}
5819
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005820#if defined(FEAT_EVAL) || defined(PROTO)
5821/*
5822 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5823 * Return FALSE when it wasn't.
5824 * Return -1 for an unknown option.
5825 */
5826 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005827was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005828{
5829 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005830 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005831
5832 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833 {
5834 flagp = insecure_flag(idx, opt_flags);
5835 return (*flagp & P_INSECURE) != 0;
5836 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005837 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005838 return -1;
5839}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005840
5841/*
5842 * Get a pointer to the flags used for the P_INSECURE flag of option
5843 * "opt_idx". For some local options a local flags field is used.
5844 */
5845 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005846insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005847{
5848 if (opt_flags & OPT_LOCAL)
5849 switch ((int)options[opt_idx].indir)
5850 {
5851#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005852 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005853#endif
5854#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005855# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005856 case PV_FDE: return &curwin->w_p_fde_flags;
5857 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005858# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005859# ifdef FEAT_BEVAL
5860 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5861# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005862# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005863 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005864# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005865 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005866# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005867 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005868# endif
5869#endif
5870 }
5871
5872 /* Nothing special, return global flags field. */
5873 return &options[opt_idx].flags;
5874}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005875#endif
5876
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005877#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005878static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005879
5880/*
5881 * Redraw the window title and/or tab page text later.
5882 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005883static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005884{
5885 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005886 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005887}
5888#endif
5889
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890/*
5891 * Set a string option to a new value (without checking the effect).
5892 * The string is copied into allocated memory.
5893 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005894 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5895 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5896 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897 */
5898 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005899set_string_option_direct(
5900 char_u *name,
5901 int opt_idx,
5902 char_u *val,
5903 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5904 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905{
5906 char_u *s;
5907 char_u **varp;
5908 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005909 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910
Bram Moolenaar89d40322006-08-29 15:30:07 +00005911 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005913 idx = findoption(name);
5914 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005915 {
5916 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005917 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005919 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920 }
5921
Bram Moolenaar89d40322006-08-29 15:30:07 +00005922 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923 return;
5924
5925 s = vim_strsave(val);
5926 if (s != NULL)
5927 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005928 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005930 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005931 free_string_option(*varp);
5932 *varp = s;
5933
5934 /* For buffer/window local option may also set the global value. */
5935 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005936 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937
Bram Moolenaar89d40322006-08-29 15:30:07 +00005938 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939
5940 /* When setting both values of a global option with a local value,
5941 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005942 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005943 {
5944 free_string_option(*varp);
5945 *varp = empty_option;
5946 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005947# ifdef FEAT_EVAL
5948 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005949 {
5950 sctx_T script_ctx;
5951
5952 if (set_sid == 0)
5953 script_ctx = current_sctx;
5954 else
5955 {
5956 script_ctx.sc_sid = set_sid;
5957 script_ctx.sc_lnum = 0;
5958 }
5959 set_option_sctx_idx(idx, opt_flags, script_ctx);
5960 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005961# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962 }
5963}
5964
5965/*
5966 * Set global value for string option when it's a local option.
5967 */
5968 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005969set_string_option_global(
5970 int opt_idx, /* option index */
5971 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005972{
5973 char_u **p, *s;
5974
5975 /* the global value is always allocated */
5976 if (options[opt_idx].var == VAR_WIN)
5977 p = (char_u **)GLOBAL_WO(varp);
5978 else
5979 p = (char_u **)options[opt_idx].var;
5980 if (options[opt_idx].indir != PV_NONE
5981 && p != varp
5982 && (s = vim_strsave(*varp)) != NULL)
5983 {
5984 free_string_option(*p);
5985 *p = s;
5986 }
5987}
5988
5989/*
5990 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005991 *
5992 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005994 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005995set_string_option(
5996 int opt_idx,
5997 char_u *value,
5998 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999{
6000 char_u *s;
6001 char_u **varp;
6002 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006003#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02006004 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006005 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006006#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006007 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006008
6009 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006010 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011
6012 s = vim_strsave(value);
6013 if (s != NULL)
6014 {
6015 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6016 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006017 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006018 ? OPT_GLOBAL : OPT_LOCAL)
6019 : opt_flags);
6020 oldval = *varp;
6021 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006022
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006023#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006024 if (!starting
6025# ifdef FEAT_CRYPT
6026 && options[opt_idx].indir != PV_KEY
6027# endif
6028 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006029 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006030 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006031 saved_newval = vim_strsave(s);
6032 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006033#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006034 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6035 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006036 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006037
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006038#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006039 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006040 if (r == NULL)
6041 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006042 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006043 vim_free(saved_oldval);
6044 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006045#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006046 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006047 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048}
6049
6050/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006051 * Return TRUE if "val" is a valid 'filetype' name.
6052 * Also used for 'syntax' and 'keymap'.
6053 */
6054 static int
6055valid_filetype(char_u *val)
6056{
6057 char_u *s;
6058
6059 for (s = val; *s != NUL; ++s)
6060 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6061 return FALSE;
6062 return TRUE;
6063}
6064
6065/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066 * Handle string options that need some action to perform when changed.
6067 * Returns NULL for success, or an error message for an error.
6068 */
6069 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006070did_set_string_option(
6071 int opt_idx, /* index in options[] table */
6072 char_u **varp, /* pointer to the option variable */
6073 int new_value_alloced, /* new value was allocated */
6074 char_u *oldval, /* previous value of the option */
6075 char_u *errbuf, /* buffer for errors, or NULL */
6076 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006077{
6078 char_u *errmsg = NULL;
6079 char_u *s, *p;
6080 int did_chartab = FALSE;
6081 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006082 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006083#ifdef FEAT_GUI
6084 /* set when changing an option that only requires a redraw in the GUI */
6085 int redraw_gui_only = FALSE;
6086#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006087 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006088#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6089 int did_swaptcap = FALSE;
6090#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091
6092 /* Get the global option to compare with, otherwise we would have to check
6093 * two values for all local options. */
6094 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6095
6096 /* Disallow changing some options from secure mode */
6097 if ((secure
6098#ifdef HAVE_SANDBOX
6099 || sandbox != 0
6100#endif
6101 ) && (options[opt_idx].flags & P_SECURE))
6102 {
6103 errmsg = e_secure;
6104 }
6105
Bram Moolenaar7554da42016-11-25 22:04:13 +01006106 /* Check for a "normal" directory or file name in some options. Disallow a
6107 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006108 * are often illegal in a file name. Be more permissive if "secure" is off.
6109 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006110 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006111 && vim_strpbrk(*varp, (char_u *)(secure
6112 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006113 || ((options[opt_idx].flags & P_NDNAME)
6114 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006115 {
6116 errmsg = e_invarg;
6117 }
6118
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 /* 'term' */
6120 else if (varp == &T_NAME)
6121 {
6122 if (T_NAME[0] == NUL)
6123 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6124#ifdef FEAT_GUI
6125 if (gui.in_use)
6126 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6127 else if (term_is_gui(T_NAME))
6128 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6129#endif
6130 else if (set_termname(T_NAME) == FAIL)
6131 errmsg = (char_u *)N_("E522: Not found in termcap");
6132 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006133 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134 /* Screen colors may have changed. */
6135 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006136
6137 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6138 * P_ALLOCED flag on 'term'. */
6139 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006140 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006141 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142 }
6143
6144 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006145 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006146 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006147 char_u *bkc = p_bkc;
6148 unsigned int *flags = &bkc_flags;
6149
6150 if (opt_flags & OPT_LOCAL)
6151 {
6152 bkc = curbuf->b_p_bkc;
6153 flags = &curbuf->b_bkc_flags;
6154 }
6155
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006156 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6157 /* make the local value empty: use the global value */
6158 *flags = 0;
6159 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006160 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006161 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6162 errmsg = e_invarg;
6163 if ((((int)*flags & BKC_AUTO) != 0)
6164 + (((int)*flags & BKC_YES) != 0)
6165 + (((int)*flags & BKC_NO) != 0) != 1)
6166 {
6167 /* Must have exactly one of "auto", "yes" and "no". */
6168 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6169 errmsg = e_invarg;
6170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006171 }
6172 }
6173
6174 /* 'backupext' and 'patchmode' */
6175 else if (varp == &p_bex || varp == &p_pm)
6176 {
6177 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6178 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6179 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6180 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006181#ifdef FEAT_LINEBREAK
6182 /* 'breakindentopt' */
6183 else if (varp == &curwin->w_p_briopt)
6184 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006185 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006186 errmsg = e_invarg;
6187 }
6188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006189
6190 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006191 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006192 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006193 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006194 */
6195 else if ( varp == &p_isi
6196 || varp == &(curbuf->b_p_isk)
6197 || varp == &p_isp
6198 || varp == &p_isf)
6199 {
6200 if (init_chartab() == FAIL)
6201 {
6202 did_chartab = TRUE; /* need to restore it below */
6203 errmsg = e_invarg; /* error in value */
6204 }
6205 }
6206
6207 /* 'helpfile' */
6208 else if (varp == &p_hf)
6209 {
6210 /* May compute new values for $VIM and $VIMRUNTIME */
6211 if (didset_vim)
6212 {
6213 vim_setenv((char_u *)"VIM", (char_u *)"");
6214 didset_vim = FALSE;
6215 }
6216 if (didset_vimruntime)
6217 {
6218 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6219 didset_vimruntime = FALSE;
6220 }
6221 }
6222
Bram Moolenaar1a384422010-07-14 19:53:30 +02006223#ifdef FEAT_SYN_HL
6224 /* 'colorcolumn' */
6225 else if (varp == &curwin->w_p_cc)
6226 errmsg = check_colorcolumn(curwin);
6227#endif
6228
Bram Moolenaar071d4272004-06-13 20:20:40 +00006229#ifdef FEAT_MULTI_LANG
6230 /* 'helplang' */
6231 else if (varp == &p_hlg)
6232 {
6233 /* Check for "", "ab", "ab,cd", etc. */
6234 for (s = p_hlg; *s != NUL; s += 3)
6235 {
6236 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6237 {
6238 errmsg = e_invarg;
6239 break;
6240 }
6241 if (s[2] == NUL)
6242 break;
6243 }
6244 }
6245#endif
6246
6247 /* 'highlight' */
6248 else if (varp == &p_hl)
6249 {
6250 if (highlight_changed() == FAIL)
6251 errmsg = e_invarg; /* invalid flags */
6252 }
6253
6254 /* 'nrformats' */
6255 else if (gvarp == &p_nf)
6256 {
6257 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6258 errmsg = e_invarg;
6259 }
6260
6261#ifdef FEAT_SESSION
6262 /* 'sessionoptions' */
6263 else if (varp == &p_ssop)
6264 {
6265 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6266 errmsg = e_invarg;
6267 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6268 {
6269 /* Don't allow both "sesdir" and "curdir". */
6270 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6271 errmsg = e_invarg;
6272 }
6273 }
6274 /* 'viewoptions' */
6275 else if (varp == &p_vop)
6276 {
6277 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6278 errmsg = e_invarg;
6279 }
6280#endif
6281
6282 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006283 else if (varp == &p_sbo)
6284 {
6285 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6286 errmsg = e_invarg;
6287 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006288
6289 /* 'ambiwidth' */
6290#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006291 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006292 {
6293 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6294 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006295 else if (set_chars_option(&p_lcs) != NULL)
6296 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006297 else if (set_chars_option(&p_fcs) != NULL)
6298 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006299 }
6300#endif
6301
6302 /* 'background' */
6303 else if (varp == &p_bg)
6304 {
6305 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6306 {
6307#ifdef FEAT_EVAL
6308 int dark = (*p_bg == 'd');
6309#endif
6310
6311 init_highlight(FALSE, FALSE);
6312
6313#ifdef FEAT_EVAL
6314 if (dark != (*p_bg == 'd')
6315 && get_var_value((char_u *)"g:colors_name") != NULL)
6316 {
6317 /* The color scheme must have set 'background' back to another
6318 * value, that's not what we want here. Disable the color
6319 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006320 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321 free_string_option(p_bg);
6322 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6323 check_string_option(&p_bg);
6324 init_highlight(FALSE, FALSE);
6325 }
6326#endif
6327 }
6328 else
6329 errmsg = e_invarg;
6330 }
6331
6332 /* 'wildmode' */
6333 else if (varp == &p_wim)
6334 {
6335 if (check_opt_wim() == FAIL)
6336 errmsg = e_invarg;
6337 }
6338
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006339#ifdef FEAT_CMDL_COMPL
6340 /* 'wildoptions' */
6341 else if (varp == &p_wop)
6342 {
6343 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6344 errmsg = e_invarg;
6345 }
6346#endif
6347
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348#ifdef FEAT_WAK
6349 /* 'winaltkeys' */
6350 else if (varp == &p_wak)
6351 {
6352 if (*p_wak == NUL
6353 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6354 errmsg = e_invarg;
6355# ifdef FEAT_MENU
6356# ifdef FEAT_GUI_MOTIF
6357 else if (gui.in_use)
6358 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6359# else
6360# ifdef FEAT_GUI_GTK
6361 else if (gui.in_use)
6362 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6363# endif
6364# endif
6365# endif
6366 }
6367#endif
6368
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369 /* 'eventignore' */
6370 else if (varp == &p_ei)
6371 {
6372 if (check_ei() == FAIL)
6373 errmsg = e_invarg;
6374 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006375
6376#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006377 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6378 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6379 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 {
6381 if (gvarp == &p_fenc)
6382 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006383 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006384 errmsg = e_modifiable;
6385 else if (vim_strchr(*varp, ',') != NULL)
6386 /* No comma allowed in 'fileencoding'; catches confusing it
6387 * with 'fileencodings'. */
6388 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006389 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006390 {
6391# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006393 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006394# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006395 /* Add 'fileencoding' to the swap file. */
6396 ml_setflags(curbuf);
6397 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006398 }
6399 if (errmsg == NULL)
6400 {
6401 /* canonize the value, so that STRCMP() can be used on it */
6402 p = enc_canonize(*varp);
6403 if (p != NULL)
6404 {
6405 vim_free(*varp);
6406 *varp = p;
6407 }
6408 if (varp == &p_enc)
6409 {
6410 errmsg = mb_init();
6411# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006412 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006413# endif
6414 }
6415 }
6416
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006417# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6419 {
6420 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6421 if (STRCMP(p_tenc, "utf-8") != 0)
6422 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6423 }
6424# endif
6425
6426 if (errmsg == NULL)
6427 {
6428# ifdef FEAT_KEYMAP
6429 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6430 * (with another encoding). */
6431 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6432 (void)keymap_init();
6433# endif
6434
6435 /* When 'termencoding' is not empty and 'encoding' changes or when
6436 * 'termencoding' changes, need to setup for keyboard input and
6437 * display output conversion. */
6438 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6439 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006440 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6441 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6442 {
6443 EMSG3(_("E950: Cannot convert between %s and %s"),
6444 p_tenc, p_enc);
6445 errmsg = e_invarg;
6446 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006447 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006448
6449# if defined(WIN3264) && defined(FEAT_MBYTE)
6450 /* $HOME may have characters in active code page. */
6451 if (varp == &p_enc)
6452 init_homedir();
6453# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 }
6455 }
6456#endif
6457
6458#if defined(FEAT_POSTSCRIPT)
6459 else if (varp == &p_penc)
6460 {
6461 /* Canonize printencoding if VIM standard one */
6462 p = enc_canonize(p_penc);
6463 if (p != NULL)
6464 {
6465 vim_free(p_penc);
6466 p_penc = p;
6467 }
6468 else
6469 {
6470 /* Ensure lower case and '-' for '_' */
6471 for (s = p_penc; *s != NUL; s++)
6472 {
6473 if (*s == '_')
6474 *s = '-';
6475 else
6476 *s = TOLOWER_ASC(*s);
6477 }
6478 }
6479 }
6480#endif
6481
Bram Moolenaar9372a112005-12-06 19:59:18 +00006482#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 else if (varp == &p_imak)
6484 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006485 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006486 errmsg = e_invarg;
6487 }
6488#endif
6489
6490#ifdef FEAT_KEYMAP
6491 else if (varp == &curbuf->b_p_keymap)
6492 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006493 if (!valid_filetype(*varp))
6494 errmsg = e_invarg;
6495 else
6496 /* load or unload key mapping tables */
6497 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498
Bram Moolenaarfab06232009-03-04 03:13:35 +00006499 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006500 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006501 if (*curbuf->b_p_keymap != NUL)
6502 {
6503 /* Installed a new keymap, switch on using it. */
6504 curbuf->b_p_iminsert = B_IMODE_LMAP;
6505 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6506 curbuf->b_p_imsearch = B_IMODE_LMAP;
6507 }
6508 else
6509 {
6510 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6511 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6512 curbuf->b_p_iminsert = B_IMODE_NONE;
6513 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6514 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6515 }
6516 if ((opt_flags & OPT_LOCAL) == 0)
6517 {
6518 set_iminsert_global();
6519 set_imsearch_global();
6520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 }
6523 }
6524#endif
6525
6526 /* 'fileformat' */
6527 else if (gvarp == &p_ff)
6528 {
6529 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6530 errmsg = e_modifiable;
6531 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6532 errmsg = e_invarg;
6533 else
6534 {
6535 /* may also change 'textmode' */
6536 if (get_fileformat(curbuf) == EOL_DOS)
6537 curbuf->b_p_tx = TRUE;
6538 else
6539 curbuf->b_p_tx = FALSE;
6540#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006541 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006542#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006543 /* update flag in swap file */
6544 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006545 /* Redraw needed when switching to/from "mac": a CR in the text
6546 * will be displayed differently. */
6547 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6548 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549 }
6550 }
6551
6552 /* 'fileformats' */
6553 else if (varp == &p_ffs)
6554 {
6555 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6556 errmsg = e_invarg;
6557 else
6558 {
6559 /* also change 'textauto' */
6560 if (*p_ffs == NUL)
6561 p_ta = FALSE;
6562 else
6563 p_ta = TRUE;
6564 }
6565 }
6566
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006567#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 /* 'cryptkey' */
6569 else if (gvarp == &p_key)
6570 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006571# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006572 /* Make sure the ":set" command doesn't show the new value in the
6573 * history. */
6574 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006575# endif
6576 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6577 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006578 ml_set_crypt_key(curbuf, oldval,
6579 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006580 }
6581
6582 else if (gvarp == &p_cm)
6583 {
6584 if (opt_flags & OPT_LOCAL)
6585 p = curbuf->b_p_cm;
6586 else
6587 p = p_cm;
6588 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6589 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006590 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006591 errmsg = e_invarg;
6592 else
6593 {
6594 /* When setting the global value to empty, make it "zip". */
6595 if (*p_cm == NUL)
6596 {
6597 if (new_value_alloced)
6598 free_string_option(p_cm);
6599 p_cm = vim_strsave((char_u *)"zip");
6600 new_value_alloced = TRUE;
6601 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006602 /* When using ":set cm=name" the local value is going to be empty.
6603 * Do that here, otherwise the crypt functions will still use the
6604 * local value. */
6605 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6606 {
6607 free_string_option(curbuf->b_p_cm);
6608 curbuf->b_p_cm = empty_option;
6609 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006610
6611 /* Need to update the swapfile when the effective method changed.
6612 * Set "s" to the effective old value, "p" to the effective new
6613 * method and compare. */
6614 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6615 s = p_cm; /* was previously using the global value */
6616 else
6617 s = oldval;
6618 if (*curbuf->b_p_cm == NUL)
6619 p = p_cm; /* is now using the global value */
6620 else
6621 p = curbuf->b_p_cm;
6622 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006623 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006624
6625 /* If the global value changes need to update the swapfile for all
6626 * buffers using that value. */
6627 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6628 {
6629 buf_T *buf;
6630
Bram Moolenaar29323592016-07-24 22:04:11 +02006631 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006632 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006633 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006634 }
6635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006636 }
6637#endif
6638
6639 /* 'matchpairs' */
6640 else if (gvarp == &p_mps)
6641 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006642#ifdef FEAT_MBYTE
6643 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006644 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006645 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006646 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006647 int x2 = -1;
6648 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006649
6650 if (*p != NUL)
6651 p += mb_ptr2len(p);
6652 if (*p != NUL)
6653 x2 = *p++;
6654 if (*p != NUL)
6655 {
6656 x3 = mb_ptr2char(p);
6657 p += mb_ptr2len(p);
6658 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006659 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006660 {
6661 errmsg = e_invarg;
6662 break;
6663 }
6664 if (*p == NUL)
6665 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006666 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006667 }
6668 else
6669#endif
6670 {
6671 /* Check for "x:y,x:y" */
6672 for (p = *varp; *p != NUL; p += 4)
6673 {
6674 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6675 {
6676 errmsg = e_invarg;
6677 break;
6678 }
6679 if (p[3] == NUL)
6680 break;
6681 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006682 }
6683 }
6684
6685#ifdef FEAT_COMMENTS
6686 /* 'comments' */
6687 else if (gvarp == &p_com)
6688 {
6689 for (s = *varp; *s; )
6690 {
6691 while (*s && *s != ':')
6692 {
6693 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6694 && !VIM_ISDIGIT(*s) && *s != '-')
6695 {
6696 errmsg = illegal_char(errbuf, *s);
6697 break;
6698 }
6699 ++s;
6700 }
6701 if (*s++ == NUL)
6702 errmsg = (char_u *)N_("E524: Missing colon");
6703 else if (*s == ',' || *s == NUL)
6704 errmsg = (char_u *)N_("E525: Zero length string");
6705 if (errmsg != NULL)
6706 break;
6707 while (*s && *s != ',')
6708 {
6709 if (*s == '\\' && s[1] != NUL)
6710 ++s;
6711 ++s;
6712 }
6713 s = skip_to_option_part(s);
6714 }
6715 }
6716#endif
6717
6718 /* 'listchars' */
6719 else if (varp == &p_lcs)
6720 {
6721 errmsg = set_chars_option(varp);
6722 }
6723
Bram Moolenaar071d4272004-06-13 20:20:40 +00006724 /* 'fillchars' */
6725 else if (varp == &p_fcs)
6726 {
6727 errmsg = set_chars_option(varp);
6728 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006729
6730#ifdef FEAT_CMDWIN
6731 /* 'cedit' */
6732 else if (varp == &p_cedit)
6733 {
6734 errmsg = check_cedit();
6735 }
6736#endif
6737
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006738 /* 'verbosefile' */
6739 else if (varp == &p_vfile)
6740 {
6741 verbose_stop();
6742 if (*p_vfile != NUL && verbose_open() == FAIL)
6743 errmsg = e_invarg;
6744 }
6745
Bram Moolenaar071d4272004-06-13 20:20:40 +00006746#ifdef FEAT_VIMINFO
6747 /* 'viminfo' */
6748 else if (varp == &p_viminfo)
6749 {
6750 for (s = p_viminfo; *s;)
6751 {
6752 /* Check it's a valid character */
6753 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6754 {
6755 errmsg = illegal_char(errbuf, *s);
6756 break;
6757 }
6758 if (*s == 'n') /* name is always last one */
6759 {
6760 break;
6761 }
6762 else if (*s == 'r') /* skip until next ',' */
6763 {
6764 while (*++s && *s != ',')
6765 ;
6766 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006767 else if (*s == '%')
6768 {
6769 /* optional number */
6770 while (vim_isdigit(*++s))
6771 ;
6772 }
6773 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006774 ++s; /* no extra chars */
6775 else /* must have a number */
6776 {
6777 while (vim_isdigit(*++s))
6778 ;
6779
6780 if (!VIM_ISDIGIT(*(s - 1)))
6781 {
6782 if (errbuf != NULL)
6783 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006784 sprintf((char *)errbuf,
6785 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 transchar_byte(*(s - 1)));
6787 errmsg = errbuf;
6788 }
6789 else
6790 errmsg = (char_u *)"";
6791 break;
6792 }
6793 }
6794 if (*s == ',')
6795 ++s;
6796 else if (*s)
6797 {
6798 if (errbuf != NULL)
6799 errmsg = (char_u *)N_("E527: Missing comma");
6800 else
6801 errmsg = (char_u *)"";
6802 break;
6803 }
6804 }
6805 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6806 errmsg = (char_u *)N_("E528: Must specify a ' value");
6807 }
6808#endif /* FEAT_VIMINFO */
6809
6810 /* terminal options */
6811 else if (istermoption(&options[opt_idx]) && full_screen)
6812 {
6813 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6814 if (varp == &T_CCO)
6815 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006816 int colors = atoi((char *)T_CCO);
6817
6818 /* Only reinitialize colors if t_Co value has really changed to
6819 * avoid expensive reload of colorscheme if t_Co is set to the
6820 * same value multiple times. */
6821 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006823 t_colors = colors;
6824 if (t_colors <= 1)
6825 {
6826 if (new_value_alloced)
6827 vim_free(T_CCO);
6828 T_CCO = empty_option;
6829 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006830#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6831 if (is_term_win32())
6832 {
6833 swap_tcap();
6834 did_swaptcap = TRUE;
6835 }
6836#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006837 /* We now have a different color setup, initialize it again. */
6838 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840 }
6841 ttest(FALSE);
6842 if (varp == &T_ME)
6843 {
6844 out_str(T_ME);
6845 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006846#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847 /* Since t_me has been set, this probably means that the user
6848 * wants to use this as default colors. Need to reset default
6849 * background/foreground colors. */
6850 mch_set_normal_colors();
6851#endif
6852 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006853 if (varp == &T_BE && termcap_active)
6854 {
6855 if (*T_BE == NUL)
6856 /* When clearing t_BE we assume the user no longer wants
6857 * bracketed paste, thus disable it by writing t_BD. */
6858 out_str(T_BD);
6859 else
6860 out_str(T_BE);
6861 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006862 }
6863
6864#ifdef FEAT_LINEBREAK
6865 /* 'showbreak' */
6866 else if (varp == &p_sbr)
6867 {
6868 for (s = p_sbr; *s; )
6869 {
6870 if (ptr2cells(s) != 1)
6871 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006872 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 }
6874 }
6875#endif
6876
6877#ifdef FEAT_GUI
6878 /* 'guifont' */
6879 else if (varp == &p_guifont)
6880 {
6881 if (gui.in_use)
6882 {
6883 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006884# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885 /*
6886 * Put up a font dialog and let the user select a new value.
6887 * If this is cancelled go back to the old value but don't
6888 * give an error message.
6889 */
6890 if (STRCMP(p, "*") == 0)
6891 {
6892 p = gui_mch_font_dialog(oldval);
6893
6894 if (new_value_alloced)
6895 free_string_option(p_guifont);
6896
6897 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6898 new_value_alloced = TRUE;
6899 }
6900# endif
6901 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6902 {
6903# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6904 if (STRCMP(p_guifont, "*") == 0)
6905 {
6906 /* Dialog was cancelled: Keep the old value without giving
6907 * an error message. */
6908 if (new_value_alloced)
6909 free_string_option(p_guifont);
6910 p_guifont = vim_strsave(oldval);
6911 new_value_alloced = TRUE;
6912 }
6913 else
6914# endif
6915 errmsg = (char_u *)N_("E596: Invalid font(s)");
6916 }
6917 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006918 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006919 }
6920# ifdef FEAT_XFONTSET
6921 else if (varp == &p_guifontset)
6922 {
6923 if (STRCMP(p_guifontset, "*") == 0)
6924 errmsg = (char_u *)N_("E597: can't select fontset");
6925 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6926 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006927 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006928 }
6929# endif
6930# ifdef FEAT_MBYTE
6931 else if (varp == &p_guifontwide)
6932 {
6933 if (STRCMP(p_guifontwide, "*") == 0)
6934 errmsg = (char_u *)N_("E533: can't select wide font");
6935 else if (gui_get_wide_font() == FAIL)
6936 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006937 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 }
6939# endif
6940#endif
6941
6942#ifdef CURSOR_SHAPE
6943 /* 'guicursor' */
6944 else if (varp == &p_guicursor)
6945 errmsg = parse_shape_opt(SHAPE_CURSOR);
6946#endif
6947
6948#ifdef FEAT_MOUSESHAPE
6949 /* 'mouseshape' */
6950 else if (varp == &p_mouseshape)
6951 {
6952 errmsg = parse_shape_opt(SHAPE_MOUSE);
6953 update_mouseshape(-1);
6954 }
6955#endif
6956
6957#ifdef FEAT_PRINTER
6958 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006959 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006960# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006961 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006962 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006963# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006964#endif
6965
6966#ifdef FEAT_LANGMAP
6967 /* 'langmap' */
6968 else if (varp == &p_langmap)
6969 langmap_set();
6970#endif
6971
6972#ifdef FEAT_LINEBREAK
6973 /* 'breakat' */
6974 else if (varp == &p_breakat)
6975 fill_breakat_flags();
6976#endif
6977
6978#ifdef FEAT_TITLE
6979 /* 'titlestring' and 'iconstring' */
6980 else if (varp == &p_titlestring || varp == &p_iconstring)
6981 {
6982# ifdef FEAT_STL_OPT
6983 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6984
6985 /* NULL => statusline syntax */
6986 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6987 stl_syntax |= flagval;
6988 else
6989 stl_syntax &= ~flagval;
6990# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006991 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992 }
6993#endif
6994
6995#ifdef FEAT_GUI
6996 /* 'guioptions' */
6997 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006998 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007000 redraw_gui_only = TRUE;
7001 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002#endif
7003
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007004#if defined(FEAT_GUI_TABLINE)
7005 /* 'guitablabel' */
7006 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007007 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007008 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007009 redraw_gui_only = TRUE;
7010 }
7011 /* 'guitabtooltip' */
7012 else if (varp == &p_gtt)
7013 {
7014 redraw_gui_only = TRUE;
7015 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007016#endif
7017
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7019 /* 'ttymouse' */
7020 else if (varp == &p_ttym)
7021 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007022 /* Switch the mouse off before changing the escape sequences used for
7023 * that. */
7024 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007025 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7026 errmsg = e_invarg;
7027 else
7028 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007029 if (termcap_active)
7030 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007031 }
7032#endif
7033
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034 /* 'selection' */
7035 else if (varp == &p_sel)
7036 {
7037 if (*p_sel == NUL
7038 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7039 errmsg = e_invarg;
7040 }
7041
7042 /* 'selectmode' */
7043 else if (varp == &p_slm)
7044 {
7045 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7046 errmsg = e_invarg;
7047 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048
7049#ifdef FEAT_BROWSE
7050 /* 'browsedir' */
7051 else if (varp == &p_bsdir)
7052 {
7053 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7054 && !mch_isdir(p_bsdir))
7055 errmsg = e_invarg;
7056 }
7057#endif
7058
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059 /* 'keymodel' */
7060 else if (varp == &p_km)
7061 {
7062 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7063 errmsg = e_invarg;
7064 else
7065 {
7066 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7067 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7068 }
7069 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070
7071 /* 'mousemodel' */
7072 else if (varp == &p_mousem)
7073 {
7074 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7075 errmsg = e_invarg;
7076#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7077 else if (*p_mousem != *oldval)
7078 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7079 * to create or delete the popup menus. */
7080 gui_motif_update_mousemodel(root_menu);
7081#endif
7082 }
7083
7084 /* 'switchbuf' */
7085 else if (varp == &p_swb)
7086 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007087 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007088 errmsg = e_invarg;
7089 }
7090
7091 /* 'debug' */
7092 else if (varp == &p_debug)
7093 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007094 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007095 errmsg = e_invarg;
7096 }
7097
7098 /* 'display' */
7099 else if (varp == &p_dy)
7100 {
7101 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7102 errmsg = e_invarg;
7103 else
7104 (void)init_chartab();
7105
7106 }
7107
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108 /* 'eadirection' */
7109 else if (varp == &p_ead)
7110 {
7111 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7112 errmsg = e_invarg;
7113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114
7115#ifdef FEAT_CLIPBOARD
7116 /* 'clipboard' */
7117 else if (varp == &p_cb)
7118 errmsg = check_clipboard_option();
7119#endif
7120
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007121#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007122 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7123 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007124 else if (varp == &(curwin->w_s->b_p_spl)
7125 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007126 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007127 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007128 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007129 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007130 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007131 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007132 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007133 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007134 /* 'spellsuggest' */
7135 else if (varp == &p_sps)
7136 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007137 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007138 errmsg = e_invarg;
7139 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007140 /* 'mkspellmem' */
7141 else if (varp == &p_msm)
7142 {
7143 if (spell_check_msm() != OK)
7144 errmsg = e_invarg;
7145 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007146#endif
7147
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 /* When 'bufhidden' is set, check for valid value. */
7149 else if (gvarp == &p_bh)
7150 {
7151 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7152 errmsg = e_invarg;
7153 }
7154
7155 /* When 'buftype' is set, check for valid value. */
7156 else if (gvarp == &p_bt)
7157 {
7158 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7159 errmsg = e_invarg;
7160 else
7161 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007162 if (curwin->w_status_height)
7163 {
7164 curwin->w_redr_status = TRUE;
7165 redraw_later(VALID);
7166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007168#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007169 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007171 }
7172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007173
7174#ifdef FEAT_STL_OPT
7175 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007176 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007177 {
7178 int wid;
7179
7180 if (varp == &p_ruf) /* reset ru_wid first */
7181 ru_wid = 0;
7182 s = *varp;
7183 if (varp == &p_ruf && *s == '%')
7184 {
7185 /* set ru_wid if 'ruf' starts with "%99(" */
7186 if (*++s == '-') /* ignore a '-' */
7187 s++;
7188 wid = getdigits(&s);
7189 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7190 ru_wid = wid;
7191 else
7192 errmsg = check_stl_option(p_ruf);
7193 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007194 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007195 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007196 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007197 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198 comp_col();
7199 }
7200#endif
7201
7202#ifdef FEAT_INS_EXPAND
7203 /* check if it is a valid value for 'complete' -- Acevedo */
7204 else if (gvarp == &p_cpt)
7205 {
7206 for (s = *varp; *s;)
7207 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007208 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209 s++;
7210 if (!*s)
7211 break;
7212 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7213 {
7214 errmsg = illegal_char(errbuf, *s);
7215 break;
7216 }
7217 if (*++s != NUL && *s != ',' && *s != ' ')
7218 {
7219 if (s[-1] == 'k' || s[-1] == 's')
7220 {
7221 /* skip optional filename after 'k' and 's' */
7222 while (*s && *s != ',' && *s != ' ')
7223 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007224 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007225 ++s;
7226 ++s;
7227 }
7228 }
7229 else
7230 {
7231 if (errbuf != NULL)
7232 {
7233 sprintf((char *)errbuf,
7234 _("E535: Illegal character after <%c>"),
7235 *--s);
7236 errmsg = errbuf;
7237 }
7238 else
7239 errmsg = (char_u *)"";
7240 break;
7241 }
7242 }
7243 }
7244 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007245
7246 /* 'completeopt' */
7247 else if (varp == &p_cot)
7248 {
7249 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7250 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007251 else
7252 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007253 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254#endif /* FEAT_INS_EXPAND */
7255
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007256#ifdef FEAT_SIGNS
7257 /* 'signcolumn' */
7258 else if (varp == &curwin->w_p_scl)
7259 {
7260 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7261 errmsg = e_invarg;
7262 }
7263#endif
7264
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265
7266#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007267 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007268 else if (varp == &p_toolbar)
7269 {
7270 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7271 &toolbar_flags, TRUE) != OK)
7272 errmsg = e_invarg;
7273 else
7274 {
7275 out_flush();
7276 gui_mch_show_toolbar((toolbar_flags &
7277 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7278 }
7279 }
7280#endif
7281
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007282#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007283 /* 'toolbariconsize': GTK+ 2 only */
7284 else if (varp == &p_tbis)
7285 {
7286 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7287 errmsg = e_invarg;
7288 else
7289 {
7290 out_flush();
7291 gui_mch_show_toolbar((toolbar_flags &
7292 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7293 }
7294 }
7295#endif
7296
7297 /* 'pastetoggle': translate key codes like in a mapping */
7298 else if (varp == &p_pt)
7299 {
7300 if (*p_pt)
7301 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007302 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007303 if (p != NULL)
7304 {
7305 if (new_value_alloced)
7306 free_string_option(p_pt);
7307 p_pt = p;
7308 new_value_alloced = TRUE;
7309 }
7310 }
7311 }
7312
7313 /* 'backspace' */
7314 else if (varp == &p_bs)
7315 {
7316 if (VIM_ISDIGIT(*p_bs))
7317 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007318 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007319 errmsg = e_invarg;
7320 }
7321 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7322 errmsg = e_invarg;
7323 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007324 else if (varp == &p_bo)
7325 {
7326 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7327 errmsg = e_invarg;
7328 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007329
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007330 /* 'tagcase' */
7331 else if (gvarp == &p_tc)
7332 {
7333 unsigned int *flags;
7334
7335 if (opt_flags & OPT_LOCAL)
7336 {
7337 p = curbuf->b_p_tc;
7338 flags = &curbuf->b_tc_flags;
7339 }
7340 else
7341 {
7342 p = p_tc;
7343 flags = &tc_flags;
7344 }
7345
7346 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7347 /* make the local value empty: use the global value */
7348 *flags = 0;
7349 else if (*p == NUL
7350 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7351 errmsg = e_invarg;
7352 }
7353
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007354#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355 /* 'casemap' */
7356 else if (varp == &p_cmp)
7357 {
7358 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7359 errmsg = e_invarg;
7360 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007361#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007362
7363#ifdef FEAT_DIFF
7364 /* 'diffopt' */
7365 else if (varp == &p_dip)
7366 {
7367 if (diffopt_changed() == FAIL)
7368 errmsg = e_invarg;
7369 }
7370#endif
7371
7372#ifdef FEAT_FOLDING
7373 /* 'foldmethod' */
7374 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7375 {
7376 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7377 || *curwin->w_p_fdm == NUL)
7378 errmsg = e_invarg;
7379 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007380 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007381 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007382 if (foldmethodIsDiff(curwin))
7383 newFoldLevel();
7384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385 }
7386# ifdef FEAT_EVAL
7387 /* 'foldexpr' */
7388 else if (varp == &curwin->w_p_fde)
7389 {
7390 if (foldmethodIsExpr(curwin))
7391 foldUpdateAll(curwin);
7392 }
7393# endif
7394 /* 'foldmarker' */
7395 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7396 {
7397 p = vim_strchr(*varp, ',');
7398 if (p == NULL)
7399 errmsg = (char_u *)N_("E536: comma required");
7400 else if (p == *varp || p[1] == NUL)
7401 errmsg = e_invarg;
7402 else if (foldmethodIsMarker(curwin))
7403 foldUpdateAll(curwin);
7404 }
7405 /* 'commentstring' */
7406 else if (gvarp == &p_cms)
7407 {
7408 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7409 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7410 }
7411 /* 'foldopen' */
7412 else if (varp == &p_fdo)
7413 {
7414 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7415 errmsg = e_invarg;
7416 }
7417 /* 'foldclose' */
7418 else if (varp == &p_fcl)
7419 {
7420 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7421 errmsg = e_invarg;
7422 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007423 /* 'foldignore' */
7424 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7425 {
7426 if (foldmethodIsIndent(curwin))
7427 foldUpdateAll(curwin);
7428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007429#endif
7430
7431#ifdef FEAT_VIRTUALEDIT
7432 /* 'virtualedit' */
7433 else if (varp == &p_ve)
7434 {
7435 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7436 errmsg = e_invarg;
7437 else if (STRCMP(p_ve, oldval) != 0)
7438 {
7439 /* Recompute cursor position in case the new 've' setting
7440 * changes something. */
7441 validate_virtcol();
7442 coladvance(curwin->w_virtcol);
7443 }
7444 }
7445#endif
7446
7447#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7448 else if (varp == &p_csqf)
7449 {
7450 if (p_csqf != NULL)
7451 {
7452 p = p_csqf;
7453 while (*p != NUL)
7454 {
7455 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7456 || p[1] == NUL
7457 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7458 || (p[2] != NUL && p[2] != ','))
7459 {
7460 errmsg = e_invarg;
7461 break;
7462 }
7463 else if (p[2] == NUL)
7464 break;
7465 else
7466 p += 3;
7467 }
7468 }
7469 }
7470#endif
7471
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007472#ifdef FEAT_CINDENT
7473 /* 'cinoptions' */
7474 else if (gvarp == &p_cino)
7475 {
7476 /* TODO: recognize errors */
7477 parse_cino(curbuf);
7478 }
7479#endif
7480
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007481#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007482 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007483 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007484 {
7485 if (!gui_mch_set_rendering_options(p_rop))
7486 errmsg = e_invarg;
7487 }
7488#endif
7489
Bram Moolenaard0b51382016-11-04 15:23:45 +01007490 else if (gvarp == &p_ft)
7491 {
7492 if (!valid_filetype(*varp))
7493 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007494 else
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007495 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007496 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007497
7498#ifdef FEAT_SYN_HL
7499 else if (gvarp == &p_syn)
7500 {
7501 if (!valid_filetype(*varp))
7502 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007503 else
7504 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007505 }
7506#endif
7507
Bram Moolenaar825680f2017-07-22 17:04:02 +02007508#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007509 /* 'termwinkey' */
7510 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007511 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007512 if (*curwin->w_p_twk != NUL
7513 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007514 errmsg = e_invarg;
7515 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007516 /* 'termwinsize' */
7517 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007518 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007519 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007520 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007521 p = skipdigits(curwin->w_p_tws);
7522 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007523 || (*p != 'x' && *p != '*')
7524 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007525 errmsg = e_invarg;
7526 }
7527 }
7528#endif
7529
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007530#ifdef FEAT_VARTABS
7531 /* 'varsofttabstop' */
7532 else if (varp == &(curbuf->b_p_vsts))
7533 {
7534 char_u *cp;
7535
7536 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7537 {
7538 if (curbuf->b_p_vsts_array)
7539 {
7540 vim_free(curbuf->b_p_vsts_array);
7541 curbuf->b_p_vsts_array = 0;
7542 }
7543 }
7544 else
7545 {
7546 for (cp = *varp; *cp; ++cp)
7547 {
7548 if (vim_isdigit(*cp))
7549 continue;
7550 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7551 continue;
7552 errmsg = e_invarg;
7553 break;
7554 }
7555 if (errmsg == NULL)
7556 {
7557 int *oldarray = curbuf->b_p_vsts_array;
7558 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7559 {
7560 if (oldarray)
7561 vim_free(oldarray);
7562 }
7563 else
7564 errmsg = e_invarg;
7565 }
7566 }
7567 }
7568
7569 /* 'vartabstop' */
7570 else if (varp == &(curbuf->b_p_vts))
7571 {
7572 char_u *cp;
7573
7574 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7575 {
7576 if (curbuf->b_p_vts_array)
7577 {
7578 vim_free(curbuf->b_p_vts_array);
7579 curbuf->b_p_vts_array = NULL;
7580 }
7581 }
7582 else
7583 {
7584 for (cp = *varp; *cp; ++cp)
7585 {
7586 if (vim_isdigit(*cp))
7587 continue;
7588 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7589 continue;
7590 errmsg = e_invarg;
7591 break;
7592 }
7593 if (errmsg == NULL)
7594 {
7595 int *oldarray = curbuf->b_p_vts_array;
7596 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7597 {
7598 if (oldarray)
7599 vim_free(oldarray);
7600#ifdef FEAT_FOLDING
7601 if (foldmethodIsIndent(curwin))
7602 foldUpdateAll(curwin);
7603#endif /* FEAT_FOLDING */
7604 }
7605 else
7606 errmsg = e_invarg;
7607 }
7608 }
7609 }
7610#endif
7611
Bram Moolenaar071d4272004-06-13 20:20:40 +00007612 /* Options that are a list of flags. */
7613 else
7614 {
7615 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007616 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007617 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007618 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007619 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007620 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007622 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007623 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007624#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007625 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007626 p = (char_u *)COCU_ALL;
7627#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007628 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007629 {
7630#ifdef FEAT_MOUSE
7631 p = (char_u *)MOUSE_ALL;
7632#else
7633 if (*p_mouse != NUL)
7634 errmsg = (char_u *)N_("E538: No mouse support");
7635#endif
7636 }
7637#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007638 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007639 p = (char_u *)GO_ALL;
7640#endif
7641 if (p != NULL)
7642 {
7643 for (s = *varp; *s; ++s)
7644 if (vim_strchr(p, *s) == NULL)
7645 {
7646 errmsg = illegal_char(errbuf, *s);
7647 break;
7648 }
7649 }
7650 }
7651
7652 /*
7653 * If error detected, restore the previous value.
7654 */
7655 if (errmsg != NULL)
7656 {
7657 if (new_value_alloced)
7658 free_string_option(*varp);
7659 *varp = oldval;
7660 /*
7661 * When resetting some values, need to act on it.
7662 */
7663 if (did_chartab)
7664 (void)init_chartab();
7665 if (varp == &p_hl)
7666 (void)highlight_changed();
7667 }
7668 else
7669 {
7670#ifdef FEAT_EVAL
7671 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007672 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673#endif
7674 /*
7675 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007676 * Use "free_oldval", because recursiveness may change the flags under
7677 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007678 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007679 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007680 free_string_option(oldval);
7681 if (new_value_alloced)
7682 options[opt_idx].flags |= P_ALLOCED;
7683 else
7684 options[opt_idx].flags &= ~P_ALLOCED;
7685
7686 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007687 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007688 {
7689 /* global option with local value set to use global value; free
7690 * the local value and make it empty */
7691 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7692 free_string_option(*(char_u **)p);
7693 *(char_u **)p = empty_option;
7694 }
7695
7696 /* May set global value for local option. */
7697 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7698 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007699
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007700 /*
7701 * Trigger the autocommand only after setting the flags.
7702 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007703#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007704 /* When 'syntax' is set, load the syntax of that name */
7705 if (varp == &(curbuf->b_p_syn))
7706 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007707 static int syn_recursive = 0;
7708
7709 ++syn_recursive;
7710 // Only pass TRUE for "force" when the value changed or not used
7711 // recursively, to avoid endless recurrence.
7712 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7713 value_changed || syn_recursive == 1, curbuf);
7714 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007715 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007716#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007717 else if (varp == &(curbuf->b_p_ft))
7718 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007719 /* 'filetype' is set, trigger the FileType autocommand.
7720 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007721 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007722 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007723 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007724 static int ft_recursive = 0;
7725
7726 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007727 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007728 // Only pass TRUE for "force" when the value changed or not
7729 // used recursively, to avoid endless recurrence.
7730 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7731 value_changed || ft_recursive == 1, curbuf);
7732 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007733 /* Just in case the old "curbuf" is now invalid. */
7734 if (varp != &(curbuf->b_p_ft))
7735 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007736 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007737 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007738#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007739 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007740 {
7741 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007742 char_u *q = curwin->w_s->b_p_spl;
7743
7744 /* Skip the first name if it is "cjk". */
7745 if (STRNCMP(q, "cjk,", 4) == 0)
7746 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007747
7748 /*
7749 * Source the spell/LANG.vim in 'runtimepath'.
7750 * They could set 'spellcapcheck' depending on the language.
7751 * Use the first name in 'spelllang' up to '_region' or
7752 * '.encoding'.
7753 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007754 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007755 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7756 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007757 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007758 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007759 }
7760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761 }
7762
7763#ifdef FEAT_MOUSE
7764 if (varp == &p_mouse)
7765 {
7766# ifdef FEAT_MOUSE_TTY
7767 if (*p_mouse == NUL)
7768 mch_setmouse(FALSE); /* switch mouse off */
7769 else
7770# endif
7771 setmouse(); /* in case 'mouse' changed */
7772 }
7773#endif
7774
Bram Moolenaar913077c2012-03-28 19:59:04 +02007775 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007776 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007777 curwin->w_set_curswant = TRUE;
7778
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007779#ifdef FEAT_GUI
7780 /* check redraw when it's not a GUI option or the GUI is active. */
7781 if (!redraw_gui_only || gui.in_use)
7782#endif
7783 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007785#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7786 if (did_swaptcap)
7787 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007788 set_termname((char_u *)"win32");
7789 init_highlight(TRUE, FALSE);
7790 }
7791#endif
7792
Bram Moolenaar071d4272004-06-13 20:20:40 +00007793 return errmsg;
7794}
7795
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007796#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007797/*
7798 * Simple int comparison function for use with qsort()
7799 */
7800 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007801int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007802{
7803 return *(const int *)a - *(const int *)b;
7804}
7805
7806/*
7807 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7808 * Returns error message, NULL if it's OK.
7809 */
7810 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007811check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007812{
7813 char_u *s;
7814 int col;
7815 int count = 0;
7816 int color_cols[256];
7817 int i;
7818 int j = 0;
7819
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007820 if (wp->w_buffer == NULL)
7821 return NULL; /* buffer was closed */
7822
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007823 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007824 {
7825 if (*s == '-' || *s == '+')
7826 {
7827 /* -N and +N: add to 'textwidth' */
7828 col = (*s == '-') ? -1 : 1;
7829 ++s;
7830 if (!VIM_ISDIGIT(*s))
7831 return e_invarg;
7832 col = col * getdigits(&s);
7833 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007834 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007835 col += wp->w_buffer->b_p_tw;
7836 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007837 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007838 }
7839 else if (VIM_ISDIGIT(*s))
7840 col = getdigits(&s);
7841 else
7842 return e_invarg;
7843 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007844skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007845 if (*s == NUL)
7846 break;
7847 if (*s != ',')
7848 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007849 if (*++s == NUL)
7850 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007851 }
7852
7853 vim_free(wp->w_p_cc_cols);
7854 if (count == 0)
7855 wp->w_p_cc_cols = NULL;
7856 else
7857 {
7858 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7859 if (wp->w_p_cc_cols != NULL)
7860 {
7861 /* sort the columns for faster usage on screen redraw inside
7862 * win_line() */
7863 qsort(color_cols, count, sizeof(int), int_cmp);
7864
7865 for (i = 0; i < count; ++i)
7866 /* skip duplicates */
7867 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7868 wp->w_p_cc_cols[j++] = color_cols[i];
7869 wp->w_p_cc_cols[j] = -1; /* end marker */
7870 }
7871 }
7872
7873 return NULL; /* no error */
7874}
7875#endif
7876
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877/*
7878 * Handle setting 'listchars' or 'fillchars'.
7879 * Returns error message, NULL if it's OK.
7880 */
7881 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007882set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007883{
7884 int round, i, len, entries;
7885 char_u *p, *s;
7886 int c1, c2 = 0;
7887 struct charstab
7888 {
7889 int *cp;
7890 char *name;
7891 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 static struct charstab filltab[] =
7893 {
7894 {&fill_stl, "stl"},
7895 {&fill_stlnc, "stlnc"},
7896 {&fill_vert, "vert"},
7897 {&fill_fold, "fold"},
7898 {&fill_diff, "diff"},
7899 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 static struct charstab lcstab[] =
7901 {
7902 {&lcs_eol, "eol"},
7903 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007904 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007906 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 {&lcs_tab2, "tab"},
7908 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007909#ifdef FEAT_CONCEAL
7910 {&lcs_conceal, "conceal"},
7911#else
7912 {NULL, "conceal"},
7913#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 };
7915 struct charstab *tab;
7916
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 {
7919 tab = lcstab;
7920 entries = sizeof(lcstab) / sizeof(struct charstab);
7921 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007922 else
7923 {
7924 tab = filltab;
7925 entries = sizeof(filltab) / sizeof(struct charstab);
7926 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927
7928 /* first round: check for valid value, second round: assign values */
7929 for (round = 0; round <= 1; ++round)
7930 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007931 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932 {
7933 /* After checking that the value is valid: set defaults: space for
7934 * 'fillchars', NUL for 'listchars' */
7935 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007936 if (tab[i].cp != NULL)
7937 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 if (varp == &p_lcs)
7939 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007940 else
7941 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007942 }
7943 p = *varp;
7944 while (*p)
7945 {
7946 for (i = 0; i < entries; ++i)
7947 {
7948 len = (int)STRLEN(tab[i].name);
7949 if (STRNCMP(p, tab[i].name, len) == 0
7950 && p[len] == ':'
7951 && p[len + 1] != NUL)
7952 {
7953 s = p + len + 1;
7954#ifdef FEAT_MBYTE
7955 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007956 if (mb_char2cells(c1) > 1)
7957 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958#else
7959 c1 = *s++;
7960#endif
7961 if (tab[i].cp == &lcs_tab2)
7962 {
7963 if (*s == NUL)
7964 continue;
7965#ifdef FEAT_MBYTE
7966 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007967 if (mb_char2cells(c2) > 1)
7968 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969#else
7970 c2 = *s++;
7971#endif
7972 }
7973 if (*s == ',' || *s == NUL)
7974 {
7975 if (round)
7976 {
7977 if (tab[i].cp == &lcs_tab2)
7978 {
7979 lcs_tab1 = c1;
7980 lcs_tab2 = c2;
7981 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007982 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 *(tab[i].cp) = c1;
7984
7985 }
7986 p = s;
7987 break;
7988 }
7989 }
7990 }
7991
7992 if (i == entries)
7993 return e_invarg;
7994 if (*p == ',')
7995 ++p;
7996 }
7997 }
7998
7999 return NULL; /* no error */
8000}
8001
8002#ifdef FEAT_STL_OPT
8003/*
8004 * Check validity of options with the 'statusline' format.
8005 * Return error message or NULL.
8006 */
8007 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008008check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009{
8010 int itemcnt = 0;
8011 int groupdepth = 0;
8012 static char_u errbuf[80];
8013
8014 while (*s && itemcnt < STL_MAX_ITEM)
8015 {
8016 /* Check for valid keys after % sequences */
8017 while (*s && *s != '%')
8018 s++;
8019 if (!*s)
8020 break;
8021 s++;
8022 if (*s != '%' && *s != ')')
8023 ++itemcnt;
8024 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8025 {
8026 s++;
8027 continue;
8028 }
8029 if (*s == ')')
8030 {
8031 s++;
8032 if (--groupdepth < 0)
8033 break;
8034 continue;
8035 }
8036 if (*s == '-')
8037 s++;
8038 while (VIM_ISDIGIT(*s))
8039 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008040 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008041 continue;
8042 if (*s == '.')
8043 {
8044 s++;
8045 while (*s && VIM_ISDIGIT(*s))
8046 s++;
8047 }
8048 if (*s == '(')
8049 {
8050 groupdepth++;
8051 continue;
8052 }
8053 if (vim_strchr(STL_ALL, *s) == NULL)
8054 {
8055 return illegal_char(errbuf, *s);
8056 }
8057 if (*s == '{')
8058 {
8059 s++;
8060 while (*s != '}' && *s)
8061 s++;
8062 if (*s != '}')
8063 return (char_u *)N_("E540: Unclosed expression sequence");
8064 }
8065 }
8066 if (itemcnt >= STL_MAX_ITEM)
8067 return (char_u *)N_("E541: too many items");
8068 if (groupdepth != 0)
8069 return (char_u *)N_("E542: unbalanced groups");
8070 return NULL;
8071}
8072#endif
8073
8074#ifdef FEAT_CLIPBOARD
8075/*
8076 * Extract the items in the 'clipboard' option and set global values.
8077 */
8078 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008079check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008080{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008081 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008082 int new_autoselect_star = FALSE;
8083 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008084 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008085 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086 regprog_T *new_exclude_prog = NULL;
8087 char_u *errmsg = NULL;
8088 char_u *p;
8089
8090 for (p = p_cb; *p != NUL; )
8091 {
8092 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8093 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008094 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095 p += 7;
8096 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008097 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008098 && (p[11] == ',' || p[11] == NUL))
8099 {
8100 new_unnamed |= CLIP_UNNAMED_PLUS;
8101 p += 11;
8102 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008103 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008104 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008105 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008106 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008107 p += 10;
8108 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008109 else if (STRNCMP(p, "autoselectplus", 14) == 0
8110 && (p[14] == ',' || p[14] == NUL))
8111 {
8112 new_autoselect_plus = TRUE;
8113 p += 14;
8114 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008116 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 {
8118 new_autoselectml = TRUE;
8119 p += 12;
8120 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008121 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8122 {
8123 new_html = TRUE;
8124 p += 4;
8125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8127 {
8128 p += 8;
8129 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8130 if (new_exclude_prog == NULL)
8131 errmsg = e_invarg;
8132 break;
8133 }
8134 else
8135 {
8136 errmsg = e_invarg;
8137 break;
8138 }
8139 if (*p == ',')
8140 ++p;
8141 }
8142 if (errmsg == NULL)
8143 {
8144 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008145 clip_autoselect_star = new_autoselect_star;
8146 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008148 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008149 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008151#ifdef FEAT_GUI_GTK
8152 if (gui.in_use)
8153 {
8154 gui_gtk_set_selection_targets();
8155 gui_gtk_set_dnd_targets();
8156 }
8157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 }
8159 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008160 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161
8162 return errmsg;
8163}
8164#endif
8165
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008166#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008167 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008168did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008169{
8170 char_u *errmsg = NULL;
8171 win_T *wp;
8172 int l;
8173
8174 if (is_spellfile)
8175 {
8176 l = (int)STRLEN(curwin->w_s->b_p_spf);
8177 if (l > 0 && (l < 4
8178 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8179 errmsg = e_invarg;
8180 }
8181
8182 if (errmsg == NULL)
8183 {
8184 FOR_ALL_WINDOWS(wp)
8185 if (wp->w_buffer == curbuf && wp->w_p_spell)
8186 {
8187 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008188 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008189 }
8190 }
8191 return errmsg;
8192}
8193
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008194/*
8195 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8196 * Return error message when failed, NULL when OK.
8197 */
8198 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008199compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008200{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008201 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008202 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008203
Bram Moolenaar860cae12010-06-05 23:22:07 +02008204 if (*synblock->b_p_spc == NUL)
8205 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008206 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008207 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008208 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008209 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008210 if (re != NULL)
8211 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008212 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008213 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008214 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008215 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008216 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008217 return e_invarg;
8218 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008219 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008220 }
8221
Bram Moolenaar473de612013-06-08 18:19:48 +02008222 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008223 return NULL;
8224}
8225#endif
8226
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008227#if defined(FEAT_EVAL) || defined(PROTO)
8228/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008229 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008230 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008231 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008232 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008233set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008234{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008235 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8236 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008237 sctx_T new_script_ctx = script_ctx;
8238
8239 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008240
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008241 /* Remember where the option was set. For local options need to do that
8242 * in the buffer or window structure. */
8243 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008244 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008245 if (both || (opt_flags & OPT_LOCAL))
8246 {
8247 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008248 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008249 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008250 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008251 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008252}
8253#endif
8254
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255/*
8256 * Set the value of a boolean option, and take care of side effects.
8257 * Returns NULL for success, or an error message for an error.
8258 */
8259 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008260set_bool_option(
8261 int opt_idx, /* index in options[] table */
8262 char_u *varp, /* pointer to the option variable */
8263 int value, /* new value */
8264 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265{
8266 int old_value = *(int *)varp;
8267
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268 /* Disallow changing some options from secure mode */
8269 if ((secure
8270#ifdef HAVE_SANDBOX
8271 || sandbox != 0
8272#endif
8273 ) && (options[opt_idx].flags & P_SECURE))
8274 return e_secure;
8275
8276 *(int *)varp = value; /* set the new value */
8277#ifdef FEAT_EVAL
8278 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008279 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008280#endif
8281
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008282#ifdef FEAT_GUI
8283 need_mouse_correct = TRUE;
8284#endif
8285
Bram Moolenaar071d4272004-06-13 20:20:40 +00008286 /* May set global value for local option. */
8287 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8288 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8289
8290 /*
8291 * Handle side effects of changing a bool option.
8292 */
8293
8294 /* 'compatible' */
8295 if ((int *)varp == &p_cp)
8296 {
8297 compatible_set();
8298 }
8299
Bram Moolenaar920694c2016-08-21 17:45:02 +02008300#ifdef FEAT_LANGMAP
8301 if ((int *)varp == &p_lrm)
8302 /* 'langremap' -> !'langnoremap' */
8303 p_lnr = !p_lrm;
8304 else if ((int *)varp == &p_lnr)
8305 /* 'langnoremap' -> !'langremap' */
8306 p_lrm = !p_lnr;
8307#endif
8308
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008309#ifdef FEAT_PERSISTENT_UNDO
8310 /* 'undofile' */
8311 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8312 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008313 /* Only take action when the option was set. When reset we do not
8314 * delete the undo file, the option may be set again without making
8315 * any changes in between. */
8316 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008317 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008318 char_u hash[UNDO_HASH_SIZE];
8319 buf_T *save_curbuf = curbuf;
8320
Bram Moolenaar29323592016-07-24 22:04:11 +02008321 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008322 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008323 /* When 'undofile' is set globally: for every buffer, otherwise
8324 * only for the current buffer: Try to read in the undofile,
8325 * if one exists, the buffer wasn't changed and the buffer was
8326 * loaded */
8327 if ((curbuf == save_curbuf
8328 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8329 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8330 {
8331 u_compute_hash(hash);
8332 u_read_undo(NULL, hash, curbuf->b_fname);
8333 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008334 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008335 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008336 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008337 }
8338#endif
8339
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340 else if ((int *)varp == &curbuf->b_p_ro)
8341 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008342 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8344 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008345
8346 /* when 'readonly' is set may give W10 again */
8347 if (curbuf->b_p_ro)
8348 curbuf->b_did_warn = FALSE;
8349
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008351 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352#endif
8353 }
8354
Bram Moolenaar9c449722010-07-20 18:44:27 +02008355#ifdef FEAT_GUI
8356 else if ((int *)varp == &p_mh)
8357 {
8358 if (!p_mh)
8359 gui_mch_mousehide(FALSE);
8360 }
8361#endif
8362
Bram Moolenaara539df02010-08-01 14:35:05 +02008363 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008365 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008366# ifdef FEAT_TERMINAL
8367 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008368 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8369 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008370 {
8371 curbuf->b_p_ma = FALSE;
8372 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8373 }
8374# endif
8375# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008376 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008377# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008378 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008379#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 /* when 'endofline' is changed, redraw the window title */
8381 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008382 {
8383 redraw_titles();
8384 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008385 /* when 'fixeol' is changed, redraw the window title */
8386 else if ((int *)varp == &curbuf->b_p_fixeol)
8387 {
8388 redraw_titles();
8389 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008390# ifdef FEAT_MBYTE
8391 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008392 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008393 {
8394 redraw_titles();
8395 }
8396# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397#endif
8398
8399 /* when 'bin' is set also set some other options */
8400 else if ((int *)varp == &curbuf->b_p_bin)
8401 {
8402 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8403#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008404 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405#endif
8406 }
8407
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 /* when 'buflisted' changes, trigger autocommands */
8409 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8410 {
8411 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8412 NULL, NULL, TRUE, curbuf);
8413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414
8415 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8416 else if ((int *)varp == &curbuf->b_p_swf)
8417 {
8418 if (curbuf->b_p_swf && p_uc)
8419 ml_open_file(curbuf); /* create the swap file */
8420 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008421 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8422 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 mf_close_file(curbuf, TRUE); /* remove the swap file */
8424 }
8425
8426 /* when 'terse' is set change 'shortmess' */
8427 else if ((int *)varp == &p_terse)
8428 {
8429 char_u *p;
8430
8431 p = vim_strchr(p_shm, SHM_SEARCH);
8432
8433 /* insert 's' in p_shm */
8434 if (p_terse && p == NULL)
8435 {
8436 STRCPY(IObuff, p_shm);
8437 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008438 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008439 }
8440 /* remove 's' from p_shm */
8441 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008442 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443 }
8444
8445 /* when 'paste' is set or reset also change other options */
8446 else if ((int *)varp == &p_paste)
8447 {
8448 paste_option_changed();
8449 }
8450
8451 /* when 'insertmode' is set from an autocommand need to do work here */
8452 else if ((int *)varp == &p_im)
8453 {
8454 if (p_im)
8455 {
8456 if ((State & INSERT) == 0)
8457 need_start_insertmode = TRUE;
8458 stop_insert_mode = FALSE;
8459 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008460 /* only reset if it was set previously */
8461 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008462 {
8463 need_start_insertmode = FALSE;
8464 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008465 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466 clear_cmdline = TRUE; /* remove "(insert)" */
8467 restart_edit = 0;
8468 }
8469 }
8470
8471 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8472 else if ((int *)varp == &p_ic && p_hls)
8473 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008474 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008475 }
8476
8477#ifdef FEAT_SEARCH_EXTRA
8478 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8479 else if ((int *)varp == &p_hls)
8480 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008481 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008482 }
8483#endif
8484
Bram Moolenaar071d4272004-06-13 20:20:40 +00008485 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8486 * at the end of normal_cmd() */
8487 else if ((int *)varp == &curwin->w_p_scb)
8488 {
8489 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008490 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008492 curwin->w_scbind_pos = curwin->w_topline;
8493 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008494 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495
Bram Moolenaar4033c552017-09-16 20:54:51 +02008496#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008497 /* There can be only one window with 'previewwindow' set. */
8498 else if ((int *)varp == &curwin->w_p_pvw)
8499 {
8500 if (curwin->w_p_pvw)
8501 {
8502 win_T *win;
8503
Bram Moolenaar29323592016-07-24 22:04:11 +02008504 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008505 if (win->w_p_pvw && win != curwin)
8506 {
8507 curwin->w_p_pvw = FALSE;
8508 return (char_u *)N_("E590: A preview window already exists");
8509 }
8510 }
8511 }
8512#endif
8513
8514 /* when 'textmode' is set or reset also change 'fileformat' */
8515 else if ((int *)varp == &curbuf->b_p_tx)
8516 {
8517 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8518 }
8519
8520 /* when 'textauto' is set or reset also change 'fileformats' */
8521 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522 set_string_option_direct((char_u *)"ffs", -1,
8523 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008524 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525
8526 /*
8527 * When 'lisp' option changes include/exclude '-' in
8528 * keyword characters.
8529 */
8530#ifdef FEAT_LISP
8531 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8532 {
8533 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8534 }
8535#endif
8536
8537#ifdef FEAT_TITLE
8538 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008539 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008541 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008542 }
8543#endif
8544
8545 else if ((int *)varp == &curbuf->b_changed)
8546 {
8547 if (!value)
8548 save_file_ff(curbuf); /* Buffer is unchanged */
8549#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008550 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008552 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008553 }
8554
8555#ifdef BACKSLASH_IN_FILENAME
8556 else if ((int *)varp == &p_ssl)
8557 {
8558 if (p_ssl)
8559 {
8560 psepc = '/';
8561 psepcN = '\\';
8562 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563 }
8564 else
8565 {
8566 psepc = '\\';
8567 psepcN = '/';
8568 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569 }
8570
8571 /* need to adjust the file name arguments and buffer names. */
8572 buflist_slash_adjust();
8573 alist_slash_adjust();
8574# ifdef FEAT_EVAL
8575 scriptnames_slash_adjust();
8576# endif
8577 }
8578#endif
8579
8580 /* If 'wrap' is set, set w_leftcol to zero. */
8581 else if ((int *)varp == &curwin->w_p_wrap)
8582 {
8583 if (curwin->w_p_wrap)
8584 curwin->w_leftcol = 0;
8585 }
8586
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 else if ((int *)varp == &p_ea)
8588 {
8589 if (p_ea && !old_value)
8590 win_equal(curwin, FALSE, 0);
8591 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008592
8593 else if ((int *)varp == &p_wiv)
8594 {
8595 /*
8596 * When 'weirdinvert' changed, set/reset 't_xs'.
8597 * Then set 'weirdinvert' according to value of 't_xs'.
8598 */
8599 if (p_wiv && !old_value)
8600 T_XS = (char_u *)"y";
8601 else if (!p_wiv && old_value)
8602 T_XS = empty_option;
8603 p_wiv = (*T_XS != NUL);
8604 }
8605
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008606#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008607 else if ((int *)varp == &p_beval)
8608 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008609 if (!balloonEvalForTerm)
8610 {
8611 if (p_beval && !old_value)
8612 gui_mch_enable_beval_area(balloonEval);
8613 else if (!p_beval && old_value)
8614 gui_mch_disable_beval_area(balloonEval);
8615 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008616 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008617#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008618#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008619 else if ((int *)varp == &p_bevalterm)
8620 {
8621 mch_bevalterm_changed();
8622 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008623#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008625#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008626 else if ((int *)varp == &p_acd)
8627 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008628 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008629 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008630 }
8631#endif
8632
8633#ifdef FEAT_DIFF
8634 /* 'diff' */
8635 else if ((int *)varp == &curwin->w_p_diff)
8636 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008637 /* May add or remove the buffer from the list of diff buffers. */
8638 diff_buf_adjust(curwin);
8639# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640 if (foldmethodIsDiff(curwin))
8641 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008642# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643 }
8644#endif
8645
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008646#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008647 /* 'imdisable' */
8648 else if ((int *)varp == &p_imdisable)
8649 {
8650 /* Only de-activate it here, it will be enabled when changing mode. */
8651 if (p_imdisable)
8652 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008653 else if (State & INSERT)
8654 /* When the option is set from an autocommand, it may need to take
8655 * effect right away. */
8656 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008657 }
8658#endif
8659
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008660#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008661 /* 'spell' */
8662 else if ((int *)varp == &curwin->w_p_spell)
8663 {
8664 if (curwin->w_p_spell)
8665 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008666 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008667 if (errmsg != NULL)
8668 EMSG(_(errmsg));
8669 }
8670 }
8671#endif
8672
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673#ifdef FEAT_FKMAP
8674 else if ((int *)varp == &p_altkeymap)
8675 {
8676 if (old_value != p_altkeymap)
8677 {
8678 if (!p_altkeymap)
8679 {
8680 p_hkmap = p_fkmap;
8681 p_fkmap = 0;
8682 }
8683 else
8684 {
8685 p_fkmap = p_hkmap;
8686 p_hkmap = 0;
8687 }
8688 (void)init_chartab();
8689 }
8690 }
8691
8692 /*
8693 * In case some second language keymapping options have changed, check
8694 * and correct the setting in a consistent way.
8695 */
8696
8697 /*
8698 * If hkmap or fkmap are set, reset Arabic keymapping.
8699 */
8700 if ((p_hkmap || p_fkmap) && p_altkeymap)
8701 {
8702 p_altkeymap = p_fkmap;
8703# ifdef FEAT_ARABIC
8704 curwin->w_p_arab = FALSE;
8705# endif
8706 (void)init_chartab();
8707 }
8708
8709 /*
8710 * If hkmap set, reset Farsi keymapping.
8711 */
8712 if (p_hkmap && p_altkeymap)
8713 {
8714 p_altkeymap = 0;
8715 p_fkmap = 0;
8716# ifdef FEAT_ARABIC
8717 curwin->w_p_arab = FALSE;
8718# endif
8719 (void)init_chartab();
8720 }
8721
8722 /*
8723 * If fkmap set, reset Hebrew keymapping.
8724 */
8725 if (p_fkmap && !p_altkeymap)
8726 {
8727 p_altkeymap = 1;
8728 p_hkmap = 0;
8729# ifdef FEAT_ARABIC
8730 curwin->w_p_arab = FALSE;
8731# endif
8732 (void)init_chartab();
8733 }
8734#endif
8735
8736#ifdef FEAT_ARABIC
8737 if ((int *)varp == &curwin->w_p_arab)
8738 {
8739 if (curwin->w_p_arab)
8740 {
8741 /*
8742 * 'arabic' is set, handle various sub-settings.
8743 */
8744 if (!p_tbidi)
8745 {
8746 /* set rightleft mode */
8747 if (!curwin->w_p_rl)
8748 {
8749 curwin->w_p_rl = TRUE;
8750 changed_window_setting();
8751 }
8752
8753 /* Enable Arabic shaping (major part of what Arabic requires) */
8754 if (!p_arshape)
8755 {
8756 p_arshape = TRUE;
8757 redraw_later_clear();
8758 }
8759 }
8760
8761 /* Arabic requires a utf-8 encoding, inform the user if its not
8762 * set. */
8763 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008764 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008765 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8766
Bram Moolenaar8820b482017-03-16 17:23:31 +01008767 msg_source(HL_ATTR(HLF_W));
8768 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008769#ifdef FEAT_EVAL
8770 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8771#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008772 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773
8774# ifdef FEAT_MBYTE
8775 /* set 'delcombine' */
8776 p_deco = TRUE;
8777# endif
8778
8779# ifdef FEAT_KEYMAP
8780 /* Force-set the necessary keymap for arabic */
8781 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8782 OPT_LOCAL);
8783# endif
8784# ifdef FEAT_FKMAP
8785 p_altkeymap = 0;
8786 p_hkmap = 0;
8787 p_fkmap = 0;
8788 (void)init_chartab();
8789# endif
8790 }
8791 else
8792 {
8793 /*
8794 * 'arabic' is reset, handle various sub-settings.
8795 */
8796 if (!p_tbidi)
8797 {
8798 /* reset rightleft mode */
8799 if (curwin->w_p_rl)
8800 {
8801 curwin->w_p_rl = FALSE;
8802 changed_window_setting();
8803 }
8804
8805 /* 'arabicshape' isn't reset, it is a global option and
8806 * another window may still need it "on". */
8807 }
8808
8809 /* 'delcombine' isn't reset, it is a global option and another
8810 * window may still want it "on". */
8811
8812# ifdef FEAT_KEYMAP
8813 /* Revert to the default keymap */
8814 curbuf->b_p_iminsert = B_IMODE_NONE;
8815 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8816# endif
8817 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008818 }
8819
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008820#endif
8821
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008822#ifdef FEAT_TERMGUICOLORS
8823 /* 'termguicolors' */
8824 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008825 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008826# ifdef FEAT_VTP
8827 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8828 if (!has_vtp_working())
8829 {
8830 p_tgc = 0;
8831 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8832 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008833 if (is_term_win32())
8834 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008835# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008836# ifdef FEAT_GUI
8837 if (!gui.in_use && !gui.starting)
8838# endif
8839 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008840# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008841 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008842 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008843 {
8844 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008845 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008846 init_highlight(TRUE, FALSE);
8847 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008848# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008849 }
8850#endif
8851
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 /*
8853 * End of handling side effects for bool options.
8854 */
8855
Bram Moolenaar53744302015-07-17 17:38:22 +02008856 /* after handling side effects, call autocommand */
8857
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 options[opt_idx].flags |= P_WAS_SET;
8859
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008860#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008861 // Don't do this while starting up or recursively.
8862 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008863 {
8864 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008865
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008866 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8867 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8868 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008869 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8870 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8871 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8872 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8873 reset_v_option_vars();
8874 }
8875#endif
8876
Bram Moolenaar071d4272004-06-13 20:20:40 +00008877 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008878 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008879 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008880 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 check_redraw(options[opt_idx].flags);
8882
8883 return NULL;
8884}
8885
8886/*
8887 * Set the value of a number option, and take care of side effects.
8888 * Returns NULL for success, or an error message for an error.
8889 */
8890 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008891set_num_option(
8892 int opt_idx, /* index in options[] table */
8893 char_u *varp, /* pointer to the option variable */
8894 long value, /* new value */
8895 char_u *errbuf, /* buffer for error messages */
8896 size_t errbuflen, /* length of "errbuf" */
8897 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 OPT_MODELINE */
8899{
8900 char_u *errmsg = NULL;
8901 long old_value = *(long *)varp;
8902 long old_Rows = Rows; /* remember old Rows */
8903 long old_Columns = Columns; /* remember old Columns */
8904 long *pp = (long *)varp;
8905
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008906 /* Disallow changing some options from secure mode. */
8907 if ((secure
8908#ifdef HAVE_SANDBOX
8909 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008911 ) && (options[opt_idx].flags & P_SECURE))
8912 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913
8914 *pp = value;
8915#ifdef FEAT_EVAL
8916 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008917 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008919#ifdef FEAT_GUI
8920 need_mouse_correct = TRUE;
8921#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922
Bram Moolenaar14f24742012-08-08 18:01:05 +02008923 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924 {
8925 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008926#ifdef FEAT_VARTABS
8927 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8928 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8929 ? tabstop_first(curbuf->b_p_vts_array)
8930 : curbuf->b_p_ts;
8931#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008934 }
8935
8936 /*
8937 * Number options that need some action when changed
8938 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 if (pp == &p_wh || pp == &p_hh)
8940 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008941 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942 if (p_wh < 1)
8943 {
8944 errmsg = e_positive;
8945 p_wh = 1;
8946 }
8947 if (p_wmh > p_wh)
8948 {
8949 errmsg = e_winheight;
8950 p_wh = p_wmh;
8951 }
8952 if (p_hh < 0)
8953 {
8954 errmsg = e_positive;
8955 p_hh = 0;
8956 }
8957
8958 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008959 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008960 {
8961 if (pp == &p_wh && curwin->w_height < p_wh)
8962 win_setheight((int)p_wh);
8963 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8964 win_setheight((int)p_hh);
8965 }
8966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008967 else if (pp == &p_wmh)
8968 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008969 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 if (p_wmh < 0)
8971 {
8972 errmsg = e_positive;
8973 p_wmh = 0;
8974 }
8975 if (p_wmh > p_wh)
8976 {
8977 errmsg = e_winheight;
8978 p_wmh = p_wh;
8979 }
8980 win_setminheight();
8981 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008982 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008983 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008984 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985 if (p_wiw < 1)
8986 {
8987 errmsg = e_positive;
8988 p_wiw = 1;
8989 }
8990 if (p_wmw > p_wiw)
8991 {
8992 errmsg = e_winwidth;
8993 p_wiw = p_wmw;
8994 }
8995
8996 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008997 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008998 win_setwidth((int)p_wiw);
8999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000 else if (pp == &p_wmw)
9001 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009002 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009003 if (p_wmw < 0)
9004 {
9005 errmsg = e_positive;
9006 p_wmw = 0;
9007 }
9008 if (p_wmw > p_wiw)
9009 {
9010 errmsg = e_winwidth;
9011 p_wmw = p_wiw;
9012 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009013 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009015
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016 /* (re)set last window status line */
9017 else if (pp == &p_ls)
9018 {
9019 last_status(FALSE);
9020 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009021
9022 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009023 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009024 {
9025 shell_new_rows(); /* recompute window positions and heights */
9026 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009027
9028#ifdef FEAT_GUI
9029 else if (pp == &p_linespace)
9030 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009031 /* Recompute gui.char_height and resize the Vim window to keep the
9032 * same number of lines. */
9033 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009034 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035 }
9036#endif
9037
9038#ifdef FEAT_FOLDING
9039 /* 'foldlevel' */
9040 else if (pp == &curwin->w_p_fdl)
9041 {
9042 if (curwin->w_p_fdl < 0)
9043 curwin->w_p_fdl = 0;
9044 newFoldLevel();
9045 }
9046
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009047 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009048 else if (pp == &curwin->w_p_fml)
9049 {
9050 foldUpdateAll(curwin);
9051 }
9052
9053 /* 'foldnestmax' */
9054 else if (pp == &curwin->w_p_fdn)
9055 {
9056 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9057 foldUpdateAll(curwin);
9058 }
9059
9060 /* 'foldcolumn' */
9061 else if (pp == &curwin->w_p_fdc)
9062 {
9063 if (curwin->w_p_fdc < 0)
9064 {
9065 errmsg = e_positive;
9066 curwin->w_p_fdc = 0;
9067 }
9068 else if (curwin->w_p_fdc > 12)
9069 {
9070 errmsg = e_invarg;
9071 curwin->w_p_fdc = 12;
9072 }
9073 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009074#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009076#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077 /* 'shiftwidth' or 'tabstop' */
9078 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9079 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009080# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081 if (foldmethodIsIndent(curwin))
9082 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009083# endif
9084# ifdef FEAT_CINDENT
9085 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9086 * parse 'cinoptions'. */
9087 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9088 parse_cino(curbuf);
9089# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009091#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009093#ifdef FEAT_MBYTE
9094 /* 'maxcombine' */
9095 else if (pp == &p_mco)
9096 {
9097 if (p_mco > MAX_MCO)
9098 p_mco = MAX_MCO;
9099 else if (p_mco < 0)
9100 p_mco = 0;
9101 screenclear(); /* will re-allocate the screen */
9102 }
9103#endif
9104
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105 else if (pp == &curbuf->b_p_iminsert)
9106 {
9107 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9108 {
9109 errmsg = e_invarg;
9110 curbuf->b_p_iminsert = B_IMODE_NONE;
9111 }
9112 p_iminsert = curbuf->b_p_iminsert;
9113 if (termcap_active) /* don't do this in the alternate screen */
9114 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009115#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 /* Show/unshow value of 'keymap' in status lines. */
9117 status_redraw_curbuf();
9118#endif
9119 }
9120
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009121#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9122 /* 'imstyle' */
9123 else if (pp == &p_imst)
9124 {
9125 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9126 errmsg = e_invarg;
9127 }
9128#endif
9129
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009130 else if (pp == &p_window)
9131 {
9132 if (p_window < 1)
9133 p_window = 1;
9134 else if (p_window >= Rows)
9135 p_window = Rows - 1;
9136 }
9137
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138 else if (pp == &curbuf->b_p_imsearch)
9139 {
9140 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9141 {
9142 errmsg = e_invarg;
9143 curbuf->b_p_imsearch = B_IMODE_NONE;
9144 }
9145 p_imsearch = curbuf->b_p_imsearch;
9146 }
9147
9148#ifdef FEAT_TITLE
9149 /* if 'titlelen' has changed, redraw the title */
9150 else if (pp == &p_titlelen)
9151 {
9152 if (p_titlelen < 0)
9153 {
9154 errmsg = e_positive;
9155 p_titlelen = 85;
9156 }
9157 if (starting != NO_SCREEN && old_value != p_titlelen)
9158 need_maketitle = TRUE;
9159 }
9160#endif
9161
9162 /* if p_ch changed value, change the command line height */
9163 else if (pp == &p_ch)
9164 {
9165 if (p_ch < 1)
9166 {
9167 errmsg = e_positive;
9168 p_ch = 1;
9169 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009170 if (p_ch > Rows - min_rows() + 1)
9171 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172
9173 /* Only compute the new window layout when startup has been
9174 * completed. Otherwise the frame sizes may be wrong. */
9175 if (p_ch != old_value && full_screen
9176#ifdef FEAT_GUI
9177 && !gui.starting
9178#endif
9179 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009180 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009181 }
9182
9183 /* when 'updatecount' changes from zero to non-zero, open swap files */
9184 else if (pp == &p_uc)
9185 {
9186 if (p_uc < 0)
9187 {
9188 errmsg = e_positive;
9189 p_uc = 100;
9190 }
9191 if (p_uc && !old_value)
9192 ml_open_files();
9193 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009194#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009195 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009196 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009197 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009198 {
9199 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009200 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009201 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009202 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009203 {
9204 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009205 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009206 }
9207 }
9208#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009209#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009210 else if (pp == &p_mzq)
9211 mzvim_reset_timer();
9212#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009214#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9215 /* 'pyxversion' */
9216 else if (pp == &p_pyx)
9217 {
9218 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9219 errmsg = e_invarg;
9220 }
9221#endif
9222
Bram Moolenaar071d4272004-06-13 20:20:40 +00009223 /* sync undo before 'undolevels' changes */
9224 else if (pp == &p_ul)
9225 {
9226 /* use the old value, otherwise u_sync() may not work properly */
9227 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009228 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009229 p_ul = value;
9230 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009231 else if (pp == &curbuf->b_p_ul)
9232 {
9233 /* use the old value, otherwise u_sync() may not work properly */
9234 curbuf->b_p_ul = old_value;
9235 u_sync(TRUE);
9236 curbuf->b_p_ul = value;
9237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009238
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009239#ifdef FEAT_LINEBREAK
9240 /* 'numberwidth' must be positive */
9241 else if (pp == &curwin->w_p_nuw)
9242 {
9243 if (curwin->w_p_nuw < 1)
9244 {
9245 errmsg = e_positive;
9246 curwin->w_p_nuw = 1;
9247 }
9248 if (curwin->w_p_nuw > 10)
9249 {
9250 errmsg = e_invarg;
9251 curwin->w_p_nuw = 10;
9252 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009253 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009254 }
9255#endif
9256
Bram Moolenaar1a384422010-07-14 19:53:30 +02009257 else if (pp == &curbuf->b_p_tw)
9258 {
9259 if (curbuf->b_p_tw < 0)
9260 {
9261 errmsg = e_positive;
9262 curbuf->b_p_tw = 0;
9263 }
9264#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009265 {
9266 win_T *wp;
9267 tabpage_T *tp;
9268
9269 FOR_ALL_TAB_WINDOWS(tp, wp)
9270 check_colorcolumn(wp);
9271 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009272#endif
9273 }
9274
Bram Moolenaar071d4272004-06-13 20:20:40 +00009275 /*
9276 * Check the bounds for numeric options here
9277 */
9278 if (Rows < min_rows() && full_screen)
9279 {
9280 if (errbuf != NULL)
9281 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009282 vim_snprintf((char *)errbuf, errbuflen,
9283 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009284 errmsg = errbuf;
9285 }
9286 Rows = min_rows();
9287 }
9288 if (Columns < MIN_COLUMNS && full_screen)
9289 {
9290 if (errbuf != NULL)
9291 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009292 vim_snprintf((char *)errbuf, errbuflen,
9293 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009294 errmsg = errbuf;
9295 }
9296 Columns = MIN_COLUMNS;
9297 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009298 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009299
Bram Moolenaar071d4272004-06-13 20:20:40 +00009300 /*
9301 * If the screen (shell) height has been changed, assume it is the
9302 * physical screenheight.
9303 */
9304 if (old_Rows != Rows || old_Columns != Columns)
9305 {
9306 /* Changing the screen size is not allowed while updating the screen. */
9307 if (updating_screen)
9308 *pp = old_value;
9309 else if (full_screen
9310#ifdef FEAT_GUI
9311 && !gui.starting
9312#endif
9313 )
9314 set_shellsize((int)Columns, (int)Rows, TRUE);
9315 else
9316 {
9317 /* Postpone the resizing; check the size and cmdline position for
9318 * messages. */
9319 check_shellsize();
9320 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9321 cmdline_row = Rows - p_ch;
9322 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009323 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009324 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009325 }
9326
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327 if (curbuf->b_p_ts <= 0)
9328 {
9329 errmsg = e_positive;
9330 curbuf->b_p_ts = 8;
9331 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332 if (p_tm < 0)
9333 {
9334 errmsg = e_positive;
9335 p_tm = 0;
9336 }
9337 if ((curwin->w_p_scr <= 0
9338 || (curwin->w_p_scr > curwin->w_height
9339 && curwin->w_height > 0))
9340 && full_screen)
9341 {
9342 if (pp == &(curwin->w_p_scr))
9343 {
9344 if (curwin->w_p_scr != 0)
9345 errmsg = e_scroll;
9346 win_comp_scroll(curwin);
9347 }
9348 /* If 'scroll' became invalid because of a side effect silently adjust
9349 * it. */
9350 else if (curwin->w_p_scr <= 0)
9351 curwin->w_p_scr = 1;
9352 else /* curwin->w_p_scr > curwin->w_height */
9353 curwin->w_p_scr = curwin->w_height;
9354 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009355 if (p_hi < 0)
9356 {
9357 errmsg = e_positive;
9358 p_hi = 0;
9359 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009360 else if (p_hi > 10000)
9361 {
9362 errmsg = e_invarg;
9363 p_hi = 10000;
9364 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009365 if (p_re < 0 || p_re > 2)
9366 {
9367 errmsg = e_invarg;
9368 p_re = 0;
9369 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370 if (p_report < 0)
9371 {
9372 errmsg = e_positive;
9373 p_report = 1;
9374 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009375 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376 {
9377 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9378 p_sj = Rows / 2;
9379 else
9380 {
9381 errmsg = e_scroll;
9382 p_sj = 1;
9383 }
9384 }
9385 if (p_so < 0 && full_screen)
9386 {
9387 errmsg = e_scroll;
9388 p_so = 0;
9389 }
9390 if (p_siso < 0 && full_screen)
9391 {
9392 errmsg = e_positive;
9393 p_siso = 0;
9394 }
9395#ifdef FEAT_CMDWIN
9396 if (p_cwh < 1)
9397 {
9398 errmsg = e_positive;
9399 p_cwh = 1;
9400 }
9401#endif
9402 if (p_ut < 0)
9403 {
9404 errmsg = e_positive;
9405 p_ut = 2000;
9406 }
9407 if (p_ss < 0)
9408 {
9409 errmsg = e_positive;
9410 p_ss = 0;
9411 }
9412
9413 /* May set global value for local option. */
9414 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9415 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9416
9417 options[opt_idx].flags |= P_WAS_SET;
9418
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009419#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009420 // Don't do this while starting up, failure or recursively.
9421 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009422 {
9423 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009424 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9425 vim_snprintf((char *)buf_new, 10, "%ld", value);
9426 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009427 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9428 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9429 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9430 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9431 reset_v_option_vars();
9432 }
9433#endif
9434
Bram Moolenaar071d4272004-06-13 20:20:40 +00009435 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009436 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009437 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009438 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009439 check_redraw(options[opt_idx].flags);
9440
9441 return errmsg;
9442}
9443
9444/*
9445 * Called after an option changed: check if something needs to be redrawn.
9446 */
9447 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009448check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009449{
9450 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009451 int doclear = (flags & P_RCLR) == P_RCLR;
9452 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009453
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9455 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009456
9457 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9458 changed_window_setting();
9459 if (flags & P_RBUF)
9460 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009461 if (flags & P_RWINONLY)
9462 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009463 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009464 redraw_all_later(CLEAR);
9465 else if (all)
9466 redraw_all_later(NOT_VALID);
9467}
9468
9469/*
9470 * Find index for option 'arg'.
9471 * Return -1 if not found.
9472 */
9473 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009474findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475{
9476 int opt_idx;
9477 char *s, *p;
9478 static short quick_tab[27] = {0, 0}; /* quick access table */
9479 int is_term_opt;
9480
9481 /*
9482 * For first call: Initialize the quick-access table.
9483 * It contains the index for the first option that starts with a certain
9484 * letter. There are 26 letters, plus the first "t_" option.
9485 */
9486 if (quick_tab[1] == 0)
9487 {
9488 p = options[0].fullname;
9489 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9490 {
9491 if (s[0] != p[0])
9492 {
9493 if (s[0] == 't' && s[1] == '_')
9494 quick_tab[26] = opt_idx;
9495 else
9496 quick_tab[CharOrdLow(s[0])] = opt_idx;
9497 }
9498 p = s;
9499 }
9500 }
9501
9502 /*
9503 * Check for name starting with an illegal character.
9504 */
9505#ifdef EBCDIC
9506 if (!islower(arg[0]))
9507#else
9508 if (arg[0] < 'a' || arg[0] > 'z')
9509#endif
9510 return -1;
9511
9512 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9513 if (is_term_opt)
9514 opt_idx = quick_tab[26];
9515 else
9516 opt_idx = quick_tab[CharOrdLow(arg[0])];
9517 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9518 {
9519 if (STRCMP(arg, s) == 0) /* match full name */
9520 break;
9521 }
9522 if (s == NULL && !is_term_opt)
9523 {
9524 opt_idx = quick_tab[CharOrdLow(arg[0])];
9525 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9526 {
9527 s = options[opt_idx].shortname;
9528 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9529 break;
9530 s = NULL;
9531 }
9532 }
9533 if (s == NULL)
9534 opt_idx = -1;
9535 return opt_idx;
9536}
9537
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009538#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009539/*
9540 * Get the value for an option.
9541 *
9542 * Returns:
9543 * Number or Toggle option: 1, *numval gets value.
9544 * String option: 0, *stringval gets allocated string.
9545 * Hidden Number or Toggle option: -1.
9546 * hidden String option: -2.
9547 * unknown option: -3.
9548 */
9549 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009550get_option_value(
9551 char_u *name,
9552 long *numval,
9553 char_u **stringval, /* NULL when only checking existence */
9554 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009555{
9556 int opt_idx;
9557 char_u *varp;
9558
9559 opt_idx = findoption(name);
9560 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009561 {
9562 int key;
9563
9564 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009565 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009566 {
9567 char_u key_name[2];
9568 char_u *p;
9569
9570 if (key < 0)
9571 {
9572 key_name[0] = KEY2TERMCAP0(key);
9573 key_name[1] = KEY2TERMCAP1(key);
9574 }
9575 else
9576 {
9577 key_name[0] = KS_KEY;
9578 key_name[1] = (key & 0xff);
9579 }
9580 p = find_termcode(key_name);
9581 if (p != NULL)
9582 {
9583 if (stringval != NULL)
9584 *stringval = vim_strsave(p);
9585 return 0;
9586 }
9587 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009588 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590
9591 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9592
9593 if (options[opt_idx].flags & P_STRING)
9594 {
9595 if (varp == NULL) /* hidden option */
9596 return -2;
9597 if (stringval != NULL)
9598 {
9599#ifdef FEAT_CRYPT
9600 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009601 if ((char_u **)varp == &curbuf->b_p_key
9602 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009603 *stringval = vim_strsave((char_u *)"*****");
9604 else
9605#endif
9606 *stringval = vim_strsave(*(char_u **)(varp));
9607 }
9608 return 0;
9609 }
9610
9611 if (varp == NULL) /* hidden option */
9612 return -1;
9613 if (options[opt_idx].flags & P_NUM)
9614 *numval = *(long *)varp;
9615 else
9616 {
9617 /* Special case: 'modified' is b_changed, but we also want to consider
9618 * it set when 'ff' or 'fenc' changed. */
9619 if ((int *)varp == &curbuf->b_changed)
9620 *numval = curbufIsChanged();
9621 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009622 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009623 }
9624 return 1;
9625}
9626#endif
9627
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009628#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009629/*
9630 * Returns the option attributes and its value. Unlike the above function it
9631 * will return either global value or local value of the option depending on
9632 * what was requested, but it will never return global value if it was
9633 * requested to return local one and vice versa. Neither it will return
9634 * buffer-local value if it was requested to return window-local one.
9635 *
9636 * Pretends that option is absent if it is not present in the requested scope
9637 * (i.e. has no global, window-local or buffer-local value depending on
9638 * opt_type). Uses
9639 *
9640 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009641 * 0 hidden or unknown option, also option that does not have requested
9642 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009643 * see SOPT_* in vim.h for other flags
9644 *
9645 * Possible opt_type values: see SREQ_* in vim.h
9646 */
9647 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009648get_option_value_strict(
9649 char_u *name,
9650 long *numval,
9651 char_u **stringval, /* NULL when only obtaining attributes */
9652 int opt_type,
9653 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009654{
9655 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009656 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009657 struct vimoption *p;
9658 int r = 0;
9659
9660 opt_idx = findoption(name);
9661 if (opt_idx < 0)
9662 return 0;
9663
9664 p = &(options[opt_idx]);
9665
9666 /* Hidden option */
9667 if (p->var == NULL)
9668 return 0;
9669
9670 if (p->flags & P_BOOL)
9671 r |= SOPT_BOOL;
9672 else if (p->flags & P_NUM)
9673 r |= SOPT_NUM;
9674 else if (p->flags & P_STRING)
9675 r |= SOPT_STRING;
9676
9677 if (p->indir == PV_NONE)
9678 {
9679 if (opt_type == SREQ_GLOBAL)
9680 r |= SOPT_GLOBAL;
9681 else
9682 return 0; /* Did not request global-only option */
9683 }
9684 else
9685 {
9686 if (p->indir & PV_BOTH)
9687 r |= SOPT_GLOBAL;
9688 else if (opt_type == SREQ_GLOBAL)
9689 return 0; /* Requested global option */
9690
9691 if (p->indir & PV_WIN)
9692 {
9693 if (opt_type == SREQ_BUF)
9694 return 0; /* Did not request window-local option */
9695 else
9696 r |= SOPT_WIN;
9697 }
9698 else if (p->indir & PV_BUF)
9699 {
9700 if (opt_type == SREQ_WIN)
9701 return 0; /* Did not request buffer-local option */
9702 else
9703 r |= SOPT_BUF;
9704 }
9705 }
9706
9707 if (stringval == NULL)
9708 return r;
9709
9710 if (opt_type == SREQ_GLOBAL)
9711 varp = p->var;
9712 else
9713 {
9714 if (opt_type == SREQ_BUF)
9715 {
9716 /* Special case: 'modified' is b_changed, but we also want to
9717 * consider it set when 'ff' or 'fenc' changed. */
9718 if (p->indir == PV_MOD)
9719 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009720 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009721 varp = NULL;
9722 }
9723#ifdef FEAT_CRYPT
9724 else if (p->indir == PV_KEY)
9725 {
9726 /* never return the value of the crypt key */
9727 *stringval = NULL;
9728 varp = NULL;
9729 }
9730#endif
9731 else
9732 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009733 buf_T *save_curbuf = curbuf;
9734
9735 // only getting a pointer, no need to use aucmd_prepbuf()
9736 curbuf = (buf_T *)from;
9737 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009738 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009739 curbuf = save_curbuf;
9740 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009741 }
9742 }
9743 else if (opt_type == SREQ_WIN)
9744 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009745 win_T *save_curwin = curwin;
9746
9747 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009748 curbuf = curwin->w_buffer;
9749 varp = get_varp(p);
9750 curwin = save_curwin;
9751 curbuf = curwin->w_buffer;
9752 }
9753 if (varp == p->var)
9754 return (r | SOPT_UNSET);
9755 }
9756
9757 if (varp != NULL)
9758 {
9759 if (p->flags & P_STRING)
9760 *stringval = vim_strsave(*(char_u **)(varp));
9761 else if (p->flags & P_NUM)
9762 *numval = *(long *) varp;
9763 else
9764 *numval = *(int *)varp;
9765 }
9766
9767 return r;
9768}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009769
9770/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009771 * Iterate over options. First argument is a pointer to a pointer to a
9772 * structure inside options[] array, second is option type like in the above
9773 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009774 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009775 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009776 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009777 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009778 * first argument to NULL.
9779 *
9780 * Returns full option name for current option on each call.
9781 */
9782 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009783option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009784{
9785 struct vimoption *ret = NULL;
9786 do
9787 {
9788 if (*option == NULL)
9789 *option = (void *) options;
9790 else if (((struct vimoption *) (*option))->fullname == NULL)
9791 {
9792 *option = NULL;
9793 return NULL;
9794 }
9795 else
9796 *option = (void *) (((struct vimoption *) (*option)) + 1);
9797
9798 ret = ((struct vimoption *) (*option));
9799
9800 /* Hidden option */
9801 if (ret->var == NULL)
9802 {
9803 ret = NULL;
9804 continue;
9805 }
9806
9807 switch (opt_type)
9808 {
9809 case SREQ_GLOBAL:
9810 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9811 ret = NULL;
9812 break;
9813 case SREQ_BUF:
9814 if (!(ret->indir & PV_BUF))
9815 ret = NULL;
9816 break;
9817 case SREQ_WIN:
9818 if (!(ret->indir & PV_WIN))
9819 ret = NULL;
9820 break;
9821 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009822 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009823 return NULL;
9824 }
9825 }
9826 while (ret == NULL);
9827
9828 return (char_u *)ret->fullname;
9829}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009830#endif
9831
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832/*
9833 * Set the value of option "name".
9834 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009835 *
9836 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009837 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009838 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009839set_option_value(
9840 char_u *name,
9841 long number,
9842 char_u *string,
9843 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844{
9845 int opt_idx;
9846 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009847 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009848
9849 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009850 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009851 {
9852 int key;
9853
9854 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009855 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009856 {
9857 char_u key_name[2];
9858
9859 if (key < 0)
9860 {
9861 key_name[0] = KEY2TERMCAP0(key);
9862 key_name[1] = KEY2TERMCAP1(key);
9863 }
9864 else
9865 {
9866 key_name[0] = KS_KEY;
9867 key_name[1] = (key & 0xff);
9868 }
9869 add_termcode(key_name, string, FALSE);
9870 if (full_screen)
9871 ttest(FALSE);
9872 redraw_all_later(CLEAR);
9873 return NULL;
9874 }
9875
Bram Moolenaar071d4272004-06-13 20:20:40 +00009876 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009877 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009878 else
9879 {
9880 flags = options[opt_idx].flags;
9881#ifdef HAVE_SANDBOX
9882 /* Disallow changing some options in the sandbox */
9883 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009884 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009885 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009886 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009889 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009890 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009891 else
9892 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009893 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894 if (varp != NULL) /* hidden option is not changed */
9895 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009896 if (number == 0 && string != NULL)
9897 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009898 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009899
9900 /* Either we are given a string or we are setting option
9901 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009902 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009903 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009904 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009905 {
9906 /* There's another character after zeros or the string
9907 * is empty. In both cases, we are trying to set a
9908 * num option using a string. */
9909 EMSG3(_("E521: Number required: &%s = '%s'"),
9910 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009911 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009912
9913 }
9914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009916 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009917 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009918 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009919 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009920 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921 }
9922 }
9923 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009924 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009925}
9926
9927/*
9928 * Get the terminal code for a terminal option.
9929 * Returns NULL when not found.
9930 */
9931 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009932get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933{
9934 int opt_idx;
9935 char_u *varp;
9936
9937 if (tname[0] != 't' || tname[1] != '_' ||
9938 tname[2] == NUL || tname[3] == NUL)
9939 return NULL;
9940 if ((opt_idx = findoption(tname)) >= 0)
9941 {
9942 varp = get_varp(&(options[opt_idx]));
9943 if (varp != NULL)
9944 varp = *(char_u **)(varp);
9945 return varp;
9946 }
9947 return find_termcode(tname + 2);
9948}
9949
9950 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009951get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009952{
9953 int i;
9954
9955 i = findoption((char_u *)"hl");
9956 if (i >= 0)
9957 return options[i].def_val[VI_DEFAULT];
9958 return (char_u *)NULL;
9959}
9960
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009961#if defined(FEAT_MBYTE) || defined(PROTO)
9962 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009963get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009964{
9965 int i;
9966
9967 i = findoption((char_u *)"enc");
9968 if (i >= 0)
9969 return options[i].def_val[VI_DEFAULT];
9970 return (char_u *)NULL;
9971}
9972#endif
9973
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974/*
9975 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009976 * When "has_lt" is true there is a '<' before "*arg_arg".
9977 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978 */
9979 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009980find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009982 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009984 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985
9986 /*
9987 * Don't use get_special_key_code() for t_xx, we don't want it to call
9988 * add_termcap_entry().
9989 */
9990 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9991 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009992 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993 {
9994 --arg; /* put arg at the '<' */
9995 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009996 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009997 if (modifiers) /* can't handle modifiers here */
9998 key = 0;
9999 }
10000 return key;
10001}
10002
10003/*
10004 * if 'all' == 0: show changed options
10005 * if 'all' == 1: show all normal options
10006 * if 'all' == 2: show all terminal options
10007 */
10008 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010009showoptions(
10010 int all,
10011 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012{
10013 struct vimoption *p;
10014 int col;
10015 int isterm;
10016 char_u *varp;
10017 struct vimoption **items;
10018 int item_count;
10019 int run;
10020 int row, rows;
10021 int cols;
10022 int i;
10023 int len;
10024
10025#define INC 20
10026#define GAP 3
10027
10028 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10029 PARAM_COUNT));
10030 if (items == NULL)
10031 return;
10032
10033 /* Highlight title */
10034 if (all == 2)
10035 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
10036 else if (opt_flags & OPT_GLOBAL)
10037 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
10038 else if (opt_flags & OPT_LOCAL)
10039 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
10040 else
10041 MSG_PUTS_TITLE(_("\n--- Options ---"));
10042
10043 /*
10044 * do the loop two times:
10045 * 1. display the short items
10046 * 2. display the long items (only strings and numbers)
10047 */
10048 for (run = 1; run <= 2 && !got_int; ++run)
10049 {
10050 /*
10051 * collect the items in items[]
10052 */
10053 item_count = 0;
10054 for (p = &options[0]; p->fullname != NULL; p++)
10055 {
10056 varp = NULL;
10057 isterm = istermoption(p);
10058 if (opt_flags != 0)
10059 {
10060 if (p->indir != PV_NONE && !isterm)
10061 varp = get_varp_scope(p, opt_flags);
10062 }
10063 else
10064 varp = get_varp(p);
10065 if (varp != NULL
10066 && ((all == 2 && isterm)
10067 || (all == 1 && !isterm)
10068 || (all == 0 && !optval_default(p, varp))))
10069 {
10070 if (p->flags & P_BOOL)
10071 len = 1; /* a toggle option fits always */
10072 else
10073 {
10074 option_value2string(p, opt_flags);
10075 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10076 }
10077 if ((len <= INC - GAP && run == 1) ||
10078 (len > INC - GAP && run == 2))
10079 items[item_count++] = p;
10080 }
10081 }
10082
10083 /*
10084 * display the items
10085 */
10086 if (run == 1)
10087 {
10088 cols = (Columns + GAP - 3) / INC;
10089 if (cols == 0)
10090 cols = 1;
10091 rows = (item_count + cols - 1) / cols;
10092 }
10093 else /* run == 2 */
10094 rows = item_count;
10095 for (row = 0; row < rows && !got_int; ++row)
10096 {
10097 msg_putchar('\n'); /* go to next line */
10098 if (got_int) /* 'q' typed in more */
10099 break;
10100 col = 0;
10101 for (i = row; i < item_count; i += rows)
10102 {
10103 msg_col = col; /* make columns */
10104 showoneopt(items[i], opt_flags);
10105 col += INC;
10106 }
10107 out_flush();
10108 ui_breakcheck();
10109 }
10110 }
10111 vim_free(items);
10112}
10113
10114/*
10115 * Return TRUE if option "p" has its default value.
10116 */
10117 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010118optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119{
10120 int dvi;
10121
10122 if (varp == NULL)
10123 return TRUE; /* hidden option is always at default */
10124 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10125 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010126 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010128 /* the cast to long is required for Manx C, long_i is
10129 * needed for MSVC */
10130 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131 /* P_STRING */
10132 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10133}
10134
10135/*
10136 * showoneopt: show the value of one option
10137 * must not be called with a hidden option!
10138 */
10139 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010140showoneopt(
10141 struct vimoption *p,
10142 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010144 char_u *varp;
10145 int save_silent = silent_mode;
10146
10147 silent_mode = FALSE;
10148 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149
10150 varp = get_varp_scope(p, opt_flags);
10151
10152 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10153 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10154 ? !curbufIsChanged() : !*(int *)varp))
10155 MSG_PUTS("no");
10156 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10157 MSG_PUTS("--");
10158 else
10159 MSG_PUTS(" ");
10160 MSG_PUTS(p->fullname);
10161 if (!(p->flags & P_BOOL))
10162 {
10163 msg_putchar('=');
10164 /* put value string in NameBuff */
10165 option_value2string(p, opt_flags);
10166 msg_outtrans(NameBuff);
10167 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010168
10169 silent_mode = save_silent;
10170 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171}
10172
10173/*
10174 * Write modified options as ":set" commands to a file.
10175 *
10176 * There are three values for "opt_flags":
10177 * OPT_GLOBAL: Write global option values and fresh values of
10178 * buffer-local options (used for start of a session
10179 * file).
10180 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10181 * curwin (used for a vimrc file).
10182 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10183 * and local values for window-local options of
10184 * curwin. Local values are also written when at the
10185 * default value, because a modeline or autocommand
10186 * may have set them when doing ":edit file" and the
10187 * user has set them back at the default or fresh
10188 * value.
10189 * When "local_only" is TRUE, don't write fresh
10190 * values, only local values (for ":mkview").
10191 * (fresh value = value used for a new buffer or window for a local option).
10192 *
10193 * Return FAIL on error, OK otherwise.
10194 */
10195 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010196makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197{
10198 struct vimoption *p;
10199 char_u *varp; /* currently used value */
10200 char_u *varp_fresh; /* local value */
10201 char_u *varp_local = NULL; /* fresh value */
10202 char *cmd;
10203 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010204 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205
10206 /*
10207 * The options that don't have a default (terminal name, columns, lines)
10208 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010209 * Do the loop over "options[]" twice: once for options with the
10210 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010212 for (pri = 1; pri >= 0; --pri)
10213 {
10214 for (p = &options[0]; !istermoption(p); p++)
10215 if (!(p->flags & P_NO_MKRC)
10216 && !istermoption(p)
10217 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 {
10219 /* skip global option when only doing locals */
10220 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10221 continue;
10222
10223 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10224 * file, they are always buffer-specific. */
10225 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10226 continue;
10227
10228 /* Global values are only written when not at the default value. */
10229 varp = get_varp_scope(p, opt_flags);
10230 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10231 continue;
10232
10233 round = 2;
10234 if (p->indir != PV_NONE)
10235 {
10236 if (p->var == VAR_WIN)
10237 {
10238 /* skip window-local option when only doing globals */
10239 if (!(opt_flags & OPT_LOCAL))
10240 continue;
10241 /* When fresh value of window-local option is not at the
10242 * default, need to write it too. */
10243 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10244 {
10245 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10246 if (!optval_default(p, varp_fresh))
10247 {
10248 round = 1;
10249 varp_local = varp;
10250 varp = varp_fresh;
10251 }
10252 }
10253 }
10254 }
10255
10256 /* Round 1: fresh value for window-local options.
10257 * Round 2: other values */
10258 for ( ; round <= 2; varp = varp_local, ++round)
10259 {
10260 if (round == 1 || (opt_flags & OPT_GLOBAL))
10261 cmd = "set";
10262 else
10263 cmd = "setlocal";
10264
10265 if (p->flags & P_BOOL)
10266 {
10267 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10268 return FAIL;
10269 }
10270 else if (p->flags & P_NUM)
10271 {
10272 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10273 return FAIL;
10274 }
10275 else /* P_STRING */
10276 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010277 int do_endif = FALSE;
10278
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279 /* Don't set 'syntax' and 'filetype' again if the value is
10280 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010281 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010282#if defined(FEAT_SYN_HL)
10283 p->indir == PV_SYN ||
10284#endif
10285 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010286 {
10287 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10288 *(char_u **)(varp)) < 0
10289 || put_eol(fd) < 0)
10290 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010291 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292 }
10293 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10294 (p->flags & P_EXPAND) != 0) == FAIL)
10295 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010296 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297 {
10298 if (put_line(fd, "endif") == FAIL)
10299 return FAIL;
10300 }
10301 }
10302 }
10303 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010304 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305 return OK;
10306}
10307
10308#if defined(FEAT_FOLDING) || defined(PROTO)
10309/*
10310 * Generate set commands for the local fold options only. Used when
10311 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10312 */
10313 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010314makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315{
10316 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10317# ifdef FEAT_EVAL
10318 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10319 == FAIL
10320# endif
10321 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10322 == FAIL
10323 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10324 == FAIL
10325 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10326 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10327 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10328 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10329 )
10330 return FAIL;
10331
10332 return OK;
10333}
10334#endif
10335
10336 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010337put_setstring(
10338 FILE *fd,
10339 char *cmd,
10340 char *name,
10341 char_u **valuep,
10342 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343{
10344 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010345 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346
10347 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10348 return FAIL;
10349 if (*valuep != NULL)
10350 {
10351 /* Output 'pastetoggle' as key names. For other
10352 * options some characters have to be escaped with
10353 * CTRL-V or backslash */
10354 if (valuep == &p_pt)
10355 {
10356 s = *valuep;
10357 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010358 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359 return FAIL;
10360 }
10361 else if (expand)
10362 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010363 buf = alloc(MAXPATHL);
10364 if (buf == NULL)
10365 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010366 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10367 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010368 {
10369 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010371 }
10372 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373 }
10374 else if (put_escstr(fd, *valuep, 2) == FAIL)
10375 return FAIL;
10376 }
10377 if (put_eol(fd) < 0)
10378 return FAIL;
10379 return OK;
10380}
10381
10382 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010383put_setnum(
10384 FILE *fd,
10385 char *cmd,
10386 char *name,
10387 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388{
10389 long wc;
10390
10391 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10392 return FAIL;
10393 if (wc_use_keyname((char_u *)valuep, &wc))
10394 {
10395 /* print 'wildchar' and 'wildcharm' as a key name */
10396 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10397 return FAIL;
10398 }
10399 else if (fprintf(fd, "%ld", *valuep) < 0)
10400 return FAIL;
10401 if (put_eol(fd) < 0)
10402 return FAIL;
10403 return OK;
10404}
10405
10406 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010407put_setbool(
10408 FILE *fd,
10409 char *cmd,
10410 char *name,
10411 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010412{
Bram Moolenaar893de922007-10-02 18:40:57 +000010413 if (value < 0) /* global/local option using global value */
10414 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10416 || put_eol(fd) < 0)
10417 return FAIL;
10418 return OK;
10419}
10420
10421/*
10422 * Clear all the terminal options.
10423 * If the option has been allocated, free the memory.
10424 * Terminal options are never hidden or indirect.
10425 */
10426 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010427clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010428{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429 /*
10430 * Reset a few things before clearing the old options. This may cause
10431 * outputting a few things that the terminal doesn't understand, but the
10432 * screen will be cleared later, so this is OK.
10433 */
10434#ifdef FEAT_MOUSE_TTY
10435 mch_setmouse(FALSE); /* switch mouse off */
10436#endif
10437#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010438 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439#endif
10440#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10441 /* When starting the GUI close the display opened for the clipboard.
10442 * After restoring the title, because that will need the display. */
10443 if (gui.starting)
10444 clear_xterm_clip();
10445#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010446 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010447
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010448 free_termoptions();
10449}
10450
10451 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010452free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010453{
10454 struct vimoption *p;
10455
Bram Moolenaar071d4272004-06-13 20:20:40 +000010456 for (p = &options[0]; p->fullname != NULL; p++)
10457 if (istermoption(p))
10458 {
10459 if (p->flags & P_ALLOCED)
10460 free_string_option(*(char_u **)(p->var));
10461 if (p->flags & P_DEF_ALLOCED)
10462 free_string_option(p->def_val[VI_DEFAULT]);
10463 *(char_u **)(p->var) = empty_option;
10464 p->def_val[VI_DEFAULT] = empty_option;
10465 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10466 }
10467 clear_termcodes();
10468}
10469
10470/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010471 * Free the string for one term option, if it was allocated.
10472 * Set the string to empty_option and clear allocated flag.
10473 * "var" points to the option value.
10474 */
10475 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010476free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010477{
10478 struct vimoption *p;
10479
10480 for (p = &options[0]; p->fullname != NULL; p++)
10481 if (p->var == var)
10482 {
10483 if (p->flags & P_ALLOCED)
10484 free_string_option(*(char_u **)(p->var));
10485 *(char_u **)(p->var) = empty_option;
10486 p->flags &= ~P_ALLOCED;
10487 break;
10488 }
10489}
10490
10491/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010492 * Set the terminal option defaults to the current value.
10493 * Used after setting the terminal name.
10494 */
10495 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010496set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497{
10498 struct vimoption *p;
10499
10500 for (p = &options[0]; p->fullname != NULL; p++)
10501 {
10502 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10503 {
10504 if (p->flags & P_DEF_ALLOCED)
10505 {
10506 free_string_option(p->def_val[VI_DEFAULT]);
10507 p->flags &= ~P_DEF_ALLOCED;
10508 }
10509 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10510 if (p->flags & P_ALLOCED)
10511 {
10512 p->flags |= P_DEF_ALLOCED;
10513 p->flags &= ~P_ALLOCED; /* don't free the value now */
10514 }
10515 }
10516 }
10517}
10518
10519/*
10520 * return TRUE if 'p' starts with 't_'
10521 */
10522 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010523istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524{
10525 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10526}
10527
10528/*
10529 * Compute columns for ruler and shown command. 'sc_col' is also used to
10530 * decide what the maximum length of a message on the status line can be.
10531 * If there is a status line for the last window, 'sc_col' is independent
10532 * of 'ru_col'.
10533 */
10534
10535#define COL_RULER 17 /* columns needed by standard ruler */
10536
10537 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010538comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010540#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010541 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542
10543 sc_col = 0;
10544 ru_col = 0;
10545 if (p_ru)
10546 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010547# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010549# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010550 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010551# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552 /* no last status line, adjust sc_col */
10553 if (!last_has_status)
10554 sc_col = ru_col;
10555 }
10556 if (p_sc)
10557 {
10558 sc_col += SHOWCMD_COLS;
10559 if (!p_ru || last_has_status) /* no need for separating space */
10560 ++sc_col;
10561 }
10562 sc_col = Columns - sc_col;
10563 ru_col = Columns - ru_col;
10564 if (sc_col <= 0) /* screen too narrow, will become a mess */
10565 sc_col = 1;
10566 if (ru_col <= 0)
10567 ru_col = 1;
10568#else
10569 sc_col = Columns;
10570 ru_col = Columns;
10571#endif
10572}
10573
10574/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010575 * Unset local option value, similar to ":set opt<".
10576 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010577 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010578unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010579{
10580 struct vimoption *p;
10581 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010582 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010583
10584 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010585 if (opt_idx < 0)
10586 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010587 p = &(options[opt_idx]);
10588
10589 switch ((int)p->indir)
10590 {
10591 /* global option with local value: use local value if it's been set */
10592 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010593 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010594 break;
10595 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010596 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010597 break;
10598 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010599 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010600 break;
10601 case PV_AR:
10602 buf->b_p_ar = -1;
10603 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010604 case PV_BKC:
10605 clear_string_option(&buf->b_p_bkc);
10606 buf->b_bkc_flags = 0;
10607 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010608 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010609 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010610 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010611 case PV_TC:
10612 clear_string_option(&buf->b_p_tc);
10613 buf->b_tc_flags = 0;
10614 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010615#ifdef FEAT_FIND_ID
10616 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010617 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010618 break;
10619 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010620 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010621 break;
10622#endif
10623#ifdef FEAT_INS_EXPAND
10624 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010625 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010626 break;
10627 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010628 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010629 break;
10630#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010631 case PV_FP:
10632 clear_string_option(&buf->b_p_fp);
10633 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010634#ifdef FEAT_QUICKFIX
10635 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010636 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010637 break;
10638 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010639 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010640 break;
10641 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010642 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010643 break;
10644#endif
10645#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10646 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010647 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010648 break;
10649#endif
10650#if defined(FEAT_CRYPT)
10651 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010652 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010653 break;
10654#endif
10655#ifdef FEAT_STL_OPT
10656 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010657 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010658 break;
10659#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010660 case PV_UL:
10661 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10662 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010663#ifdef FEAT_LISP
10664 case PV_LW:
10665 clear_string_option(&buf->b_p_lw);
10666 break;
10667#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010668#ifdef FEAT_MBYTE
10669 case PV_MENC:
10670 clear_string_option(&buf->b_p_menc);
10671 break;
10672#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010673 }
10674}
10675
10676/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010677 * Get pointer to option variable, depending on local or global scope.
10678 */
10679 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010680get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010681{
10682 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10683 {
10684 if (p->var == VAR_WIN)
10685 return (char_u *)GLOBAL_WO(get_varp(p));
10686 return p->var;
10687 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010688 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689 {
10690 switch ((int)p->indir)
10691 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010692 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010693#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010694 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10695 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10696 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010698 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10699 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10700 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010701 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010702 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010703 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010705 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10706 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707#endif
10708#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010709 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10710 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010712#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10713 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10714#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010715#if defined(FEAT_CRYPT)
10716 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10717#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010718#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010719 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010720#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010721 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010722#ifdef FEAT_LISP
10723 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10724#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010725 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010726#ifdef FEAT_MBYTE
10727 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 }
10730 return NULL; /* "cannot happen" */
10731 }
10732 return get_varp(p);
10733}
10734
10735/*
10736 * Get pointer to option variable.
10737 */
10738 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010739get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010740{
10741 /* hidden option, always return NULL */
10742 if (p->var == NULL)
10743 return NULL;
10744
10745 switch ((int)p->indir)
10746 {
10747 case PV_NONE: return p->var;
10748
10749 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010750 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010752 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010754 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010756 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010758 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010760 case PV_TC: return *curbuf->b_p_tc != NUL
10761 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010762 case PV_BKC: return *curbuf->b_p_bkc != NUL
10763 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010765 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010767 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10769#endif
10770#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010771 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010773 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10775#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010776 case PV_FP: return *curbuf->b_p_fp != NUL
10777 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010779 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010781 case PV_GP: return *curbuf->b_p_gp != NUL
10782 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10783 case PV_MP: return *curbuf->b_p_mp != NUL
10784 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010786#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10787 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10788 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10789#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010790#if defined(FEAT_CRYPT)
10791 case PV_CM: return *curbuf->b_p_cm != NUL
10792 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10793#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010794#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010795 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010796 ? (char_u *)&(curwin->w_p_stl) : p->var;
10797#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010798 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10799 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010800#ifdef FEAT_LISP
10801 case PV_LW: return *curbuf->b_p_lw != NUL
10802 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10803#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010804#ifdef FEAT_MBYTE
10805 case PV_MENC: return *curbuf->b_p_menc != NUL
10806 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10807#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808
10809#ifdef FEAT_ARABIC
10810 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10811#endif
10812 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010813#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010814 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10815#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010816#ifdef FEAT_SYN_HL
10817 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10818 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010819 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010820#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821#ifdef FEAT_DIFF
10822 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10823#endif
10824#ifdef FEAT_FOLDING
10825 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10826 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10827 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10828 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10829 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10830 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10831 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10832# ifdef FEAT_EVAL
10833 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10834 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10835# endif
10836 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10837#endif
10838 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010839 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010840#ifdef FEAT_LINEBREAK
10841 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10842#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010844 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010845#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10847#endif
10848#ifdef FEAT_RIGHTLEFT
10849 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10850 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10851#endif
10852 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10853 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10854#ifdef FEAT_LINEBREAK
10855 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010856 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10857 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010860 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010861#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010862 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10863 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10864#endif
10865#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010866 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10867 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10868 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010869#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870
10871 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10872 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10873#ifdef FEAT_MBYTE
10874 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10877 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10879 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10880#ifdef FEAT_CINDENT
10881 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10882 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10883 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10884#endif
10885#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10886 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10887#endif
10888#ifdef FEAT_COMMENTS
10889 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10890#endif
10891#ifdef FEAT_FOLDING
10892 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10893#endif
10894#ifdef FEAT_INS_EXPAND
10895 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10896#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010897#ifdef FEAT_COMPL_FUNC
10898 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010899 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010900#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010902 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010903 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10904#ifdef FEAT_MBYTE
10905 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10906#endif
10907 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010908 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010910 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010911 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10912 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10913 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10914 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10915#ifdef FEAT_FIND_ID
10916# ifdef FEAT_EVAL
10917 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10918# endif
10919#endif
10920#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10921 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10922 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10923#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010924#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010925 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10926#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010927#ifdef FEAT_CRYPT
10928 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10929#endif
10930#ifdef FEAT_LISP
10931 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10932#endif
10933 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10934 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10935 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10936 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10937 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010939#ifdef FEAT_TEXTOBJ
10940 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10941#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10943#ifdef FEAT_SMARTINDENT
10944 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10945#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10948#ifdef FEAT_SEARCHPATH
10949 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10950#endif
10951 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10952#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010953 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010954 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10955#endif
10956#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010957 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10958 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10959 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960#endif
10961 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10962 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10963 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10964 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010965#ifdef FEAT_PERSISTENT_UNDO
10966 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010968 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10969#ifdef FEAT_KEYMAP
10970 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10971#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010972#ifdef FEAT_SIGNS
10973 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10974#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020010975#ifdef FEAT_VARTABS
10976 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
10977 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
10978#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010979 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010980 }
10981 /* always return a valid pointer to avoid a crash! */
10982 return (char_u *)&(curbuf->b_p_wm);
10983}
10984
10985/*
10986 * Get the value of 'equalprg', either the buffer-local one or the global one.
10987 */
10988 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010989get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990{
10991 if (*curbuf->b_p_ep == NUL)
10992 return p_ep;
10993 return curbuf->b_p_ep;
10994}
10995
Bram Moolenaar071d4272004-06-13 20:20:40 +000010996/*
10997 * Copy options from one window to another.
10998 * Used when splitting a window.
10999 */
11000 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011001win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011002{
11003 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11004 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11005# ifdef FEAT_RIGHTLEFT
11006# ifdef FEAT_FKMAP
11007 /* Is this right? */
11008 wp_to->w_farsi = wp_from->w_farsi;
11009# endif
11010# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011011#if defined(FEAT_LINEBREAK)
11012 briopt_check(wp_to);
11013#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011014}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011015
11016/*
11017 * Copy the options from one winopt_T to another.
11018 * Doesn't free the old option values in "to", use clear_winopt() for that.
11019 * The 'scroll' option is not copied, because it depends on the window height.
11020 * The 'previewwindow' option is reset, there can be only one preview window.
11021 */
11022 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011023copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011024{
11025#ifdef FEAT_ARABIC
11026 to->wo_arab = from->wo_arab;
11027#endif
11028 to->wo_list = from->wo_list;
11029 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011030 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011031#ifdef FEAT_LINEBREAK
11032 to->wo_nuw = from->wo_nuw;
11033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011034#ifdef FEAT_RIGHTLEFT
11035 to->wo_rl = from->wo_rl;
11036 to->wo_rlc = vim_strsave(from->wo_rlc);
11037#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011038#ifdef FEAT_STL_OPT
11039 to->wo_stl = vim_strsave(from->wo_stl);
11040#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011041 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011042#ifdef FEAT_DIFF
11043 to->wo_wrap_save = from->wo_wrap_save;
11044#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011045#ifdef FEAT_LINEBREAK
11046 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011047 to->wo_bri = from->wo_bri;
11048 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011050 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011051 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011052 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011053 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011054#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011055 to->wo_spell = from->wo_spell;
11056#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011057#ifdef FEAT_SYN_HL
11058 to->wo_cuc = from->wo_cuc;
11059 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011060 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011062#ifdef FEAT_DIFF
11063 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011064 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011065#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011066#ifdef FEAT_CONCEAL
11067 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011068 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011069#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011070#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011071 to->wo_twk = vim_strsave(from->wo_twk);
11072 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074#ifdef FEAT_FOLDING
11075 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011076 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011078 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079 to->wo_fdi = vim_strsave(from->wo_fdi);
11080 to->wo_fml = from->wo_fml;
11081 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011082 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011084 to->wo_fdm_save = from->wo_diff_saved
11085 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011086 to->wo_fdn = from->wo_fdn;
11087# ifdef FEAT_EVAL
11088 to->wo_fde = vim_strsave(from->wo_fde);
11089 to->wo_fdt = vim_strsave(from->wo_fdt);
11090# endif
11091 to->wo_fmr = vim_strsave(from->wo_fmr);
11092#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011093#ifdef FEAT_SIGNS
11094 to->wo_scl = vim_strsave(from->wo_scl);
11095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096 check_winopt(to); /* don't want NULL pointers */
11097}
11098
11099/*
11100 * Check string options in a window for a NULL value.
11101 */
11102 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011103check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104{
11105 check_winopt(&win->w_onebuf_opt);
11106 check_winopt(&win->w_allbuf_opt);
11107}
11108
11109/*
11110 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11111 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011112 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011113check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114{
11115#ifdef FEAT_FOLDING
11116 check_string_option(&wop->wo_fdi);
11117 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011118 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011119# ifdef FEAT_EVAL
11120 check_string_option(&wop->wo_fde);
11121 check_string_option(&wop->wo_fdt);
11122# endif
11123 check_string_option(&wop->wo_fmr);
11124#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011125#ifdef FEAT_SIGNS
11126 check_string_option(&wop->wo_scl);
11127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011128#ifdef FEAT_RIGHTLEFT
11129 check_string_option(&wop->wo_rlc);
11130#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011131#ifdef FEAT_STL_OPT
11132 check_string_option(&wop->wo_stl);
11133#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011134#ifdef FEAT_SYN_HL
11135 check_string_option(&wop->wo_cc);
11136#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011137#ifdef FEAT_CONCEAL
11138 check_string_option(&wop->wo_cocu);
11139#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011140#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011141 check_string_option(&wop->wo_twk);
11142 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011143#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011144#ifdef FEAT_LINEBREAK
11145 check_string_option(&wop->wo_briopt);
11146#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147}
11148
11149/*
11150 * Free the allocated memory inside a winopt_T.
11151 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011152 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011153clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154{
11155#ifdef FEAT_FOLDING
11156 clear_string_option(&wop->wo_fdi);
11157 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011158 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011159# ifdef FEAT_EVAL
11160 clear_string_option(&wop->wo_fde);
11161 clear_string_option(&wop->wo_fdt);
11162# endif
11163 clear_string_option(&wop->wo_fmr);
11164#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011165#ifdef FEAT_SIGNS
11166 clear_string_option(&wop->wo_scl);
11167#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011168#ifdef FEAT_LINEBREAK
11169 clear_string_option(&wop->wo_briopt);
11170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011171#ifdef FEAT_RIGHTLEFT
11172 clear_string_option(&wop->wo_rlc);
11173#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011174#ifdef FEAT_STL_OPT
11175 clear_string_option(&wop->wo_stl);
11176#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011177#ifdef FEAT_SYN_HL
11178 clear_string_option(&wop->wo_cc);
11179#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011180#ifdef FEAT_CONCEAL
11181 clear_string_option(&wop->wo_cocu);
11182#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011183#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011184 clear_string_option(&wop->wo_twk);
11185 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011186#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187}
11188
11189/*
11190 * Copy global option values to local options for one buffer.
11191 * Used when creating a new buffer and sometimes when entering a buffer.
11192 * flags:
11193 * BCO_ENTER We will enter the buf buffer.
11194 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11195 * appropriate.
11196 * BCO_NOHELP Don't copy the values to a help buffer.
11197 */
11198 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011199buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011200{
11201 int should_copy = TRUE;
11202 char_u *save_p_isk = NULL; /* init for GCC */
11203 int dont_do_help;
11204 int did_isk = FALSE;
11205
11206 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011207 * Skip this when the option defaults have not been set yet. Happens when
11208 * main() allocates the first buffer.
11209 */
11210 if (p_cpo != NULL)
11211 {
11212 /*
11213 * Always copy when entering and 'cpo' contains 'S'.
11214 * Don't copy when already initialized.
11215 * Don't copy when 'cpo' contains 's' and not entering.
11216 * 'S' BCO_ENTER initialized 's' should_copy
11217 * yes yes X X TRUE
11218 * yes no yes X FALSE
11219 * no X yes X FALSE
11220 * X no no yes FALSE
11221 * X no no no TRUE
11222 * no yes no X TRUE
11223 */
11224 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11225 && (buf->b_p_initialized
11226 || (!(flags & BCO_ENTER)
11227 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11228 should_copy = FALSE;
11229
11230 if (should_copy || (flags & BCO_ALWAYS))
11231 {
11232 /* Don't copy the options specific to a help buffer when
11233 * BCO_NOHELP is given or the options were initialized already
11234 * (jumping back to a help file with CTRL-T or CTRL-O) */
11235 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11236 || buf->b_p_initialized;
11237 if (dont_do_help) /* don't free b_p_isk */
11238 {
11239 save_p_isk = buf->b_p_isk;
11240 buf->b_p_isk = NULL;
11241 }
11242 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011243 * Always free the allocated strings. If not already initialized,
11244 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245 */
11246 if (!buf->b_p_initialized)
11247 {
11248 free_buf_options(buf, TRUE);
11249 buf->b_p_ro = FALSE; /* don't copy readonly */
11250 buf->b_p_tx = p_tx;
11251#ifdef FEAT_MBYTE
11252 buf->b_p_fenc = vim_strsave(p_fenc);
11253#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011254 switch (*p_ffs)
11255 {
11256 case 'm':
11257 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11258 case 'd':
11259 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11260 case 'u':
11261 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11262 default:
11263 buf->b_p_ff = vim_strsave(p_ff);
11264 }
11265 if (buf->b_p_ff != NULL)
11266 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267 buf->b_p_bh = empty_option;
11268 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269 }
11270 else
11271 free_buf_options(buf, FALSE);
11272
11273 buf->b_p_ai = p_ai;
11274 buf->b_p_ai_nopaste = p_ai_nopaste;
11275 buf->b_p_sw = p_sw;
11276 buf->b_p_tw = p_tw;
11277 buf->b_p_tw_nopaste = p_tw_nopaste;
11278 buf->b_p_tw_nobin = p_tw_nobin;
11279 buf->b_p_wm = p_wm;
11280 buf->b_p_wm_nopaste = p_wm_nopaste;
11281 buf->b_p_wm_nobin = p_wm_nobin;
11282 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011283#ifdef FEAT_MBYTE
11284 buf->b_p_bomb = p_bomb;
11285#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011286 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011287 buf->b_p_et = p_et;
11288 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011289 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011290 buf->b_p_ml = p_ml;
11291 buf->b_p_ml_nobin = p_ml_nobin;
11292 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011293 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011294#ifdef FEAT_INS_EXPAND
11295 buf->b_p_cpt = vim_strsave(p_cpt);
11296#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011297#ifdef FEAT_COMPL_FUNC
11298 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011299 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011301 buf->b_p_sts = p_sts;
11302 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011303#ifdef FEAT_VARTABS
11304 buf->b_p_vsts = vim_strsave(p_vsts);
11305 if (p_vsts && p_vsts != empty_option)
11306 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11307 else
11308 buf->b_p_vsts_array = 0;
11309 buf->b_p_vsts_nopaste = p_vsts_nopaste
11310 ? vim_strsave(p_vsts_nopaste) : NULL;
11311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011312 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011313#ifdef FEAT_COMMENTS
11314 buf->b_p_com = vim_strsave(p_com);
11315#endif
11316#ifdef FEAT_FOLDING
11317 buf->b_p_cms = vim_strsave(p_cms);
11318#endif
11319 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011320 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011321 buf->b_p_nf = vim_strsave(p_nf);
11322 buf->b_p_mps = vim_strsave(p_mps);
11323#ifdef FEAT_SMARTINDENT
11324 buf->b_p_si = p_si;
11325#endif
11326 buf->b_p_ci = p_ci;
11327#ifdef FEAT_CINDENT
11328 buf->b_p_cin = p_cin;
11329 buf->b_p_cink = vim_strsave(p_cink);
11330 buf->b_p_cino = vim_strsave(p_cino);
11331#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332 /* Don't copy 'filetype', it must be detected */
11333 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011334 buf->b_p_pi = p_pi;
11335#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11336 buf->b_p_cinw = vim_strsave(p_cinw);
11337#endif
11338#ifdef FEAT_LISP
11339 buf->b_p_lisp = p_lisp;
11340#endif
11341#ifdef FEAT_SYN_HL
11342 /* Don't copy 'syntax', it must be set */
11343 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011344 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011345 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011346#endif
11347#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011348 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011349 (void)compile_cap_prog(&buf->b_s);
11350 buf->b_s.b_p_spf = vim_strsave(p_spf);
11351 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011352#endif
11353#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11354 buf->b_p_inde = vim_strsave(p_inde);
11355 buf->b_p_indk = vim_strsave(p_indk);
11356#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011357 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011358#if defined(FEAT_EVAL)
11359 buf->b_p_fex = vim_strsave(p_fex);
11360#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011361#ifdef FEAT_CRYPT
11362 buf->b_p_key = vim_strsave(p_key);
11363#endif
11364#ifdef FEAT_SEARCHPATH
11365 buf->b_p_sua = vim_strsave(p_sua);
11366#endif
11367#ifdef FEAT_KEYMAP
11368 buf->b_p_keymap = vim_strsave(p_keymap);
11369 buf->b_kmap_state |= KEYMAP_INIT;
11370#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011371#ifdef FEAT_TERMINAL
11372 buf->b_p_twsl = p_twsl;
11373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011374 /* This isn't really an option, but copying the langmap and IME
11375 * state from the current buffer is better than resetting it. */
11376 buf->b_p_iminsert = p_iminsert;
11377 buf->b_p_imsearch = p_imsearch;
11378
11379 /* options that are normally global but also have a local value
11380 * are not copied, start using the global value */
11381 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011382 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011383 buf->b_p_bkc = empty_option;
11384 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011385#ifdef FEAT_QUICKFIX
11386 buf->b_p_gp = empty_option;
11387 buf->b_p_mp = empty_option;
11388 buf->b_p_efm = empty_option;
11389#endif
11390 buf->b_p_ep = empty_option;
11391 buf->b_p_kp = empty_option;
11392 buf->b_p_path = empty_option;
11393 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011394 buf->b_p_tc = empty_option;
11395 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011396#ifdef FEAT_FIND_ID
11397 buf->b_p_def = empty_option;
11398 buf->b_p_inc = empty_option;
11399# ifdef FEAT_EVAL
11400 buf->b_p_inex = vim_strsave(p_inex);
11401# endif
11402#endif
11403#ifdef FEAT_INS_EXPAND
11404 buf->b_p_dict = empty_option;
11405 buf->b_p_tsr = empty_option;
11406#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011407#ifdef FEAT_TEXTOBJ
11408 buf->b_p_qe = vim_strsave(p_qe);
11409#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011410#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11411 buf->b_p_bexpr = empty_option;
11412#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011413#if defined(FEAT_CRYPT)
11414 buf->b_p_cm = empty_option;
11415#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011416#ifdef FEAT_PERSISTENT_UNDO
11417 buf->b_p_udf = p_udf;
11418#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011419#ifdef FEAT_LISP
11420 buf->b_p_lw = empty_option;
11421#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011422#ifdef FEAT_MBYTE
11423 buf->b_p_menc = empty_option;
11424#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011425
11426 /*
11427 * Don't copy the options set by ex_help(), use the saved values,
11428 * when going from a help buffer to a non-help buffer.
11429 * Don't touch these at all when BCO_NOHELP is used and going from
11430 * or to a help buffer.
11431 */
11432 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011433 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011434 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011435#ifdef FEAT_VARTABS
11436 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11437 tabstop_set(p_vts, &buf->b_p_vts_array);
11438 else
11439 buf->b_p_vts_array = NULL;
11440#endif
11441 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011442 else
11443 {
11444 buf->b_p_isk = vim_strsave(p_isk);
11445 did_isk = TRUE;
11446 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011447#ifdef FEAT_VARTABS
11448 buf->b_p_vts = vim_strsave(p_vts);
11449 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11450 tabstop_set(p_vts, &buf->b_p_vts_array);
11451 else
11452 buf->b_p_vts_array = NULL;
11453#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011454 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011455 if (buf->b_p_bt[0] == 'h')
11456 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011457 buf->b_p_ma = p_ma;
11458 }
11459 }
11460
11461 /*
11462 * When the options should be copied (ignoring BCO_ALWAYS), set the
11463 * flag that indicates that the options have been initialized.
11464 */
11465 if (should_copy)
11466 buf->b_p_initialized = TRUE;
11467 }
11468
11469 check_buf_options(buf); /* make sure we don't have NULLs */
11470 if (did_isk)
11471 (void)buf_init_chartab(buf, FALSE);
11472}
11473
11474/*
11475 * Reset the 'modifiable' option and its default value.
11476 */
11477 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011478reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011479{
11480 int opt_idx;
11481
11482 curbuf->b_p_ma = FALSE;
11483 p_ma = FALSE;
11484 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011485 if (opt_idx >= 0)
11486 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011487}
11488
11489/*
11490 * Set the global value for 'iminsert' to the local value.
11491 */
11492 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011493set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011494{
11495 p_iminsert = curbuf->b_p_iminsert;
11496}
11497
11498/*
11499 * Set the global value for 'imsearch' to the local value.
11500 */
11501 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011502set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011503{
11504 p_imsearch = curbuf->b_p_imsearch;
11505}
11506
11507#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11508static int expand_option_idx = -1;
11509static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11510static int expand_option_flags = 0;
11511
11512 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011513set_context_in_set_cmd(
11514 expand_T *xp,
11515 char_u *arg,
11516 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011517{
11518 int nextchar;
11519 long_u flags = 0; /* init for GCC */
11520 int opt_idx = 0; /* init for GCC */
11521 char_u *p;
11522 char_u *s;
11523 int is_term_option = FALSE;
11524 int key;
11525
11526 expand_option_flags = opt_flags;
11527
11528 xp->xp_context = EXPAND_SETTINGS;
11529 if (*arg == NUL)
11530 {
11531 xp->xp_pattern = arg;
11532 return;
11533 }
11534 p = arg + STRLEN(arg) - 1;
11535 if (*p == ' ' && *(p - 1) != '\\')
11536 {
11537 xp->xp_pattern = p + 1;
11538 return;
11539 }
11540 while (p > arg)
11541 {
11542 s = p;
11543 /* count number of backslashes before ' ' or ',' */
11544 if (*p == ' ' || *p == ',')
11545 {
11546 while (s > arg && *(s - 1) == '\\')
11547 --s;
11548 }
11549 /* break at a space with an even number of backslashes */
11550 if (*p == ' ' && ((p - s) & 1) == 0)
11551 {
11552 ++p;
11553 break;
11554 }
11555 --p;
11556 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011557 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011558 {
11559 xp->xp_context = EXPAND_BOOL_SETTINGS;
11560 p += 2;
11561 }
11562 if (STRNCMP(p, "inv", 3) == 0)
11563 {
11564 xp->xp_context = EXPAND_BOOL_SETTINGS;
11565 p += 3;
11566 }
11567 xp->xp_pattern = arg = p;
11568 if (*arg == '<')
11569 {
11570 while (*p != '>')
11571 if (*p++ == NUL) /* expand terminal option name */
11572 return;
11573 key = get_special_key_code(arg + 1);
11574 if (key == 0) /* unknown name */
11575 {
11576 xp->xp_context = EXPAND_NOTHING;
11577 return;
11578 }
11579 nextchar = *++p;
11580 is_term_option = TRUE;
11581 expand_option_name[2] = KEY2TERMCAP0(key);
11582 expand_option_name[3] = KEY2TERMCAP1(key);
11583 }
11584 else
11585 {
11586 if (p[0] == 't' && p[1] == '_')
11587 {
11588 p += 2;
11589 if (*p != NUL)
11590 ++p;
11591 if (*p == NUL)
11592 return; /* expand option name */
11593 nextchar = *++p;
11594 is_term_option = TRUE;
11595 expand_option_name[2] = p[-2];
11596 expand_option_name[3] = p[-1];
11597 }
11598 else
11599 {
11600 /* Allow * wildcard */
11601 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11602 p++;
11603 if (*p == NUL)
11604 return;
11605 nextchar = *p;
11606 *p = NUL;
11607 opt_idx = findoption(arg);
11608 *p = nextchar;
11609 if (opt_idx == -1 || options[opt_idx].var == NULL)
11610 {
11611 xp->xp_context = EXPAND_NOTHING;
11612 return;
11613 }
11614 flags = options[opt_idx].flags;
11615 if (flags & P_BOOL)
11616 {
11617 xp->xp_context = EXPAND_NOTHING;
11618 return;
11619 }
11620 }
11621 }
11622 /* handle "-=" and "+=" */
11623 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11624 {
11625 ++p;
11626 nextchar = '=';
11627 }
11628 if ((nextchar != '=' && nextchar != ':')
11629 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11630 {
11631 xp->xp_context = EXPAND_UNSUCCESSFUL;
11632 return;
11633 }
11634 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11635 {
11636 xp->xp_context = EXPAND_OLD_SETTING;
11637 if (is_term_option)
11638 expand_option_idx = -1;
11639 else
11640 expand_option_idx = opt_idx;
11641 xp->xp_pattern = p + 1;
11642 return;
11643 }
11644 xp->xp_context = EXPAND_NOTHING;
11645 if (is_term_option || (flags & P_NUM))
11646 return;
11647
11648 xp->xp_pattern = p + 1;
11649
11650 if (flags & P_EXPAND)
11651 {
11652 p = options[opt_idx].var;
11653 if (p == (char_u *)&p_bdir
11654 || p == (char_u *)&p_dir
11655 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011656 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011657 || p == (char_u *)&p_rtp
11658#ifdef FEAT_SEARCHPATH
11659 || p == (char_u *)&p_cdpath
11660#endif
11661#ifdef FEAT_SESSION
11662 || p == (char_u *)&p_vdir
11663#endif
11664 )
11665 {
11666 xp->xp_context = EXPAND_DIRECTORIES;
11667 if (p == (char_u *)&p_path
11668#ifdef FEAT_SEARCHPATH
11669 || p == (char_u *)&p_cdpath
11670#endif
11671 )
11672 xp->xp_backslash = XP_BS_THREE;
11673 else
11674 xp->xp_backslash = XP_BS_ONE;
11675 }
11676 else
11677 {
11678 xp->xp_context = EXPAND_FILES;
11679 /* for 'tags' need three backslashes for a space */
11680 if (p == (char_u *)&p_tags)
11681 xp->xp_backslash = XP_BS_THREE;
11682 else
11683 xp->xp_backslash = XP_BS_ONE;
11684 }
11685 }
11686
11687 /* For an option that is a list of file names, find the start of the
11688 * last file name. */
11689 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11690 {
11691 /* count number of backslashes before ' ' or ',' */
11692 if (*p == ' ' || *p == ',')
11693 {
11694 s = p;
11695 while (s > xp->xp_pattern && *(s - 1) == '\\')
11696 --s;
11697 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11698 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11699 {
11700 xp->xp_pattern = p + 1;
11701 break;
11702 }
11703 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011704
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011705#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011706 /* for 'spellsuggest' start at "file:" */
11707 if (options[opt_idx].var == (char_u *)&p_sps
11708 && STRNCMP(p, "file:", 5) == 0)
11709 {
11710 xp->xp_pattern = p + 5;
11711 break;
11712 }
11713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714 }
11715
11716 return;
11717}
11718
11719 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011720ExpandSettings(
11721 expand_T *xp,
11722 regmatch_T *regmatch,
11723 int *num_file,
11724 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011725{
11726 int num_normal = 0; /* Nr of matching non-term-code settings */
11727 int num_term = 0; /* Nr of matching terminal code settings */
11728 int opt_idx;
11729 int match;
11730 int count = 0;
11731 char_u *str;
11732 int loop;
11733 int is_term_opt;
11734 char_u name_buf[MAX_KEY_NAME_LEN];
11735 static char *(names[]) = {"all", "termcap"};
11736 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11737
11738 /* do this loop twice:
11739 * loop == 0: count the number of matching options
11740 * loop == 1: copy the matching options into allocated memory
11741 */
11742 for (loop = 0; loop <= 1; ++loop)
11743 {
11744 regmatch->rm_ic = ic;
11745 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11746 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011747 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11748 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11750 {
11751 if (loop == 0)
11752 num_normal++;
11753 else
11754 (*file)[count++] = vim_strsave((char_u *)names[match]);
11755 }
11756 }
11757 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11758 opt_idx++)
11759 {
11760 if (options[opt_idx].var == NULL)
11761 continue;
11762 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11763 && !(options[opt_idx].flags & P_BOOL))
11764 continue;
11765 is_term_opt = istermoption(&options[opt_idx]);
11766 if (is_term_opt && num_normal > 0)
11767 continue;
11768 match = FALSE;
11769 if (vim_regexec(regmatch, str, (colnr_T)0)
11770 || (options[opt_idx].shortname != NULL
11771 && vim_regexec(regmatch,
11772 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11773 match = TRUE;
11774 else if (is_term_opt)
11775 {
11776 name_buf[0] = '<';
11777 name_buf[1] = 't';
11778 name_buf[2] = '_';
11779 name_buf[3] = str[2];
11780 name_buf[4] = str[3];
11781 name_buf[5] = '>';
11782 name_buf[6] = NUL;
11783 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11784 {
11785 match = TRUE;
11786 str = name_buf;
11787 }
11788 }
11789 if (match)
11790 {
11791 if (loop == 0)
11792 {
11793 if (is_term_opt)
11794 num_term++;
11795 else
11796 num_normal++;
11797 }
11798 else
11799 (*file)[count++] = vim_strsave(str);
11800 }
11801 }
11802 /*
11803 * Check terminal key codes, these are not in the option table
11804 */
11805 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11806 {
11807 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11808 {
11809 if (!isprint(str[0]) || !isprint(str[1]))
11810 continue;
11811
11812 name_buf[0] = 't';
11813 name_buf[1] = '_';
11814 name_buf[2] = str[0];
11815 name_buf[3] = str[1];
11816 name_buf[4] = NUL;
11817
11818 match = FALSE;
11819 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11820 match = TRUE;
11821 else
11822 {
11823 name_buf[0] = '<';
11824 name_buf[1] = 't';
11825 name_buf[2] = '_';
11826 name_buf[3] = str[0];
11827 name_buf[4] = str[1];
11828 name_buf[5] = '>';
11829 name_buf[6] = NUL;
11830
11831 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11832 match = TRUE;
11833 }
11834 if (match)
11835 {
11836 if (loop == 0)
11837 num_term++;
11838 else
11839 (*file)[count++] = vim_strsave(name_buf);
11840 }
11841 }
11842
11843 /*
11844 * Check special key names.
11845 */
11846 regmatch->rm_ic = TRUE; /* ignore case here */
11847 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11848 {
11849 name_buf[0] = '<';
11850 STRCPY(name_buf + 1, str);
11851 STRCAT(name_buf, ">");
11852
11853 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11854 {
11855 if (loop == 0)
11856 num_term++;
11857 else
11858 (*file)[count++] = vim_strsave(name_buf);
11859 }
11860 }
11861 }
11862 if (loop == 0)
11863 {
11864 if (num_normal > 0)
11865 *num_file = num_normal;
11866 else if (num_term > 0)
11867 *num_file = num_term;
11868 else
11869 return OK;
11870 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11871 if (*file == NULL)
11872 {
11873 *file = (char_u **)"";
11874 return FAIL;
11875 }
11876 }
11877 }
11878 return OK;
11879}
11880
11881 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011882ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883{
11884 char_u *var = NULL; /* init for GCC */
11885 char_u *buf;
11886
11887 *num_file = 0;
11888 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11889 if (*file == NULL)
11890 return FAIL;
11891
11892 /*
11893 * For a terminal key code expand_option_idx is < 0.
11894 */
11895 if (expand_option_idx < 0)
11896 {
11897 var = find_termcode(expand_option_name + 2);
11898 if (var == NULL)
11899 expand_option_idx = findoption(expand_option_name);
11900 }
11901
11902 if (expand_option_idx >= 0)
11903 {
11904 /* put string of option value in NameBuff */
11905 option_value2string(&options[expand_option_idx], expand_option_flags);
11906 var = NameBuff;
11907 }
11908 else if (var == NULL)
11909 var = (char_u *)"";
11910
11911 /* A backslash is required before some characters. This is the reverse of
11912 * what happens in do_set(). */
11913 buf = vim_strsave_escaped(var, escape_chars);
11914
11915 if (buf == NULL)
11916 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011917 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918 return FAIL;
11919 }
11920
11921#ifdef BACKSLASH_IN_FILENAME
11922 /* For MS-Windows et al. we don't double backslashes at the start and
11923 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011924 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925 if (var[0] == '\\' && var[1] == '\\'
11926 && expand_option_idx >= 0
11927 && (options[expand_option_idx].flags & P_EXPAND)
11928 && vim_isfilec(var[2])
11929 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011930 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931#endif
11932
11933 *file[0] = buf;
11934 *num_file = 1;
11935 return OK;
11936}
11937#endif
11938
11939/*
11940 * Get the value for the numeric or string option *opp in a nice format into
11941 * NameBuff[]. Must not be called with a hidden option!
11942 */
11943 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011944option_value2string(
11945 struct vimoption *opp,
11946 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947{
11948 char_u *varp;
11949
11950 varp = get_varp_scope(opp, opt_flags);
11951
11952 if (opp->flags & P_NUM)
11953 {
11954 long wc = 0;
11955
11956 if (wc_use_keyname(varp, &wc))
11957 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11958 else if (wc != 0)
11959 STRCPY(NameBuff, transchar((int)wc));
11960 else
11961 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11962 }
11963 else /* P_STRING */
11964 {
11965 varp = *(char_u **)(varp);
11966 if (varp == NULL) /* just in case */
11967 NameBuff[0] = NUL;
11968#ifdef FEAT_CRYPT
11969 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011970 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011971 STRCPY(NameBuff, "*****");
11972#endif
11973 else if (opp->flags & P_EXPAND)
11974 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11975 /* Translate 'pastetoggle' into special key names */
11976 else if ((char_u **)opp->var == &p_pt)
11977 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11978 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011979 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980 }
11981}
11982
11983/*
11984 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11985 * printed as a keyname.
11986 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11987 */
11988 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011989wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011990{
11991 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11992 {
11993 *wcp = *(long *)varp;
11994 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11995 return TRUE;
11996 }
11997 return FALSE;
11998}
11999
Bram Moolenaar01615492015-02-03 13:00:38 +010012000#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012002 * Any character has an equivalent 'langmap' character. This is used for
12003 * keyboards that have a special language mode that sends characters above
12004 * 128 (although other characters can be translated too). The "to" field is a
12005 * Vim command character. This avoids having to switch the keyboard back to
12006 * ASCII mode when leaving Insert mode.
12007 *
12008 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12009 * commands.
12010 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
12011 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
12012 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012013 */
Bram Moolenaar01615492015-02-03 13:00:38 +010012014# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012015/*
12016 * With multi-byte support use growarray for 'langmap' chars >= 256
12017 */
12018typedef struct
12019{
12020 int from;
12021 int to;
12022} langmap_entry_T;
12023
12024static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010012025static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012026
12027/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012028 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12029 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012030 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012031 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012032langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012033{
12034 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012035 int a = 0;
12036 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012037
12038 /* Do a binary search for an existing entry. */
12039 while (a != b)
12040 {
12041 int i = (a + b) / 2;
12042 int d = entries[i].from - from;
12043
12044 if (d == 0)
12045 {
12046 entries[i].to = to;
12047 return;
12048 }
12049 if (d < 0)
12050 a = i + 1;
12051 else
12052 b = i;
12053 }
12054
12055 if (ga_grow(&langmap_mapga, 1) != OK)
12056 return; /* out of memory */
12057
12058 /* insert new entry at position "a" */
12059 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12060 mch_memmove(entries + 1, entries,
12061 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12062 ++langmap_mapga.ga_len;
12063 entries[0].from = from;
12064 entries[0].to = to;
12065}
12066
12067/*
12068 * Apply 'langmap' to multi-byte character "c" and return the result.
12069 */
12070 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012071langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012072{
12073 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12074 int a = 0;
12075 int b = langmap_mapga.ga_len;
12076
12077 while (a != b)
12078 {
12079 int i = (a + b) / 2;
12080 int d = entries[i].from - c;
12081
12082 if (d == 0)
12083 return entries[i].to; /* found matching entry */
12084 if (d < 0)
12085 a = i + 1;
12086 else
12087 b = i;
12088 }
12089 return c; /* no entry found, return "c" unmodified */
12090}
12091# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092
12093 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012094langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095{
12096 int i;
12097
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012098 for (i = 0; i < 256; i++)
12099 langmap_mapchar[i] = i; /* we init with a one-to-one map */
12100# ifdef FEAT_MBYTE
12101 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
12102# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103}
12104
12105/*
12106 * Called when langmap option is set; the language map can be
12107 * changed at any time!
12108 */
12109 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012110langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111{
12112 char_u *p;
12113 char_u *p2;
12114 int from, to;
12115
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012116#ifdef FEAT_MBYTE
12117 ga_clear(&langmap_mapga); /* clear the previous map first */
12118#endif
12119 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120
12121 for (p = p_langmap; p[0] != NUL; )
12122 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012123 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012124 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012125 {
12126 if (p2[0] == '\\' && p2[1] != NUL)
12127 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128 }
12129 if (p2[0] == ';')
12130 ++p2; /* abcd;ABCD form, p2 points to A */
12131 else
12132 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12133 while (p[0])
12134 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012135 if (p[0] == ',')
12136 {
12137 ++p;
12138 break;
12139 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140 if (p[0] == '\\' && p[1] != NUL)
12141 ++p;
12142#ifdef FEAT_MBYTE
12143 from = (*mb_ptr2char)(p);
12144#else
12145 from = p[0];
12146#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012147 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148 if (p2 == NULL)
12149 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012150 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012151 if (p[0] != ',')
12152 {
12153 if (p[0] == '\\')
12154 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012156 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012157#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012158 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012159#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012160 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161 }
12162 else
12163 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012164 if (p2[0] != ',')
12165 {
12166 if (p2[0] == '\\')
12167 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012169 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012171 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012172#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012174 }
12175 if (to == NUL)
12176 {
12177 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12178 transchar(from));
12179 return;
12180 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012181
12182#ifdef FEAT_MBYTE
12183 if (from >= 256)
12184 langmap_set_entry(from, to);
12185 else
12186#endif
12187 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012188
12189 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012190 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012191 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012192 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012193 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012194 if (*p == ';')
12195 {
12196 p = p2;
12197 if (p[0] != NUL)
12198 {
12199 if (p[0] != ',')
12200 {
12201 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12202 return;
12203 }
12204 ++p;
12205 }
12206 break;
12207 }
12208 }
12209 }
12210 }
12211}
12212#endif
12213
12214/*
12215 * Return TRUE if format option 'x' is in effect.
12216 * Take care of no formatting when 'paste' is set.
12217 */
12218 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012219has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012220{
12221 if (p_paste)
12222 return FALSE;
12223 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12224}
12225
12226/*
12227 * Return TRUE if "x" is present in 'shortmess' option, or
12228 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12229 */
12230 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012231shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012232{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012233 return p_shm != NULL &&
12234 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012235 || (vim_strchr(p_shm, 'a') != NULL
12236 && vim_strchr((char_u *)SHM_A, x) != NULL));
12237}
12238
12239/*
12240 * paste_option_changed() - Called after p_paste was set or reset.
12241 */
12242 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012243paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012244{
12245 static int old_p_paste = FALSE;
12246 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012247 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248#ifdef FEAT_CMDL_INFO
12249 static int save_ru = 0;
12250#endif
12251#ifdef FEAT_RIGHTLEFT
12252 static int save_ri = 0;
12253 static int save_hkmap = 0;
12254#endif
12255 buf_T *buf;
12256
12257 if (p_paste)
12258 {
12259 /*
12260 * Paste switched from off to on.
12261 * Save the current values, so they can be restored later.
12262 */
12263 if (!old_p_paste)
12264 {
12265 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012266 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012267 {
12268 buf->b_p_tw_nopaste = buf->b_p_tw;
12269 buf->b_p_wm_nopaste = buf->b_p_wm;
12270 buf->b_p_sts_nopaste = buf->b_p_sts;
12271 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012272 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012273#ifdef FEAT_VARTABS
12274 if (buf->b_p_vsts_nopaste)
12275 vim_free(buf->b_p_vsts_nopaste);
12276 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12277 ? vim_strsave(buf->b_p_vsts) : NULL;
12278#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012279 }
12280
12281 /* save global options */
12282 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012283 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012284#ifdef FEAT_CMDL_INFO
12285 save_ru = p_ru;
12286#endif
12287#ifdef FEAT_RIGHTLEFT
12288 save_ri = p_ri;
12289 save_hkmap = p_hkmap;
12290#endif
12291 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012292 p_ai_nopaste = p_ai;
12293 p_et_nopaste = p_et;
12294 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295 p_tw_nopaste = p_tw;
12296 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012297#ifdef FEAT_VARTABS
12298 if (p_vsts_nopaste)
12299 vim_free(p_vsts_nopaste);
12300 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12301#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302 }
12303
12304 /*
12305 * Always set the option values, also when 'paste' is set when it is
12306 * already on.
12307 */
12308 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012309 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012310 {
12311 buf->b_p_tw = 0; /* textwidth is 0 */
12312 buf->b_p_wm = 0; /* wrapmargin is 0 */
12313 buf->b_p_sts = 0; /* softtabstop is 0 */
12314 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012315 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012316#ifdef FEAT_VARTABS
12317 if (buf->b_p_vsts)
12318 free_string_option(buf->b_p_vsts);
12319 buf->b_p_vsts = empty_option;
12320 if (buf->b_p_vsts_array)
12321 vim_free(buf->b_p_vsts_array);
12322 buf->b_p_vsts_array = 0;
12323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012324 }
12325
12326 /* set global options */
12327 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012328 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012329#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012330 if (p_ru)
12331 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012332 p_ru = 0; /* no ruler */
12333#endif
12334#ifdef FEAT_RIGHTLEFT
12335 p_ri = 0; /* no reverse insert */
12336 p_hkmap = 0; /* no Hebrew keyboard */
12337#endif
12338 /* set global values for local buffer options */
12339 p_tw = 0;
12340 p_wm = 0;
12341 p_sts = 0;
12342 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012343#ifdef FEAT_VARTABS
12344 if (p_vsts)
12345 free_string_option(p_vsts);
12346 p_vsts = empty_option;
12347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012348 }
12349
12350 /*
12351 * Paste switched from on to off: Restore saved values.
12352 */
12353 else if (old_p_paste)
12354 {
12355 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012356 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012357 {
12358 buf->b_p_tw = buf->b_p_tw_nopaste;
12359 buf->b_p_wm = buf->b_p_wm_nopaste;
12360 buf->b_p_sts = buf->b_p_sts_nopaste;
12361 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012362 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012363#ifdef FEAT_VARTABS
12364 if (buf->b_p_vsts)
12365 free_string_option(buf->b_p_vsts);
12366 buf->b_p_vsts = buf->b_p_vsts_nopaste
12367 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12368 if (buf->b_p_vsts_array)
12369 vim_free(buf->b_p_vsts_array);
12370 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12371 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12372 else
12373 buf->b_p_vsts_array = 0;
12374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012375 }
12376
12377 /* restore global options */
12378 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012379 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012380#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381 if (p_ru != save_ru)
12382 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012383 p_ru = save_ru;
12384#endif
12385#ifdef FEAT_RIGHTLEFT
12386 p_ri = save_ri;
12387 p_hkmap = save_hkmap;
12388#endif
12389 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012390 p_ai = p_ai_nopaste;
12391 p_et = p_et_nopaste;
12392 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012393 p_tw = p_tw_nopaste;
12394 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012395#ifdef FEAT_VARTABS
12396 if (p_vsts)
12397 free_string_option(p_vsts);
12398 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012400 }
12401
12402 old_p_paste = p_paste;
12403}
12404
12405/*
12406 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12407 *
12408 * Reset 'compatible' and set the values for options that didn't get set yet
12409 * to the Vim defaults.
12410 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012411 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012412 */
12413 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012414vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012415{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012416 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012417 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012418 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012419
12420 if (!option_was_set((char_u *)"cp"))
12421 {
12422 p_cp = FALSE;
12423 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12424 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12425 set_option_default(opt_idx, OPT_FREE, FALSE);
12426 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012427 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012428 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012429
12430 if (fname != NULL)
12431 {
12432 p = vim_getenv(envname, &dofree);
12433 if (p == NULL)
12434 {
12435 /* Set $MYVIMRC to the first vimrc file found. */
12436 p = FullName_save(fname, FALSE);
12437 if (p != NULL)
12438 {
12439 vim_setenv(envname, p);
12440 vim_free(p);
12441 }
12442 }
12443 else if (dofree)
12444 vim_free(p);
12445 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012446}
12447
12448/*
12449 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12450 */
12451 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012452change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012453{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012454 int opt_idx;
12455
Bram Moolenaar071d4272004-06-13 20:20:40 +000012456 if (p_cp != on)
12457 {
12458 p_cp = on;
12459 compatible_set();
12460 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012461 opt_idx = findoption((char_u *)"cp");
12462 if (opt_idx >= 0)
12463 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012464}
12465
12466/*
12467 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012468 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012469 */
12470 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012471option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472{
12473 int idx;
12474
12475 idx = findoption(name);
12476 if (idx < 0) /* unknown option */
12477 return FALSE;
12478 if (options[idx].flags & P_WAS_SET)
12479 return TRUE;
12480 return FALSE;
12481}
12482
12483/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012484 * Reset the flag indicating option "name" was set.
12485 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012486 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012487reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012488{
12489 int idx = findoption(name);
12490
12491 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012492 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012493 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012494 return OK;
12495 }
12496 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012497}
12498
12499/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012500 * compatible_set() - Called when 'compatible' has been set or unset.
12501 *
12502 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12503 * flag) to a Vi compatible value.
12504 * When 'compatible' is unset: Set all options that have a different default
12505 * for Vim (without the P_VI_DEF flag) to that default.
12506 */
12507 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012508compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012509{
12510 int opt_idx;
12511
12512 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12513 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12514 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12515 set_option_default(opt_idx, OPT_FREE, p_cp);
12516 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012517 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012518}
12519
12520#ifdef FEAT_LINEBREAK
12521
12522# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12523 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012524 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012525# endif
12526
12527/*
12528 * fill_breakat_flags() -- called when 'breakat' changes value.
12529 */
12530 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012531fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012532{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012533 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012534 int i;
12535
12536 for (i = 0; i < 256; i++)
12537 breakat_flags[i] = FALSE;
12538
12539 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012540 for (p = p_breakat; *p; p++)
12541 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012542}
12543
12544# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012545 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012546# endif
12547
12548#endif
12549
12550/*
12551 * Check an option that can be a range of string values.
12552 *
12553 * Return OK for correct value, FAIL otherwise.
12554 * Empty is always OK.
12555 */
12556 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012557check_opt_strings(
12558 char_u *val,
12559 char **values,
12560 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012561{
12562 return opt_strings_flags(val, values, NULL, list);
12563}
12564
12565/*
12566 * Handle an option that can be a range of string values.
12567 * Set a flag in "*flagp" for each string present.
12568 *
12569 * Return OK for correct value, FAIL otherwise.
12570 * Empty is always OK.
12571 */
12572 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012573opt_strings_flags(
12574 char_u *val, /* new value */
12575 char **values, /* array of valid string values */
12576 unsigned *flagp,
12577 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012578{
12579 int i;
12580 int len;
12581 unsigned new_flags = 0;
12582
12583 while (*val)
12584 {
12585 for (i = 0; ; ++i)
12586 {
12587 if (values[i] == NULL) /* val not found in values[] */
12588 return FAIL;
12589
12590 len = (int)STRLEN(values[i]);
12591 if (STRNCMP(values[i], val, len) == 0
12592 && ((list && val[len] == ',') || val[len] == NUL))
12593 {
12594 val += len + (val[len] == ',');
12595 new_flags |= (1 << i);
12596 break; /* check next item in val list */
12597 }
12598 }
12599 }
12600 if (flagp != NULL)
12601 *flagp = new_flags;
12602
12603 return OK;
12604}
12605
12606/*
12607 * Read the 'wildmode' option, fill wim_flags[].
12608 */
12609 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012610check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012611{
12612 char_u new_wim_flags[4];
12613 char_u *p;
12614 int i;
12615 int idx = 0;
12616
12617 for (i = 0; i < 4; ++i)
12618 new_wim_flags[i] = 0;
12619
12620 for (p = p_wim; *p; ++p)
12621 {
12622 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12623 ;
12624 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12625 return FAIL;
12626 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12627 new_wim_flags[idx] |= WIM_LONGEST;
12628 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12629 new_wim_flags[idx] |= WIM_FULL;
12630 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12631 new_wim_flags[idx] |= WIM_LIST;
12632 else
12633 return FAIL;
12634 p += i;
12635 if (*p == NUL)
12636 break;
12637 if (*p == ',')
12638 {
12639 if (idx == 3)
12640 return FAIL;
12641 ++idx;
12642 }
12643 }
12644
12645 /* fill remaining entries with last flag */
12646 while (idx < 3)
12647 {
12648 new_wim_flags[idx + 1] = new_wim_flags[idx];
12649 ++idx;
12650 }
12651
12652 /* only when there are no errors, wim_flags[] is changed */
12653 for (i = 0; i < 4; ++i)
12654 wim_flags[i] = new_wim_flags[i];
12655 return OK;
12656}
12657
12658/*
12659 * Check if backspacing over something is allowed.
12660 */
12661 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012662can_bs(
12663 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012664{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012665#ifdef FEAT_JOB_CHANNEL
12666 if (what == BS_START && bt_prompt(curbuf))
12667 return FALSE;
12668#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012669 switch (*p_bs)
12670 {
12671 case '2': return TRUE;
12672 case '1': return (what != BS_START);
12673 case '0': return FALSE;
12674 }
12675 return vim_strchr(p_bs, what) != NULL;
12676}
12677
12678/*
12679 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12680 * the file must be considered changed when the value is different.
12681 */
12682 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012683save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012684{
12685 buf->b_start_ffc = *buf->b_p_ff;
12686 buf->b_start_eol = buf->b_p_eol;
12687#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012688 buf->b_start_bomb = buf->b_p_bomb;
12689
Bram Moolenaar071d4272004-06-13 20:20:40 +000012690 /* Only use free/alloc when necessary, they take time. */
12691 if (buf->b_start_fenc == NULL
12692 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12693 {
12694 vim_free(buf->b_start_fenc);
12695 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12696 }
12697#endif
12698}
12699
12700/*
12701 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12702 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012703 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12704 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012705 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012706 * When "ignore_empty" is true don't consider a new, empty buffer to be
12707 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012708 */
12709 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012710file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012711{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012712 /* In a buffer that was never loaded the options are not valid. */
12713 if (buf->b_flags & BF_NEVERLOADED)
12714 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012715 if (ignore_empty
12716 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012717 && buf->b_ml.ml_line_count == 1
12718 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12719 return FALSE;
12720 if (buf->b_start_ffc != *buf->b_p_ff)
12721 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012722 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012723 return TRUE;
12724#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012725 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12726 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012727 if (buf->b_start_fenc == NULL)
12728 return (*buf->b_p_fenc != NUL);
12729 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12730#else
12731 return FALSE;
12732#endif
12733}
12734
12735/*
12736 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12737 */
12738 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012739check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012740{
12741 return check_opt_strings(p, p_ff_values, FALSE);
12742}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012743
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012744#ifdef FEAT_VARTABS
12745
12746/*
12747 * Set the integer values corresponding to the string setting of 'vartabstop'.
12748 */
12749 int
12750tabstop_set(char_u *var, int **array)
12751{
12752 int valcount = 1;
12753 int t;
12754 char_u *cp;
12755
12756 if ((!var[0] || (var[0] == '0' && !var[1])))
12757 {
12758 *array = NULL;
12759 return TRUE;
12760 }
12761
12762 for (cp = var; *cp; ++cp)
12763 {
12764 if (cp == var || *(cp - 1) == ',')
12765 {
12766 char_u *end;
12767 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12768 {
12769 if (cp != end)
12770 EMSG(_(e_positive));
12771 else
12772 EMSG(_(e_invarg));
12773 return FALSE;
12774 }
12775 }
12776
12777 if (VIM_ISDIGIT(*cp))
12778 continue;
12779 if (*cp == ',' && cp > var && *(cp - 1) != ',')
12780 {
12781 ++valcount;
12782 continue;
12783 }
12784 EMSG(_(e_invarg));
12785 return FALSE;
12786 }
12787
12788 *array = (int *) alloc((unsigned) ((valcount + 1) * sizeof(int)));
12789 (*array)[0] = valcount;
12790
12791 t = 1;
12792 for (cp = var; *cp;)
12793 {
12794 (*array)[t++] = atoi((char *)cp);
12795 while (*cp && *cp != ',')
12796 ++cp;
12797 if (*cp)
12798 ++cp;
12799 }
12800
12801 return TRUE;
12802}
12803
12804/*
12805 * Calculate the number of screen spaces a tab will occupy.
12806 * If "vts" is set then the tab widths are taken from that array,
12807 * otherwise the value of ts is used.
12808 */
12809 int
12810tabstop_padding(colnr_T col, int ts_arg, int *vts)
12811{
12812 int ts = ts_arg == 0 ? 8 : ts_arg;
12813 int tabcount;
12814 colnr_T tabcol = 0;
12815 int t;
12816 int padding = 0;
12817
12818 if (vts == NULL || vts[0] == 0)
12819 return ts - (col % ts);
12820
12821 tabcount = vts[0];
12822
12823 for (t = 1; t <= tabcount; ++t)
12824 {
12825 tabcol += vts[t];
12826 if (tabcol > col)
12827 {
12828 padding = (int)(tabcol - col);
12829 break;
12830 }
12831 }
12832 if (t > tabcount)
12833 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12834
12835 return padding;
12836}
12837
12838/*
12839 * Find the size of the tab that covers a particular column.
12840 */
12841 int
12842tabstop_at(colnr_T col, int ts, int *vts)
12843{
12844 int tabcount;
12845 colnr_T tabcol = 0;
12846 int t;
12847 int tab_size = 0;
12848
12849 if (vts == 0 || vts[0] == 0)
12850 return ts;
12851
12852 tabcount = vts[0];
12853 for (t = 1; t <= tabcount; ++t)
12854 {
12855 tabcol += vts[t];
12856 if (tabcol > col)
12857 {
12858 tab_size = vts[t];
12859 break;
12860 }
12861 }
12862 if (t > tabcount)
12863 tab_size = vts[tabcount];
12864
12865 return tab_size;
12866}
12867
12868/*
12869 * Find the column on which a tab starts.
12870 */
12871 colnr_T
12872tabstop_start(colnr_T col, int ts, int *vts)
12873{
12874 int tabcount;
12875 colnr_T tabcol = 0;
12876 int t;
12877 int excess;
12878
Bram Moolenaar0119a592018-06-24 23:53:28 +020012879 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012880 return (col / ts) * ts;
12881
12882 tabcount = vts[0];
12883 for (t = 1; t <= tabcount; ++t)
12884 {
12885 tabcol += vts[t];
12886 if (tabcol > col)
12887 return tabcol - vts[t];
12888 }
12889
12890 excess = tabcol % vts[tabcount];
12891 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12892}
12893
12894/*
12895 * Find the number of tabs and spaces necessary to get from one column
12896 * to another.
12897 */
12898 void
12899tabstop_fromto(
12900 colnr_T start_col,
12901 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012902 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012903 int *vts,
12904 int *ntabs,
12905 int *nspcs)
12906{
12907 int spaces = end_col - start_col;
12908 colnr_T tabcol = 0;
12909 int padding = 0;
12910 int tabcount;
12911 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012912 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012913
Bram Moolenaar0119a592018-06-24 23:53:28 +020012914 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012915 {
12916 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012917 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012918
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012919 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012920 if (spaces >= initspc)
12921 {
12922 spaces -= initspc;
12923 tabs++;
12924 }
12925 tabs += spaces / ts;
12926 spaces -= (spaces / ts) * ts;
12927
12928 *ntabs = tabs;
12929 *nspcs = spaces;
12930 return;
12931 }
12932
12933 /* Find the padding needed to reach the next tabstop. */
12934 tabcount = vts[0];
12935 for (t = 1; t <= tabcount; ++t)
12936 {
12937 tabcol += vts[t];
12938 if (tabcol > start_col)
12939 {
12940 padding = (int)(tabcol - start_col);
12941 break;
12942 }
12943 }
12944 if (t > tabcount)
12945 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12946
12947 /* If the space needed is less than the padding no tabs can be used. */
12948 if (spaces < padding)
12949 {
12950 *ntabs = 0;
12951 *nspcs = spaces;
12952 return;
12953 }
12954
12955 *ntabs = 1;
12956 spaces -= padding;
12957
12958 /* At least one tab has been used. See if any more will fit. */
12959 while (spaces != 0 && ++t <= tabcount)
12960 {
12961 padding = vts[t];
12962 if (spaces < padding)
12963 {
12964 *nspcs = spaces;
12965 return;
12966 }
12967 ++*ntabs;
12968 spaces -= padding;
12969 }
12970
12971 *ntabs += spaces / vts[tabcount];
12972 *nspcs = spaces % vts[tabcount];
12973}
12974
12975/*
12976 * See if two tabstop arrays contain the same values.
12977 */
12978 int
12979tabstop_eq(int *ts1, int *ts2)
12980{
12981 int t;
12982
12983 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
12984 return FALSE;
12985 if (ts1 == ts2)
12986 return TRUE;
12987 if (ts1[0] != ts2[0])
12988 return FALSE;
12989
12990 for (t = 1; t <= ts1[0]; ++t)
12991 if (ts1[t] != ts2[t])
12992 return FALSE;
12993
12994 return TRUE;
12995}
12996
12997/*
12998 * Copy a tabstop array, allocating space for the new array.
12999 */
13000 int *
13001tabstop_copy(int *oldts)
13002{
13003 int *newts;
13004 int t;
13005
13006 if (oldts == 0)
13007 return 0;
13008
13009 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
13010 for (t = 0; t <= oldts[0]; ++t)
13011 newts[t] = oldts[t];
13012
13013 return newts;
13014}
13015
13016/*
13017 * Return a count of the number of tabstops.
13018 */
13019 int
13020tabstop_count(int *ts)
13021{
13022 return ts != NULL ? ts[0] : 0;
13023}
13024
13025/*
13026 * Return the first tabstop, or 8 if there are no tabstops defined.
13027 */
13028 int
13029tabstop_first(int *ts)
13030{
13031 return ts != NULL ? ts[1] : 8;
13032}
13033
13034#endif
13035
Bram Moolenaar14f24742012-08-08 18:01:05 +020013036/*
13037 * Return the effective shiftwidth value for current buffer, using the
13038 * 'tabstop' value when 'shiftwidth' is zero.
13039 */
13040 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013041get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013042{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013043 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020013044}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013045
13046/*
13047 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013048 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013049 */
13050 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013051get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013052{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013053 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013054}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013055
13056/*
13057 * Check matchpairs option for "*initc".
13058 * If there is a match set "*initc" to the matching character and "*findc" to
13059 * the opposite character. Set "*backwards" to the direction.
13060 * When "switchit" is TRUE swap the direction.
13061 */
13062 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013063find_mps_values(
13064 int *initc,
13065 int *findc,
13066 int *backwards,
13067 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013068{
13069 char_u *ptr;
13070
13071 ptr = curbuf->b_p_mps;
13072 while (*ptr != NUL)
13073 {
13074#ifdef FEAT_MBYTE
13075 if (has_mbyte)
13076 {
13077 char_u *prev;
13078
13079 if (mb_ptr2char(ptr) == *initc)
13080 {
13081 if (switchit)
13082 {
13083 *findc = *initc;
13084 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13085 *backwards = TRUE;
13086 }
13087 else
13088 {
13089 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13090 *backwards = FALSE;
13091 }
13092 return;
13093 }
13094 prev = ptr;
13095 ptr += mb_ptr2len(ptr) + 1;
13096 if (mb_ptr2char(ptr) == *initc)
13097 {
13098 if (switchit)
13099 {
13100 *findc = *initc;
13101 *initc = mb_ptr2char(prev);
13102 *backwards = FALSE;
13103 }
13104 else
13105 {
13106 *findc = mb_ptr2char(prev);
13107 *backwards = TRUE;
13108 }
13109 return;
13110 }
13111 ptr += mb_ptr2len(ptr);
13112 }
13113 else
13114#endif
13115 {
13116 if (*ptr == *initc)
13117 {
13118 if (switchit)
13119 {
13120 *backwards = TRUE;
13121 *findc = *initc;
13122 *initc = ptr[2];
13123 }
13124 else
13125 {
13126 *backwards = FALSE;
13127 *findc = ptr[2];
13128 }
13129 return;
13130 }
13131 ptr += 2;
13132 if (*ptr == *initc)
13133 {
13134 if (switchit)
13135 {
13136 *backwards = FALSE;
13137 *findc = *initc;
13138 *initc = ptr[-2];
13139 }
13140 else
13141 {
13142 *backwards = TRUE;
13143 *findc = ptr[-2];
13144 }
13145 return;
13146 }
13147 ++ptr;
13148 }
13149 if (*ptr == ',')
13150 ++ptr;
13151 }
13152}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013153
13154#if defined(FEAT_LINEBREAK) || defined(PROTO)
13155/*
13156 * This is called when 'breakindentopt' is changed and when a window is
13157 * initialized.
13158 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013159 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013160briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013161{
13162 char_u *p;
13163 int bri_shift = 0;
13164 long bri_min = 20;
13165 int bri_sbr = FALSE;
13166
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013167 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013168 while (*p != NUL)
13169 {
13170 if (STRNCMP(p, "shift:", 6) == 0
13171 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13172 {
13173 p += 6;
13174 bri_shift = getdigits(&p);
13175 }
13176 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13177 {
13178 p += 4;
13179 bri_min = getdigits(&p);
13180 }
13181 else if (STRNCMP(p, "sbr", 3) == 0)
13182 {
13183 p += 3;
13184 bri_sbr = TRUE;
13185 }
13186 if (*p != ',' && *p != NUL)
13187 return FAIL;
13188 if (*p == ',')
13189 ++p;
13190 }
13191
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013192 wp->w_p_brishift = bri_shift;
13193 wp->w_p_brimin = bri_min;
13194 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013195
13196 return OK;
13197}
13198#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013199
13200/*
13201 * Get the local or global value of 'backupcopy'.
13202 */
13203 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013204get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013205{
13206 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13207}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013208
13209#if defined(FEAT_SIGNS) || defined(PROTO)
13210/*
13211 * Return TRUE when window "wp" has a column to draw signs in.
13212 */
13213 int
13214signcolumn_on(win_T *wp)
13215{
13216 if (*wp->w_p_scl == 'n')
13217 return FALSE;
13218 if (*wp->w_p_scl == 'y')
13219 return TRUE;
13220 return (wp->w_buffer->b_signlist != NULL
13221# ifdef FEAT_NETBEANS_INTG
13222 || wp->w_buffer->b_has_sign_column
13223# endif
13224 );
13225}
13226#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013227
13228#if defined(FEAT_EVAL) || defined(PROTO)
13229/*
13230 * Get window or buffer local options.
13231 */
13232 dict_T *
13233get_winbuf_options(int bufopt)
13234{
13235 dict_T *d;
13236 int opt_idx;
13237
13238 d = dict_alloc();
13239 if (d == NULL)
13240 return NULL;
13241
13242 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13243 {
13244 struct vimoption *opt = &options[opt_idx];
13245
13246 if ((bufopt && (opt->indir & PV_BUF))
13247 || (!bufopt && (opt->indir & PV_WIN)))
13248 {
13249 char_u *varp = get_varp(opt);
13250
13251 if (varp != NULL)
13252 {
13253 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013254 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013255 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013256 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013257 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013258 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013259 }
13260 }
13261 }
13262
13263 return d;
13264}
13265#endif