blob: 6d861837c4e0143e4769511ca08574858f1bc0c8 [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{
407 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) */
416#ifdef FEAT_EVAL
417 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000418# define SCRIPTID_INIT , 0
419#else
420# define SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000518 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000527 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000564 SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +0100573 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autoindent", "ai", P_BOOL|P_VI_DEF,
575 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autoprint", "ap", P_BOOL|P_VI_DEF,
578 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"autowrite", "aw", P_BOOL|P_VI_DEF,
584 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"autowriteall","awa", P_BOOL|P_VI_DEF,
587 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000597 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000603 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000611 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000624 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000633 SCRIPTID_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 Moolenaarc43a8b82017-02-25 21:12:29 +0100642 SCRIPTID_INIT},
643 {"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
651 SCRIPTID_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
660 SCRIPTID_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
669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"beautify", "bf", P_BOOL|P_VI_DEF,
671 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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,
675 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000678 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000681 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000688 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000697 SCRIPTID_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
706 SCRIPTID_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
716 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000725 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000729 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000733 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000737 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000746 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000755 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000764 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000773 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000780 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000789 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000796 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000806 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000820 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000823 {(char_u *)1L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000830 {(char_u *)7L, (char_u *)0L} SCRIPTID_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
837 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000840 {(char_u *)80L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000851 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000860 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000865 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000874 SCRIPTID_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
883 SCRIPTID_INIT},
884 {"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}
891 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000900 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000909 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000916 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000919 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000922 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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}
926 SCRIPTID_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 Moolenaar49771f42010-07-20 17:32:38 +0200935 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000942 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000951 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000960 SCRIPTID_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
967 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000974 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000988 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar860cae12010-06-05 23:22:07 +0200991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"debug", NULL, P_STRING|P_VI_DEF,
1007 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001008 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001017 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001024 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001031 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001047 SCRIPTID_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,
1052 {(char_u *)"filler", (char_u *)NULL}
1053#else
1054 (char_u *)NULL, PV_NONE,
1055 {(char_u *)"", (char_u *)NULL}
1056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001068 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001071 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001075 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1077 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001078 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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
1087 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001096 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001099 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1107 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001117 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001126 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127 {"esckeys", "ek", P_BOOL|P_VIM,
1128 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001129 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001132 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001135 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001138 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001148 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001157 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001161 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_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}
1165 SCRIPTID_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
1174 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001178 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001182 SCRIPTID_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,
1185 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193 {"flash", "fl", P_BOOL|P_VI_DEF,
1194 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001195 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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
1204 SCRIPTID_INIT},
1205 {"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
1213 SCRIPTID_INIT},
1214 {"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
1222 SCRIPTID_INIT},
1223 {"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 Moolenaar2c4278f2009-05-17 11:33:22 +00001231 SCRIPTID_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
1240 SCRIPTID_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
1249 SCRIPTID_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
1258 SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +01001268 SCRIPTID_INIT},
1269 {"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
1277 SCRIPTID_INIT},
1278 {"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
1286 SCRIPTID_INIT},
1287 {"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
1295 SCRIPTID_INIT},
1296 {"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
1305 SCRIPTID_INIT},
1306 {"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
1314 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001323 SCRIPTID_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}
1327 SCRIPTID_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*",
1331 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001334 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001343 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {"graphic", "gr", P_BOOL|P_VI_DEF,
1348 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001358 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001384 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001399 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001408 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001426 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001433 {(char_u *)50L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001446 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001453 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001462 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001471 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1473 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)0L, (char_u *)0L} SCRIPTID_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}
1478 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001481 {(char_u *)20L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001490 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"hidden", "hid", P_BOOL|P_VI_DEF,
1492 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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}
1497 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {"history", "hi", P_NUM|P_VIM,
1499 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001500 {(char_u *)0L, (char_u *)50L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001507 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001517 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001524 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001531 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1533 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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
1543 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001550 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001569 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001573 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001577 SCRIPTID_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
1586 SCRIPTID_INIT},
1587 {"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 Moolenaarabab85a2013-06-26 19:18:05 +02001595 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001604 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001613 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001625 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"infercase", "inf", P_BOOL|P_VI_DEF,
1636 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001640 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001663 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001680 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001699 } SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001713 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001716 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001725 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001734 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001737 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001754 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001763 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)"", (char_u *)0L} SCRIPTID_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
1777 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaarda9ce2c2016-09-02 19:34:10 +02001784 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001787 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1789 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001797 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001806 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001818 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001834 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1842 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar25e4fcd2016-01-09 14:57:47 +01001852 SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +01001861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {"magic", NULL, P_BOOL|P_VI_DEF,
1863 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001873 SCRIPTID_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
1882 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001895 SCRIPTID_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}
1899 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"matchtime", "mat", P_NUM|P_VI_DEF,
1901 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)5L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001909 {(char_u *)2, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001916 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1918 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)1000L, (char_u *)0L} SCRIPTID_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}
1923 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001924 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1925 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)1000L, (char_u *)0L} SCRIPTID_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}
1930 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"mesg", NULL, P_BOOL|P_VI_DEF,
1939 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001949 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"modeline", "ml", P_BOOL|P_VIM,
1951 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"modelines", "mls", P_NUM|P_VI_DEF,
1954 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)5L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"more", NULL, P_BOOL|P_VIM,
1963 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001973 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002000 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002009 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2011 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 {(char_u *)500L, (char_u *)0L} SCRIPTID_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
2021 SCRIPTID_INIT},
2022 {"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
2030 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002037 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038 {"novice", NULL, P_BOOL|P_VI_DEF,
2039 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002040 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002044 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002047 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)8L, (char_u *)4L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"open", NULL, P_BOOL|P_VI_DEF,
2065 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002074 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002077 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"optimize", "opt", P_BOOL|P_VI_DEF,
2079 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaarb07269a2011-05-19 13:41:14 +02002083 {(char_u *)0L, (char_u *)0L} SCRIPTID_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}
2088 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002092 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2097 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002107 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002110 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002119 (char_u *)0L} SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +01002128 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002131 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002138 {(char_u *)12L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002154 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002163 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002172 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002187 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002198 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002207 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002216 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002225 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002235 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar42443c72018-02-10 18:28:52 +01002242 {(char_u *)15L, (char_u *)15L} SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +01002251 SCRIPTID_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
2260 SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +01002269 SCRIPTID_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
2278 SCRIPTID_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}
2286 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002295 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002298 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"redraw", NULL, P_BOOL|P_VI_DEF,
2300 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002309 {"regexpengine", "re", P_NUM|P_VI_DEF,
2310 (char_u *)&p_re, PV_NONE,
2311 {(char_u *)0L, (char_u *)0L} SCRIPTID_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,
2314 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"remap", NULL, P_BOOL|P_VI_DEF,
2316 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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
2326 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"report", NULL, P_NUM|P_VI_DEF,
2328 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)2L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002350 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002359 SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +01002368 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002382 {(char_u *)"", (char_u *)0L} SCRIPTID_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}
2387 SCRIPTID_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 Moolenaaraf2d20c2017-10-29 15:26:57 +01002390 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)1L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002403 SCRIPTID_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}
2407 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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}
2414 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002417 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002427 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002440 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002449 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002464 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002467 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)">", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002477 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002478 {"shelltemp", "stmp", P_BOOL,
2479 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002480 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002487 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002496 (char_u *)0L} SCRIPTID_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
2505 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2510 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)8L, (char_u *)0L} SCRIPTID_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"}
2515 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002538 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2540 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2543 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 {"showmode", "smd", P_BOOL|P_VIM,
2546 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2552 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaarb3384832016-08-12 18:51:58 +02002565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2567 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2570 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2586 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002603 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002613 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002623 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002632 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002635 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002638 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002641 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002652 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002661 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"swapsync", "sws", P_STRING|P_VI_DEF,
2666 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002679 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002688 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002695 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)10L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)8L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002709 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002710 {"tagcase", "tc", P_STRING|P_VIM,
2711 (char_u *)&p_tc, PV_TC,
2712 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"taglength", "tl", P_NUM|P_VI_DEF,
2714 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"tagrelative", "tr", P_BOOL|P_VIM,
2717 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002727 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2729 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +01002739 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002742 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002758 SCRIPTID_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
2767 SCRIPTID_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
2776 SCRIPTID_INIT},
2777 {"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
2785 SCRIPTID_INIT},
2786 {"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
2794 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 {"terse", NULL, P_BOOL|P_VI_DEF,
2796 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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}
2801 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002810 (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002823 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"timeout", "to", P_BOOL|P_VI_DEF,
2825 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2828 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)1000L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)85L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002853 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002869 SCRIPTID_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 Moolenaara713ff82017-02-25 22:18:43 +01002878 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2883 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002884 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2886 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002887 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2899 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)999L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002903 {(char_u *)"", (char_u *)0L} SCRIPTID_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
2913 SCRIPTID_INIT},
2914 {"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
2920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002929 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002930 {"undoreload", "ur", P_NUM|P_VI_DEF,
2931 (char_u *)&p_ur, PV_NONE,
2932 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 {"updatecount", "uc", P_NUM|P_VI_DEF,
2934 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"updatetime", "ut", P_NUM|P_VI_DEF,
2937 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)4000L, (char_u *)0L} SCRIPTID_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
2947 SCRIPTID_INIT},
2948 {"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
2956 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 {"verbose", "vbs", P_NUM|P_VI_DEF,
2958 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002959 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002962 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002971 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002981 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00002999 SCRIPTID_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
3009 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003019 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3021 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"w300", NULL, P_NUM|P_VI_DEF,
3024 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003025 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 {"w1200", NULL, P_NUM|P_VI_DEF,
3027 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"w9600", NULL, P_NUM|P_VI_DEF,
3030 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003031 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 {"warn", NULL, P_BOOL|P_VI_DEF,
3033 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003034 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003040 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_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}
3044 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003047 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003054 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003055 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3056 (char_u *)&p_wic, PV_NONE,
3057 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003067 {(char_u *)"full", (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003076 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003085 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003088 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003091 {(char_u *)1L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003094 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003100 {(char_u *)1L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003103 {(char_u *)1L, (char_u *)0L} SCRIPTID_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
3117 SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003120 {(char_u *)20L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003123 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3125 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003126 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3128 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003129 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 {"write", NULL, P_BOOL|P_VI_DEF,
3131 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003132 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 {"writeany", "wa", P_BOOL|P_VI_DEF,
3134 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003135 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003144 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 {"writedelay", "wd", P_NUM|P_VI_DEF,
3146 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003147 {(char_u *)0L, (char_u *)0L} SCRIPTID_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 Moolenaar2c4278f2009-05-17 11:33:22 +00003152 {(char_u *)"", (char_u *)0L} SCRIPTID_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 Moolenaarce1c3272017-08-20 15:05:15 +02003195 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 p_term("t_RV", T_CRV)
3197 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003198 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003200 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003201 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003202 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003204 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003206 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207 p_term("t_te", T_TE)
3208 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003209 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003210 p_term("t_ts", T_TS)
3211 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 p_term("t_ue", T_UE)
3213 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003214 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215 p_term("t_vb", T_VB)
3216 p_term("t_ve", T_VE)
3217 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003218 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 p_term("t_vs", T_VS)
3220 p_term("t_WP", T_CWP)
3221 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003222 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 p_term("t_xs", T_XS)
3224 p_term("t_ZH", T_CZH)
3225 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003226 p_term("t_8f", T_8F)
3227 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228
3229/* terminal key codes are not in here */
3230
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003231 /* end marker */
3232 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233};
3234
3235#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3236
3237#ifdef FEAT_MBYTE
3238static char *(p_ambw_values[]) = {"single", "double", NULL};
3239#endif
3240static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003241static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003243#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003244static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003245#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003246#ifdef FEAT_CMDL_COMPL
3247static char *(p_wop_values[]) = {"tagfile", NULL};
3248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249#ifdef FEAT_WAK
3250static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3251#endif
3252static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3254static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#ifdef FEAT_BROWSE
3257static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003260static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003262static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003263static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3265#ifdef FEAT_FOLDING
3266static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003267# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003269# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270 NULL};
3271static char *(p_fcl_values[]) = {"all", NULL};
3272#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003273#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003274static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003275#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003276#ifdef FEAT_SIGNS
3277static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3278#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static void set_option_default(int, int opt_flags, int compatible);
3281static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003282static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static char_u *term_bg_default(void);
3284static void did_set_option(int opt_idx, int opt_flags, int new_value);
3285static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003289static char_u *option_expand(int opt_idx, char_u *val);
3290static void didset_options(void);
3291static void didset_options2(void);
3292static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003293#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003294static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003295#else
3296# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3297#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003298static void set_string_option_global(int opt_idx, char_u **varp);
3299static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3300static 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);
3301static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003302#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003303static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003304#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003308#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static char_u *did_set_spell_option(int is_spellfile);
3310static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003311#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003312#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003313static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003314#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003315static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3316static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3317static void check_redraw(long_u flags);
3318static int findoption(char_u *);
3319static int find_key_option(char_u *);
3320static void showoptions(int all, int opt_flags);
3321static int optval_default(struct vimoption *, char_u *varp);
3322static void showoneopt(struct vimoption *, int opt_flags);
3323static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3324static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3325static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3326static int istermoption(struct vimoption *);
3327static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3328static char_u *get_varp(struct vimoption *);
3329static void option_value2string(struct vimoption *, int opt_flags);
3330static void check_winopt(winopt_T *wop);
3331static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003333static void langmap_init(void);
3334static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003336static void paste_option_changed(void);
3337static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003339static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003341static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3342static int check_opt_strings(char_u *val, char **values, int);
3343static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003344#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003345static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347
3348/*
3349 * Initialize the options, first part.
3350 *
3351 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003352 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353 */
3354 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003355set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356{
3357 char_u *p;
3358 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003359 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360
3361#ifdef FEAT_LANGMAP
3362 langmap_init();
3363#endif
3364
3365 /* Be Vi compatible by default */
3366 p_cp = TRUE;
3367
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003368 /* Use POSIX compatibility when $VIM_POSIX is set. */
3369 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003370 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003371 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003372 set_string_default("shm", (char_u *)"A");
3373 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003374
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375 /*
3376 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003377 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003379 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003380#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003381 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003383 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384# endif
3385#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003386 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003387 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388
3389#ifdef FEAT_WILDIGN
3390 /*
3391 * Set the default for 'backupskip' to include environment variables for
3392 * temp files.
3393 */
3394 {
3395# ifdef UNIX
3396 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3397# else
3398 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3399# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003400 int len;
3401 garray_T ga;
3402 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403
3404 ga_init2(&ga, 1, 100);
3405 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3406 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003407 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408# ifdef UNIX
3409 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003410# ifdef MACOS_X
3411 p = (char_u *)"/private/tmp";
3412# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003414# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415 else
3416# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003417 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 if (p != NULL && *p != NUL)
3419 {
3420 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003421 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422 if (ga_grow(&ga, len) == OK)
3423 {
3424 if (ga.ga_len > 0)
3425 STRCAT(ga.ga_data, ",");
3426 STRCAT(ga.ga_data, p);
3427 add_pathsep(ga.ga_data);
3428 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 ga.ga_len += len;
3430 }
3431 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003432 if (mustfree)
3433 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434 }
3435 if (ga.ga_data != NULL)
3436 {
3437 set_string_default("bsk", ga.ga_data);
3438 vim_free(ga.ga_data);
3439 }
3440 }
3441#endif
3442
3443 /*
3444 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3445 */
3446 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003447 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003449#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3450 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3451#endif
3452 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003454 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003455 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003456#else
3457# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003458 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003459 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003461 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462# endif
3463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003465 opt_idx = findoption((char_u *)"maxmem");
3466 if (opt_idx >= 0)
3467 {
3468#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003469 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3470 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003471#endif
3472 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3473 }
3474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475 }
3476
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477#ifdef FEAT_SEARCHPATH
3478 {
3479 char_u *cdpath;
3480 char_u *buf;
3481 int i;
3482 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003483 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484
3485 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003486 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 if (cdpath != NULL)
3488 {
3489 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3490 if (buf != NULL)
3491 {
3492 buf[0] = ','; /* start with ",", current dir first */
3493 j = 1;
3494 for (i = 0; cdpath[i] != NUL; ++i)
3495 {
3496 if (vim_ispathlistsep(cdpath[i]))
3497 buf[j++] = ',';
3498 else
3499 {
3500 if (cdpath[i] == ' ' || cdpath[i] == ',')
3501 buf[j++] = '\\';
3502 buf[j++] = cdpath[i];
3503 }
3504 }
3505 buf[j] = NUL;
3506 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003507 if (opt_idx >= 0)
3508 {
3509 options[opt_idx].def_val[VI_DEFAULT] = buf;
3510 options[opt_idx].flags |= P_DEF_ALLOCED;
3511 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003512 else
3513 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003515 if (mustfree)
3516 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003517 }
3518 }
3519#endif
3520
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003521#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003522 /* Set print encoding on platforms that don't default to latin1 */
3523 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003524# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003525 (char_u *)"cp1252"
3526# else
3527# ifdef VMS
3528 (char_u *)"dec-mcs"
3529# else
3530# ifdef EBCDIC
3531 (char_u *)"ebcdic-uk"
3532# else
3533# ifdef MAC
3534 (char_u *)"mac-roman"
3535# else /* HPUX */
3536 (char_u *)"hp-roman8"
3537# endif
3538# endif
3539# endif
3540# endif
3541 );
3542#endif
3543
3544#ifdef FEAT_POSTSCRIPT
3545 /* 'printexpr' must be allocated to be able to evaluate it. */
3546 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003547# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003548 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003549# else
3550# ifdef VMS
3551 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3552
3553# else
3554 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3555# endif
3556# endif
3557 );
3558#endif
3559
3560 /*
3561 * Set all the options (except the terminal options) to their default
3562 * value. Also set the global value for local options.
3563 */
3564 set_options_default(0);
3565
Bram Moolenaar07268702018-03-01 21:57:32 +01003566#ifdef CLEAN_RUNTIMEPATH
3567 if (clean_arg)
3568 {
3569 opt_idx = findoption((char_u *)"runtimepath");
3570 if (opt_idx >= 0)
3571 {
3572 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3573 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3574 }
3575 opt_idx = findoption((char_u *)"packpath");
3576 if (opt_idx >= 0)
3577 {
3578 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3579 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3580 }
3581 }
3582#endif
3583
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584#ifdef FEAT_GUI
3585 if (found_reverse_arg)
3586 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3587#endif
3588
3589 curbuf->b_p_initialized = TRUE;
3590 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003591 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 check_buf_options(curbuf);
3593 check_win_options(curwin);
3594 check_options();
3595
3596 /* Must be before option_expand(), because that one needs vim_isIDc() */
3597 didset_options();
3598
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003599#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003600 /* Use the current chartab for the generic chartab. This is not in
3601 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003602 init_spell_chartab();
3603#endif
3604
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 /*
3606 * Expand environment variables and things like "~" for the defaults.
3607 * If option_expand() returns non-NULL the variable is expanded. This can
3608 * only happen for non-indirect options.
3609 * Also set the default to the expanded value, so ":set" does not list
3610 * them.
3611 * Don't set the P_ALLOCED flag, because we don't want to free the
3612 * default.
3613 */
3614 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3615 {
3616 if ((options[opt_idx].flags & P_GETTEXT)
3617 && options[opt_idx].var != NULL)
3618 p = (char_u *)_(*(char **)options[opt_idx].var);
3619 else
3620 p = option_expand(opt_idx, NULL);
3621 if (p != NULL && (p = vim_strsave(p)) != NULL)
3622 {
3623 *(char_u **)options[opt_idx].var = p;
3624 /* VIMEXP
3625 * Defaults for all expanded options are currently the same for Vi
3626 * and Vim. When this changes, add some code here! Also need to
3627 * split P_DEF_ALLOCED in two.
3628 */
3629 if (options[opt_idx].flags & P_DEF_ALLOCED)
3630 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3631 options[opt_idx].def_val[VI_DEFAULT] = p;
3632 options[opt_idx].flags |= P_DEF_ALLOCED;
3633 }
3634 }
3635
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 save_file_ff(curbuf); /* Buffer is unchanged */
3637
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638#if defined(FEAT_ARABIC)
3639 /* Detect use of mlterm.
3640 * Mlterm is a terminal emulator akin to xterm that has some special
3641 * abilities (bidi namely).
3642 * NOTE: mlterm's author is being asked to 'set' a variable
3643 * instead of an environment variable due to inheritance.
3644 */
3645 if (mch_getenv((char_u *)"MLTERM") != NULL)
3646 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3647#endif
3648
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003649 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650
3651#ifdef FEAT_MBYTE
3652# if defined(WIN3264) && defined(FEAT_GETTEXT)
3653 /*
3654 * If $LANG isn't set, try to get a good value for it. This makes the
3655 * right language be used automatically. Don't do this for English.
3656 */
3657 if (mch_getenv((char_u *)"LANG") == NULL)
3658 {
3659 char buf[20];
3660
3661 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3662 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3663 * only the first two. */
3664 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3665 (LPTSTR)buf, 20);
3666 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3667 {
3668 /* There are a few exceptions (probably more) */
3669 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3670 STRCPY(buf, "zh_TW");
3671 else if (STRNICMP(buf, "chs", 3) == 0
3672 || STRNICMP(buf, "zhc", 3) == 0)
3673 STRCPY(buf, "zh_CN");
3674 else if (STRNICMP(buf, "jp", 2) == 0)
3675 STRCPY(buf, "ja");
3676 else
3677 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003678 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679 }
3680 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003681# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003682# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003683 /* Moved to os_mac_conv.c to avoid dependency problems. */
3684 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003685# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686# endif
3687
3688 /* enc_locale() will try to find the encoding of the current locale. */
3689 p = enc_locale();
3690 if (p != NULL)
3691 {
3692 char_u *save_enc;
3693
3694 /* Try setting 'encoding' and check if the value is valid.
3695 * If not, go back to the default "latin1". */
3696 save_enc = p_enc;
3697 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003698 if (STRCMP(p_enc, "gb18030") == 0)
3699 {
3700 /* We don't support "gb18030", but "cp936" is a good substitute
3701 * for practical purposes, thus use that. It's not an alias to
3702 * still support conversion between gb18030 and utf-8. */
3703 p_enc = vim_strsave((char_u *)"cp936");
3704 vim_free(p);
3705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 if (mb_init() == NULL)
3707 {
3708 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003709 if (opt_idx >= 0)
3710 {
3711 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3712 options[opt_idx].flags |= P_DEF_ALLOCED;
3713 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003714
Bram Moolenaard0573012017-10-28 21:11:06 +02003715#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003716 if (STRCMP(p_enc, "latin1") == 0
3717# ifdef FEAT_MBYTE
3718 || enc_utf8
3719# endif
3720 )
3721 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003722 /* Adjust the default for 'isprint' and 'iskeyword' to match
3723 * latin1. Also set the defaults for when 'nocompatible' is
3724 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003725 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003726 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003727 set_string_option_direct((char_u *)"isk", -1,
3728 ISK_LATIN1, OPT_FREE, SID_NONE);
3729 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003730 if (opt_idx >= 0)
3731 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003732 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003733 if (opt_idx >= 0)
3734 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003735 (void)init_chartab();
3736 }
3737#endif
3738
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739# if defined(WIN3264) && !defined(FEAT_GUI)
3740 /* Win32 console: When GetACP() returns a different value from
3741 * GetConsoleCP() set 'termencoding'. */
3742 if (GetACP() != GetConsoleCP())
3743 {
3744 char buf[50];
3745
3746 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3747 p_tenc = vim_strsave((char_u *)buf);
3748 if (p_tenc != NULL)
3749 {
3750 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003751 if (opt_idx >= 0)
3752 {
3753 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3754 options[opt_idx].flags |= P_DEF_ALLOCED;
3755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756 convert_setup(&input_conv, p_tenc, p_enc);
3757 convert_setup(&output_conv, p_enc, p_tenc);
3758 }
3759 else
3760 p_tenc = empty_option;
3761 }
3762# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003763# if defined(WIN3264) && defined(FEAT_MBYTE)
3764 /* $HOME may have characters in active code page. */
3765 init_homedir();
3766# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767 }
3768 else
3769 {
3770 vim_free(p_enc);
3771 p_enc = save_enc;
3772 }
3773 }
3774#endif
3775
3776#ifdef FEAT_MULTI_LANG
3777 /* Set the default for 'helplang'. */
3778 set_helplang_default(get_mess_lang());
3779#endif
3780}
3781
3782/*
3783 * Set an option to its default value.
3784 * This does not take care of side effects!
3785 */
3786 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003787set_option_default(
3788 int opt_idx,
3789 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3790 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791{
3792 char_u *varp; /* pointer to variable for current option */
3793 int dvi; /* index in def_val[] */
3794 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003795 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003796 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3797
3798 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3799 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003800 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 {
3802 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3803 if (flags & P_STRING)
3804 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003805 /* Use set_string_option_direct() for local options to handle
3806 * freeing and allocating the value. */
3807 if (options[opt_idx].indir != PV_NONE)
3808 set_string_option_direct(NULL, opt_idx,
3809 options[opt_idx].def_val[dvi], opt_flags, 0);
3810 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003812 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3813 free_string_option(*(char_u **)(varp));
3814 *(char_u **)varp = options[opt_idx].def_val[dvi];
3815 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 }
3817 }
3818 else if (flags & P_NUM)
3819 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003820 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 win_comp_scroll(curwin);
3822 else
3823 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003824 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 /* May also set global value for local option. */
3826 if (both)
3827 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3828 *(long *)varp;
3829 }
3830 }
3831 else /* P_BOOL */
3832 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003833 /* the cast to long is required for Manx C, long_i is needed for
3834 * MSVC */
3835 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003836#ifdef UNIX
3837 /* 'modeline' defaults to off for root */
3838 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3839 *(int *)varp = FALSE;
3840#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 /* May also set global value for local option. */
3842 if (both)
3843 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3844 *(int *)varp;
3845 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003846
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003847 /* The default value is not insecure. */
3848 flagsp = insecure_flag(opt_idx, opt_flags);
3849 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 }
3851
3852#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003853 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854#endif
3855}
3856
3857/*
3858 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003859 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860 */
3861 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003862set_options_default(
3863 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864{
3865 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003867 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868
3869 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003870 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003871#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003872 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003873 || (TRUE
3874# if defined(FEAT_MBYTE)
3875 && options[i].var != (char_u *)&p_enc
3876# endif
3877# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003878 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003879 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003880# endif
3881 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003882#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003883 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 set_option_default(i, opt_flags, p_cp);
3885
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003887 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003889#ifdef FEAT_CINDENT
3890 parse_cino(curbuf);
3891#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892}
3893
3894/*
3895 * Set the Vi-default value of a string option.
3896 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003897 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003899 static void
3900set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901{
3902 char_u *p;
3903 int opt_idx;
3904
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003905 if (escape && vim_strchr(val, ' ') != NULL)
3906 p = vim_strsave_escaped(val, (char_u *)" ");
3907 else
3908 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 if (p != NULL) /* we don't want a NULL */
3910 {
3911 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003912 if (opt_idx >= 0)
3913 {
3914 if (options[opt_idx].flags & P_DEF_ALLOCED)
3915 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3916 options[opt_idx].def_val[VI_DEFAULT] = p;
3917 options[opt_idx].flags |= P_DEF_ALLOCED;
3918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 }
3920}
3921
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003922 void
3923set_string_default(char *name, char_u *val)
3924{
3925 set_string_default_esc(name, val, FALSE);
3926}
3927
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928/*
3929 * Set the Vi-default value of a number option.
3930 * Used for 'lines' and 'columns'.
3931 */
3932 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003933set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003935 int opt_idx;
3936
3937 opt_idx = findoption((char_u *)name);
3938 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003939 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940}
3941
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003942#if defined(EXITFREE) || defined(PROTO)
3943/*
3944 * Free all options.
3945 */
3946 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003947free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003948{
3949 int i;
3950
3951 for (i = 0; !istermoption(&options[i]); i++)
3952 {
3953 if (options[i].indir == PV_NONE)
3954 {
3955 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003956 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003957 free_string_option(*(char_u **)options[i].var);
3958 if (options[i].flags & P_DEF_ALLOCED)
3959 free_string_option(options[i].def_val[VI_DEFAULT]);
3960 }
3961 else if (options[i].var != VAR_WIN
3962 && (options[i].flags & P_STRING))
3963 /* buffer-local option: free global value */
3964 free_string_option(*(char_u **)options[i].var);
3965 }
3966}
3967#endif
3968
3969
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970/*
3971 * Initialize the options, part two: After getting Rows and Columns and
3972 * setting 'term'.
3973 */
3974 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003975set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003977 int idx;
3978
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003980 * 'scroll' defaults to half the window height. The stored default is zero,
3981 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003983 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003984 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003985 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 comp_col();
3987
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003988 /*
3989 * 'window' is only for backwards compatibility with Vi.
3990 * Default is Rows - 1.
3991 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003992 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003993 p_window = Rows - 1;
3994 set_number_default("window", Rows - 1);
3995
Bram Moolenaarf740b292006-02-16 22:11:02 +00003996 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003997#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003998 /*
3999 * If 'background' wasn't set by the user, try guessing the value,
4000 * depending on the terminal name. Only need to check for terminals
4001 * with a dark background, that can handle color.
4002 */
4003 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004004 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4005 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004006 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004007 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004008 /* don't mark it as set, when starting the GUI it may be
4009 * changed again */
4010 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011 }
4012#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004013
4014#ifdef CURSOR_SHAPE
4015 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4016#endif
4017#ifdef FEAT_MOUSESHAPE
4018 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4019#endif
4020#ifdef FEAT_PRINTER
4021 (void)parse_printoptions(); /* parse 'printoptions' default value */
4022#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023}
4024
4025/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004026 * Return "dark" or "light" depending on the kind of terminal.
4027 * This is just guessing! Recognized are:
4028 * "linux" Linux console
4029 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004030 * "cygwin.*" Cygwin shell
4031 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004032 * We also check the COLORFGBG environment variable, which is set by
4033 * rxvt and derivatives. This variable contains either two or three
4034 * values separated by semicolons; we want the last value in either
4035 * case. If this value is 0-6 or 8, our background is dark.
4036 */
4037 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004038term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004039{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004040#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004041 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004042 return (char_u *)"dark";
4043#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004044 char_u *p;
4045
Bram Moolenaarf740b292006-02-16 22:11:02 +00004046 if (STRCMP(T_NAME, "linux") == 0
4047 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004048 || STRNCMP(T_NAME, "cygwin", 6) == 0
4049 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004050 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4051 && (p = vim_strrchr(p, ';')) != NULL
4052 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4053 && p[2] == NUL))
4054 return (char_u *)"dark";
4055 return (char_u *)"light";
4056#endif
4057}
4058
4059/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060 * Initialize the options, part three: After reading the .vimrc
4061 */
4062 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004063set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004065#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066/*
4067 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4068 * This is done after other initializations, where 'shell' might have been
4069 * set, but only if they have not been set before.
4070 */
4071 char_u *p;
4072 int idx_srr;
4073 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004074# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 int idx_sp;
4076 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004077# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078
4079 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004080 if (idx_srr < 0)
4081 do_srr = FALSE;
4082 else
4083 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004086 if (idx_sp < 0)
4087 do_sp = FALSE;
4088 else
4089 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004090# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004091 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 if (p != NULL)
4093 {
4094 /*
4095 * Default for p_sp is "| tee", for p_srr is ">".
4096 * For known shells it is changed here to include stderr.
4097 */
4098 if ( fnamecmp(p, "csh") == 0
4099 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004100# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 || fnamecmp(p, "csh.exe") == 0
4102 || fnamecmp(p, "tcsh.exe") == 0
4103# endif
4104 )
4105 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004106# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 if (do_sp)
4108 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004109# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004111# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004113# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4115 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004116# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 if (do_srr)
4118 {
4119 p_srr = (char_u *)">&";
4120 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4121 }
4122 }
4123 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004124 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 if ( fnamecmp(p, "sh") == 0
4126 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004127 || fnamecmp(p, "mksh") == 0
4128 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004130 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004132 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004133# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 || fnamecmp(p, "cmd") == 0
4135 || fnamecmp(p, "sh.exe") == 0
4136 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004137 || fnamecmp(p, "mksh.exe") == 0
4138 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004140 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 || fnamecmp(p, "bash.exe") == 0
4142 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004144 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004146# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 if (do_sp)
4148 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004149# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004151# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004153# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4155 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004156# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 if (do_srr)
4158 {
4159 p_srr = (char_u *)">%s 2>&1";
4160 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4161 }
4162 }
4163 vim_free(p);
4164 }
4165#endif
4166
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004167#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004168 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004169 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4170 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 * This is done after other initializations, where 'shell' might have been
4172 * set, but only if they have not been set before. Default for p_shcf is
4173 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004174 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004175 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004176 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 {
4178 int idx3;
4179
4180 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004181 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182 {
4183 p_shcf = (char_u *)"-c";
4184 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4185 }
4186
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 /* Somehow Win32 requires the quotes around the redirection too */
4188 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004189 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 {
4191 p_sxq = (char_u *)"\"";
4192 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4193 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004195 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4196 {
4197 int idx3;
4198
4199 /*
4200 * cmd.exe on Windows will strip the first and last double quote given
4201 * on the command line, e.g. most of the time things like:
4202 * cmd /c "my path/to/echo" "my args to echo"
4203 * become:
4204 * my path/to/echo" "my args to echo
4205 * when executed.
4206 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004207 * To avoid this, set shellxquote to surround the command in
4208 * parenthesis. This appears to make most commands work, without
4209 * breaking commands that worked previously, such as
4210 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004211 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004212 idx3 = findoption((char_u *)"sxq");
4213 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4214 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004215 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004216 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4217 }
4218
Bram Moolenaara64ba222012-02-12 23:23:31 +01004219 idx3 = findoption((char_u *)"shcf");
4220 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4221 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004222 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004223 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4224 }
4225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226#endif
4227
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004228 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004229 {
4230 int idx_ffs = findoption((char_u *)"ffs");
4231
4232 /* Apply the first entry of 'fileformats' to the initial buffer. */
4233 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4234 set_fileformat(default_fileformat(), OPT_LOCAL);
4235 }
4236
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237#ifdef FEAT_TITLE
4238 set_title_defaults();
4239#endif
4240}
4241
4242#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4243/*
4244 * When 'helplang' is still at its default value, set it to "lang".
4245 * Only the first two characters of "lang" are used.
4246 */
4247 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004248set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004249{
4250 int idx;
4251
4252 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4253 return;
4254 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004255 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256 {
4257 if (options[idx].flags & P_ALLOCED)
4258 free_string_option(p_hlg);
4259 p_hlg = vim_strsave(lang);
4260 if (p_hlg == NULL)
4261 p_hlg = empty_option;
4262 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004263 {
4264 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4265 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4266 {
4267 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4268 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4269 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004271 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272 options[idx].flags |= P_ALLOCED;
4273 }
4274}
4275#endif
4276
4277#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004278static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279
4280 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004281gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282{
4283 if (gui_get_lightness(gui.back_pixel) < 127)
4284 return (char_u *)"dark";
4285 return (char_u *)"light";
4286}
4287
4288/*
4289 * Option initializations that can only be done after opening the GUI window.
4290 */
4291 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004292init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004293{
4294 /* Set the 'background' option according to the lightness of the
4295 * background color, unless the user has set it already. */
4296 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4297 {
4298 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4299 highlight_changed();
4300 }
4301}
4302#endif
4303
4304#ifdef FEAT_TITLE
4305/*
4306 * 'title' and 'icon' only default to true if they have not been set or reset
4307 * in .vimrc and we can read the old value.
4308 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4309 * they can be reset. This reduces startup time when using X on a remote
4310 * machine.
4311 */
4312 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004313set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314{
4315 int idx1;
4316 long val;
4317
4318 /*
4319 * If GUI is (going to be) used, we can always set the window title and
4320 * icon name. Saves a bit of time, because the X11 display server does
4321 * not need to be contacted.
4322 */
4323 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004324 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 {
4326#ifdef FEAT_GUI
4327 if (gui.starting || gui.in_use)
4328 val = TRUE;
4329 else
4330#endif
4331 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004332 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004333 p_title = val;
4334 }
4335 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004336 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004337 {
4338#ifdef FEAT_GUI
4339 if (gui.starting || gui.in_use)
4340 val = TRUE;
4341 else
4342#endif
4343 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004344 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004345 p_icon = val;
4346 }
4347}
4348#endif
4349
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004350#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004351 static void
4352trigger_optionsset_string(
4353 int opt_idx,
4354 int opt_flags,
4355 char_u *oldval,
4356 char_u *newval)
4357{
4358 if (oldval != NULL && newval != NULL)
4359 {
4360 char_u buf_type[7];
4361
4362 sprintf((char *)buf_type, "%s",
4363 (opt_flags & OPT_LOCAL) ? "local" : "global");
4364 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4365 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4366 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4367 apply_autocmds(EVENT_OPTIONSET,
4368 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4369 reset_v_option_vars();
4370 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004371}
4372#endif
4373
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374/*
4375 * Parse 'arg' for option settings.
4376 *
4377 * 'arg' may be IObuff, but only when no errors can be present and option
4378 * does not need to be expanded with option_expand().
4379 * "opt_flags":
4380 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004381 * OPT_GLOBAL for ":setglobal"
4382 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004384 * OPT_WINONLY to only set window-local options
4385 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004386 *
4387 * returns FAIL if an error is detected, OK otherwise
4388 */
4389 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004390do_set(
4391 char_u *arg, /* option string (may be written to!) */
4392 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004393{
4394 int opt_idx;
4395 char_u *errmsg;
4396 char_u errbuf[80];
4397 char_u *startarg;
4398 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4399 int nextchar; /* next non-white char after option name */
4400 int afterchar; /* character just after option name */
4401 int len;
4402 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004403 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 int key;
4405 long_u flags; /* flags for current option */
4406 char_u *varp = NULL; /* pointer to variable for current option */
4407 int did_show = FALSE; /* already showed one value */
4408 int adding; /* "opt+=arg" */
4409 int prepending; /* "opt^=arg" */
4410 int removing; /* "opt-=arg" */
4411 int cp_val = 0;
4412 char_u key_name[2];
4413
4414 if (*arg == NUL)
4415 {
4416 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004417 did_show = TRUE;
4418 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004419 }
4420
4421 while (*arg != NUL) /* loop to process all options */
4422 {
4423 errmsg = NULL;
4424 startarg = arg; /* remember for error message */
4425
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004426 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4427 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004428 {
4429 /*
4430 * ":set all" show all options.
4431 * ":set all&" set all options to their default value.
4432 */
4433 arg += 3;
4434 if (*arg == '&')
4435 {
4436 ++arg;
4437 /* Only for :set command set global value of local options. */
4438 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004439 didset_options();
4440 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004441 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004442 }
4443 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004444 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004446 did_show = TRUE;
4447 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004448 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004449 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 {
4451 showoptions(2, opt_flags);
4452 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004453 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004454 arg += 7;
4455 }
4456 else
4457 {
4458 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004459 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004460 {
4461 prefix = 0;
4462 arg += 2;
4463 }
4464 else if (STRNCMP(arg, "inv", 3) == 0)
4465 {
4466 prefix = 2;
4467 arg += 3;
4468 }
4469
4470 /* find end of name */
4471 key = 0;
4472 if (*arg == '<')
4473 {
4474 nextchar = 0;
4475 opt_idx = -1;
4476 /* look out for <t_>;> */
4477 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4478 len = 5;
4479 else
4480 {
4481 len = 1;
4482 while (arg[len] != NUL && arg[len] != '>')
4483 ++len;
4484 }
4485 if (arg[len] != '>')
4486 {
4487 errmsg = e_invarg;
4488 goto skip;
4489 }
4490 arg[len] = NUL; /* put NUL after name */
4491 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4492 opt_idx = findoption(arg + 1);
4493 arg[len++] = '>'; /* restore '>' */
4494 if (opt_idx == -1)
4495 key = find_key_option(arg + 1);
4496 }
4497 else
4498 {
4499 len = 0;
4500 /*
4501 * The two characters after "t_" may not be alphanumeric.
4502 */
4503 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4504 len = 4;
4505 else
4506 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4507 ++len;
4508 nextchar = arg[len];
4509 arg[len] = NUL; /* put NUL after name */
4510 opt_idx = findoption(arg);
4511 arg[len] = nextchar; /* restore nextchar */
4512 if (opt_idx == -1)
4513 key = find_key_option(arg);
4514 }
4515
4516 /* remember character after option name */
4517 afterchar = arg[len];
4518
4519 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004520 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004521 ++len;
4522
4523 adding = FALSE;
4524 prepending = FALSE;
4525 removing = FALSE;
4526 if (arg[len] != NUL && arg[len + 1] == '=')
4527 {
4528 if (arg[len] == '+')
4529 {
4530 adding = TRUE; /* "+=" */
4531 ++len;
4532 }
4533 else if (arg[len] == '^')
4534 {
4535 prepending = TRUE; /* "^=" */
4536 ++len;
4537 }
4538 else if (arg[len] == '-')
4539 {
4540 removing = TRUE; /* "-=" */
4541 ++len;
4542 }
4543 }
4544 nextchar = arg[len];
4545
4546 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4547 {
4548 errmsg = (char_u *)N_("E518: Unknown option");
4549 goto skip;
4550 }
4551
4552 if (opt_idx >= 0)
4553 {
4554 if (options[opt_idx].var == NULL) /* hidden option: skip */
4555 {
4556 /* Only give an error message when requesting the value of
4557 * a hidden option, ignore setting it. */
4558 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4559 && (!(options[opt_idx].flags & P_BOOL)
4560 || nextchar == '?'))
4561 errmsg = (char_u *)N_("E519: Option not supported");
4562 goto skip;
4563 }
4564
4565 flags = options[opt_idx].flags;
4566 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4567 }
4568 else
4569 {
4570 flags = P_STRING;
4571 if (key < 0)
4572 {
4573 key_name[0] = KEY2TERMCAP0(key);
4574 key_name[1] = KEY2TERMCAP1(key);
4575 }
4576 else
4577 {
4578 key_name[0] = KS_KEY;
4579 key_name[1] = (key & 0xff);
4580 }
4581 }
4582
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004583 /* Skip all options that are not window-local (used when showing
4584 * an already loaded buffer in a window). */
4585 if ((opt_flags & OPT_WINONLY)
4586 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4587 goto skip;
4588
Bram Moolenaara3227e22006-03-08 21:32:40 +00004589 /* Skip all options that are window-local (used for :vimgrep). */
4590 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4591 && options[opt_idx].var == VAR_WIN)
4592 goto skip;
4593
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004594 /* Disallow changing some options from modelines. */
4595 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004596 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004597 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004598 {
4599 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4600 goto skip;
4601 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004602#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004603 /* In diff mode some options are overruled. This avoids that
4604 * 'foldmethod' becomes "marker" instead of "diff" and that
4605 * "wrap" gets set. */
4606 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004607 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004608 && (
4609#ifdef FEAT_FOLDING
4610 options[opt_idx].indir == PV_FDM ||
4611#endif
4612 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004613 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 }
4616
4617#ifdef HAVE_SANDBOX
4618 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004619 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004620 {
4621 errmsg = (char_u *)_(e_sandbox);
4622 goto skip;
4623 }
4624#endif
4625
4626 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4627 {
4628 arg += len;
4629 cp_val = p_cp;
4630 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4631 {
4632 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4633 {
4634 cp_val = FALSE;
4635 arg += 3;
4636 }
4637 else /* "opt&vi": set to Vi default */
4638 {
4639 cp_val = TRUE;
4640 arg += 2;
4641 }
4642 }
4643 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004644 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004645 {
4646 errmsg = e_trailing;
4647 goto skip;
4648 }
4649 }
4650
4651 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004652 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4653 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004654 */
4655 if (nextchar == '?'
4656 || (prefix == 1
4657 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4658 && !(flags & P_BOOL)))
4659 {
4660 /*
4661 * print value
4662 */
4663 if (did_show)
4664 msg_putchar('\n'); /* cursor below last one */
4665 else
4666 {
4667 gotocmdline(TRUE); /* cursor at status line */
4668 did_show = TRUE; /* remember that we did a line */
4669 }
4670 if (opt_idx >= 0)
4671 {
4672 showoneopt(&options[opt_idx], opt_flags);
4673#ifdef FEAT_EVAL
4674 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004675 {
4676 /* Mention where the option was last set. */
4677 if (varp == options[opt_idx].var)
4678 last_set_msg(options[opt_idx].scriptID);
4679 else if ((int)options[opt_idx].indir & PV_WIN)
4680 last_set_msg(curwin->w_p_scriptID[
4681 (int)options[opt_idx].indir & PV_MASK]);
4682 else if ((int)options[opt_idx].indir & PV_BUF)
4683 last_set_msg(curbuf->b_p_scriptID[
4684 (int)options[opt_idx].indir & PV_MASK]);
4685 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004686#endif
4687 }
4688 else
4689 {
4690 char_u *p;
4691
4692 p = find_termcode(key_name);
4693 if (p == NULL)
4694 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004695 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004696 goto skip;
4697 }
4698 else
4699 (void)show_one_termcode(key_name, p, TRUE);
4700 }
4701 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004702 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004703 errmsg = e_trailing;
4704 }
4705 else
4706 {
4707 if (flags & P_BOOL) /* boolean */
4708 {
4709 if (nextchar == '=' || nextchar == ':')
4710 {
4711 errmsg = e_invarg;
4712 goto skip;
4713 }
4714
4715 /*
4716 * ":set opt!": invert
4717 * ":set opt&": reset to default value
4718 * ":set opt<": reset to global value
4719 */
4720 if (nextchar == '!')
4721 value = *(int *)(varp) ^ 1;
4722 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004723 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724 ((flags & P_VI_DEF) || cp_val)
4725 ? VI_DEFAULT : VIM_DEFAULT];
4726 else if (nextchar == '<')
4727 {
4728 /* For 'autoread' -1 means to use global value. */
4729 if ((int *)varp == &curbuf->b_p_ar
4730 && opt_flags == OPT_LOCAL)
4731 value = -1;
4732 else
4733 value = *(int *)get_varp_scope(&(options[opt_idx]),
4734 OPT_GLOBAL);
4735 }
4736 else
4737 {
4738 /*
4739 * ":set invopt": invert
4740 * ":set opt" or ":set noopt": set or reset
4741 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004742 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004743 {
4744 errmsg = e_trailing;
4745 goto skip;
4746 }
4747 if (prefix == 2) /* inv */
4748 value = *(int *)(varp) ^ 1;
4749 else
4750 value = prefix;
4751 }
4752
4753 errmsg = set_bool_option(opt_idx, varp, (int)value,
4754 opt_flags);
4755 }
4756 else /* numeric or string */
4757 {
4758 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4759 || prefix != 1)
4760 {
4761 errmsg = e_invarg;
4762 goto skip;
4763 }
4764
4765 if (flags & P_NUM) /* numeric */
4766 {
4767 /*
4768 * Different ways to set a number option:
4769 * & set to default value
4770 * < set to global value
4771 * <xx> accept special key codes for 'wildchar'
4772 * c accept any non-digit for 'wildchar'
4773 * [-]0-9 set number
4774 * other error
4775 */
4776 ++arg;
4777 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004778 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004779 ((flags & P_VI_DEF) || cp_val)
4780 ? VI_DEFAULT : VIM_DEFAULT];
4781 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004782 {
4783 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4784 * use the global value. */
4785 if ((long *)varp == &curbuf->b_p_ul
4786 && opt_flags == OPT_LOCAL)
4787 value = NO_LOCAL_UNDOLEVEL;
4788 else
4789 value = *(long *)get_varp_scope(
4790 &(options[opt_idx]), OPT_GLOBAL);
4791 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004792 else if (((long *)varp == &p_wc
4793 || (long *)varp == &p_wcm)
4794 && (*arg == '<'
4795 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004796 || (*arg != NUL
4797 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 && !VIM_ISDIGIT(*arg))))
4799 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004800 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004801 if (value == 0 && (long *)varp != &p_wcm)
4802 {
4803 errmsg = e_invarg;
4804 goto skip;
4805 }
4806 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4808 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004809 /* Allow negative (for 'undolevels'), octal and
4810 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004811 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4812 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004813 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004814 {
4815 errmsg = e_invarg;
4816 goto skip;
4817 }
4818 }
4819 else
4820 {
4821 errmsg = (char_u *)N_("E521: Number required after =");
4822 goto skip;
4823 }
4824
4825 if (adding)
4826 value = *(long *)varp + value;
4827 if (prepending)
4828 value = *(long *)varp * value;
4829 if (removing)
4830 value = *(long *)varp - value;
4831 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004832 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004833 }
4834 else if (opt_idx >= 0) /* string */
4835 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004836 char_u *save_arg = NULL;
4837 char_u *s = NULL;
4838 char_u *oldval = NULL; /* previous value if *varp */
4839 char_u *newval;
4840 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004841#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004842 char_u *saved_origval = NULL;
4843 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004844#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004845 unsigned newlen;
4846 int comma;
4847 int bs;
4848 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004849 was allocated */
4850
4851 /* When using ":set opt=val" for a global option
4852 * with a local value the local value will be
4853 * reset, use the global value here. */
4854 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004855 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004856 varp = options[opt_idx].var;
4857
4858 /* The old value is kept until we are sure that the
4859 * new value is valid. */
4860 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004861
4862 /* When setting the local value of a global
4863 * option, the old value may be the global value. */
4864 if (((int)options[opt_idx].indir & PV_BOTH)
4865 && (opt_flags & OPT_LOCAL))
4866 origval = *(char_u **)get_varp(
4867 &options[opt_idx]);
4868 else
4869 origval = oldval;
4870
Bram Moolenaar071d4272004-06-13 20:20:40 +00004871 if (nextchar == '&') /* set to default val */
4872 {
4873 newval = options[opt_idx].def_val[
4874 ((flags & P_VI_DEF) || cp_val)
4875 ? VI_DEFAULT : VIM_DEFAULT];
4876 if ((char_u **)varp == &p_bg)
4877 {
4878 /* guess the value of 'background' */
4879#ifdef FEAT_GUI
4880 if (gui.in_use)
4881 newval = gui_bg_default();
4882 else
4883#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004884 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004885 }
4886
4887 /* expand environment variables and ~ (since the
4888 * default value was already expanded, only
4889 * required when an environment variable was set
4890 * later */
4891 if (newval == NULL)
4892 newval = empty_option;
4893 else
4894 {
4895 s = option_expand(opt_idx, newval);
4896 if (s == NULL)
4897 s = newval;
4898 newval = vim_strsave(s);
4899 }
4900 new_value_alloced = TRUE;
4901 }
4902 else if (nextchar == '<') /* set to global val */
4903 {
4904 newval = vim_strsave(*(char_u **)get_varp_scope(
4905 &(options[opt_idx]), OPT_GLOBAL));
4906 new_value_alloced = TRUE;
4907 }
4908 else
4909 {
4910 ++arg; /* jump to after the '=' or ':' */
4911
4912 /*
4913 * Set 'keywordprg' to ":help" if an empty
4914 * value was passed to :set by the user.
4915 * Misuse errbuf[] for the resulting string.
4916 */
4917 if (varp == (char_u *)&p_kp
4918 && (*arg == NUL || *arg == ' '))
4919 {
4920 STRCPY(errbuf, ":help");
4921 save_arg = arg;
4922 arg = errbuf;
4923 }
4924 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004925 * Convert 'backspace' number to string, for
4926 * adding, prepending and removing string.
4927 */
4928 else if (varp == (char_u *)&p_bs
4929 && VIM_ISDIGIT(**(char_u **)varp))
4930 {
4931 i = getdigits((char_u **)varp);
4932 switch (i)
4933 {
4934 case 0:
4935 *(char_u **)varp = empty_option;
4936 break;
4937 case 1:
4938 *(char_u **)varp = vim_strsave(
4939 (char_u *)"indent,eol");
4940 break;
4941 case 2:
4942 *(char_u **)varp = vim_strsave(
4943 (char_u *)"indent,eol,start");
4944 break;
4945 }
4946 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004947 if (origval == oldval)
4948 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004949 oldval = *(char_u **)varp;
4950 }
4951 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004952 * Convert 'whichwrap' number to string, for
4953 * backwards compatibility with Vim 3.0.
4954 * Misuse errbuf[] for the resulting string.
4955 */
4956 else if (varp == (char_u *)&p_ww
4957 && VIM_ISDIGIT(*arg))
4958 {
4959 *errbuf = NUL;
4960 i = getdigits(&arg);
4961 if (i & 1)
4962 STRCAT(errbuf, "b,");
4963 if (i & 2)
4964 STRCAT(errbuf, "s,");
4965 if (i & 4)
4966 STRCAT(errbuf, "h,l,");
4967 if (i & 8)
4968 STRCAT(errbuf, "<,>,");
4969 if (i & 16)
4970 STRCAT(errbuf, "[,],");
4971 if (*errbuf != NUL) /* remove trailing , */
4972 errbuf[STRLEN(errbuf) - 1] = NUL;
4973 save_arg = arg;
4974 arg = errbuf;
4975 }
4976 /*
4977 * Remove '>' before 'dir' and 'bdir', for
4978 * backwards compatibility with version 3.0
4979 */
4980 else if ( *arg == '>'
4981 && (varp == (char_u *)&p_dir
4982 || varp == (char_u *)&p_bdir))
4983 {
4984 ++arg;
4985 }
4986
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 /*
4988 * Copy the new string into allocated memory.
4989 * Can't use set_string_option_direct(), because
4990 * we need to remove the backslashes.
4991 */
4992 /* get a bit too much */
4993 newlen = (unsigned)STRLEN(arg) + 1;
4994 if (adding || prepending || removing)
4995 newlen += (unsigned)STRLEN(origval) + 1;
4996 newval = alloc(newlen);
4997 if (newval == NULL) /* out of mem, don't change */
4998 break;
4999 s = newval;
5000
5001 /*
5002 * Copy the string, skip over escaped chars.
5003 * For MS-DOS and WIN32 backslashes before normal
5004 * file name characters are not removed, and keep
5005 * backslash at start, for "\\machine\path", but
5006 * do remove it for "\\\\machine\\path".
5007 * The reverse is found in ExpandOldSetting().
5008 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005009 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005010 {
5011 if (*arg == '\\' && arg[1] != NUL
5012#ifdef BACKSLASH_IN_FILENAME
5013 && !((flags & P_EXPAND)
5014 && vim_isfilec(arg[1])
5015 && (arg[1] != '\\'
5016 || (s == newval
5017 && arg[2] != '\\')))
5018#endif
5019 )
5020 ++arg; /* remove backslash */
5021#ifdef FEAT_MBYTE
5022 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005023 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005024 {
5025 /* copy multibyte char */
5026 mch_memmove(s, arg, (size_t)i);
5027 arg += i;
5028 s += i;
5029 }
5030 else
5031#endif
5032 *s++ = *arg++;
5033 }
5034 *s = NUL;
5035
5036 /*
5037 * Expand environment variables and ~.
5038 * Don't do it when adding without inserting a
5039 * comma.
5040 */
5041 if (!(adding || prepending || removing)
5042 || (flags & P_COMMA))
5043 {
5044 s = option_expand(opt_idx, newval);
5045 if (s != NULL)
5046 {
5047 vim_free(newval);
5048 newlen = (unsigned)STRLEN(s) + 1;
5049 if (adding || prepending || removing)
5050 newlen += (unsigned)STRLEN(origval) + 1;
5051 newval = alloc(newlen);
5052 if (newval == NULL)
5053 break;
5054 STRCPY(newval, s);
5055 }
5056 }
5057
5058 /* locate newval[] in origval[] when removing it
5059 * and when adding to avoid duplicates */
5060 i = 0; /* init for GCC */
5061 if (removing || (flags & P_NODUP))
5062 {
5063 i = (int)STRLEN(newval);
5064 bs = 0;
5065 for (s = origval; *s; ++s)
5066 {
5067 if ((!(flags & P_COMMA)
5068 || s == origval
5069 || (s[-1] == ',' && !(bs & 1)))
5070 && STRNCMP(s, newval, i) == 0
5071 && (!(flags & P_COMMA)
5072 || s[i] == ','
5073 || s[i] == NUL))
5074 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005075 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005076 * even number of backslashes or a single
5077 * backslash preceded by a comma before it
5078 * is recognized as a separator */
5079 if ((s > origval + 1
5080 && s[-1] == '\\'
5081 && s[-2] != ',')
5082 || (s == origval + 1
5083 && s[-1] == '\\'))
5084
Bram Moolenaar071d4272004-06-13 20:20:40 +00005085 ++bs;
5086 else
5087 bs = 0;
5088 }
5089
5090 /* do not add if already there */
5091 if ((adding || prepending) && *s)
5092 {
5093 prepending = FALSE;
5094 adding = FALSE;
5095 STRCPY(newval, origval);
5096 }
5097 }
5098
5099 /* concatenate the two strings; add a ',' if
5100 * needed */
5101 if (adding || prepending)
5102 {
5103 comma = ((flags & P_COMMA) && *origval != NUL
5104 && *newval != NUL);
5105 if (adding)
5106 {
5107 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005108 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005109 if (comma && i > 1
5110 && (flags & P_ONECOMMA) == P_ONECOMMA
5111 && origval[i - 1] == ','
5112 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005113 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005114 mch_memmove(newval + i + comma, newval,
5115 STRLEN(newval) + 1);
5116 mch_memmove(newval, origval, (size_t)i);
5117 }
5118 else
5119 {
5120 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005121 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122 }
5123 if (comma)
5124 newval[i] = ',';
5125 }
5126
5127 /* Remove newval[] from origval[]. (Note: "i" has
5128 * been set above and is used here). */
5129 if (removing)
5130 {
5131 STRCPY(newval, origval);
5132 if (*s)
5133 {
5134 /* may need to remove a comma */
5135 if (flags & P_COMMA)
5136 {
5137 if (s == origval)
5138 {
5139 /* include comma after string */
5140 if (s[i] == ',')
5141 ++i;
5142 }
5143 else
5144 {
5145 /* include comma before string */
5146 --s;
5147 ++i;
5148 }
5149 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005150 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005151 }
5152 }
5153
5154 if (flags & P_FLAGLIST)
5155 {
5156 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005157 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005158 {
5159 /* if options have P_FLAGLIST and
5160 * P_ONECOMMA such as 'whichwrap' */
5161 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005162 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005163 if (*s != ',' && *(s + 1) == ','
5164 && vim_strchr(s + 2, *s) != NULL)
5165 {
5166 /* Remove the duplicated value and
5167 * the next comma. */
5168 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005169 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005171 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005172 else
5173 {
5174 if ((!(flags & P_COMMA) || *s != ',')
5175 && vim_strchr(s + 1, *s) != NULL)
5176 {
5177 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005178 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005179 }
5180 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005181 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005183 }
5184
5185 if (save_arg != NULL) /* number for 'whichwrap' */
5186 arg = save_arg;
5187 new_value_alloced = TRUE;
5188 }
5189
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005190 /*
5191 * Set the new value.
5192 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005193 *(char_u **)(varp) = newval;
5194
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005195#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005196 if (!starting
5197# ifdef FEAT_CRYPT
5198 && options[opt_idx].indir != PV_KEY
5199# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005200 && origval != NULL && newval != NULL)
5201 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005202 /* origval may be freed by
5203 * did_set_string_option(), make a copy. */
5204 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005205 /* newval (and varp) may become invalid if the
5206 * buffer is closed by autocommands. */
5207 saved_newval = vim_strsave(newval);
5208 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005209#endif
5210
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005212 * ":set" on local options. Note: when setting 'syntax'
5213 * or 'filetype' autocommands may be triggered that can
5214 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005215 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5216 new_value_alloced, oldval, errbuf, opt_flags);
5217
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005218#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005219 if (errmsg == NULL)
5220 trigger_optionsset_string(opt_idx, opt_flags,
5221 saved_origval, saved_newval);
5222 vim_free(saved_origval);
5223 vim_free(saved_newval);
5224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225 /* If error detected, print the error message. */
5226 if (errmsg != NULL)
5227 goto skip;
5228 }
5229 else /* key code option */
5230 {
5231 char_u *p;
5232
5233 if (nextchar == '&')
5234 {
5235 if (add_termcap_entry(key_name, TRUE) == FAIL)
5236 errmsg = (char_u *)N_("E522: Not found in termcap");
5237 }
5238 else
5239 {
5240 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005241 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 if (*p == '\\' && p[1] != NUL)
5243 ++p;
5244 nextchar = *p;
5245 *p = NUL;
5246 add_termcode(key_name, arg, FALSE);
5247 *p = nextchar;
5248 }
5249 if (full_screen)
5250 ttest(FALSE);
5251 redraw_all_later(CLEAR);
5252 }
5253 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005254
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005256 did_set_option(opt_idx, opt_flags,
5257 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005258 }
5259
5260skip:
5261 /*
5262 * Advance to next argument.
5263 * - skip until a blank found, taking care of backslashes
5264 * - skip blanks
5265 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5266 */
5267 for (i = 0; i < 2 ; ++i)
5268 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005269 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005270 if (*arg++ == '\\' && *arg != NUL)
5271 ++arg;
5272 arg = skipwhite(arg);
5273 if (*arg != '=')
5274 break;
5275 }
5276 }
5277
5278 if (errmsg != NULL)
5279 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005280 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005281 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005282 if (i + (arg - startarg) < IOSIZE)
5283 {
5284 /* append the argument with the error */
5285 STRCAT(IObuff, ": ");
5286 mch_memmove(IObuff + i, startarg, (arg - startarg));
5287 IObuff[i + (arg - startarg)] = NUL;
5288 }
5289 /* make sure all characters are printable */
5290 trans_characters(IObuff, IOSIZE);
5291
5292 ++no_wait_return; /* wait_return done later */
5293 emsg(IObuff); /* show error highlighted */
5294 --no_wait_return;
5295
5296 return FAIL;
5297 }
5298
5299 arg = skipwhite(arg);
5300 }
5301
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005302theend:
5303 if (silent_mode && did_show)
5304 {
5305 /* After displaying option values in silent mode. */
5306 silent_mode = FALSE;
5307 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5308 msg_putchar('\n');
5309 cursor_on(); /* msg_start() switches it off */
5310 out_flush();
5311 silent_mode = TRUE;
5312 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5313 }
5314
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315 return OK;
5316}
5317
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005318/*
5319 * Call this when an option has been given a new value through a user command.
5320 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5321 */
5322 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005323did_set_option(
5324 int opt_idx,
5325 int opt_flags, /* possibly with OPT_MODELINE */
5326 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005327{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005328 long_u *p;
5329
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005330 options[opt_idx].flags |= P_WAS_SET;
5331
5332 /* When an option is set in the sandbox, from a modeline or in secure mode
5333 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005334 * flag. */
5335 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005336 if (secure
5337#ifdef HAVE_SANDBOX
5338 || sandbox != 0
5339#endif
5340 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005341 *p = *p | P_INSECURE;
5342 else if (new_value)
5343 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005344}
5345
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005347illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348{
5349 if (errbuf == NULL)
5350 return (char_u *)"";
5351 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005352 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353 return errbuf;
5354}
5355
5356/*
5357 * Convert a key name or string into a key value.
5358 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005359 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005361 int
5362string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363{
5364 if (*arg == '<')
5365 return find_key_option(arg + 1);
5366 if (*arg == '^')
5367 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005368 if (multi_byte)
5369 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005370 return *arg;
5371}
5372
5373#ifdef FEAT_CMDWIN
5374/*
5375 * Check value of 'cedit' and set cedit_key.
5376 * Returns NULL if value is OK, error message otherwise.
5377 */
5378 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005379check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005380{
5381 int n;
5382
5383 if (*p_cedit == NUL)
5384 cedit_key = -1;
5385 else
5386 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005387 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005388 if (vim_isprintc(n))
5389 return e_invarg;
5390 cedit_key = n;
5391 }
5392 return NULL;
5393}
5394#endif
5395
5396#ifdef FEAT_TITLE
5397/*
5398 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5399 * maketitle() to create and display it.
5400 * When switching the title or icon off, call mch_restore_title() to get
5401 * the old value back.
5402 */
5403 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005404did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005405{
5406 if (starting != NO_SCREEN
5407#ifdef FEAT_GUI
5408 && !gui.starting
5409#endif
5410 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005411 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005412}
5413#endif
5414
5415/*
5416 * set_options_bin - called when 'bin' changes value.
5417 */
5418 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005419set_options_bin(
5420 int oldval,
5421 int newval,
5422 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005423{
5424 /*
5425 * The option values that are changed when 'bin' changes are
5426 * copied when 'bin is set and restored when 'bin' is reset.
5427 */
5428 if (newval)
5429 {
5430 if (!oldval) /* switched on */
5431 {
5432 if (!(opt_flags & OPT_GLOBAL))
5433 {
5434 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5435 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5436 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5437 curbuf->b_p_et_nobin = curbuf->b_p_et;
5438 }
5439 if (!(opt_flags & OPT_LOCAL))
5440 {
5441 p_tw_nobin = p_tw;
5442 p_wm_nobin = p_wm;
5443 p_ml_nobin = p_ml;
5444 p_et_nobin = p_et;
5445 }
5446 }
5447
5448 if (!(opt_flags & OPT_GLOBAL))
5449 {
5450 curbuf->b_p_tw = 0; /* no automatic line wrap */
5451 curbuf->b_p_wm = 0; /* no automatic line wrap */
5452 curbuf->b_p_ml = 0; /* no modelines */
5453 curbuf->b_p_et = 0; /* no expandtab */
5454 }
5455 if (!(opt_flags & OPT_LOCAL))
5456 {
5457 p_tw = 0;
5458 p_wm = 0;
5459 p_ml = FALSE;
5460 p_et = FALSE;
5461 p_bin = TRUE; /* needed when called for the "-b" argument */
5462 }
5463 }
5464 else if (oldval) /* switched off */
5465 {
5466 if (!(opt_flags & OPT_GLOBAL))
5467 {
5468 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5469 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5470 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5471 curbuf->b_p_et = curbuf->b_p_et_nobin;
5472 }
5473 if (!(opt_flags & OPT_LOCAL))
5474 {
5475 p_tw = p_tw_nobin;
5476 p_wm = p_wm_nobin;
5477 p_ml = p_ml_nobin;
5478 p_et = p_et_nobin;
5479 }
5480 }
5481}
5482
5483#ifdef FEAT_VIMINFO
5484/*
5485 * Find the parameter represented by the given character (eg ', :, ", or /),
5486 * and return its associated value in the 'viminfo' string.
5487 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005488 * If the parameter is not specified in the string or there is no following
5489 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005490 */
5491 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005492get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005493{
5494 char_u *p;
5495
5496 p = find_viminfo_parameter(type);
5497 if (p != NULL && VIM_ISDIGIT(*p))
5498 return atoi((char *)p);
5499 return -1;
5500}
5501
5502/*
5503 * Find the parameter represented by the given character (eg ''', ':', '"', or
5504 * '/') in the 'viminfo' option and return a pointer to the string after it.
5505 * Return NULL if the parameter is not specified in the string.
5506 */
5507 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005508find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509{
5510 char_u *p;
5511
5512 for (p = p_viminfo; *p; ++p)
5513 {
5514 if (*p == type)
5515 return p + 1;
5516 if (*p == 'n') /* 'n' is always the last one */
5517 break;
5518 p = vim_strchr(p, ','); /* skip until next ',' */
5519 if (p == NULL) /* hit the end without finding parameter */
5520 break;
5521 }
5522 return NULL;
5523}
5524#endif
5525
5526/*
5527 * Expand environment variables for some string options.
5528 * These string options cannot be indirect!
5529 * If "val" is NULL expand the current value of the option.
5530 * Return pointer to NameBuff, or NULL when not expanded.
5531 */
5532 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005533option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005534{
5535 /* if option doesn't need expansion nothing to do */
5536 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5537 return NULL;
5538
5539 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5540 * expand_env() would truncate the string. */
5541 if (val != NULL && STRLEN(val) > MAXPATHL)
5542 return NULL;
5543
5544 if (val == NULL)
5545 val = *(char_u **)options[opt_idx].var;
5546
5547 /*
5548 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5549 * Escape spaces when expanding 'tags', they are used to separate file
5550 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005551 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552 */
5553 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005554 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005555#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005556 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5557#endif
5558 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5560 return NULL;
5561
5562 return NameBuff;
5563}
5564
5565/*
5566 * After setting various option values: recompute variables that depend on
5567 * option values.
5568 */
5569 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005570didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571{
5572 /* initialize the table for 'iskeyword' et.al. */
5573 (void)init_chartab();
5574
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005575#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005576 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005579 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005580#ifdef FEAT_SESSION
5581 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5582 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5583#endif
5584#ifdef FEAT_FOLDING
5585 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5586#endif
5587 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005588 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589#ifdef FEAT_VIRTUALEDIT
5590 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5591#endif
5592#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5593 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5594#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005595#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005596 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005597 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005598 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005599 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005600#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005601#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5602 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5603#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005604#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5606#endif
5607#ifdef FEAT_CMDWIN
5608 /* set cedit_key */
5609 (void)check_cedit();
5610#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005611#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005612 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005613#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005614#ifdef FEAT_LINEBREAK
5615 /* initialize the table for 'breakat'. */
5616 fill_breakat_flags();
5617#endif
5618
5619}
5620
5621/*
5622 * More side effects of setting options.
5623 */
5624 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005625didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005626{
5627 /* Initialize the highlight_attr[] table. */
5628 (void)highlight_changed();
5629
5630 /* Parse default for 'wildmode' */
5631 check_opt_wim();
5632
5633 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005634 /* Parse default for 'fillchars'. */
5635 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005636
5637#ifdef FEAT_CLIPBOARD
5638 /* Parse default for 'clipboard' */
5639 (void)check_clipboard_option();
5640#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005641#ifdef FEAT_VARTABS
5642 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5643 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645}
5646
5647/*
5648 * Check for string options that are NULL (normally only termcap options).
5649 */
5650 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005651check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652{
5653 int opt_idx;
5654
5655 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5656 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5657 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5658}
5659
5660/*
5661 * Check string options in a buffer for NULL value.
5662 */
5663 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005664check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666 check_string_option(&buf->b_p_bh);
5667 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668#ifdef FEAT_MBYTE
5669 check_string_option(&buf->b_p_fenc);
5670#endif
5671 check_string_option(&buf->b_p_ff);
5672#ifdef FEAT_FIND_ID
5673 check_string_option(&buf->b_p_def);
5674 check_string_option(&buf->b_p_inc);
5675# ifdef FEAT_EVAL
5676 check_string_option(&buf->b_p_inex);
5677# endif
5678#endif
5679#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5680 check_string_option(&buf->b_p_inde);
5681 check_string_option(&buf->b_p_indk);
5682#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005683#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5684 check_string_option(&buf->b_p_bexpr);
5685#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005686#if defined(FEAT_CRYPT)
5687 check_string_option(&buf->b_p_cm);
5688#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005689 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005690#if defined(FEAT_EVAL)
5691 check_string_option(&buf->b_p_fex);
5692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693#ifdef FEAT_CRYPT
5694 check_string_option(&buf->b_p_key);
5695#endif
5696 check_string_option(&buf->b_p_kp);
5697 check_string_option(&buf->b_p_mps);
5698 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005699 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700 check_string_option(&buf->b_p_isk);
5701#ifdef FEAT_COMMENTS
5702 check_string_option(&buf->b_p_com);
5703#endif
5704#ifdef FEAT_FOLDING
5705 check_string_option(&buf->b_p_cms);
5706#endif
5707 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005708#ifdef FEAT_TEXTOBJ
5709 check_string_option(&buf->b_p_qe);
5710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711#ifdef FEAT_SYN_HL
5712 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005713 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005714#endif
5715#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005716 check_string_option(&buf->b_s.b_p_spc);
5717 check_string_option(&buf->b_s.b_p_spf);
5718 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719#endif
5720#ifdef FEAT_SEARCHPATH
5721 check_string_option(&buf->b_p_sua);
5722#endif
5723#ifdef FEAT_CINDENT
5724 check_string_option(&buf->b_p_cink);
5725 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005726 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5730 check_string_option(&buf->b_p_cinw);
5731#endif
5732#ifdef FEAT_INS_EXPAND
5733 check_string_option(&buf->b_p_cpt);
5734#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005735#ifdef FEAT_COMPL_FUNC
5736 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005737 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739#ifdef FEAT_KEYMAP
5740 check_string_option(&buf->b_p_keymap);
5741#endif
5742#ifdef FEAT_QUICKFIX
5743 check_string_option(&buf->b_p_gp);
5744 check_string_option(&buf->b_p_mp);
5745 check_string_option(&buf->b_p_efm);
5746#endif
5747 check_string_option(&buf->b_p_ep);
5748 check_string_option(&buf->b_p_path);
5749 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005750 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751#ifdef FEAT_INS_EXPAND
5752 check_string_option(&buf->b_p_dict);
5753 check_string_option(&buf->b_p_tsr);
5754#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005755#ifdef FEAT_LISP
5756 check_string_option(&buf->b_p_lw);
5757#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005758 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005759#ifdef FEAT_MBYTE
5760 check_string_option(&buf->b_p_menc);
5761#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005762#ifdef FEAT_VARTABS
5763 check_string_option(&buf->b_p_vsts);
5764 check_string_option(&buf->b_p_vts);
5765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005766}
5767
5768/*
5769 * Free the string allocated for an option.
5770 * Checks for the string being empty_option. This may happen if we're out of
5771 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5772 * check_options().
5773 * Does NOT check for P_ALLOCED flag!
5774 */
5775 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005776free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005777{
5778 if (p != empty_option)
5779 vim_free(p);
5780}
5781
5782 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005783clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005784{
5785 if (*pp != empty_option)
5786 vim_free(*pp);
5787 *pp = empty_option;
5788}
5789
5790 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005791check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005792{
5793 if (*pp == NULL)
5794 *pp = empty_option;
5795}
5796
5797/*
5798 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5799 */
5800 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005801set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005802{
5803 int opt_idx;
5804
5805 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5806 if (options[opt_idx].var == (char_u *)p)
5807 {
5808 options[opt_idx].flags |= P_ALLOCED;
5809 return;
5810 }
5811 return; /* cannot happen: didn't find it! */
5812}
5813
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005814#if defined(FEAT_EVAL) || defined(PROTO)
5815/*
5816 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5817 * Return FALSE when it wasn't.
5818 * Return -1 for an unknown option.
5819 */
5820 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005821was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005822{
5823 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005824 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005825
5826 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005827 {
5828 flagp = insecure_flag(idx, opt_flags);
5829 return (*flagp & P_INSECURE) != 0;
5830 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005831 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005832 return -1;
5833}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005834
5835/*
5836 * Get a pointer to the flags used for the P_INSECURE flag of option
5837 * "opt_idx". For some local options a local flags field is used.
5838 */
5839 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005840insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005841{
5842 if (opt_flags & OPT_LOCAL)
5843 switch ((int)options[opt_idx].indir)
5844 {
5845#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005846 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005847#endif
5848#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005849# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005850 case PV_FDE: return &curwin->w_p_fde_flags;
5851 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005852# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005853# ifdef FEAT_BEVAL
5854 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5855# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005856# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005857 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005858# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005859 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005860# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005861 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005862# endif
5863#endif
5864 }
5865
5866 /* Nothing special, return global flags field. */
5867 return &options[opt_idx].flags;
5868}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005869#endif
5870
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005871#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005872static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005873
5874/*
5875 * Redraw the window title and/or tab page text later.
5876 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005877static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005878{
5879 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005880 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005881}
5882#endif
5883
Bram Moolenaar071d4272004-06-13 20:20:40 +00005884/*
5885 * Set a string option to a new value (without checking the effect).
5886 * The string is copied into allocated memory.
5887 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005888 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005889 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890 */
5891 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005892set_string_option_direct(
5893 char_u *name,
5894 int opt_idx,
5895 char_u *val,
5896 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5897 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898{
5899 char_u *s;
5900 char_u **varp;
5901 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005902 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005903
Bram Moolenaar89d40322006-08-29 15:30:07 +00005904 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005906 idx = findoption(name);
5907 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005908 {
5909 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005910 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005912 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 }
5914
Bram Moolenaar89d40322006-08-29 15:30:07 +00005915 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 return;
5917
5918 s = vim_strsave(val);
5919 if (s != NULL)
5920 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005921 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005922 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005923 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924 free_string_option(*varp);
5925 *varp = s;
5926
5927 /* For buffer/window local option may also set the global value. */
5928 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005929 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930
Bram Moolenaar89d40322006-08-29 15:30:07 +00005931 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932
5933 /* When setting both values of a global option with a local value,
5934 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005935 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936 {
5937 free_string_option(*varp);
5938 *varp = empty_option;
5939 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005940# ifdef FEAT_EVAL
5941 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005942 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005943 set_sid == 0 ? current_SID : set_sid);
5944# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005945 }
5946}
5947
5948/*
5949 * Set global value for string option when it's a local option.
5950 */
5951 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005952set_string_option_global(
5953 int opt_idx, /* option index */
5954 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955{
5956 char_u **p, *s;
5957
5958 /* the global value is always allocated */
5959 if (options[opt_idx].var == VAR_WIN)
5960 p = (char_u **)GLOBAL_WO(varp);
5961 else
5962 p = (char_u **)options[opt_idx].var;
5963 if (options[opt_idx].indir != PV_NONE
5964 && p != varp
5965 && (s = vim_strsave(*varp)) != NULL)
5966 {
5967 free_string_option(*p);
5968 *p = s;
5969 }
5970}
5971
5972/*
5973 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005974 *
5975 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005977 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005978set_string_option(
5979 int opt_idx,
5980 char_u *value,
5981 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005982{
5983 char_u *s;
5984 char_u **varp;
5985 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005986#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005987 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005988 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005989#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005990 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991
5992 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005993 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005994
5995 s = vim_strsave(value);
5996 if (s != NULL)
5997 {
5998 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5999 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006000 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001 ? OPT_GLOBAL : OPT_LOCAL)
6002 : opt_flags);
6003 oldval = *varp;
6004 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006005
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006006#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006007 if (!starting
6008# ifdef FEAT_CRYPT
6009 && options[opt_idx].indir != PV_KEY
6010# endif
6011 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006012 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006013 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006014 saved_newval = vim_strsave(s);
6015 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006016#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006017 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6018 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006019 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006020
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006021#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006022 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006023 if (r == NULL)
6024 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006025 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006026 vim_free(saved_oldval);
6027 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006029 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006030 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006031}
6032
6033/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006034 * Return TRUE if "val" is a valid 'filetype' name.
6035 * Also used for 'syntax' and 'keymap'.
6036 */
6037 static int
6038valid_filetype(char_u *val)
6039{
6040 char_u *s;
6041
6042 for (s = val; *s != NUL; ++s)
6043 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6044 return FALSE;
6045 return TRUE;
6046}
6047
6048/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006049 * Handle string options that need some action to perform when changed.
6050 * Returns NULL for success, or an error message for an error.
6051 */
6052 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006053did_set_string_option(
6054 int opt_idx, /* index in options[] table */
6055 char_u **varp, /* pointer to the option variable */
6056 int new_value_alloced, /* new value was allocated */
6057 char_u *oldval, /* previous value of the option */
6058 char_u *errbuf, /* buffer for errors, or NULL */
6059 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060{
6061 char_u *errmsg = NULL;
6062 char_u *s, *p;
6063 int did_chartab = FALSE;
6064 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006065 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006066#ifdef FEAT_GUI
6067 /* set when changing an option that only requires a redraw in the GUI */
6068 int redraw_gui_only = FALSE;
6069#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006070 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006071#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6072 int did_swaptcap = FALSE;
6073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074
6075 /* Get the global option to compare with, otherwise we would have to check
6076 * two values for all local options. */
6077 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6078
6079 /* Disallow changing some options from secure mode */
6080 if ((secure
6081#ifdef HAVE_SANDBOX
6082 || sandbox != 0
6083#endif
6084 ) && (options[opt_idx].flags & P_SECURE))
6085 {
6086 errmsg = e_secure;
6087 }
6088
Bram Moolenaar7554da42016-11-25 22:04:13 +01006089 /* Check for a "normal" directory or file name in some options. Disallow a
6090 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006091 * are often illegal in a file name. Be more permissive if "secure" is off.
6092 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006093 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006094 && vim_strpbrk(*varp, (char_u *)(secure
6095 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006096 || ((options[opt_idx].flags & P_NDNAME)
6097 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006098 {
6099 errmsg = e_invarg;
6100 }
6101
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102 /* 'term' */
6103 else if (varp == &T_NAME)
6104 {
6105 if (T_NAME[0] == NUL)
6106 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6107#ifdef FEAT_GUI
6108 if (gui.in_use)
6109 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6110 else if (term_is_gui(T_NAME))
6111 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6112#endif
6113 else if (set_termname(T_NAME) == FAIL)
6114 errmsg = (char_u *)N_("E522: Not found in termcap");
6115 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006116 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 /* Screen colors may have changed. */
6118 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006119
6120 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6121 * P_ALLOCED flag on 'term'. */
6122 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006123 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006124 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006125 }
6126
6127 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006128 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006130 char_u *bkc = p_bkc;
6131 unsigned int *flags = &bkc_flags;
6132
6133 if (opt_flags & OPT_LOCAL)
6134 {
6135 bkc = curbuf->b_p_bkc;
6136 flags = &curbuf->b_bkc_flags;
6137 }
6138
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006139 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6140 /* make the local value empty: use the global value */
6141 *flags = 0;
6142 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006144 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6145 errmsg = e_invarg;
6146 if ((((int)*flags & BKC_AUTO) != 0)
6147 + (((int)*flags & BKC_YES) != 0)
6148 + (((int)*flags & BKC_NO) != 0) != 1)
6149 {
6150 /* Must have exactly one of "auto", "yes" and "no". */
6151 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6152 errmsg = e_invarg;
6153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154 }
6155 }
6156
6157 /* 'backupext' and 'patchmode' */
6158 else if (varp == &p_bex || varp == &p_pm)
6159 {
6160 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6161 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6162 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6163 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006164#ifdef FEAT_LINEBREAK
6165 /* 'breakindentopt' */
6166 else if (varp == &curwin->w_p_briopt)
6167 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006168 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006169 errmsg = e_invarg;
6170 }
6171#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006172
6173 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006174 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006175 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006176 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006177 */
6178 else if ( varp == &p_isi
6179 || varp == &(curbuf->b_p_isk)
6180 || varp == &p_isp
6181 || varp == &p_isf)
6182 {
6183 if (init_chartab() == FAIL)
6184 {
6185 did_chartab = TRUE; /* need to restore it below */
6186 errmsg = e_invarg; /* error in value */
6187 }
6188 }
6189
6190 /* 'helpfile' */
6191 else if (varp == &p_hf)
6192 {
6193 /* May compute new values for $VIM and $VIMRUNTIME */
6194 if (didset_vim)
6195 {
6196 vim_setenv((char_u *)"VIM", (char_u *)"");
6197 didset_vim = FALSE;
6198 }
6199 if (didset_vimruntime)
6200 {
6201 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6202 didset_vimruntime = FALSE;
6203 }
6204 }
6205
Bram Moolenaar1a384422010-07-14 19:53:30 +02006206#ifdef FEAT_SYN_HL
6207 /* 'colorcolumn' */
6208 else if (varp == &curwin->w_p_cc)
6209 errmsg = check_colorcolumn(curwin);
6210#endif
6211
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212#ifdef FEAT_MULTI_LANG
6213 /* 'helplang' */
6214 else if (varp == &p_hlg)
6215 {
6216 /* Check for "", "ab", "ab,cd", etc. */
6217 for (s = p_hlg; *s != NUL; s += 3)
6218 {
6219 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6220 {
6221 errmsg = e_invarg;
6222 break;
6223 }
6224 if (s[2] == NUL)
6225 break;
6226 }
6227 }
6228#endif
6229
6230 /* 'highlight' */
6231 else if (varp == &p_hl)
6232 {
6233 if (highlight_changed() == FAIL)
6234 errmsg = e_invarg; /* invalid flags */
6235 }
6236
6237 /* 'nrformats' */
6238 else if (gvarp == &p_nf)
6239 {
6240 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6241 errmsg = e_invarg;
6242 }
6243
6244#ifdef FEAT_SESSION
6245 /* 'sessionoptions' */
6246 else if (varp == &p_ssop)
6247 {
6248 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6249 errmsg = e_invarg;
6250 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6251 {
6252 /* Don't allow both "sesdir" and "curdir". */
6253 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6254 errmsg = e_invarg;
6255 }
6256 }
6257 /* 'viewoptions' */
6258 else if (varp == &p_vop)
6259 {
6260 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6261 errmsg = e_invarg;
6262 }
6263#endif
6264
6265 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266 else if (varp == &p_sbo)
6267 {
6268 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6269 errmsg = e_invarg;
6270 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006271
6272 /* 'ambiwidth' */
6273#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006274 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006275 {
6276 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6277 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006278 else if (set_chars_option(&p_lcs) != NULL)
6279 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006280 else if (set_chars_option(&p_fcs) != NULL)
6281 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282 }
6283#endif
6284
6285 /* 'background' */
6286 else if (varp == &p_bg)
6287 {
6288 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6289 {
6290#ifdef FEAT_EVAL
6291 int dark = (*p_bg == 'd');
6292#endif
6293
6294 init_highlight(FALSE, FALSE);
6295
6296#ifdef FEAT_EVAL
6297 if (dark != (*p_bg == 'd')
6298 && get_var_value((char_u *)"g:colors_name") != NULL)
6299 {
6300 /* The color scheme must have set 'background' back to another
6301 * value, that's not what we want here. Disable the color
6302 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006303 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006304 free_string_option(p_bg);
6305 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6306 check_string_option(&p_bg);
6307 init_highlight(FALSE, FALSE);
6308 }
6309#endif
6310 }
6311 else
6312 errmsg = e_invarg;
6313 }
6314
6315 /* 'wildmode' */
6316 else if (varp == &p_wim)
6317 {
6318 if (check_opt_wim() == FAIL)
6319 errmsg = e_invarg;
6320 }
6321
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006322#ifdef FEAT_CMDL_COMPL
6323 /* 'wildoptions' */
6324 else if (varp == &p_wop)
6325 {
6326 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6327 errmsg = e_invarg;
6328 }
6329#endif
6330
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331#ifdef FEAT_WAK
6332 /* 'winaltkeys' */
6333 else if (varp == &p_wak)
6334 {
6335 if (*p_wak == NUL
6336 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6337 errmsg = e_invarg;
6338# ifdef FEAT_MENU
6339# ifdef FEAT_GUI_MOTIF
6340 else if (gui.in_use)
6341 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6342# else
6343# ifdef FEAT_GUI_GTK
6344 else if (gui.in_use)
6345 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6346# endif
6347# endif
6348# endif
6349 }
6350#endif
6351
Bram Moolenaar071d4272004-06-13 20:20:40 +00006352 /* 'eventignore' */
6353 else if (varp == &p_ei)
6354 {
6355 if (check_ei() == FAIL)
6356 errmsg = e_invarg;
6357 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006358
6359#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006360 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6361 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6362 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 {
6364 if (gvarp == &p_fenc)
6365 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006366 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367 errmsg = e_modifiable;
6368 else if (vim_strchr(*varp, ',') != NULL)
6369 /* No comma allowed in 'fileencoding'; catches confusing it
6370 * with 'fileencodings'. */
6371 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006373 {
6374# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006375 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006376 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006378 /* Add 'fileencoding' to the swap file. */
6379 ml_setflags(curbuf);
6380 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381 }
6382 if (errmsg == NULL)
6383 {
6384 /* canonize the value, so that STRCMP() can be used on it */
6385 p = enc_canonize(*varp);
6386 if (p != NULL)
6387 {
6388 vim_free(*varp);
6389 *varp = p;
6390 }
6391 if (varp == &p_enc)
6392 {
6393 errmsg = mb_init();
6394# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006395 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396# endif
6397 }
6398 }
6399
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006400# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6402 {
6403 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6404 if (STRCMP(p_tenc, "utf-8") != 0)
6405 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6406 }
6407# endif
6408
6409 if (errmsg == NULL)
6410 {
6411# ifdef FEAT_KEYMAP
6412 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6413 * (with another encoding). */
6414 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6415 (void)keymap_init();
6416# endif
6417
6418 /* When 'termencoding' is not empty and 'encoding' changes or when
6419 * 'termencoding' changes, need to setup for keyboard input and
6420 * display output conversion. */
6421 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6422 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006423 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6424 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6425 {
6426 EMSG3(_("E950: Cannot convert between %s and %s"),
6427 p_tenc, p_enc);
6428 errmsg = e_invarg;
6429 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006431
6432# if defined(WIN3264) && defined(FEAT_MBYTE)
6433 /* $HOME may have characters in active code page. */
6434 if (varp == &p_enc)
6435 init_homedir();
6436# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437 }
6438 }
6439#endif
6440
6441#if defined(FEAT_POSTSCRIPT)
6442 else if (varp == &p_penc)
6443 {
6444 /* Canonize printencoding if VIM standard one */
6445 p = enc_canonize(p_penc);
6446 if (p != NULL)
6447 {
6448 vim_free(p_penc);
6449 p_penc = p;
6450 }
6451 else
6452 {
6453 /* Ensure lower case and '-' for '_' */
6454 for (s = p_penc; *s != NUL; s++)
6455 {
6456 if (*s == '_')
6457 *s = '-';
6458 else
6459 *s = TOLOWER_ASC(*s);
6460 }
6461 }
6462 }
6463#endif
6464
Bram Moolenaar9372a112005-12-06 19:59:18 +00006465#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466 else if (varp == &p_imak)
6467 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006468 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006469 errmsg = e_invarg;
6470 }
6471#endif
6472
6473#ifdef FEAT_KEYMAP
6474 else if (varp == &curbuf->b_p_keymap)
6475 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006476 if (!valid_filetype(*varp))
6477 errmsg = e_invarg;
6478 else
6479 /* load or unload key mapping tables */
6480 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006481
Bram Moolenaarfab06232009-03-04 03:13:35 +00006482 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006484 if (*curbuf->b_p_keymap != NUL)
6485 {
6486 /* Installed a new keymap, switch on using it. */
6487 curbuf->b_p_iminsert = B_IMODE_LMAP;
6488 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6489 curbuf->b_p_imsearch = B_IMODE_LMAP;
6490 }
6491 else
6492 {
6493 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6494 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6495 curbuf->b_p_iminsert = B_IMODE_NONE;
6496 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6497 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6498 }
6499 if ((opt_flags & OPT_LOCAL) == 0)
6500 {
6501 set_iminsert_global();
6502 set_imsearch_global();
6503 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006504 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006505 }
6506 }
6507#endif
6508
6509 /* 'fileformat' */
6510 else if (gvarp == &p_ff)
6511 {
6512 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6513 errmsg = e_modifiable;
6514 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6515 errmsg = e_invarg;
6516 else
6517 {
6518 /* may also change 'textmode' */
6519 if (get_fileformat(curbuf) == EOL_DOS)
6520 curbuf->b_p_tx = TRUE;
6521 else
6522 curbuf->b_p_tx = FALSE;
6523#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006524 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006525#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006526 /* update flag in swap file */
6527 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006528 /* Redraw needed when switching to/from "mac": a CR in the text
6529 * will be displayed differently. */
6530 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6531 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006532 }
6533 }
6534
6535 /* 'fileformats' */
6536 else if (varp == &p_ffs)
6537 {
6538 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6539 errmsg = e_invarg;
6540 else
6541 {
6542 /* also change 'textauto' */
6543 if (*p_ffs == NUL)
6544 p_ta = FALSE;
6545 else
6546 p_ta = TRUE;
6547 }
6548 }
6549
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006550#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006551 /* 'cryptkey' */
6552 else if (gvarp == &p_key)
6553 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006554# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 /* Make sure the ":set" command doesn't show the new value in the
6556 * history. */
6557 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006558# endif
6559 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6560 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006561 ml_set_crypt_key(curbuf, oldval,
6562 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006563 }
6564
6565 else if (gvarp == &p_cm)
6566 {
6567 if (opt_flags & OPT_LOCAL)
6568 p = curbuf->b_p_cm;
6569 else
6570 p = p_cm;
6571 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6572 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006573 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006574 errmsg = e_invarg;
6575 else
6576 {
6577 /* When setting the global value to empty, make it "zip". */
6578 if (*p_cm == NUL)
6579 {
6580 if (new_value_alloced)
6581 free_string_option(p_cm);
6582 p_cm = vim_strsave((char_u *)"zip");
6583 new_value_alloced = TRUE;
6584 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006585 /* When using ":set cm=name" the local value is going to be empty.
6586 * Do that here, otherwise the crypt functions will still use the
6587 * local value. */
6588 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6589 {
6590 free_string_option(curbuf->b_p_cm);
6591 curbuf->b_p_cm = empty_option;
6592 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006593
6594 /* Need to update the swapfile when the effective method changed.
6595 * Set "s" to the effective old value, "p" to the effective new
6596 * method and compare. */
6597 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6598 s = p_cm; /* was previously using the global value */
6599 else
6600 s = oldval;
6601 if (*curbuf->b_p_cm == NUL)
6602 p = p_cm; /* is now using the global value */
6603 else
6604 p = curbuf->b_p_cm;
6605 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006606 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006607
6608 /* If the global value changes need to update the swapfile for all
6609 * buffers using that value. */
6610 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6611 {
6612 buf_T *buf;
6613
Bram Moolenaar29323592016-07-24 22:04:11 +02006614 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006615 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006616 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006617 }
6618 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619 }
6620#endif
6621
6622 /* 'matchpairs' */
6623 else if (gvarp == &p_mps)
6624 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006625#ifdef FEAT_MBYTE
6626 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006627 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006628 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006630 int x2 = -1;
6631 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006632
6633 if (*p != NUL)
6634 p += mb_ptr2len(p);
6635 if (*p != NUL)
6636 x2 = *p++;
6637 if (*p != NUL)
6638 {
6639 x3 = mb_ptr2char(p);
6640 p += mb_ptr2len(p);
6641 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006642 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006643 {
6644 errmsg = e_invarg;
6645 break;
6646 }
6647 if (*p == NUL)
6648 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006649 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006650 }
6651 else
6652#endif
6653 {
6654 /* Check for "x:y,x:y" */
6655 for (p = *varp; *p != NUL; p += 4)
6656 {
6657 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6658 {
6659 errmsg = e_invarg;
6660 break;
6661 }
6662 if (p[3] == NUL)
6663 break;
6664 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665 }
6666 }
6667
6668#ifdef FEAT_COMMENTS
6669 /* 'comments' */
6670 else if (gvarp == &p_com)
6671 {
6672 for (s = *varp; *s; )
6673 {
6674 while (*s && *s != ':')
6675 {
6676 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6677 && !VIM_ISDIGIT(*s) && *s != '-')
6678 {
6679 errmsg = illegal_char(errbuf, *s);
6680 break;
6681 }
6682 ++s;
6683 }
6684 if (*s++ == NUL)
6685 errmsg = (char_u *)N_("E524: Missing colon");
6686 else if (*s == ',' || *s == NUL)
6687 errmsg = (char_u *)N_("E525: Zero length string");
6688 if (errmsg != NULL)
6689 break;
6690 while (*s && *s != ',')
6691 {
6692 if (*s == '\\' && s[1] != NUL)
6693 ++s;
6694 ++s;
6695 }
6696 s = skip_to_option_part(s);
6697 }
6698 }
6699#endif
6700
6701 /* 'listchars' */
6702 else if (varp == &p_lcs)
6703 {
6704 errmsg = set_chars_option(varp);
6705 }
6706
Bram Moolenaar071d4272004-06-13 20:20:40 +00006707 /* 'fillchars' */
6708 else if (varp == &p_fcs)
6709 {
6710 errmsg = set_chars_option(varp);
6711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006712
6713#ifdef FEAT_CMDWIN
6714 /* 'cedit' */
6715 else if (varp == &p_cedit)
6716 {
6717 errmsg = check_cedit();
6718 }
6719#endif
6720
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006721 /* 'verbosefile' */
6722 else if (varp == &p_vfile)
6723 {
6724 verbose_stop();
6725 if (*p_vfile != NUL && verbose_open() == FAIL)
6726 errmsg = e_invarg;
6727 }
6728
Bram Moolenaar071d4272004-06-13 20:20:40 +00006729#ifdef FEAT_VIMINFO
6730 /* 'viminfo' */
6731 else if (varp == &p_viminfo)
6732 {
6733 for (s = p_viminfo; *s;)
6734 {
6735 /* Check it's a valid character */
6736 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6737 {
6738 errmsg = illegal_char(errbuf, *s);
6739 break;
6740 }
6741 if (*s == 'n') /* name is always last one */
6742 {
6743 break;
6744 }
6745 else if (*s == 'r') /* skip until next ',' */
6746 {
6747 while (*++s && *s != ',')
6748 ;
6749 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006750 else if (*s == '%')
6751 {
6752 /* optional number */
6753 while (vim_isdigit(*++s))
6754 ;
6755 }
6756 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 ++s; /* no extra chars */
6758 else /* must have a number */
6759 {
6760 while (vim_isdigit(*++s))
6761 ;
6762
6763 if (!VIM_ISDIGIT(*(s - 1)))
6764 {
6765 if (errbuf != NULL)
6766 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006767 sprintf((char *)errbuf,
6768 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006769 transchar_byte(*(s - 1)));
6770 errmsg = errbuf;
6771 }
6772 else
6773 errmsg = (char_u *)"";
6774 break;
6775 }
6776 }
6777 if (*s == ',')
6778 ++s;
6779 else if (*s)
6780 {
6781 if (errbuf != NULL)
6782 errmsg = (char_u *)N_("E527: Missing comma");
6783 else
6784 errmsg = (char_u *)"";
6785 break;
6786 }
6787 }
6788 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6789 errmsg = (char_u *)N_("E528: Must specify a ' value");
6790 }
6791#endif /* FEAT_VIMINFO */
6792
6793 /* terminal options */
6794 else if (istermoption(&options[opt_idx]) && full_screen)
6795 {
6796 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6797 if (varp == &T_CCO)
6798 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006799 int colors = atoi((char *)T_CCO);
6800
6801 /* Only reinitialize colors if t_Co value has really changed to
6802 * avoid expensive reload of colorscheme if t_Co is set to the
6803 * same value multiple times. */
6804 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006805 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006806 t_colors = colors;
6807 if (t_colors <= 1)
6808 {
6809 if (new_value_alloced)
6810 vim_free(T_CCO);
6811 T_CCO = empty_option;
6812 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006813#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6814 if (is_term_win32())
6815 {
6816 swap_tcap();
6817 did_swaptcap = TRUE;
6818 }
6819#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006820 /* We now have a different color setup, initialize it again. */
6821 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823 }
6824 ttest(FALSE);
6825 if (varp == &T_ME)
6826 {
6827 out_str(T_ME);
6828 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006829#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006830 /* Since t_me has been set, this probably means that the user
6831 * wants to use this as default colors. Need to reset default
6832 * background/foreground colors. */
6833 mch_set_normal_colors();
6834#endif
6835 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006836 if (varp == &T_BE && termcap_active)
6837 {
6838 if (*T_BE == NUL)
6839 /* When clearing t_BE we assume the user no longer wants
6840 * bracketed paste, thus disable it by writing t_BD. */
6841 out_str(T_BD);
6842 else
6843 out_str(T_BE);
6844 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845 }
6846
6847#ifdef FEAT_LINEBREAK
6848 /* 'showbreak' */
6849 else if (varp == &p_sbr)
6850 {
6851 for (s = p_sbr; *s; )
6852 {
6853 if (ptr2cells(s) != 1)
6854 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006855 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856 }
6857 }
6858#endif
6859
6860#ifdef FEAT_GUI
6861 /* 'guifont' */
6862 else if (varp == &p_guifont)
6863 {
6864 if (gui.in_use)
6865 {
6866 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006867# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006868 /*
6869 * Put up a font dialog and let the user select a new value.
6870 * If this is cancelled go back to the old value but don't
6871 * give an error message.
6872 */
6873 if (STRCMP(p, "*") == 0)
6874 {
6875 p = gui_mch_font_dialog(oldval);
6876
6877 if (new_value_alloced)
6878 free_string_option(p_guifont);
6879
6880 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6881 new_value_alloced = TRUE;
6882 }
6883# endif
6884 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6885 {
6886# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6887 if (STRCMP(p_guifont, "*") == 0)
6888 {
6889 /* Dialog was cancelled: Keep the old value without giving
6890 * an error message. */
6891 if (new_value_alloced)
6892 free_string_option(p_guifont);
6893 p_guifont = vim_strsave(oldval);
6894 new_value_alloced = TRUE;
6895 }
6896 else
6897# endif
6898 errmsg = (char_u *)N_("E596: Invalid font(s)");
6899 }
6900 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006901 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006902 }
6903# ifdef FEAT_XFONTSET
6904 else if (varp == &p_guifontset)
6905 {
6906 if (STRCMP(p_guifontset, "*") == 0)
6907 errmsg = (char_u *)N_("E597: can't select fontset");
6908 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6909 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006910 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911 }
6912# endif
6913# ifdef FEAT_MBYTE
6914 else if (varp == &p_guifontwide)
6915 {
6916 if (STRCMP(p_guifontwide, "*") == 0)
6917 errmsg = (char_u *)N_("E533: can't select wide font");
6918 else if (gui_get_wide_font() == FAIL)
6919 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006920 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006921 }
6922# endif
6923#endif
6924
6925#ifdef CURSOR_SHAPE
6926 /* 'guicursor' */
6927 else if (varp == &p_guicursor)
6928 errmsg = parse_shape_opt(SHAPE_CURSOR);
6929#endif
6930
6931#ifdef FEAT_MOUSESHAPE
6932 /* 'mouseshape' */
6933 else if (varp == &p_mouseshape)
6934 {
6935 errmsg = parse_shape_opt(SHAPE_MOUSE);
6936 update_mouseshape(-1);
6937 }
6938#endif
6939
6940#ifdef FEAT_PRINTER
6941 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006942 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006943# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006944 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006945 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006946# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947#endif
6948
6949#ifdef FEAT_LANGMAP
6950 /* 'langmap' */
6951 else if (varp == &p_langmap)
6952 langmap_set();
6953#endif
6954
6955#ifdef FEAT_LINEBREAK
6956 /* 'breakat' */
6957 else if (varp == &p_breakat)
6958 fill_breakat_flags();
6959#endif
6960
6961#ifdef FEAT_TITLE
6962 /* 'titlestring' and 'iconstring' */
6963 else if (varp == &p_titlestring || varp == &p_iconstring)
6964 {
6965# ifdef FEAT_STL_OPT
6966 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6967
6968 /* NULL => statusline syntax */
6969 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6970 stl_syntax |= flagval;
6971 else
6972 stl_syntax &= ~flagval;
6973# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006974 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006975 }
6976#endif
6977
6978#ifdef FEAT_GUI
6979 /* 'guioptions' */
6980 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006981 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006983 redraw_gui_only = TRUE;
6984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985#endif
6986
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006987#if defined(FEAT_GUI_TABLINE)
6988 /* 'guitablabel' */
6989 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006990 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006991 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006992 redraw_gui_only = TRUE;
6993 }
6994 /* 'guitabtooltip' */
6995 else if (varp == &p_gtt)
6996 {
6997 redraw_gui_only = TRUE;
6998 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006999#endif
7000
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7002 /* 'ttymouse' */
7003 else if (varp == &p_ttym)
7004 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007005 /* Switch the mouse off before changing the escape sequences used for
7006 * that. */
7007 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7009 errmsg = e_invarg;
7010 else
7011 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007012 if (termcap_active)
7013 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 }
7015#endif
7016
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 /* 'selection' */
7018 else if (varp == &p_sel)
7019 {
7020 if (*p_sel == NUL
7021 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7022 errmsg = e_invarg;
7023 }
7024
7025 /* 'selectmode' */
7026 else if (varp == &p_slm)
7027 {
7028 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7029 errmsg = e_invarg;
7030 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007031
7032#ifdef FEAT_BROWSE
7033 /* 'browsedir' */
7034 else if (varp == &p_bsdir)
7035 {
7036 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7037 && !mch_isdir(p_bsdir))
7038 errmsg = e_invarg;
7039 }
7040#endif
7041
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 /* 'keymodel' */
7043 else if (varp == &p_km)
7044 {
7045 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7046 errmsg = e_invarg;
7047 else
7048 {
7049 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7050 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7051 }
7052 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007053
7054 /* 'mousemodel' */
7055 else if (varp == &p_mousem)
7056 {
7057 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7058 errmsg = e_invarg;
7059#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7060 else if (*p_mousem != *oldval)
7061 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7062 * to create or delete the popup menus. */
7063 gui_motif_update_mousemodel(root_menu);
7064#endif
7065 }
7066
7067 /* 'switchbuf' */
7068 else if (varp == &p_swb)
7069 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007070 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 errmsg = e_invarg;
7072 }
7073
7074 /* 'debug' */
7075 else if (varp == &p_debug)
7076 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007077 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 errmsg = e_invarg;
7079 }
7080
7081 /* 'display' */
7082 else if (varp == &p_dy)
7083 {
7084 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7085 errmsg = e_invarg;
7086 else
7087 (void)init_chartab();
7088
7089 }
7090
Bram Moolenaar071d4272004-06-13 20:20:40 +00007091 /* 'eadirection' */
7092 else if (varp == &p_ead)
7093 {
7094 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7095 errmsg = e_invarg;
7096 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007097
7098#ifdef FEAT_CLIPBOARD
7099 /* 'clipboard' */
7100 else if (varp == &p_cb)
7101 errmsg = check_clipboard_option();
7102#endif
7103
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007104#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007105 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7106 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007107 else if (varp == &(curwin->w_s->b_p_spl)
7108 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007109 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007110 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007111 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007112 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007113 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007114 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007115 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007116 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007117 /* 'spellsuggest' */
7118 else if (varp == &p_sps)
7119 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007120 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007121 errmsg = e_invarg;
7122 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007123 /* 'mkspellmem' */
7124 else if (varp == &p_msm)
7125 {
7126 if (spell_check_msm() != OK)
7127 errmsg = e_invarg;
7128 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007129#endif
7130
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131 /* When 'bufhidden' is set, check for valid value. */
7132 else if (gvarp == &p_bh)
7133 {
7134 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7135 errmsg = e_invarg;
7136 }
7137
7138 /* When 'buftype' is set, check for valid value. */
7139 else if (gvarp == &p_bt)
7140 {
7141 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7142 errmsg = e_invarg;
7143 else
7144 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007145 if (curwin->w_status_height)
7146 {
7147 curwin->w_redr_status = TRUE;
7148 redraw_later(VALID);
7149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007150 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007151#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007152 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 }
7155 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007156
7157#ifdef FEAT_STL_OPT
7158 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007159 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007160 {
7161 int wid;
7162
7163 if (varp == &p_ruf) /* reset ru_wid first */
7164 ru_wid = 0;
7165 s = *varp;
7166 if (varp == &p_ruf && *s == '%')
7167 {
7168 /* set ru_wid if 'ruf' starts with "%99(" */
7169 if (*++s == '-') /* ignore a '-' */
7170 s++;
7171 wid = getdigits(&s);
7172 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7173 ru_wid = wid;
7174 else
7175 errmsg = check_stl_option(p_ruf);
7176 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007177 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007178 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007180 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 comp_col();
7182 }
7183#endif
7184
7185#ifdef FEAT_INS_EXPAND
7186 /* check if it is a valid value for 'complete' -- Acevedo */
7187 else if (gvarp == &p_cpt)
7188 {
7189 for (s = *varp; *s;)
7190 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007191 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007192 s++;
7193 if (!*s)
7194 break;
7195 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7196 {
7197 errmsg = illegal_char(errbuf, *s);
7198 break;
7199 }
7200 if (*++s != NUL && *s != ',' && *s != ' ')
7201 {
7202 if (s[-1] == 'k' || s[-1] == 's')
7203 {
7204 /* skip optional filename after 'k' and 's' */
7205 while (*s && *s != ',' && *s != ' ')
7206 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007207 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007208 ++s;
7209 ++s;
7210 }
7211 }
7212 else
7213 {
7214 if (errbuf != NULL)
7215 {
7216 sprintf((char *)errbuf,
7217 _("E535: Illegal character after <%c>"),
7218 *--s);
7219 errmsg = errbuf;
7220 }
7221 else
7222 errmsg = (char_u *)"";
7223 break;
7224 }
7225 }
7226 }
7227 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007228
7229 /* 'completeopt' */
7230 else if (varp == &p_cot)
7231 {
7232 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7233 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007234 else
7235 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007236 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007237#endif /* FEAT_INS_EXPAND */
7238
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007239#ifdef FEAT_SIGNS
7240 /* 'signcolumn' */
7241 else if (varp == &curwin->w_p_scl)
7242 {
7243 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7244 errmsg = e_invarg;
7245 }
7246#endif
7247
Bram Moolenaar071d4272004-06-13 20:20:40 +00007248
7249#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007250 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 else if (varp == &p_toolbar)
7252 {
7253 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7254 &toolbar_flags, TRUE) != OK)
7255 errmsg = e_invarg;
7256 else
7257 {
7258 out_flush();
7259 gui_mch_show_toolbar((toolbar_flags &
7260 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7261 }
7262 }
7263#endif
7264
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007265#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007266 /* 'toolbariconsize': GTK+ 2 only */
7267 else if (varp == &p_tbis)
7268 {
7269 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7270 errmsg = e_invarg;
7271 else
7272 {
7273 out_flush();
7274 gui_mch_show_toolbar((toolbar_flags &
7275 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7276 }
7277 }
7278#endif
7279
7280 /* 'pastetoggle': translate key codes like in a mapping */
7281 else if (varp == &p_pt)
7282 {
7283 if (*p_pt)
7284 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007285 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007286 if (p != NULL)
7287 {
7288 if (new_value_alloced)
7289 free_string_option(p_pt);
7290 p_pt = p;
7291 new_value_alloced = TRUE;
7292 }
7293 }
7294 }
7295
7296 /* 'backspace' */
7297 else if (varp == &p_bs)
7298 {
7299 if (VIM_ISDIGIT(*p_bs))
7300 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007301 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007302 errmsg = e_invarg;
7303 }
7304 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7305 errmsg = e_invarg;
7306 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007307 else if (varp == &p_bo)
7308 {
7309 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7310 errmsg = e_invarg;
7311 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007312
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007313 /* 'tagcase' */
7314 else if (gvarp == &p_tc)
7315 {
7316 unsigned int *flags;
7317
7318 if (opt_flags & OPT_LOCAL)
7319 {
7320 p = curbuf->b_p_tc;
7321 flags = &curbuf->b_tc_flags;
7322 }
7323 else
7324 {
7325 p = p_tc;
7326 flags = &tc_flags;
7327 }
7328
7329 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7330 /* make the local value empty: use the global value */
7331 *flags = 0;
7332 else if (*p == NUL
7333 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7334 errmsg = e_invarg;
7335 }
7336
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007337#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007338 /* 'casemap' */
7339 else if (varp == &p_cmp)
7340 {
7341 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7342 errmsg = e_invarg;
7343 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007345
7346#ifdef FEAT_DIFF
7347 /* 'diffopt' */
7348 else if (varp == &p_dip)
7349 {
7350 if (diffopt_changed() == FAIL)
7351 errmsg = e_invarg;
7352 }
7353#endif
7354
7355#ifdef FEAT_FOLDING
7356 /* 'foldmethod' */
7357 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7358 {
7359 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7360 || *curwin->w_p_fdm == NUL)
7361 errmsg = e_invarg;
7362 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007363 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007364 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007365 if (foldmethodIsDiff(curwin))
7366 newFoldLevel();
7367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368 }
7369# ifdef FEAT_EVAL
7370 /* 'foldexpr' */
7371 else if (varp == &curwin->w_p_fde)
7372 {
7373 if (foldmethodIsExpr(curwin))
7374 foldUpdateAll(curwin);
7375 }
7376# endif
7377 /* 'foldmarker' */
7378 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7379 {
7380 p = vim_strchr(*varp, ',');
7381 if (p == NULL)
7382 errmsg = (char_u *)N_("E536: comma required");
7383 else if (p == *varp || p[1] == NUL)
7384 errmsg = e_invarg;
7385 else if (foldmethodIsMarker(curwin))
7386 foldUpdateAll(curwin);
7387 }
7388 /* 'commentstring' */
7389 else if (gvarp == &p_cms)
7390 {
7391 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7392 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7393 }
7394 /* 'foldopen' */
7395 else if (varp == &p_fdo)
7396 {
7397 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7398 errmsg = e_invarg;
7399 }
7400 /* 'foldclose' */
7401 else if (varp == &p_fcl)
7402 {
7403 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7404 errmsg = e_invarg;
7405 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007406 /* 'foldignore' */
7407 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7408 {
7409 if (foldmethodIsIndent(curwin))
7410 foldUpdateAll(curwin);
7411 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007412#endif
7413
7414#ifdef FEAT_VIRTUALEDIT
7415 /* 'virtualedit' */
7416 else if (varp == &p_ve)
7417 {
7418 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7419 errmsg = e_invarg;
7420 else if (STRCMP(p_ve, oldval) != 0)
7421 {
7422 /* Recompute cursor position in case the new 've' setting
7423 * changes something. */
7424 validate_virtcol();
7425 coladvance(curwin->w_virtcol);
7426 }
7427 }
7428#endif
7429
7430#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7431 else if (varp == &p_csqf)
7432 {
7433 if (p_csqf != NULL)
7434 {
7435 p = p_csqf;
7436 while (*p != NUL)
7437 {
7438 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7439 || p[1] == NUL
7440 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7441 || (p[2] != NUL && p[2] != ','))
7442 {
7443 errmsg = e_invarg;
7444 break;
7445 }
7446 else if (p[2] == NUL)
7447 break;
7448 else
7449 p += 3;
7450 }
7451 }
7452 }
7453#endif
7454
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007455#ifdef FEAT_CINDENT
7456 /* 'cinoptions' */
7457 else if (gvarp == &p_cino)
7458 {
7459 /* TODO: recognize errors */
7460 parse_cino(curbuf);
7461 }
7462#endif
7463
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007464#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007465 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007466 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007467 {
7468 if (!gui_mch_set_rendering_options(p_rop))
7469 errmsg = e_invarg;
7470 }
7471#endif
7472
Bram Moolenaard0b51382016-11-04 15:23:45 +01007473 else if (gvarp == &p_ft)
7474 {
7475 if (!valid_filetype(*varp))
7476 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007477 else
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007478 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007479 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007480
7481#ifdef FEAT_SYN_HL
7482 else if (gvarp == &p_syn)
7483 {
7484 if (!valid_filetype(*varp))
7485 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007486 else
7487 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007488 }
7489#endif
7490
Bram Moolenaar825680f2017-07-22 17:04:02 +02007491#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007492 /* 'termwinkey' */
7493 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007494 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007495 if (*curwin->w_p_twk != NUL
7496 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007497 errmsg = e_invarg;
7498 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007499 /* 'termwinsize' */
7500 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007501 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007502 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007503 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007504 p = skipdigits(curwin->w_p_tws);
7505 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007506 || (*p != 'x' && *p != '*')
7507 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007508 errmsg = e_invarg;
7509 }
7510 }
7511#endif
7512
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007513#ifdef FEAT_VARTABS
7514 /* 'varsofttabstop' */
7515 else if (varp == &(curbuf->b_p_vsts))
7516 {
7517 char_u *cp;
7518
7519 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7520 {
7521 if (curbuf->b_p_vsts_array)
7522 {
7523 vim_free(curbuf->b_p_vsts_array);
7524 curbuf->b_p_vsts_array = 0;
7525 }
7526 }
7527 else
7528 {
7529 for (cp = *varp; *cp; ++cp)
7530 {
7531 if (vim_isdigit(*cp))
7532 continue;
7533 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7534 continue;
7535 errmsg = e_invarg;
7536 break;
7537 }
7538 if (errmsg == NULL)
7539 {
7540 int *oldarray = curbuf->b_p_vsts_array;
7541 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7542 {
7543 if (oldarray)
7544 vim_free(oldarray);
7545 }
7546 else
7547 errmsg = e_invarg;
7548 }
7549 }
7550 }
7551
7552 /* 'vartabstop' */
7553 else if (varp == &(curbuf->b_p_vts))
7554 {
7555 char_u *cp;
7556
7557 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7558 {
7559 if (curbuf->b_p_vts_array)
7560 {
7561 vim_free(curbuf->b_p_vts_array);
7562 curbuf->b_p_vts_array = NULL;
7563 }
7564 }
7565 else
7566 {
7567 for (cp = *varp; *cp; ++cp)
7568 {
7569 if (vim_isdigit(*cp))
7570 continue;
7571 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7572 continue;
7573 errmsg = e_invarg;
7574 break;
7575 }
7576 if (errmsg == NULL)
7577 {
7578 int *oldarray = curbuf->b_p_vts_array;
7579 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7580 {
7581 if (oldarray)
7582 vim_free(oldarray);
7583#ifdef FEAT_FOLDING
7584 if (foldmethodIsIndent(curwin))
7585 foldUpdateAll(curwin);
7586#endif /* FEAT_FOLDING */
7587 }
7588 else
7589 errmsg = e_invarg;
7590 }
7591 }
7592 }
7593#endif
7594
Bram Moolenaar071d4272004-06-13 20:20:40 +00007595 /* Options that are a list of flags. */
7596 else
7597 {
7598 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007599 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007600 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007601 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007603 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007604 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007605 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007606 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007607#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007608 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007609 p = (char_u *)COCU_ALL;
7610#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007611 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007612 {
7613#ifdef FEAT_MOUSE
7614 p = (char_u *)MOUSE_ALL;
7615#else
7616 if (*p_mouse != NUL)
7617 errmsg = (char_u *)N_("E538: No mouse support");
7618#endif
7619 }
7620#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007621 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007622 p = (char_u *)GO_ALL;
7623#endif
7624 if (p != NULL)
7625 {
7626 for (s = *varp; *s; ++s)
7627 if (vim_strchr(p, *s) == NULL)
7628 {
7629 errmsg = illegal_char(errbuf, *s);
7630 break;
7631 }
7632 }
7633 }
7634
7635 /*
7636 * If error detected, restore the previous value.
7637 */
7638 if (errmsg != NULL)
7639 {
7640 if (new_value_alloced)
7641 free_string_option(*varp);
7642 *varp = oldval;
7643 /*
7644 * When resetting some values, need to act on it.
7645 */
7646 if (did_chartab)
7647 (void)init_chartab();
7648 if (varp == &p_hl)
7649 (void)highlight_changed();
7650 }
7651 else
7652 {
7653#ifdef FEAT_EVAL
7654 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007655 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007656#endif
7657 /*
7658 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007659 * Use "free_oldval", because recursiveness may change the flags under
7660 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007662 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007663 free_string_option(oldval);
7664 if (new_value_alloced)
7665 options[opt_idx].flags |= P_ALLOCED;
7666 else
7667 options[opt_idx].flags &= ~P_ALLOCED;
7668
7669 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007670 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007671 {
7672 /* global option with local value set to use global value; free
7673 * the local value and make it empty */
7674 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7675 free_string_option(*(char_u **)p);
7676 *(char_u **)p = empty_option;
7677 }
7678
7679 /* May set global value for local option. */
7680 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7681 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007682
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007683 /*
7684 * Trigger the autocommand only after setting the flags.
7685 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007686#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007687 /* When 'syntax' is set, load the syntax of that name */
7688 if (varp == &(curbuf->b_p_syn))
7689 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007690 static int syn_recursive = 0;
7691
7692 ++syn_recursive;
7693 // Only pass TRUE for "force" when the value changed or not used
7694 // recursively, to avoid endless recurrence.
7695 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7696 value_changed || syn_recursive == 1, curbuf);
7697 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007698 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007699#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007700 else if (varp == &(curbuf->b_p_ft))
7701 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007702 /* 'filetype' is set, trigger the FileType autocommand.
7703 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007704 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007705 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007706 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007707 static int ft_recursive = 0;
7708
7709 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007710 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007711 // Only pass TRUE for "force" when the value changed or not
7712 // used recursively, to avoid endless recurrence.
7713 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7714 value_changed || ft_recursive == 1, curbuf);
7715 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007716 /* Just in case the old "curbuf" is now invalid. */
7717 if (varp != &(curbuf->b_p_ft))
7718 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007719 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007720 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007721#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007722 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007723 {
7724 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007725 char_u *q = curwin->w_s->b_p_spl;
7726
7727 /* Skip the first name if it is "cjk". */
7728 if (STRNCMP(q, "cjk,", 4) == 0)
7729 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007730
7731 /*
7732 * Source the spell/LANG.vim in 'runtimepath'.
7733 * They could set 'spellcapcheck' depending on the language.
7734 * Use the first name in 'spelllang' up to '_region' or
7735 * '.encoding'.
7736 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007737 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007738 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7739 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007740 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007741 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007742 }
7743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007744 }
7745
7746#ifdef FEAT_MOUSE
7747 if (varp == &p_mouse)
7748 {
7749# ifdef FEAT_MOUSE_TTY
7750 if (*p_mouse == NUL)
7751 mch_setmouse(FALSE); /* switch mouse off */
7752 else
7753# endif
7754 setmouse(); /* in case 'mouse' changed */
7755 }
7756#endif
7757
Bram Moolenaar913077c2012-03-28 19:59:04 +02007758 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007759 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007760 curwin->w_set_curswant = TRUE;
7761
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007762#ifdef FEAT_GUI
7763 /* check redraw when it's not a GUI option or the GUI is active. */
7764 if (!redraw_gui_only || gui.in_use)
7765#endif
7766 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007768#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7769 if (did_swaptcap)
7770 {
7771 if (t_colors < 256)
7772 p_tgc = 0;
7773 set_termname((char_u *)"win32");
7774 init_highlight(TRUE, FALSE);
7775 }
7776#endif
7777
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 return errmsg;
7779}
7780
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007781#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007782/*
7783 * Simple int comparison function for use with qsort()
7784 */
7785 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007786int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007787{
7788 return *(const int *)a - *(const int *)b;
7789}
7790
7791/*
7792 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7793 * Returns error message, NULL if it's OK.
7794 */
7795 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007796check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007797{
7798 char_u *s;
7799 int col;
7800 int count = 0;
7801 int color_cols[256];
7802 int i;
7803 int j = 0;
7804
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007805 if (wp->w_buffer == NULL)
7806 return NULL; /* buffer was closed */
7807
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007808 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007809 {
7810 if (*s == '-' || *s == '+')
7811 {
7812 /* -N and +N: add to 'textwidth' */
7813 col = (*s == '-') ? -1 : 1;
7814 ++s;
7815 if (!VIM_ISDIGIT(*s))
7816 return e_invarg;
7817 col = col * getdigits(&s);
7818 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007819 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007820 col += wp->w_buffer->b_p_tw;
7821 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007822 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007823 }
7824 else if (VIM_ISDIGIT(*s))
7825 col = getdigits(&s);
7826 else
7827 return e_invarg;
7828 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007829skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007830 if (*s == NUL)
7831 break;
7832 if (*s != ',')
7833 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007834 if (*++s == NUL)
7835 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007836 }
7837
7838 vim_free(wp->w_p_cc_cols);
7839 if (count == 0)
7840 wp->w_p_cc_cols = NULL;
7841 else
7842 {
7843 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7844 if (wp->w_p_cc_cols != NULL)
7845 {
7846 /* sort the columns for faster usage on screen redraw inside
7847 * win_line() */
7848 qsort(color_cols, count, sizeof(int), int_cmp);
7849
7850 for (i = 0; i < count; ++i)
7851 /* skip duplicates */
7852 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7853 wp->w_p_cc_cols[j++] = color_cols[i];
7854 wp->w_p_cc_cols[j] = -1; /* end marker */
7855 }
7856 }
7857
7858 return NULL; /* no error */
7859}
7860#endif
7861
Bram Moolenaar071d4272004-06-13 20:20:40 +00007862/*
7863 * Handle setting 'listchars' or 'fillchars'.
7864 * Returns error message, NULL if it's OK.
7865 */
7866 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007867set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868{
7869 int round, i, len, entries;
7870 char_u *p, *s;
7871 int c1, c2 = 0;
7872 struct charstab
7873 {
7874 int *cp;
7875 char *name;
7876 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 static struct charstab filltab[] =
7878 {
7879 {&fill_stl, "stl"},
7880 {&fill_stlnc, "stlnc"},
7881 {&fill_vert, "vert"},
7882 {&fill_fold, "fold"},
7883 {&fill_diff, "diff"},
7884 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007885 static struct charstab lcstab[] =
7886 {
7887 {&lcs_eol, "eol"},
7888 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007889 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007891 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 {&lcs_tab2, "tab"},
7893 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007894#ifdef FEAT_CONCEAL
7895 {&lcs_conceal, "conceal"},
7896#else
7897 {NULL, "conceal"},
7898#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899 };
7900 struct charstab *tab;
7901
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 {
7904 tab = lcstab;
7905 entries = sizeof(lcstab) / sizeof(struct charstab);
7906 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 else
7908 {
7909 tab = filltab;
7910 entries = sizeof(filltab) / sizeof(struct charstab);
7911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007912
7913 /* first round: check for valid value, second round: assign values */
7914 for (round = 0; round <= 1; ++round)
7915 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007916 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 {
7918 /* After checking that the value is valid: set defaults: space for
7919 * 'fillchars', NUL for 'listchars' */
7920 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007921 if (tab[i].cp != NULL)
7922 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923 if (varp == &p_lcs)
7924 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 else
7926 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 }
7928 p = *varp;
7929 while (*p)
7930 {
7931 for (i = 0; i < entries; ++i)
7932 {
7933 len = (int)STRLEN(tab[i].name);
7934 if (STRNCMP(p, tab[i].name, len) == 0
7935 && p[len] == ':'
7936 && p[len + 1] != NUL)
7937 {
7938 s = p + len + 1;
7939#ifdef FEAT_MBYTE
7940 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007941 if (mb_char2cells(c1) > 1)
7942 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943#else
7944 c1 = *s++;
7945#endif
7946 if (tab[i].cp == &lcs_tab2)
7947 {
7948 if (*s == NUL)
7949 continue;
7950#ifdef FEAT_MBYTE
7951 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007952 if (mb_char2cells(c2) > 1)
7953 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954#else
7955 c2 = *s++;
7956#endif
7957 }
7958 if (*s == ',' || *s == NUL)
7959 {
7960 if (round)
7961 {
7962 if (tab[i].cp == &lcs_tab2)
7963 {
7964 lcs_tab1 = c1;
7965 lcs_tab2 = c2;
7966 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007967 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 *(tab[i].cp) = c1;
7969
7970 }
7971 p = s;
7972 break;
7973 }
7974 }
7975 }
7976
7977 if (i == entries)
7978 return e_invarg;
7979 if (*p == ',')
7980 ++p;
7981 }
7982 }
7983
7984 return NULL; /* no error */
7985}
7986
7987#ifdef FEAT_STL_OPT
7988/*
7989 * Check validity of options with the 'statusline' format.
7990 * Return error message or NULL.
7991 */
7992 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007993check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007994{
7995 int itemcnt = 0;
7996 int groupdepth = 0;
7997 static char_u errbuf[80];
7998
7999 while (*s && itemcnt < STL_MAX_ITEM)
8000 {
8001 /* Check for valid keys after % sequences */
8002 while (*s && *s != '%')
8003 s++;
8004 if (!*s)
8005 break;
8006 s++;
8007 if (*s != '%' && *s != ')')
8008 ++itemcnt;
8009 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8010 {
8011 s++;
8012 continue;
8013 }
8014 if (*s == ')')
8015 {
8016 s++;
8017 if (--groupdepth < 0)
8018 break;
8019 continue;
8020 }
8021 if (*s == '-')
8022 s++;
8023 while (VIM_ISDIGIT(*s))
8024 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008025 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026 continue;
8027 if (*s == '.')
8028 {
8029 s++;
8030 while (*s && VIM_ISDIGIT(*s))
8031 s++;
8032 }
8033 if (*s == '(')
8034 {
8035 groupdepth++;
8036 continue;
8037 }
8038 if (vim_strchr(STL_ALL, *s) == NULL)
8039 {
8040 return illegal_char(errbuf, *s);
8041 }
8042 if (*s == '{')
8043 {
8044 s++;
8045 while (*s != '}' && *s)
8046 s++;
8047 if (*s != '}')
8048 return (char_u *)N_("E540: Unclosed expression sequence");
8049 }
8050 }
8051 if (itemcnt >= STL_MAX_ITEM)
8052 return (char_u *)N_("E541: too many items");
8053 if (groupdepth != 0)
8054 return (char_u *)N_("E542: unbalanced groups");
8055 return NULL;
8056}
8057#endif
8058
8059#ifdef FEAT_CLIPBOARD
8060/*
8061 * Extract the items in the 'clipboard' option and set global values.
8062 */
8063 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008064check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008065{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008066 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008067 int new_autoselect_star = FALSE;
8068 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008070 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008071 regprog_T *new_exclude_prog = NULL;
8072 char_u *errmsg = NULL;
8073 char_u *p;
8074
8075 for (p = p_cb; *p != NUL; )
8076 {
8077 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8078 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008079 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008080 p += 7;
8081 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008082 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008083 && (p[11] == ',' || p[11] == NUL))
8084 {
8085 new_unnamed |= CLIP_UNNAMED_PLUS;
8086 p += 11;
8087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008088 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008089 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008091 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008092 p += 10;
8093 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008094 else if (STRNCMP(p, "autoselectplus", 14) == 0
8095 && (p[14] == ',' || p[14] == NUL))
8096 {
8097 new_autoselect_plus = TRUE;
8098 p += 14;
8099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008101 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008102 {
8103 new_autoselectml = TRUE;
8104 p += 12;
8105 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008106 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8107 {
8108 new_html = TRUE;
8109 p += 4;
8110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8112 {
8113 p += 8;
8114 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8115 if (new_exclude_prog == NULL)
8116 errmsg = e_invarg;
8117 break;
8118 }
8119 else
8120 {
8121 errmsg = e_invarg;
8122 break;
8123 }
8124 if (*p == ',')
8125 ++p;
8126 }
8127 if (errmsg == NULL)
8128 {
8129 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008130 clip_autoselect_star = new_autoselect_star;
8131 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008133 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008134 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008136#ifdef FEAT_GUI_GTK
8137 if (gui.in_use)
8138 {
8139 gui_gtk_set_selection_targets();
8140 gui_gtk_set_dnd_targets();
8141 }
8142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 }
8144 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008145 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146
8147 return errmsg;
8148}
8149#endif
8150
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008151#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008152 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008153did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008154{
8155 char_u *errmsg = NULL;
8156 win_T *wp;
8157 int l;
8158
8159 if (is_spellfile)
8160 {
8161 l = (int)STRLEN(curwin->w_s->b_p_spf);
8162 if (l > 0 && (l < 4
8163 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8164 errmsg = e_invarg;
8165 }
8166
8167 if (errmsg == NULL)
8168 {
8169 FOR_ALL_WINDOWS(wp)
8170 if (wp->w_buffer == curbuf && wp->w_p_spell)
8171 {
8172 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008173 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008174 }
8175 }
8176 return errmsg;
8177}
8178
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008179/*
8180 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8181 * Return error message when failed, NULL when OK.
8182 */
8183 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008184compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008185{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008186 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008187 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008188
Bram Moolenaar860cae12010-06-05 23:22:07 +02008189 if (*synblock->b_p_spc == NUL)
8190 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008191 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008192 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008193 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008194 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008195 if (re != NULL)
8196 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008197 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008198 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008199 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008200 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008201 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008202 return e_invarg;
8203 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008204 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008205 }
8206
Bram Moolenaar473de612013-06-08 18:19:48 +02008207 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008208 return NULL;
8209}
8210#endif
8211
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008212#if defined(FEAT_EVAL) || defined(PROTO)
8213/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008214 * Set the scriptID for an option, taking care of setting the buffer- or
8215 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008216 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008217 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008218set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008219{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008220 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8221 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008222
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008223 /* Remember where the option was set. For local options need to do that
8224 * in the buffer or window structure. */
8225 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008226 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008227 if (both || (opt_flags & OPT_LOCAL))
8228 {
8229 if (indir & PV_BUF)
8230 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8231 else if (indir & PV_WIN)
8232 curwin->w_p_scriptID[indir & PV_MASK] = id;
8233 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008234}
8235#endif
8236
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237/*
8238 * Set the value of a boolean option, and take care of side effects.
8239 * Returns NULL for success, or an error message for an error.
8240 */
8241 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008242set_bool_option(
8243 int opt_idx, /* index in options[] table */
8244 char_u *varp, /* pointer to the option variable */
8245 int value, /* new value */
8246 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008247{
8248 int old_value = *(int *)varp;
8249
Bram Moolenaar071d4272004-06-13 20:20:40 +00008250 /* Disallow changing some options from secure mode */
8251 if ((secure
8252#ifdef HAVE_SANDBOX
8253 || sandbox != 0
8254#endif
8255 ) && (options[opt_idx].flags & P_SECURE))
8256 return e_secure;
8257
8258 *(int *)varp = value; /* set the new value */
8259#ifdef FEAT_EVAL
8260 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008261 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008262#endif
8263
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008264#ifdef FEAT_GUI
8265 need_mouse_correct = TRUE;
8266#endif
8267
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268 /* May set global value for local option. */
8269 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8270 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8271
8272 /*
8273 * Handle side effects of changing a bool option.
8274 */
8275
8276 /* 'compatible' */
8277 if ((int *)varp == &p_cp)
8278 {
8279 compatible_set();
8280 }
8281
Bram Moolenaar920694c2016-08-21 17:45:02 +02008282#ifdef FEAT_LANGMAP
8283 if ((int *)varp == &p_lrm)
8284 /* 'langremap' -> !'langnoremap' */
8285 p_lnr = !p_lrm;
8286 else if ((int *)varp == &p_lnr)
8287 /* 'langnoremap' -> !'langremap' */
8288 p_lrm = !p_lnr;
8289#endif
8290
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008291#ifdef FEAT_PERSISTENT_UNDO
8292 /* 'undofile' */
8293 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8294 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008295 /* Only take action when the option was set. When reset we do not
8296 * delete the undo file, the option may be set again without making
8297 * any changes in between. */
8298 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008299 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008300 char_u hash[UNDO_HASH_SIZE];
8301 buf_T *save_curbuf = curbuf;
8302
Bram Moolenaar29323592016-07-24 22:04:11 +02008303 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008304 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008305 /* When 'undofile' is set globally: for every buffer, otherwise
8306 * only for the current buffer: Try to read in the undofile,
8307 * if one exists, the buffer wasn't changed and the buffer was
8308 * loaded */
8309 if ((curbuf == save_curbuf
8310 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8311 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8312 {
8313 u_compute_hash(hash);
8314 u_read_undo(NULL, hash, curbuf->b_fname);
8315 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008316 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008317 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008318 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008319 }
8320#endif
8321
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322 else if ((int *)varp == &curbuf->b_p_ro)
8323 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008324 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008325 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8326 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008327
8328 /* when 'readonly' is set may give W10 again */
8329 if (curbuf->b_p_ro)
8330 curbuf->b_did_warn = FALSE;
8331
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008333 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008334#endif
8335 }
8336
Bram Moolenaar9c449722010-07-20 18:44:27 +02008337#ifdef FEAT_GUI
8338 else if ((int *)varp == &p_mh)
8339 {
8340 if (!p_mh)
8341 gui_mch_mousehide(FALSE);
8342 }
8343#endif
8344
Bram Moolenaara539df02010-08-01 14:35:05 +02008345 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008346 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008347 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008348# ifdef FEAT_TERMINAL
8349 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008350 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8351 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008352 {
8353 curbuf->b_p_ma = FALSE;
8354 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8355 }
8356# endif
8357# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008358 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008359# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008360 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008361#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 /* when 'endofline' is changed, redraw the window title */
8363 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008364 {
8365 redraw_titles();
8366 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008367 /* when 'fixeol' is changed, redraw the window title */
8368 else if ((int *)varp == &curbuf->b_p_fixeol)
8369 {
8370 redraw_titles();
8371 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008372# ifdef FEAT_MBYTE
8373 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008374 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008375 {
8376 redraw_titles();
8377 }
8378# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008379#endif
8380
8381 /* when 'bin' is set also set some other options */
8382 else if ((int *)varp == &curbuf->b_p_bin)
8383 {
8384 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8385#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008386 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387#endif
8388 }
8389
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390 /* when 'buflisted' changes, trigger autocommands */
8391 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8392 {
8393 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8394 NULL, NULL, TRUE, curbuf);
8395 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396
8397 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8398 else if ((int *)varp == &curbuf->b_p_swf)
8399 {
8400 if (curbuf->b_p_swf && p_uc)
8401 ml_open_file(curbuf); /* create the swap file */
8402 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008403 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8404 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 mf_close_file(curbuf, TRUE); /* remove the swap file */
8406 }
8407
8408 /* when 'terse' is set change 'shortmess' */
8409 else if ((int *)varp == &p_terse)
8410 {
8411 char_u *p;
8412
8413 p = vim_strchr(p_shm, SHM_SEARCH);
8414
8415 /* insert 's' in p_shm */
8416 if (p_terse && p == NULL)
8417 {
8418 STRCPY(IObuff, p_shm);
8419 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008420 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 }
8422 /* remove 's' from p_shm */
8423 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008424 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425 }
8426
8427 /* when 'paste' is set or reset also change other options */
8428 else if ((int *)varp == &p_paste)
8429 {
8430 paste_option_changed();
8431 }
8432
8433 /* when 'insertmode' is set from an autocommand need to do work here */
8434 else if ((int *)varp == &p_im)
8435 {
8436 if (p_im)
8437 {
8438 if ((State & INSERT) == 0)
8439 need_start_insertmode = TRUE;
8440 stop_insert_mode = FALSE;
8441 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008442 /* only reset if it was set previously */
8443 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444 {
8445 need_start_insertmode = FALSE;
8446 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008447 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008448 clear_cmdline = TRUE; /* remove "(insert)" */
8449 restart_edit = 0;
8450 }
8451 }
8452
8453 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8454 else if ((int *)varp == &p_ic && p_hls)
8455 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008456 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 }
8458
8459#ifdef FEAT_SEARCH_EXTRA
8460 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8461 else if ((int *)varp == &p_hls)
8462 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008463 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 }
8465#endif
8466
Bram Moolenaar071d4272004-06-13 20:20:40 +00008467 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8468 * at the end of normal_cmd() */
8469 else if ((int *)varp == &curwin->w_p_scb)
8470 {
8471 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008472 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008474 curwin->w_scbind_pos = curwin->w_topline;
8475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008476 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477
Bram Moolenaar4033c552017-09-16 20:54:51 +02008478#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008479 /* There can be only one window with 'previewwindow' set. */
8480 else if ((int *)varp == &curwin->w_p_pvw)
8481 {
8482 if (curwin->w_p_pvw)
8483 {
8484 win_T *win;
8485
Bram Moolenaar29323592016-07-24 22:04:11 +02008486 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008487 if (win->w_p_pvw && win != curwin)
8488 {
8489 curwin->w_p_pvw = FALSE;
8490 return (char_u *)N_("E590: A preview window already exists");
8491 }
8492 }
8493 }
8494#endif
8495
8496 /* when 'textmode' is set or reset also change 'fileformat' */
8497 else if ((int *)varp == &curbuf->b_p_tx)
8498 {
8499 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8500 }
8501
8502 /* when 'textauto' is set or reset also change 'fileformats' */
8503 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008504 set_string_option_direct((char_u *)"ffs", -1,
8505 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008506 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507
8508 /*
8509 * When 'lisp' option changes include/exclude '-' in
8510 * keyword characters.
8511 */
8512#ifdef FEAT_LISP
8513 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8514 {
8515 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8516 }
8517#endif
8518
8519#ifdef FEAT_TITLE
8520 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008521 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008523 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524 }
8525#endif
8526
8527 else if ((int *)varp == &curbuf->b_changed)
8528 {
8529 if (!value)
8530 save_file_ff(curbuf); /* Buffer is unchanged */
8531#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008532 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008534 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008535 }
8536
8537#ifdef BACKSLASH_IN_FILENAME
8538 else if ((int *)varp == &p_ssl)
8539 {
8540 if (p_ssl)
8541 {
8542 psepc = '/';
8543 psepcN = '\\';
8544 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 }
8546 else
8547 {
8548 psepc = '\\';
8549 psepcN = '/';
8550 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551 }
8552
8553 /* need to adjust the file name arguments and buffer names. */
8554 buflist_slash_adjust();
8555 alist_slash_adjust();
8556# ifdef FEAT_EVAL
8557 scriptnames_slash_adjust();
8558# endif
8559 }
8560#endif
8561
8562 /* If 'wrap' is set, set w_leftcol to zero. */
8563 else if ((int *)varp == &curwin->w_p_wrap)
8564 {
8565 if (curwin->w_p_wrap)
8566 curwin->w_leftcol = 0;
8567 }
8568
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569 else if ((int *)varp == &p_ea)
8570 {
8571 if (p_ea && !old_value)
8572 win_equal(curwin, FALSE, 0);
8573 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574
8575 else if ((int *)varp == &p_wiv)
8576 {
8577 /*
8578 * When 'weirdinvert' changed, set/reset 't_xs'.
8579 * Then set 'weirdinvert' according to value of 't_xs'.
8580 */
8581 if (p_wiv && !old_value)
8582 T_XS = (char_u *)"y";
8583 else if (!p_wiv && old_value)
8584 T_XS = empty_option;
8585 p_wiv = (*T_XS != NUL);
8586 }
8587
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008588#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008589 else if ((int *)varp == &p_beval)
8590 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008591 if (!balloonEvalForTerm)
8592 {
8593 if (p_beval && !old_value)
8594 gui_mch_enable_beval_area(balloonEval);
8595 else if (!p_beval && old_value)
8596 gui_mch_disable_beval_area(balloonEval);
8597 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008599#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008600#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008601 else if ((int *)varp == &p_bevalterm)
8602 {
8603 mch_bevalterm_changed();
8604 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008605#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008606
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008607#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608 else if ((int *)varp == &p_acd)
8609 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008610 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008611 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008612 }
8613#endif
8614
8615#ifdef FEAT_DIFF
8616 /* 'diff' */
8617 else if ((int *)varp == &curwin->w_p_diff)
8618 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008619 /* May add or remove the buffer from the list of diff buffers. */
8620 diff_buf_adjust(curwin);
8621# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622 if (foldmethodIsDiff(curwin))
8623 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 }
8626#endif
8627
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008628#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629 /* 'imdisable' */
8630 else if ((int *)varp == &p_imdisable)
8631 {
8632 /* Only de-activate it here, it will be enabled when changing mode. */
8633 if (p_imdisable)
8634 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008635 else if (State & INSERT)
8636 /* When the option is set from an autocommand, it may need to take
8637 * effect right away. */
8638 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 }
8640#endif
8641
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008642#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008643 /* 'spell' */
8644 else if ((int *)varp == &curwin->w_p_spell)
8645 {
8646 if (curwin->w_p_spell)
8647 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008648 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008649 if (errmsg != NULL)
8650 EMSG(_(errmsg));
8651 }
8652 }
8653#endif
8654
Bram Moolenaar071d4272004-06-13 20:20:40 +00008655#ifdef FEAT_FKMAP
8656 else if ((int *)varp == &p_altkeymap)
8657 {
8658 if (old_value != p_altkeymap)
8659 {
8660 if (!p_altkeymap)
8661 {
8662 p_hkmap = p_fkmap;
8663 p_fkmap = 0;
8664 }
8665 else
8666 {
8667 p_fkmap = p_hkmap;
8668 p_hkmap = 0;
8669 }
8670 (void)init_chartab();
8671 }
8672 }
8673
8674 /*
8675 * In case some second language keymapping options have changed, check
8676 * and correct the setting in a consistent way.
8677 */
8678
8679 /*
8680 * If hkmap or fkmap are set, reset Arabic keymapping.
8681 */
8682 if ((p_hkmap || p_fkmap) && p_altkeymap)
8683 {
8684 p_altkeymap = p_fkmap;
8685# ifdef FEAT_ARABIC
8686 curwin->w_p_arab = FALSE;
8687# endif
8688 (void)init_chartab();
8689 }
8690
8691 /*
8692 * If hkmap set, reset Farsi keymapping.
8693 */
8694 if (p_hkmap && p_altkeymap)
8695 {
8696 p_altkeymap = 0;
8697 p_fkmap = 0;
8698# ifdef FEAT_ARABIC
8699 curwin->w_p_arab = FALSE;
8700# endif
8701 (void)init_chartab();
8702 }
8703
8704 /*
8705 * If fkmap set, reset Hebrew keymapping.
8706 */
8707 if (p_fkmap && !p_altkeymap)
8708 {
8709 p_altkeymap = 1;
8710 p_hkmap = 0;
8711# ifdef FEAT_ARABIC
8712 curwin->w_p_arab = FALSE;
8713# endif
8714 (void)init_chartab();
8715 }
8716#endif
8717
8718#ifdef FEAT_ARABIC
8719 if ((int *)varp == &curwin->w_p_arab)
8720 {
8721 if (curwin->w_p_arab)
8722 {
8723 /*
8724 * 'arabic' is set, handle various sub-settings.
8725 */
8726 if (!p_tbidi)
8727 {
8728 /* set rightleft mode */
8729 if (!curwin->w_p_rl)
8730 {
8731 curwin->w_p_rl = TRUE;
8732 changed_window_setting();
8733 }
8734
8735 /* Enable Arabic shaping (major part of what Arabic requires) */
8736 if (!p_arshape)
8737 {
8738 p_arshape = TRUE;
8739 redraw_later_clear();
8740 }
8741 }
8742
8743 /* Arabic requires a utf-8 encoding, inform the user if its not
8744 * set. */
8745 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008746 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008747 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8748
Bram Moolenaar8820b482017-03-16 17:23:31 +01008749 msg_source(HL_ATTR(HLF_W));
8750 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008751#ifdef FEAT_EVAL
8752 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8753#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755
8756# ifdef FEAT_MBYTE
8757 /* set 'delcombine' */
8758 p_deco = TRUE;
8759# endif
8760
8761# ifdef FEAT_KEYMAP
8762 /* Force-set the necessary keymap for arabic */
8763 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8764 OPT_LOCAL);
8765# endif
8766# ifdef FEAT_FKMAP
8767 p_altkeymap = 0;
8768 p_hkmap = 0;
8769 p_fkmap = 0;
8770 (void)init_chartab();
8771# endif
8772 }
8773 else
8774 {
8775 /*
8776 * 'arabic' is reset, handle various sub-settings.
8777 */
8778 if (!p_tbidi)
8779 {
8780 /* reset rightleft mode */
8781 if (curwin->w_p_rl)
8782 {
8783 curwin->w_p_rl = FALSE;
8784 changed_window_setting();
8785 }
8786
8787 /* 'arabicshape' isn't reset, it is a global option and
8788 * another window may still need it "on". */
8789 }
8790
8791 /* 'delcombine' isn't reset, it is a global option and another
8792 * window may still want it "on". */
8793
8794# ifdef FEAT_KEYMAP
8795 /* Revert to the default keymap */
8796 curbuf->b_p_iminsert = B_IMODE_NONE;
8797 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8798# endif
8799 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008800 }
8801
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008802#endif
8803
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008804#ifdef FEAT_TERMGUICOLORS
8805 /* 'termguicolors' */
8806 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008807 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008808# ifdef FEAT_VTP
8809 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8810 if (!has_vtp_working())
8811 {
8812 p_tgc = 0;
8813 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8814 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008815 if (is_term_win32())
8816 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008817# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008818# ifdef FEAT_GUI
8819 if (!gui.in_use && !gui.starting)
8820# endif
8821 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008822# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008823 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008824 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008825 {
8826 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008827 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008828 init_highlight(TRUE, FALSE);
8829 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008830# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008831 }
8832#endif
8833
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 /*
8835 * End of handling side effects for bool options.
8836 */
8837
Bram Moolenaar53744302015-07-17 17:38:22 +02008838 /* after handling side effects, call autocommand */
8839
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 options[opt_idx].flags |= P_WAS_SET;
8841
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008842#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008843 if (!starting)
8844 {
8845 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008846 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8847 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8848 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008849 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8850 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8851 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8852 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8853 reset_v_option_vars();
8854 }
8855#endif
8856
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008858 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008859 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008860 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 check_redraw(options[opt_idx].flags);
8862
8863 return NULL;
8864}
8865
8866/*
8867 * Set the value of a number option, and take care of side effects.
8868 * Returns NULL for success, or an error message for an error.
8869 */
8870 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008871set_num_option(
8872 int opt_idx, /* index in options[] table */
8873 char_u *varp, /* pointer to the option variable */
8874 long value, /* new value */
8875 char_u *errbuf, /* buffer for error messages */
8876 size_t errbuflen, /* length of "errbuf" */
8877 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008878 OPT_MODELINE */
8879{
8880 char_u *errmsg = NULL;
8881 long old_value = *(long *)varp;
8882 long old_Rows = Rows; /* remember old Rows */
8883 long old_Columns = Columns; /* remember old Columns */
8884 long *pp = (long *)varp;
8885
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008886 /* Disallow changing some options from secure mode. */
8887 if ((secure
8888#ifdef HAVE_SANDBOX
8889 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008890#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008891 ) && (options[opt_idx].flags & P_SECURE))
8892 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893
8894 *pp = value;
8895#ifdef FEAT_EVAL
8896 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008897 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008899#ifdef FEAT_GUI
8900 need_mouse_correct = TRUE;
8901#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902
Bram Moolenaar14f24742012-08-08 18:01:05 +02008903 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008904 {
8905 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008906#ifdef FEAT_VARTABS
8907 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8908 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8909 ? tabstop_first(curbuf->b_p_vts_array)
8910 : curbuf->b_p_ts;
8911#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008912 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008913#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008914 }
8915
8916 /*
8917 * Number options that need some action when changed
8918 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919 if (pp == &p_wh || pp == &p_hh)
8920 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008921 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 if (p_wh < 1)
8923 {
8924 errmsg = e_positive;
8925 p_wh = 1;
8926 }
8927 if (p_wmh > p_wh)
8928 {
8929 errmsg = e_winheight;
8930 p_wh = p_wmh;
8931 }
8932 if (p_hh < 0)
8933 {
8934 errmsg = e_positive;
8935 p_hh = 0;
8936 }
8937
8938 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008939 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940 {
8941 if (pp == &p_wh && curwin->w_height < p_wh)
8942 win_setheight((int)p_wh);
8943 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8944 win_setheight((int)p_hh);
8945 }
8946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008947 else if (pp == &p_wmh)
8948 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008949 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008950 if (p_wmh < 0)
8951 {
8952 errmsg = e_positive;
8953 p_wmh = 0;
8954 }
8955 if (p_wmh > p_wh)
8956 {
8957 errmsg = e_winheight;
8958 p_wmh = p_wh;
8959 }
8960 win_setminheight();
8961 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008962 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008964 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 if (p_wiw < 1)
8966 {
8967 errmsg = e_positive;
8968 p_wiw = 1;
8969 }
8970 if (p_wmw > p_wiw)
8971 {
8972 errmsg = e_winwidth;
8973 p_wiw = p_wmw;
8974 }
8975
8976 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008977 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 win_setwidth((int)p_wiw);
8979 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 else if (pp == &p_wmw)
8981 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008982 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008983 if (p_wmw < 0)
8984 {
8985 errmsg = e_positive;
8986 p_wmw = 0;
8987 }
8988 if (p_wmw > p_wiw)
8989 {
8990 errmsg = e_winwidth;
8991 p_wmw = p_wiw;
8992 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008993 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995
Bram Moolenaar071d4272004-06-13 20:20:40 +00008996 /* (re)set last window status line */
8997 else if (pp == &p_ls)
8998 {
8999 last_status(FALSE);
9000 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009001
9002 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009003 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009004 {
9005 shell_new_rows(); /* recompute window positions and heights */
9006 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009007
9008#ifdef FEAT_GUI
9009 else if (pp == &p_linespace)
9010 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009011 /* Recompute gui.char_height and resize the Vim window to keep the
9012 * same number of lines. */
9013 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009014 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009015 }
9016#endif
9017
9018#ifdef FEAT_FOLDING
9019 /* 'foldlevel' */
9020 else if (pp == &curwin->w_p_fdl)
9021 {
9022 if (curwin->w_p_fdl < 0)
9023 curwin->w_p_fdl = 0;
9024 newFoldLevel();
9025 }
9026
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009027 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009028 else if (pp == &curwin->w_p_fml)
9029 {
9030 foldUpdateAll(curwin);
9031 }
9032
9033 /* 'foldnestmax' */
9034 else if (pp == &curwin->w_p_fdn)
9035 {
9036 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9037 foldUpdateAll(curwin);
9038 }
9039
9040 /* 'foldcolumn' */
9041 else if (pp == &curwin->w_p_fdc)
9042 {
9043 if (curwin->w_p_fdc < 0)
9044 {
9045 errmsg = e_positive;
9046 curwin->w_p_fdc = 0;
9047 }
9048 else if (curwin->w_p_fdc > 12)
9049 {
9050 errmsg = e_invarg;
9051 curwin->w_p_fdc = 12;
9052 }
9053 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009054#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009055
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009056#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009057 /* 'shiftwidth' or 'tabstop' */
9058 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9059 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009060# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061 if (foldmethodIsIndent(curwin))
9062 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009063# endif
9064# ifdef FEAT_CINDENT
9065 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9066 * parse 'cinoptions'. */
9067 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9068 parse_cino(curbuf);
9069# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009070 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009073#ifdef FEAT_MBYTE
9074 /* 'maxcombine' */
9075 else if (pp == &p_mco)
9076 {
9077 if (p_mco > MAX_MCO)
9078 p_mco = MAX_MCO;
9079 else if (p_mco < 0)
9080 p_mco = 0;
9081 screenclear(); /* will re-allocate the screen */
9082 }
9083#endif
9084
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085 else if (pp == &curbuf->b_p_iminsert)
9086 {
9087 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9088 {
9089 errmsg = e_invarg;
9090 curbuf->b_p_iminsert = B_IMODE_NONE;
9091 }
9092 p_iminsert = curbuf->b_p_iminsert;
9093 if (termcap_active) /* don't do this in the alternate screen */
9094 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009095#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 /* Show/unshow value of 'keymap' in status lines. */
9097 status_redraw_curbuf();
9098#endif
9099 }
9100
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009101#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9102 /* 'imstyle' */
9103 else if (pp == &p_imst)
9104 {
9105 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9106 errmsg = e_invarg;
9107 }
9108#endif
9109
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009110 else if (pp == &p_window)
9111 {
9112 if (p_window < 1)
9113 p_window = 1;
9114 else if (p_window >= Rows)
9115 p_window = Rows - 1;
9116 }
9117
Bram Moolenaar071d4272004-06-13 20:20:40 +00009118 else if (pp == &curbuf->b_p_imsearch)
9119 {
9120 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9121 {
9122 errmsg = e_invarg;
9123 curbuf->b_p_imsearch = B_IMODE_NONE;
9124 }
9125 p_imsearch = curbuf->b_p_imsearch;
9126 }
9127
9128#ifdef FEAT_TITLE
9129 /* if 'titlelen' has changed, redraw the title */
9130 else if (pp == &p_titlelen)
9131 {
9132 if (p_titlelen < 0)
9133 {
9134 errmsg = e_positive;
9135 p_titlelen = 85;
9136 }
9137 if (starting != NO_SCREEN && old_value != p_titlelen)
9138 need_maketitle = TRUE;
9139 }
9140#endif
9141
9142 /* if p_ch changed value, change the command line height */
9143 else if (pp == &p_ch)
9144 {
9145 if (p_ch < 1)
9146 {
9147 errmsg = e_positive;
9148 p_ch = 1;
9149 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009150 if (p_ch > Rows - min_rows() + 1)
9151 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009152
9153 /* Only compute the new window layout when startup has been
9154 * completed. Otherwise the frame sizes may be wrong. */
9155 if (p_ch != old_value && full_screen
9156#ifdef FEAT_GUI
9157 && !gui.starting
9158#endif
9159 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009160 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009161 }
9162
9163 /* when 'updatecount' changes from zero to non-zero, open swap files */
9164 else if (pp == &p_uc)
9165 {
9166 if (p_uc < 0)
9167 {
9168 errmsg = e_positive;
9169 p_uc = 100;
9170 }
9171 if (p_uc && !old_value)
9172 ml_open_files();
9173 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009174#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009175 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009176 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009177 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009178 {
9179 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009180 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009181 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009182 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009183 {
9184 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009185 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009186 }
9187 }
9188#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009189#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009190 else if (pp == &p_mzq)
9191 mzvim_reset_timer();
9192#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009193
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009194#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9195 /* 'pyxversion' */
9196 else if (pp == &p_pyx)
9197 {
9198 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9199 errmsg = e_invarg;
9200 }
9201#endif
9202
Bram Moolenaar071d4272004-06-13 20:20:40 +00009203 /* sync undo before 'undolevels' changes */
9204 else if (pp == &p_ul)
9205 {
9206 /* use the old value, otherwise u_sync() may not work properly */
9207 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009208 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009209 p_ul = value;
9210 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009211 else if (pp == &curbuf->b_p_ul)
9212 {
9213 /* use the old value, otherwise u_sync() may not work properly */
9214 curbuf->b_p_ul = old_value;
9215 u_sync(TRUE);
9216 curbuf->b_p_ul = value;
9217 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009218
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009219#ifdef FEAT_LINEBREAK
9220 /* 'numberwidth' must be positive */
9221 else if (pp == &curwin->w_p_nuw)
9222 {
9223 if (curwin->w_p_nuw < 1)
9224 {
9225 errmsg = e_positive;
9226 curwin->w_p_nuw = 1;
9227 }
9228 if (curwin->w_p_nuw > 10)
9229 {
9230 errmsg = e_invarg;
9231 curwin->w_p_nuw = 10;
9232 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009233 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009234 }
9235#endif
9236
Bram Moolenaar1a384422010-07-14 19:53:30 +02009237 else if (pp == &curbuf->b_p_tw)
9238 {
9239 if (curbuf->b_p_tw < 0)
9240 {
9241 errmsg = e_positive;
9242 curbuf->b_p_tw = 0;
9243 }
9244#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009245 {
9246 win_T *wp;
9247 tabpage_T *tp;
9248
9249 FOR_ALL_TAB_WINDOWS(tp, wp)
9250 check_colorcolumn(wp);
9251 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009252#endif
9253 }
9254
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 /*
9256 * Check the bounds for numeric options here
9257 */
9258 if (Rows < min_rows() && full_screen)
9259 {
9260 if (errbuf != NULL)
9261 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009262 vim_snprintf((char *)errbuf, errbuflen,
9263 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009264 errmsg = errbuf;
9265 }
9266 Rows = min_rows();
9267 }
9268 if (Columns < MIN_COLUMNS && full_screen)
9269 {
9270 if (errbuf != NULL)
9271 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009272 vim_snprintf((char *)errbuf, errbuflen,
9273 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009274 errmsg = errbuf;
9275 }
9276 Columns = MIN_COLUMNS;
9277 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009278 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280 /*
9281 * If the screen (shell) height has been changed, assume it is the
9282 * physical screenheight.
9283 */
9284 if (old_Rows != Rows || old_Columns != Columns)
9285 {
9286 /* Changing the screen size is not allowed while updating the screen. */
9287 if (updating_screen)
9288 *pp = old_value;
9289 else if (full_screen
9290#ifdef FEAT_GUI
9291 && !gui.starting
9292#endif
9293 )
9294 set_shellsize((int)Columns, (int)Rows, TRUE);
9295 else
9296 {
9297 /* Postpone the resizing; check the size and cmdline position for
9298 * messages. */
9299 check_shellsize();
9300 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9301 cmdline_row = Rows - p_ch;
9302 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009303 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009304 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305 }
9306
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 if (curbuf->b_p_ts <= 0)
9308 {
9309 errmsg = e_positive;
9310 curbuf->b_p_ts = 8;
9311 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312 if (p_tm < 0)
9313 {
9314 errmsg = e_positive;
9315 p_tm = 0;
9316 }
9317 if ((curwin->w_p_scr <= 0
9318 || (curwin->w_p_scr > curwin->w_height
9319 && curwin->w_height > 0))
9320 && full_screen)
9321 {
9322 if (pp == &(curwin->w_p_scr))
9323 {
9324 if (curwin->w_p_scr != 0)
9325 errmsg = e_scroll;
9326 win_comp_scroll(curwin);
9327 }
9328 /* If 'scroll' became invalid because of a side effect silently adjust
9329 * it. */
9330 else if (curwin->w_p_scr <= 0)
9331 curwin->w_p_scr = 1;
9332 else /* curwin->w_p_scr > curwin->w_height */
9333 curwin->w_p_scr = curwin->w_height;
9334 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009335 if (p_hi < 0)
9336 {
9337 errmsg = e_positive;
9338 p_hi = 0;
9339 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009340 else if (p_hi > 10000)
9341 {
9342 errmsg = e_invarg;
9343 p_hi = 10000;
9344 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009345 if (p_re < 0 || p_re > 2)
9346 {
9347 errmsg = e_invarg;
9348 p_re = 0;
9349 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350 if (p_report < 0)
9351 {
9352 errmsg = e_positive;
9353 p_report = 1;
9354 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009355 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356 {
9357 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9358 p_sj = Rows / 2;
9359 else
9360 {
9361 errmsg = e_scroll;
9362 p_sj = 1;
9363 }
9364 }
9365 if (p_so < 0 && full_screen)
9366 {
9367 errmsg = e_scroll;
9368 p_so = 0;
9369 }
9370 if (p_siso < 0 && full_screen)
9371 {
9372 errmsg = e_positive;
9373 p_siso = 0;
9374 }
9375#ifdef FEAT_CMDWIN
9376 if (p_cwh < 1)
9377 {
9378 errmsg = e_positive;
9379 p_cwh = 1;
9380 }
9381#endif
9382 if (p_ut < 0)
9383 {
9384 errmsg = e_positive;
9385 p_ut = 2000;
9386 }
9387 if (p_ss < 0)
9388 {
9389 errmsg = e_positive;
9390 p_ss = 0;
9391 }
9392
9393 /* May set global value for local option. */
9394 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9395 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9396
9397 options[opt_idx].flags |= P_WAS_SET;
9398
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009399#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009400 if (!starting && errmsg == NULL)
9401 {
9402 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009403 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9404 vim_snprintf((char *)buf_new, 10, "%ld", value);
9405 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009406 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9407 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9408 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9409 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9410 reset_v_option_vars();
9411 }
9412#endif
9413
Bram Moolenaar071d4272004-06-13 20:20:40 +00009414 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009415 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009416 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009417 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418 check_redraw(options[opt_idx].flags);
9419
9420 return errmsg;
9421}
9422
9423/*
9424 * Called after an option changed: check if something needs to be redrawn.
9425 */
9426 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009427check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009428{
9429 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009430 int doclear = (flags & P_RCLR) == P_RCLR;
9431 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9434 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009435
9436 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9437 changed_window_setting();
9438 if (flags & P_RBUF)
9439 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009440 if (flags & P_RWINONLY)
9441 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009442 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443 redraw_all_later(CLEAR);
9444 else if (all)
9445 redraw_all_later(NOT_VALID);
9446}
9447
9448/*
9449 * Find index for option 'arg'.
9450 * Return -1 if not found.
9451 */
9452 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009453findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454{
9455 int opt_idx;
9456 char *s, *p;
9457 static short quick_tab[27] = {0, 0}; /* quick access table */
9458 int is_term_opt;
9459
9460 /*
9461 * For first call: Initialize the quick-access table.
9462 * It contains the index for the first option that starts with a certain
9463 * letter. There are 26 letters, plus the first "t_" option.
9464 */
9465 if (quick_tab[1] == 0)
9466 {
9467 p = options[0].fullname;
9468 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9469 {
9470 if (s[0] != p[0])
9471 {
9472 if (s[0] == 't' && s[1] == '_')
9473 quick_tab[26] = opt_idx;
9474 else
9475 quick_tab[CharOrdLow(s[0])] = opt_idx;
9476 }
9477 p = s;
9478 }
9479 }
9480
9481 /*
9482 * Check for name starting with an illegal character.
9483 */
9484#ifdef EBCDIC
9485 if (!islower(arg[0]))
9486#else
9487 if (arg[0] < 'a' || arg[0] > 'z')
9488#endif
9489 return -1;
9490
9491 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9492 if (is_term_opt)
9493 opt_idx = quick_tab[26];
9494 else
9495 opt_idx = quick_tab[CharOrdLow(arg[0])];
9496 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9497 {
9498 if (STRCMP(arg, s) == 0) /* match full name */
9499 break;
9500 }
9501 if (s == NULL && !is_term_opt)
9502 {
9503 opt_idx = quick_tab[CharOrdLow(arg[0])];
9504 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9505 {
9506 s = options[opt_idx].shortname;
9507 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9508 break;
9509 s = NULL;
9510 }
9511 }
9512 if (s == NULL)
9513 opt_idx = -1;
9514 return opt_idx;
9515}
9516
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009517#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009518/*
9519 * Get the value for an option.
9520 *
9521 * Returns:
9522 * Number or Toggle option: 1, *numval gets value.
9523 * String option: 0, *stringval gets allocated string.
9524 * Hidden Number or Toggle option: -1.
9525 * hidden String option: -2.
9526 * unknown option: -3.
9527 */
9528 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009529get_option_value(
9530 char_u *name,
9531 long *numval,
9532 char_u **stringval, /* NULL when only checking existence */
9533 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009534{
9535 int opt_idx;
9536 char_u *varp;
9537
9538 opt_idx = findoption(name);
9539 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009540 {
9541 int key;
9542
9543 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9544 && (key = find_key_option(name)) != 0)
9545 {
9546 char_u key_name[2];
9547 char_u *p;
9548
9549 if (key < 0)
9550 {
9551 key_name[0] = KEY2TERMCAP0(key);
9552 key_name[1] = KEY2TERMCAP1(key);
9553 }
9554 else
9555 {
9556 key_name[0] = KS_KEY;
9557 key_name[1] = (key & 0xff);
9558 }
9559 p = find_termcode(key_name);
9560 if (p != NULL)
9561 {
9562 if (stringval != NULL)
9563 *stringval = vim_strsave(p);
9564 return 0;
9565 }
9566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009568 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009569
9570 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9571
9572 if (options[opt_idx].flags & P_STRING)
9573 {
9574 if (varp == NULL) /* hidden option */
9575 return -2;
9576 if (stringval != NULL)
9577 {
9578#ifdef FEAT_CRYPT
9579 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009580 if ((char_u **)varp == &curbuf->b_p_key
9581 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582 *stringval = vim_strsave((char_u *)"*****");
9583 else
9584#endif
9585 *stringval = vim_strsave(*(char_u **)(varp));
9586 }
9587 return 0;
9588 }
9589
9590 if (varp == NULL) /* hidden option */
9591 return -1;
9592 if (options[opt_idx].flags & P_NUM)
9593 *numval = *(long *)varp;
9594 else
9595 {
9596 /* Special case: 'modified' is b_changed, but we also want to consider
9597 * it set when 'ff' or 'fenc' changed. */
9598 if ((int *)varp == &curbuf->b_changed)
9599 *numval = curbufIsChanged();
9600 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009601 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009602 }
9603 return 1;
9604}
9605#endif
9606
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009607#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009608/*
9609 * Returns the option attributes and its value. Unlike the above function it
9610 * will return either global value or local value of the option depending on
9611 * what was requested, but it will never return global value if it was
9612 * requested to return local one and vice versa. Neither it will return
9613 * buffer-local value if it was requested to return window-local one.
9614 *
9615 * Pretends that option is absent if it is not present in the requested scope
9616 * (i.e. has no global, window-local or buffer-local value depending on
9617 * opt_type). Uses
9618 *
9619 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009620 * 0 hidden or unknown option, also option that does not have requested
9621 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009622 * see SOPT_* in vim.h for other flags
9623 *
9624 * Possible opt_type values: see SREQ_* in vim.h
9625 */
9626 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009627get_option_value_strict(
9628 char_u *name,
9629 long *numval,
9630 char_u **stringval, /* NULL when only obtaining attributes */
9631 int opt_type,
9632 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009633{
9634 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009635 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009636 struct vimoption *p;
9637 int r = 0;
9638
9639 opt_idx = findoption(name);
9640 if (opt_idx < 0)
9641 return 0;
9642
9643 p = &(options[opt_idx]);
9644
9645 /* Hidden option */
9646 if (p->var == NULL)
9647 return 0;
9648
9649 if (p->flags & P_BOOL)
9650 r |= SOPT_BOOL;
9651 else if (p->flags & P_NUM)
9652 r |= SOPT_NUM;
9653 else if (p->flags & P_STRING)
9654 r |= SOPT_STRING;
9655
9656 if (p->indir == PV_NONE)
9657 {
9658 if (opt_type == SREQ_GLOBAL)
9659 r |= SOPT_GLOBAL;
9660 else
9661 return 0; /* Did not request global-only option */
9662 }
9663 else
9664 {
9665 if (p->indir & PV_BOTH)
9666 r |= SOPT_GLOBAL;
9667 else if (opt_type == SREQ_GLOBAL)
9668 return 0; /* Requested global option */
9669
9670 if (p->indir & PV_WIN)
9671 {
9672 if (opt_type == SREQ_BUF)
9673 return 0; /* Did not request window-local option */
9674 else
9675 r |= SOPT_WIN;
9676 }
9677 else if (p->indir & PV_BUF)
9678 {
9679 if (opt_type == SREQ_WIN)
9680 return 0; /* Did not request buffer-local option */
9681 else
9682 r |= SOPT_BUF;
9683 }
9684 }
9685
9686 if (stringval == NULL)
9687 return r;
9688
9689 if (opt_type == SREQ_GLOBAL)
9690 varp = p->var;
9691 else
9692 {
9693 if (opt_type == SREQ_BUF)
9694 {
9695 /* Special case: 'modified' is b_changed, but we also want to
9696 * consider it set when 'ff' or 'fenc' changed. */
9697 if (p->indir == PV_MOD)
9698 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009699 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009700 varp = NULL;
9701 }
9702#ifdef FEAT_CRYPT
9703 else if (p->indir == PV_KEY)
9704 {
9705 /* never return the value of the crypt key */
9706 *stringval = NULL;
9707 varp = NULL;
9708 }
9709#endif
9710 else
9711 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009712 buf_T *save_curbuf = curbuf;
9713
9714 // only getting a pointer, no need to use aucmd_prepbuf()
9715 curbuf = (buf_T *)from;
9716 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009717 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009718 curbuf = save_curbuf;
9719 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009720 }
9721 }
9722 else if (opt_type == SREQ_WIN)
9723 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009724 win_T *save_curwin = curwin;
9725
9726 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009727 curbuf = curwin->w_buffer;
9728 varp = get_varp(p);
9729 curwin = save_curwin;
9730 curbuf = curwin->w_buffer;
9731 }
9732 if (varp == p->var)
9733 return (r | SOPT_UNSET);
9734 }
9735
9736 if (varp != NULL)
9737 {
9738 if (p->flags & P_STRING)
9739 *stringval = vim_strsave(*(char_u **)(varp));
9740 else if (p->flags & P_NUM)
9741 *numval = *(long *) varp;
9742 else
9743 *numval = *(int *)varp;
9744 }
9745
9746 return r;
9747}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009748
9749/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009750 * Iterate over options. First argument is a pointer to a pointer to a
9751 * structure inside options[] array, second is option type like in the above
9752 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009753 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009754 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009755 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009756 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009757 * first argument to NULL.
9758 *
9759 * Returns full option name for current option on each call.
9760 */
9761 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009762option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009763{
9764 struct vimoption *ret = NULL;
9765 do
9766 {
9767 if (*option == NULL)
9768 *option = (void *) options;
9769 else if (((struct vimoption *) (*option))->fullname == NULL)
9770 {
9771 *option = NULL;
9772 return NULL;
9773 }
9774 else
9775 *option = (void *) (((struct vimoption *) (*option)) + 1);
9776
9777 ret = ((struct vimoption *) (*option));
9778
9779 /* Hidden option */
9780 if (ret->var == NULL)
9781 {
9782 ret = NULL;
9783 continue;
9784 }
9785
9786 switch (opt_type)
9787 {
9788 case SREQ_GLOBAL:
9789 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9790 ret = NULL;
9791 break;
9792 case SREQ_BUF:
9793 if (!(ret->indir & PV_BUF))
9794 ret = NULL;
9795 break;
9796 case SREQ_WIN:
9797 if (!(ret->indir & PV_WIN))
9798 ret = NULL;
9799 break;
9800 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009801 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009802 return NULL;
9803 }
9804 }
9805 while (ret == NULL);
9806
9807 return (char_u *)ret->fullname;
9808}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009809#endif
9810
Bram Moolenaar071d4272004-06-13 20:20:40 +00009811/*
9812 * Set the value of option "name".
9813 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009814 *
9815 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009817 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009818set_option_value(
9819 char_u *name,
9820 long number,
9821 char_u *string,
9822 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009823{
9824 int opt_idx;
9825 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009826 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009827
9828 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009829 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009830 {
9831 int key;
9832
9833 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9834 && (key = find_key_option(name)) != 0)
9835 {
9836 char_u key_name[2];
9837
9838 if (key < 0)
9839 {
9840 key_name[0] = KEY2TERMCAP0(key);
9841 key_name[1] = KEY2TERMCAP1(key);
9842 }
9843 else
9844 {
9845 key_name[0] = KS_KEY;
9846 key_name[1] = (key & 0xff);
9847 }
9848 add_termcode(key_name, string, FALSE);
9849 if (full_screen)
9850 ttest(FALSE);
9851 redraw_all_later(CLEAR);
9852 return NULL;
9853 }
9854
Bram Moolenaar071d4272004-06-13 20:20:40 +00009855 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009857 else
9858 {
9859 flags = options[opt_idx].flags;
9860#ifdef HAVE_SANDBOX
9861 /* Disallow changing some options in the sandbox */
9862 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009863 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009864 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009865 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009866 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009867#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009868 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009869 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 else
9871 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009872 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009873 if (varp != NULL) /* hidden option is not changed */
9874 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009875 if (number == 0 && string != NULL)
9876 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009877 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009878
9879 /* Either we are given a string or we are setting option
9880 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009881 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009882 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009883 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009884 {
9885 /* There's another character after zeros or the string
9886 * is empty. In both cases, we are trying to set a
9887 * num option using a string. */
9888 EMSG3(_("E521: Number required: &%s = '%s'"),
9889 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009890 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009891
9892 }
9893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009895 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009896 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009897 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009898 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009899 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009900 }
9901 }
9902 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009903 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009904}
9905
9906/*
9907 * Get the terminal code for a terminal option.
9908 * Returns NULL when not found.
9909 */
9910 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009911get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912{
9913 int opt_idx;
9914 char_u *varp;
9915
9916 if (tname[0] != 't' || tname[1] != '_' ||
9917 tname[2] == NUL || tname[3] == NUL)
9918 return NULL;
9919 if ((opt_idx = findoption(tname)) >= 0)
9920 {
9921 varp = get_varp(&(options[opt_idx]));
9922 if (varp != NULL)
9923 varp = *(char_u **)(varp);
9924 return varp;
9925 }
9926 return find_termcode(tname + 2);
9927}
9928
9929 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009930get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931{
9932 int i;
9933
9934 i = findoption((char_u *)"hl");
9935 if (i >= 0)
9936 return options[i].def_val[VI_DEFAULT];
9937 return (char_u *)NULL;
9938}
9939
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009940#if defined(FEAT_MBYTE) || defined(PROTO)
9941 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009942get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009943{
9944 int i;
9945
9946 i = findoption((char_u *)"enc");
9947 if (i >= 0)
9948 return options[i].def_val[VI_DEFAULT];
9949 return (char_u *)NULL;
9950}
9951#endif
9952
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953/*
9954 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9955 */
9956 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009957find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958{
9959 int key;
9960 int modifiers;
9961
9962 /*
9963 * Don't use get_special_key_code() for t_xx, we don't want it to call
9964 * add_termcap_entry().
9965 */
9966 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9967 key = TERMCAP2KEY(arg[2], arg[3]);
9968 else
9969 {
9970 --arg; /* put arg at the '<' */
9971 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009972 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973 if (modifiers) /* can't handle modifiers here */
9974 key = 0;
9975 }
9976 return key;
9977}
9978
9979/*
9980 * if 'all' == 0: show changed options
9981 * if 'all' == 1: show all normal options
9982 * if 'all' == 2: show all terminal options
9983 */
9984 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009985showoptions(
9986 int all,
9987 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988{
9989 struct vimoption *p;
9990 int col;
9991 int isterm;
9992 char_u *varp;
9993 struct vimoption **items;
9994 int item_count;
9995 int run;
9996 int row, rows;
9997 int cols;
9998 int i;
9999 int len;
10000
10001#define INC 20
10002#define GAP 3
10003
10004 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10005 PARAM_COUNT));
10006 if (items == NULL)
10007 return;
10008
10009 /* Highlight title */
10010 if (all == 2)
10011 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
10012 else if (opt_flags & OPT_GLOBAL)
10013 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
10014 else if (opt_flags & OPT_LOCAL)
10015 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
10016 else
10017 MSG_PUTS_TITLE(_("\n--- Options ---"));
10018
10019 /*
10020 * do the loop two times:
10021 * 1. display the short items
10022 * 2. display the long items (only strings and numbers)
10023 */
10024 for (run = 1; run <= 2 && !got_int; ++run)
10025 {
10026 /*
10027 * collect the items in items[]
10028 */
10029 item_count = 0;
10030 for (p = &options[0]; p->fullname != NULL; p++)
10031 {
10032 varp = NULL;
10033 isterm = istermoption(p);
10034 if (opt_flags != 0)
10035 {
10036 if (p->indir != PV_NONE && !isterm)
10037 varp = get_varp_scope(p, opt_flags);
10038 }
10039 else
10040 varp = get_varp(p);
10041 if (varp != NULL
10042 && ((all == 2 && isterm)
10043 || (all == 1 && !isterm)
10044 || (all == 0 && !optval_default(p, varp))))
10045 {
10046 if (p->flags & P_BOOL)
10047 len = 1; /* a toggle option fits always */
10048 else
10049 {
10050 option_value2string(p, opt_flags);
10051 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10052 }
10053 if ((len <= INC - GAP && run == 1) ||
10054 (len > INC - GAP && run == 2))
10055 items[item_count++] = p;
10056 }
10057 }
10058
10059 /*
10060 * display the items
10061 */
10062 if (run == 1)
10063 {
10064 cols = (Columns + GAP - 3) / INC;
10065 if (cols == 0)
10066 cols = 1;
10067 rows = (item_count + cols - 1) / cols;
10068 }
10069 else /* run == 2 */
10070 rows = item_count;
10071 for (row = 0; row < rows && !got_int; ++row)
10072 {
10073 msg_putchar('\n'); /* go to next line */
10074 if (got_int) /* 'q' typed in more */
10075 break;
10076 col = 0;
10077 for (i = row; i < item_count; i += rows)
10078 {
10079 msg_col = col; /* make columns */
10080 showoneopt(items[i], opt_flags);
10081 col += INC;
10082 }
10083 out_flush();
10084 ui_breakcheck();
10085 }
10086 }
10087 vim_free(items);
10088}
10089
10090/*
10091 * Return TRUE if option "p" has its default value.
10092 */
10093 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010094optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010095{
10096 int dvi;
10097
10098 if (varp == NULL)
10099 return TRUE; /* hidden option is always at default */
10100 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10101 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010102 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010103 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010104 /* the cast to long is required for Manx C, long_i is
10105 * needed for MSVC */
10106 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010107 /* P_STRING */
10108 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10109}
10110
10111/*
10112 * showoneopt: show the value of one option
10113 * must not be called with a hidden option!
10114 */
10115 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010116showoneopt(
10117 struct vimoption *p,
10118 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010120 char_u *varp;
10121 int save_silent = silent_mode;
10122
10123 silent_mode = FALSE;
10124 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125
10126 varp = get_varp_scope(p, opt_flags);
10127
10128 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10129 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10130 ? !curbufIsChanged() : !*(int *)varp))
10131 MSG_PUTS("no");
10132 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10133 MSG_PUTS("--");
10134 else
10135 MSG_PUTS(" ");
10136 MSG_PUTS(p->fullname);
10137 if (!(p->flags & P_BOOL))
10138 {
10139 msg_putchar('=');
10140 /* put value string in NameBuff */
10141 option_value2string(p, opt_flags);
10142 msg_outtrans(NameBuff);
10143 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010144
10145 silent_mode = save_silent;
10146 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147}
10148
10149/*
10150 * Write modified options as ":set" commands to a file.
10151 *
10152 * There are three values for "opt_flags":
10153 * OPT_GLOBAL: Write global option values and fresh values of
10154 * buffer-local options (used for start of a session
10155 * file).
10156 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10157 * curwin (used for a vimrc file).
10158 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10159 * and local values for window-local options of
10160 * curwin. Local values are also written when at the
10161 * default value, because a modeline or autocommand
10162 * may have set them when doing ":edit file" and the
10163 * user has set them back at the default or fresh
10164 * value.
10165 * When "local_only" is TRUE, don't write fresh
10166 * values, only local values (for ":mkview").
10167 * (fresh value = value used for a new buffer or window for a local option).
10168 *
10169 * Return FAIL on error, OK otherwise.
10170 */
10171 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010172makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173{
10174 struct vimoption *p;
10175 char_u *varp; /* currently used value */
10176 char_u *varp_fresh; /* local value */
10177 char_u *varp_local = NULL; /* fresh value */
10178 char *cmd;
10179 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010180 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181
10182 /*
10183 * The options that don't have a default (terminal name, columns, lines)
10184 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010185 * Do the loop over "options[]" twice: once for options with the
10186 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010188 for (pri = 1; pri >= 0; --pri)
10189 {
10190 for (p = &options[0]; !istermoption(p); p++)
10191 if (!(p->flags & P_NO_MKRC)
10192 && !istermoption(p)
10193 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194 {
10195 /* skip global option when only doing locals */
10196 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10197 continue;
10198
10199 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10200 * file, they are always buffer-specific. */
10201 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10202 continue;
10203
10204 /* Global values are only written when not at the default value. */
10205 varp = get_varp_scope(p, opt_flags);
10206 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10207 continue;
10208
10209 round = 2;
10210 if (p->indir != PV_NONE)
10211 {
10212 if (p->var == VAR_WIN)
10213 {
10214 /* skip window-local option when only doing globals */
10215 if (!(opt_flags & OPT_LOCAL))
10216 continue;
10217 /* When fresh value of window-local option is not at the
10218 * default, need to write it too. */
10219 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10220 {
10221 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10222 if (!optval_default(p, varp_fresh))
10223 {
10224 round = 1;
10225 varp_local = varp;
10226 varp = varp_fresh;
10227 }
10228 }
10229 }
10230 }
10231
10232 /* Round 1: fresh value for window-local options.
10233 * Round 2: other values */
10234 for ( ; round <= 2; varp = varp_local, ++round)
10235 {
10236 if (round == 1 || (opt_flags & OPT_GLOBAL))
10237 cmd = "set";
10238 else
10239 cmd = "setlocal";
10240
10241 if (p->flags & P_BOOL)
10242 {
10243 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10244 return FAIL;
10245 }
10246 else if (p->flags & P_NUM)
10247 {
10248 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10249 return FAIL;
10250 }
10251 else /* P_STRING */
10252 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010253 int do_endif = FALSE;
10254
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 /* Don't set 'syntax' and 'filetype' again if the value is
10256 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010257 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010258#if defined(FEAT_SYN_HL)
10259 p->indir == PV_SYN ||
10260#endif
10261 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 {
10263 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10264 *(char_u **)(varp)) < 0
10265 || put_eol(fd) < 0)
10266 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010267 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268 }
10269 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10270 (p->flags & P_EXPAND) != 0) == FAIL)
10271 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010272 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273 {
10274 if (put_line(fd, "endif") == FAIL)
10275 return FAIL;
10276 }
10277 }
10278 }
10279 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010280 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281 return OK;
10282}
10283
10284#if defined(FEAT_FOLDING) || defined(PROTO)
10285/*
10286 * Generate set commands for the local fold options only. Used when
10287 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10288 */
10289 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010290makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010291{
10292 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10293# ifdef FEAT_EVAL
10294 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10295 == FAIL
10296# endif
10297 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10298 == FAIL
10299 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10300 == FAIL
10301 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10302 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10303 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10304 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10305 )
10306 return FAIL;
10307
10308 return OK;
10309}
10310#endif
10311
10312 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010313put_setstring(
10314 FILE *fd,
10315 char *cmd,
10316 char *name,
10317 char_u **valuep,
10318 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319{
10320 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010321 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322
10323 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10324 return FAIL;
10325 if (*valuep != NULL)
10326 {
10327 /* Output 'pastetoggle' as key names. For other
10328 * options some characters have to be escaped with
10329 * CTRL-V or backslash */
10330 if (valuep == &p_pt)
10331 {
10332 s = *valuep;
10333 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010334 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335 return FAIL;
10336 }
10337 else if (expand)
10338 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010339 buf = alloc(MAXPATHL);
10340 if (buf == NULL)
10341 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10343 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010344 {
10345 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010347 }
10348 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349 }
10350 else if (put_escstr(fd, *valuep, 2) == FAIL)
10351 return FAIL;
10352 }
10353 if (put_eol(fd) < 0)
10354 return FAIL;
10355 return OK;
10356}
10357
10358 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010359put_setnum(
10360 FILE *fd,
10361 char *cmd,
10362 char *name,
10363 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010364{
10365 long wc;
10366
10367 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10368 return FAIL;
10369 if (wc_use_keyname((char_u *)valuep, &wc))
10370 {
10371 /* print 'wildchar' and 'wildcharm' as a key name */
10372 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10373 return FAIL;
10374 }
10375 else if (fprintf(fd, "%ld", *valuep) < 0)
10376 return FAIL;
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_setbool(
10384 FILE *fd,
10385 char *cmd,
10386 char *name,
10387 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388{
Bram Moolenaar893de922007-10-02 18:40:57 +000010389 if (value < 0) /* global/local option using global value */
10390 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010391 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10392 || put_eol(fd) < 0)
10393 return FAIL;
10394 return OK;
10395}
10396
10397/*
10398 * Clear all the terminal options.
10399 * If the option has been allocated, free the memory.
10400 * Terminal options are never hidden or indirect.
10401 */
10402 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010403clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010405 /*
10406 * Reset a few things before clearing the old options. This may cause
10407 * outputting a few things that the terminal doesn't understand, but the
10408 * screen will be cleared later, so this is OK.
10409 */
10410#ifdef FEAT_MOUSE_TTY
10411 mch_setmouse(FALSE); /* switch mouse off */
10412#endif
10413#ifdef FEAT_TITLE
10414 mch_restore_title(3); /* restore window titles */
10415#endif
10416#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10417 /* When starting the GUI close the display opened for the clipboard.
10418 * After restoring the title, because that will need the display. */
10419 if (gui.starting)
10420 clear_xterm_clip();
10421#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010422 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010423
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010424 free_termoptions();
10425}
10426
10427 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010428free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010429{
10430 struct vimoption *p;
10431
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432 for (p = &options[0]; p->fullname != NULL; p++)
10433 if (istermoption(p))
10434 {
10435 if (p->flags & P_ALLOCED)
10436 free_string_option(*(char_u **)(p->var));
10437 if (p->flags & P_DEF_ALLOCED)
10438 free_string_option(p->def_val[VI_DEFAULT]);
10439 *(char_u **)(p->var) = empty_option;
10440 p->def_val[VI_DEFAULT] = empty_option;
10441 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10442 }
10443 clear_termcodes();
10444}
10445
10446/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010447 * Free the string for one term option, if it was allocated.
10448 * Set the string to empty_option and clear allocated flag.
10449 * "var" points to the option value.
10450 */
10451 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010452free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010453{
10454 struct vimoption *p;
10455
10456 for (p = &options[0]; p->fullname != NULL; p++)
10457 if (p->var == var)
10458 {
10459 if (p->flags & P_ALLOCED)
10460 free_string_option(*(char_u **)(p->var));
10461 *(char_u **)(p->var) = empty_option;
10462 p->flags &= ~P_ALLOCED;
10463 break;
10464 }
10465}
10466
10467/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010468 * Set the terminal option defaults to the current value.
10469 * Used after setting the terminal name.
10470 */
10471 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010472set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010473{
10474 struct vimoption *p;
10475
10476 for (p = &options[0]; p->fullname != NULL; p++)
10477 {
10478 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10479 {
10480 if (p->flags & P_DEF_ALLOCED)
10481 {
10482 free_string_option(p->def_val[VI_DEFAULT]);
10483 p->flags &= ~P_DEF_ALLOCED;
10484 }
10485 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10486 if (p->flags & P_ALLOCED)
10487 {
10488 p->flags |= P_DEF_ALLOCED;
10489 p->flags &= ~P_ALLOCED; /* don't free the value now */
10490 }
10491 }
10492 }
10493}
10494
10495/*
10496 * return TRUE if 'p' starts with 't_'
10497 */
10498 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010499istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500{
10501 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10502}
10503
10504/*
10505 * Compute columns for ruler and shown command. 'sc_col' is also used to
10506 * decide what the maximum length of a message on the status line can be.
10507 * If there is a status line for the last window, 'sc_col' is independent
10508 * of 'ru_col'.
10509 */
10510
10511#define COL_RULER 17 /* columns needed by standard ruler */
10512
10513 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010514comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010516#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010517 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010518
10519 sc_col = 0;
10520 ru_col = 0;
10521 if (p_ru)
10522 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010523# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010525# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010527# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528 /* no last status line, adjust sc_col */
10529 if (!last_has_status)
10530 sc_col = ru_col;
10531 }
10532 if (p_sc)
10533 {
10534 sc_col += SHOWCMD_COLS;
10535 if (!p_ru || last_has_status) /* no need for separating space */
10536 ++sc_col;
10537 }
10538 sc_col = Columns - sc_col;
10539 ru_col = Columns - ru_col;
10540 if (sc_col <= 0) /* screen too narrow, will become a mess */
10541 sc_col = 1;
10542 if (ru_col <= 0)
10543 ru_col = 1;
10544#else
10545 sc_col = Columns;
10546 ru_col = Columns;
10547#endif
10548}
10549
10550/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010551 * Unset local option value, similar to ":set opt<".
10552 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010553 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010554unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010555{
10556 struct vimoption *p;
10557 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010558 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010559
10560 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010561 if (opt_idx < 0)
10562 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010563 p = &(options[opt_idx]);
10564
10565 switch ((int)p->indir)
10566 {
10567 /* global option with local value: use local value if it's been set */
10568 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010569 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010570 break;
10571 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010572 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010573 break;
10574 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010575 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010576 break;
10577 case PV_AR:
10578 buf->b_p_ar = -1;
10579 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010580 case PV_BKC:
10581 clear_string_option(&buf->b_p_bkc);
10582 buf->b_bkc_flags = 0;
10583 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010584 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010585 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010586 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010587 case PV_TC:
10588 clear_string_option(&buf->b_p_tc);
10589 buf->b_tc_flags = 0;
10590 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010591#ifdef FEAT_FIND_ID
10592 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010593 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010594 break;
10595 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010596 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010597 break;
10598#endif
10599#ifdef FEAT_INS_EXPAND
10600 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010601 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010602 break;
10603 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010604 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010605 break;
10606#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010607 case PV_FP:
10608 clear_string_option(&buf->b_p_fp);
10609 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010610#ifdef FEAT_QUICKFIX
10611 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010612 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010613 break;
10614 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010615 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010616 break;
10617 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010618 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010619 break;
10620#endif
10621#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10622 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010623 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010624 break;
10625#endif
10626#if defined(FEAT_CRYPT)
10627 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010628 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010629 break;
10630#endif
10631#ifdef FEAT_STL_OPT
10632 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010633 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010634 break;
10635#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010636 case PV_UL:
10637 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10638 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010639#ifdef FEAT_LISP
10640 case PV_LW:
10641 clear_string_option(&buf->b_p_lw);
10642 break;
10643#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010644#ifdef FEAT_MBYTE
10645 case PV_MENC:
10646 clear_string_option(&buf->b_p_menc);
10647 break;
10648#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010649 }
10650}
10651
10652/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653 * Get pointer to option variable, depending on local or global scope.
10654 */
10655 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010656get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657{
10658 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10659 {
10660 if (p->var == VAR_WIN)
10661 return (char_u *)GLOBAL_WO(get_varp(p));
10662 return p->var;
10663 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010664 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010665 {
10666 switch ((int)p->indir)
10667 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010668 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010669#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010670 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10671 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10672 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010673#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010674 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10675 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10676 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010677 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010678 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010679 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010681 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10682 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010683#endif
10684#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010685 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10686 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010687#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010688#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10689 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10690#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010691#if defined(FEAT_CRYPT)
10692 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10693#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010694#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010695 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010696#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010697 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010698#ifdef FEAT_LISP
10699 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10700#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010701 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010702#ifdef FEAT_MBYTE
10703 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705 }
10706 return NULL; /* "cannot happen" */
10707 }
10708 return get_varp(p);
10709}
10710
10711/*
10712 * Get pointer to option variable.
10713 */
10714 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010715get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716{
10717 /* hidden option, always return NULL */
10718 if (p->var == NULL)
10719 return NULL;
10720
10721 switch ((int)p->indir)
10722 {
10723 case PV_NONE: return p->var;
10724
10725 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010726 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010728 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010730 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010732 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010733 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010734 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010736 case PV_TC: return *curbuf->b_p_tc != NUL
10737 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010738 case PV_BKC: return *curbuf->b_p_bkc != NUL
10739 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010740#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010741 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010742 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010743 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10745#endif
10746#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010747 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010749 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10751#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010752 case PV_FP: return *curbuf->b_p_fp != NUL
10753 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010755 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010756 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010757 case PV_GP: return *curbuf->b_p_gp != NUL
10758 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10759 case PV_MP: return *curbuf->b_p_mp != NUL
10760 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010762#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10763 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10764 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10765#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010766#if defined(FEAT_CRYPT)
10767 case PV_CM: return *curbuf->b_p_cm != NUL
10768 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10769#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010770#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010771 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010772 ? (char_u *)&(curwin->w_p_stl) : p->var;
10773#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010774 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10775 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010776#ifdef FEAT_LISP
10777 case PV_LW: return *curbuf->b_p_lw != NUL
10778 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10779#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010780#ifdef FEAT_MBYTE
10781 case PV_MENC: return *curbuf->b_p_menc != NUL
10782 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10783#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010784
10785#ifdef FEAT_ARABIC
10786 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10787#endif
10788 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010789#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010790 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10791#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010792#ifdef FEAT_SYN_HL
10793 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10794 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010795 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797#ifdef FEAT_DIFF
10798 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10799#endif
10800#ifdef FEAT_FOLDING
10801 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10802 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10803 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10804 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10805 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10806 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10807 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10808# ifdef FEAT_EVAL
10809 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10810 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10811# endif
10812 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10813#endif
10814 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010815 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010816#ifdef FEAT_LINEBREAK
10817 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10818#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010820 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010821#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10823#endif
10824#ifdef FEAT_RIGHTLEFT
10825 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10826 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10827#endif
10828 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10829 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10830#ifdef FEAT_LINEBREAK
10831 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010832 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10833 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010836 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010837#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010838 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10839 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10840#endif
10841#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010842 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10843 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10844 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846
10847 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10848 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10849#ifdef FEAT_MBYTE
10850 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10851#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10853 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10855 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10856#ifdef FEAT_CINDENT
10857 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10858 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10859 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10860#endif
10861#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10862 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10863#endif
10864#ifdef FEAT_COMMENTS
10865 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10866#endif
10867#ifdef FEAT_FOLDING
10868 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10869#endif
10870#ifdef FEAT_INS_EXPAND
10871 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10872#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010873#ifdef FEAT_COMPL_FUNC
10874 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010875 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010876#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010877 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010878 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10880#ifdef FEAT_MBYTE
10881 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10882#endif
10883 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010885 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010886 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10888 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10889 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10890 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10891#ifdef FEAT_FIND_ID
10892# ifdef FEAT_EVAL
10893 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10894# endif
10895#endif
10896#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10897 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10898 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10899#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010900#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010901 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10902#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010903#ifdef FEAT_CRYPT
10904 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10905#endif
10906#ifdef FEAT_LISP
10907 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10908#endif
10909 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10910 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10911 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10912 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10913 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010915#ifdef FEAT_TEXTOBJ
10916 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10917#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10919#ifdef FEAT_SMARTINDENT
10920 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10921#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10924#ifdef FEAT_SEARCHPATH
10925 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10926#endif
10927 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10928#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010929 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010930 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10931#endif
10932#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010933 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10934 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10935 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936#endif
10937 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10938 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10939 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10940 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010941#ifdef FEAT_PERSISTENT_UNDO
10942 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10943#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10945#ifdef FEAT_KEYMAP
10946 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10947#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010948#ifdef FEAT_SIGNS
10949 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10950#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020010951#ifdef FEAT_VARTABS
10952 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
10953 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
10954#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010955 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010956 }
10957 /* always return a valid pointer to avoid a crash! */
10958 return (char_u *)&(curbuf->b_p_wm);
10959}
10960
10961/*
10962 * Get the value of 'equalprg', either the buffer-local one or the global one.
10963 */
10964 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010965get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010966{
10967 if (*curbuf->b_p_ep == NUL)
10968 return p_ep;
10969 return curbuf->b_p_ep;
10970}
10971
Bram Moolenaar071d4272004-06-13 20:20:40 +000010972/*
10973 * Copy options from one window to another.
10974 * Used when splitting a window.
10975 */
10976 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010977win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010978{
10979 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10980 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10981# ifdef FEAT_RIGHTLEFT
10982# ifdef FEAT_FKMAP
10983 /* Is this right? */
10984 wp_to->w_farsi = wp_from->w_farsi;
10985# endif
10986# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010987#if defined(FEAT_LINEBREAK)
10988 briopt_check(wp_to);
10989#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010991
10992/*
10993 * Copy the options from one winopt_T to another.
10994 * Doesn't free the old option values in "to", use clear_winopt() for that.
10995 * The 'scroll' option is not copied, because it depends on the window height.
10996 * The 'previewwindow' option is reset, there can be only one preview window.
10997 */
10998 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010999copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011000{
11001#ifdef FEAT_ARABIC
11002 to->wo_arab = from->wo_arab;
11003#endif
11004 to->wo_list = from->wo_list;
11005 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011006 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011007#ifdef FEAT_LINEBREAK
11008 to->wo_nuw = from->wo_nuw;
11009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010#ifdef FEAT_RIGHTLEFT
11011 to->wo_rl = from->wo_rl;
11012 to->wo_rlc = vim_strsave(from->wo_rlc);
11013#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011014#ifdef FEAT_STL_OPT
11015 to->wo_stl = vim_strsave(from->wo_stl);
11016#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011017 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011018#ifdef FEAT_DIFF
11019 to->wo_wrap_save = from->wo_wrap_save;
11020#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011021#ifdef FEAT_LINEBREAK
11022 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011023 to->wo_bri = from->wo_bri;
11024 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011026 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011027 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011028 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011029 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011030#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011031 to->wo_spell = from->wo_spell;
11032#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011033#ifdef FEAT_SYN_HL
11034 to->wo_cuc = from->wo_cuc;
11035 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011036 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011037#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038#ifdef FEAT_DIFF
11039 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011040 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011041#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011042#ifdef FEAT_CONCEAL
11043 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011044 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011045#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011046#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011047 to->wo_twk = vim_strsave(from->wo_twk);
11048 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011050#ifdef FEAT_FOLDING
11051 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011052 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011053 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011054 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055 to->wo_fdi = vim_strsave(from->wo_fdi);
11056 to->wo_fml = from->wo_fml;
11057 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011058 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011059 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011060 to->wo_fdm_save = from->wo_diff_saved
11061 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011062 to->wo_fdn = from->wo_fdn;
11063# ifdef FEAT_EVAL
11064 to->wo_fde = vim_strsave(from->wo_fde);
11065 to->wo_fdt = vim_strsave(from->wo_fdt);
11066# endif
11067 to->wo_fmr = vim_strsave(from->wo_fmr);
11068#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011069#ifdef FEAT_SIGNS
11070 to->wo_scl = vim_strsave(from->wo_scl);
11071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072 check_winopt(to); /* don't want NULL pointers */
11073}
11074
11075/*
11076 * Check string options in a window for a NULL value.
11077 */
11078 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011079check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080{
11081 check_winopt(&win->w_onebuf_opt);
11082 check_winopt(&win->w_allbuf_opt);
11083}
11084
11085/*
11086 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11087 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011088 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011089check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011090{
11091#ifdef FEAT_FOLDING
11092 check_string_option(&wop->wo_fdi);
11093 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011094 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095# ifdef FEAT_EVAL
11096 check_string_option(&wop->wo_fde);
11097 check_string_option(&wop->wo_fdt);
11098# endif
11099 check_string_option(&wop->wo_fmr);
11100#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011101#ifdef FEAT_SIGNS
11102 check_string_option(&wop->wo_scl);
11103#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104#ifdef FEAT_RIGHTLEFT
11105 check_string_option(&wop->wo_rlc);
11106#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011107#ifdef FEAT_STL_OPT
11108 check_string_option(&wop->wo_stl);
11109#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011110#ifdef FEAT_SYN_HL
11111 check_string_option(&wop->wo_cc);
11112#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011113#ifdef FEAT_CONCEAL
11114 check_string_option(&wop->wo_cocu);
11115#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011116#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011117 check_string_option(&wop->wo_twk);
11118 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011119#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011120#ifdef FEAT_LINEBREAK
11121 check_string_option(&wop->wo_briopt);
11122#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011123}
11124
11125/*
11126 * Free the allocated memory inside a winopt_T.
11127 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011128 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011129clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130{
11131#ifdef FEAT_FOLDING
11132 clear_string_option(&wop->wo_fdi);
11133 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011134 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011135# ifdef FEAT_EVAL
11136 clear_string_option(&wop->wo_fde);
11137 clear_string_option(&wop->wo_fdt);
11138# endif
11139 clear_string_option(&wop->wo_fmr);
11140#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011141#ifdef FEAT_SIGNS
11142 clear_string_option(&wop->wo_scl);
11143#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011144#ifdef FEAT_LINEBREAK
11145 clear_string_option(&wop->wo_briopt);
11146#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147#ifdef FEAT_RIGHTLEFT
11148 clear_string_option(&wop->wo_rlc);
11149#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011150#ifdef FEAT_STL_OPT
11151 clear_string_option(&wop->wo_stl);
11152#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011153#ifdef FEAT_SYN_HL
11154 clear_string_option(&wop->wo_cc);
11155#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011156#ifdef FEAT_CONCEAL
11157 clear_string_option(&wop->wo_cocu);
11158#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011159#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011160 clear_string_option(&wop->wo_twk);
11161 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011162#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011163}
11164
11165/*
11166 * Copy global option values to local options for one buffer.
11167 * Used when creating a new buffer and sometimes when entering a buffer.
11168 * flags:
11169 * BCO_ENTER We will enter the buf buffer.
11170 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11171 * appropriate.
11172 * BCO_NOHELP Don't copy the values to a help buffer.
11173 */
11174 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011175buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011176{
11177 int should_copy = TRUE;
11178 char_u *save_p_isk = NULL; /* init for GCC */
11179 int dont_do_help;
11180 int did_isk = FALSE;
11181
11182 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011183 * Skip this when the option defaults have not been set yet. Happens when
11184 * main() allocates the first buffer.
11185 */
11186 if (p_cpo != NULL)
11187 {
11188 /*
11189 * Always copy when entering and 'cpo' contains 'S'.
11190 * Don't copy when already initialized.
11191 * Don't copy when 'cpo' contains 's' and not entering.
11192 * 'S' BCO_ENTER initialized 's' should_copy
11193 * yes yes X X TRUE
11194 * yes no yes X FALSE
11195 * no X yes X FALSE
11196 * X no no yes FALSE
11197 * X no no no TRUE
11198 * no yes no X TRUE
11199 */
11200 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11201 && (buf->b_p_initialized
11202 || (!(flags & BCO_ENTER)
11203 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11204 should_copy = FALSE;
11205
11206 if (should_copy || (flags & BCO_ALWAYS))
11207 {
11208 /* Don't copy the options specific to a help buffer when
11209 * BCO_NOHELP is given or the options were initialized already
11210 * (jumping back to a help file with CTRL-T or CTRL-O) */
11211 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11212 || buf->b_p_initialized;
11213 if (dont_do_help) /* don't free b_p_isk */
11214 {
11215 save_p_isk = buf->b_p_isk;
11216 buf->b_p_isk = NULL;
11217 }
11218 /*
11219 * Always free the allocated strings.
11220 * If not already initialized, set 'readonly' and copy 'fileformat'.
11221 */
11222 if (!buf->b_p_initialized)
11223 {
11224 free_buf_options(buf, TRUE);
11225 buf->b_p_ro = FALSE; /* don't copy readonly */
11226 buf->b_p_tx = p_tx;
11227#ifdef FEAT_MBYTE
11228 buf->b_p_fenc = vim_strsave(p_fenc);
11229#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011230 switch (*p_ffs)
11231 {
11232 case 'm':
11233 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11234 case 'd':
11235 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11236 case 'u':
11237 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11238 default:
11239 buf->b_p_ff = vim_strsave(p_ff);
11240 }
11241 if (buf->b_p_ff != NULL)
11242 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011243 buf->b_p_bh = empty_option;
11244 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245 }
11246 else
11247 free_buf_options(buf, FALSE);
11248
11249 buf->b_p_ai = p_ai;
11250 buf->b_p_ai_nopaste = p_ai_nopaste;
11251 buf->b_p_sw = p_sw;
11252 buf->b_p_tw = p_tw;
11253 buf->b_p_tw_nopaste = p_tw_nopaste;
11254 buf->b_p_tw_nobin = p_tw_nobin;
11255 buf->b_p_wm = p_wm;
11256 buf->b_p_wm_nopaste = p_wm_nopaste;
11257 buf->b_p_wm_nobin = p_wm_nobin;
11258 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011259#ifdef FEAT_MBYTE
11260 buf->b_p_bomb = p_bomb;
11261#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011262 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011263 buf->b_p_et = p_et;
11264 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011265 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266 buf->b_p_ml = p_ml;
11267 buf->b_p_ml_nobin = p_ml_nobin;
11268 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011269 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011270#ifdef FEAT_INS_EXPAND
11271 buf->b_p_cpt = vim_strsave(p_cpt);
11272#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011273#ifdef FEAT_COMPL_FUNC
11274 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011275 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011276#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277 buf->b_p_sts = p_sts;
11278 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011279#ifdef FEAT_VARTABS
11280 buf->b_p_vsts = vim_strsave(p_vsts);
11281 if (p_vsts && p_vsts != empty_option)
11282 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11283 else
11284 buf->b_p_vsts_array = 0;
11285 buf->b_p_vsts_nopaste = p_vsts_nopaste
11286 ? vim_strsave(p_vsts_nopaste) : NULL;
11287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011289#ifdef FEAT_COMMENTS
11290 buf->b_p_com = vim_strsave(p_com);
11291#endif
11292#ifdef FEAT_FOLDING
11293 buf->b_p_cms = vim_strsave(p_cms);
11294#endif
11295 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011296 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297 buf->b_p_nf = vim_strsave(p_nf);
11298 buf->b_p_mps = vim_strsave(p_mps);
11299#ifdef FEAT_SMARTINDENT
11300 buf->b_p_si = p_si;
11301#endif
11302 buf->b_p_ci = p_ci;
11303#ifdef FEAT_CINDENT
11304 buf->b_p_cin = p_cin;
11305 buf->b_p_cink = vim_strsave(p_cink);
11306 buf->b_p_cino = vim_strsave(p_cino);
11307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308 /* Don't copy 'filetype', it must be detected */
11309 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310 buf->b_p_pi = p_pi;
11311#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11312 buf->b_p_cinw = vim_strsave(p_cinw);
11313#endif
11314#ifdef FEAT_LISP
11315 buf->b_p_lisp = p_lisp;
11316#endif
11317#ifdef FEAT_SYN_HL
11318 /* Don't copy 'syntax', it must be set */
11319 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011320 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011321 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011322#endif
11323#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011324 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011325 (void)compile_cap_prog(&buf->b_s);
11326 buf->b_s.b_p_spf = vim_strsave(p_spf);
11327 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328#endif
11329#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11330 buf->b_p_inde = vim_strsave(p_inde);
11331 buf->b_p_indk = vim_strsave(p_indk);
11332#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011333 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011334#if defined(FEAT_EVAL)
11335 buf->b_p_fex = vim_strsave(p_fex);
11336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011337#ifdef FEAT_CRYPT
11338 buf->b_p_key = vim_strsave(p_key);
11339#endif
11340#ifdef FEAT_SEARCHPATH
11341 buf->b_p_sua = vim_strsave(p_sua);
11342#endif
11343#ifdef FEAT_KEYMAP
11344 buf->b_p_keymap = vim_strsave(p_keymap);
11345 buf->b_kmap_state |= KEYMAP_INIT;
11346#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011347#ifdef FEAT_TERMINAL
11348 buf->b_p_twsl = p_twsl;
11349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350 /* This isn't really an option, but copying the langmap and IME
11351 * state from the current buffer is better than resetting it. */
11352 buf->b_p_iminsert = p_iminsert;
11353 buf->b_p_imsearch = p_imsearch;
11354
11355 /* options that are normally global but also have a local value
11356 * are not copied, start using the global value */
11357 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011358 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011359 buf->b_p_bkc = empty_option;
11360 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011361#ifdef FEAT_QUICKFIX
11362 buf->b_p_gp = empty_option;
11363 buf->b_p_mp = empty_option;
11364 buf->b_p_efm = empty_option;
11365#endif
11366 buf->b_p_ep = empty_option;
11367 buf->b_p_kp = empty_option;
11368 buf->b_p_path = empty_option;
11369 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011370 buf->b_p_tc = empty_option;
11371 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372#ifdef FEAT_FIND_ID
11373 buf->b_p_def = empty_option;
11374 buf->b_p_inc = empty_option;
11375# ifdef FEAT_EVAL
11376 buf->b_p_inex = vim_strsave(p_inex);
11377# endif
11378#endif
11379#ifdef FEAT_INS_EXPAND
11380 buf->b_p_dict = empty_option;
11381 buf->b_p_tsr = empty_option;
11382#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011383#ifdef FEAT_TEXTOBJ
11384 buf->b_p_qe = vim_strsave(p_qe);
11385#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011386#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11387 buf->b_p_bexpr = empty_option;
11388#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011389#if defined(FEAT_CRYPT)
11390 buf->b_p_cm = empty_option;
11391#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011392#ifdef FEAT_PERSISTENT_UNDO
11393 buf->b_p_udf = p_udf;
11394#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011395#ifdef FEAT_LISP
11396 buf->b_p_lw = empty_option;
11397#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011398#ifdef FEAT_MBYTE
11399 buf->b_p_menc = empty_option;
11400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401
11402 /*
11403 * Don't copy the options set by ex_help(), use the saved values,
11404 * when going from a help buffer to a non-help buffer.
11405 * Don't touch these at all when BCO_NOHELP is used and going from
11406 * or to a help buffer.
11407 */
11408 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011409 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011411#ifdef FEAT_VARTABS
11412 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11413 tabstop_set(p_vts, &buf->b_p_vts_array);
11414 else
11415 buf->b_p_vts_array = NULL;
11416#endif
11417 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011418 else
11419 {
11420 buf->b_p_isk = vim_strsave(p_isk);
11421 did_isk = TRUE;
11422 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011423#ifdef FEAT_VARTABS
11424 buf->b_p_vts = vim_strsave(p_vts);
11425 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11426 tabstop_set(p_vts, &buf->b_p_vts_array);
11427 else
11428 buf->b_p_vts_array = NULL;
11429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011430 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431 if (buf->b_p_bt[0] == 'h')
11432 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433 buf->b_p_ma = p_ma;
11434 }
11435 }
11436
11437 /*
11438 * When the options should be copied (ignoring BCO_ALWAYS), set the
11439 * flag that indicates that the options have been initialized.
11440 */
11441 if (should_copy)
11442 buf->b_p_initialized = TRUE;
11443 }
11444
11445 check_buf_options(buf); /* make sure we don't have NULLs */
11446 if (did_isk)
11447 (void)buf_init_chartab(buf, FALSE);
11448}
11449
11450/*
11451 * Reset the 'modifiable' option and its default value.
11452 */
11453 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011454reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011455{
11456 int opt_idx;
11457
11458 curbuf->b_p_ma = FALSE;
11459 p_ma = FALSE;
11460 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011461 if (opt_idx >= 0)
11462 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011463}
11464
11465/*
11466 * Set the global value for 'iminsert' to the local value.
11467 */
11468 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011469set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011470{
11471 p_iminsert = curbuf->b_p_iminsert;
11472}
11473
11474/*
11475 * Set the global value for 'imsearch' to the local value.
11476 */
11477 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011478set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011479{
11480 p_imsearch = curbuf->b_p_imsearch;
11481}
11482
11483#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11484static int expand_option_idx = -1;
11485static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11486static int expand_option_flags = 0;
11487
11488 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011489set_context_in_set_cmd(
11490 expand_T *xp,
11491 char_u *arg,
11492 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011493{
11494 int nextchar;
11495 long_u flags = 0; /* init for GCC */
11496 int opt_idx = 0; /* init for GCC */
11497 char_u *p;
11498 char_u *s;
11499 int is_term_option = FALSE;
11500 int key;
11501
11502 expand_option_flags = opt_flags;
11503
11504 xp->xp_context = EXPAND_SETTINGS;
11505 if (*arg == NUL)
11506 {
11507 xp->xp_pattern = arg;
11508 return;
11509 }
11510 p = arg + STRLEN(arg) - 1;
11511 if (*p == ' ' && *(p - 1) != '\\')
11512 {
11513 xp->xp_pattern = p + 1;
11514 return;
11515 }
11516 while (p > arg)
11517 {
11518 s = p;
11519 /* count number of backslashes before ' ' or ',' */
11520 if (*p == ' ' || *p == ',')
11521 {
11522 while (s > arg && *(s - 1) == '\\')
11523 --s;
11524 }
11525 /* break at a space with an even number of backslashes */
11526 if (*p == ' ' && ((p - s) & 1) == 0)
11527 {
11528 ++p;
11529 break;
11530 }
11531 --p;
11532 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011533 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 {
11535 xp->xp_context = EXPAND_BOOL_SETTINGS;
11536 p += 2;
11537 }
11538 if (STRNCMP(p, "inv", 3) == 0)
11539 {
11540 xp->xp_context = EXPAND_BOOL_SETTINGS;
11541 p += 3;
11542 }
11543 xp->xp_pattern = arg = p;
11544 if (*arg == '<')
11545 {
11546 while (*p != '>')
11547 if (*p++ == NUL) /* expand terminal option name */
11548 return;
11549 key = get_special_key_code(arg + 1);
11550 if (key == 0) /* unknown name */
11551 {
11552 xp->xp_context = EXPAND_NOTHING;
11553 return;
11554 }
11555 nextchar = *++p;
11556 is_term_option = TRUE;
11557 expand_option_name[2] = KEY2TERMCAP0(key);
11558 expand_option_name[3] = KEY2TERMCAP1(key);
11559 }
11560 else
11561 {
11562 if (p[0] == 't' && p[1] == '_')
11563 {
11564 p += 2;
11565 if (*p != NUL)
11566 ++p;
11567 if (*p == NUL)
11568 return; /* expand option name */
11569 nextchar = *++p;
11570 is_term_option = TRUE;
11571 expand_option_name[2] = p[-2];
11572 expand_option_name[3] = p[-1];
11573 }
11574 else
11575 {
11576 /* Allow * wildcard */
11577 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11578 p++;
11579 if (*p == NUL)
11580 return;
11581 nextchar = *p;
11582 *p = NUL;
11583 opt_idx = findoption(arg);
11584 *p = nextchar;
11585 if (opt_idx == -1 || options[opt_idx].var == NULL)
11586 {
11587 xp->xp_context = EXPAND_NOTHING;
11588 return;
11589 }
11590 flags = options[opt_idx].flags;
11591 if (flags & P_BOOL)
11592 {
11593 xp->xp_context = EXPAND_NOTHING;
11594 return;
11595 }
11596 }
11597 }
11598 /* handle "-=" and "+=" */
11599 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11600 {
11601 ++p;
11602 nextchar = '=';
11603 }
11604 if ((nextchar != '=' && nextchar != ':')
11605 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11606 {
11607 xp->xp_context = EXPAND_UNSUCCESSFUL;
11608 return;
11609 }
11610 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11611 {
11612 xp->xp_context = EXPAND_OLD_SETTING;
11613 if (is_term_option)
11614 expand_option_idx = -1;
11615 else
11616 expand_option_idx = opt_idx;
11617 xp->xp_pattern = p + 1;
11618 return;
11619 }
11620 xp->xp_context = EXPAND_NOTHING;
11621 if (is_term_option || (flags & P_NUM))
11622 return;
11623
11624 xp->xp_pattern = p + 1;
11625
11626 if (flags & P_EXPAND)
11627 {
11628 p = options[opt_idx].var;
11629 if (p == (char_u *)&p_bdir
11630 || p == (char_u *)&p_dir
11631 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011632 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633 || p == (char_u *)&p_rtp
11634#ifdef FEAT_SEARCHPATH
11635 || p == (char_u *)&p_cdpath
11636#endif
11637#ifdef FEAT_SESSION
11638 || p == (char_u *)&p_vdir
11639#endif
11640 )
11641 {
11642 xp->xp_context = EXPAND_DIRECTORIES;
11643 if (p == (char_u *)&p_path
11644#ifdef FEAT_SEARCHPATH
11645 || p == (char_u *)&p_cdpath
11646#endif
11647 )
11648 xp->xp_backslash = XP_BS_THREE;
11649 else
11650 xp->xp_backslash = XP_BS_ONE;
11651 }
11652 else
11653 {
11654 xp->xp_context = EXPAND_FILES;
11655 /* for 'tags' need three backslashes for a space */
11656 if (p == (char_u *)&p_tags)
11657 xp->xp_backslash = XP_BS_THREE;
11658 else
11659 xp->xp_backslash = XP_BS_ONE;
11660 }
11661 }
11662
11663 /* For an option that is a list of file names, find the start of the
11664 * last file name. */
11665 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11666 {
11667 /* count number of backslashes before ' ' or ',' */
11668 if (*p == ' ' || *p == ',')
11669 {
11670 s = p;
11671 while (s > xp->xp_pattern && *(s - 1) == '\\')
11672 --s;
11673 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11674 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11675 {
11676 xp->xp_pattern = p + 1;
11677 break;
11678 }
11679 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011680
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011681#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011682 /* for 'spellsuggest' start at "file:" */
11683 if (options[opt_idx].var == (char_u *)&p_sps
11684 && STRNCMP(p, "file:", 5) == 0)
11685 {
11686 xp->xp_pattern = p + 5;
11687 break;
11688 }
11689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011690 }
11691
11692 return;
11693}
11694
11695 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011696ExpandSettings(
11697 expand_T *xp,
11698 regmatch_T *regmatch,
11699 int *num_file,
11700 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701{
11702 int num_normal = 0; /* Nr of matching non-term-code settings */
11703 int num_term = 0; /* Nr of matching terminal code settings */
11704 int opt_idx;
11705 int match;
11706 int count = 0;
11707 char_u *str;
11708 int loop;
11709 int is_term_opt;
11710 char_u name_buf[MAX_KEY_NAME_LEN];
11711 static char *(names[]) = {"all", "termcap"};
11712 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11713
11714 /* do this loop twice:
11715 * loop == 0: count the number of matching options
11716 * loop == 1: copy the matching options into allocated memory
11717 */
11718 for (loop = 0; loop <= 1; ++loop)
11719 {
11720 regmatch->rm_ic = ic;
11721 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11722 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011723 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11724 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011725 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11726 {
11727 if (loop == 0)
11728 num_normal++;
11729 else
11730 (*file)[count++] = vim_strsave((char_u *)names[match]);
11731 }
11732 }
11733 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11734 opt_idx++)
11735 {
11736 if (options[opt_idx].var == NULL)
11737 continue;
11738 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11739 && !(options[opt_idx].flags & P_BOOL))
11740 continue;
11741 is_term_opt = istermoption(&options[opt_idx]);
11742 if (is_term_opt && num_normal > 0)
11743 continue;
11744 match = FALSE;
11745 if (vim_regexec(regmatch, str, (colnr_T)0)
11746 || (options[opt_idx].shortname != NULL
11747 && vim_regexec(regmatch,
11748 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11749 match = TRUE;
11750 else if (is_term_opt)
11751 {
11752 name_buf[0] = '<';
11753 name_buf[1] = 't';
11754 name_buf[2] = '_';
11755 name_buf[3] = str[2];
11756 name_buf[4] = str[3];
11757 name_buf[5] = '>';
11758 name_buf[6] = NUL;
11759 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11760 {
11761 match = TRUE;
11762 str = name_buf;
11763 }
11764 }
11765 if (match)
11766 {
11767 if (loop == 0)
11768 {
11769 if (is_term_opt)
11770 num_term++;
11771 else
11772 num_normal++;
11773 }
11774 else
11775 (*file)[count++] = vim_strsave(str);
11776 }
11777 }
11778 /*
11779 * Check terminal key codes, these are not in the option table
11780 */
11781 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11782 {
11783 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11784 {
11785 if (!isprint(str[0]) || !isprint(str[1]))
11786 continue;
11787
11788 name_buf[0] = 't';
11789 name_buf[1] = '_';
11790 name_buf[2] = str[0];
11791 name_buf[3] = str[1];
11792 name_buf[4] = NUL;
11793
11794 match = FALSE;
11795 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11796 match = TRUE;
11797 else
11798 {
11799 name_buf[0] = '<';
11800 name_buf[1] = 't';
11801 name_buf[2] = '_';
11802 name_buf[3] = str[0];
11803 name_buf[4] = str[1];
11804 name_buf[5] = '>';
11805 name_buf[6] = NUL;
11806
11807 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11808 match = TRUE;
11809 }
11810 if (match)
11811 {
11812 if (loop == 0)
11813 num_term++;
11814 else
11815 (*file)[count++] = vim_strsave(name_buf);
11816 }
11817 }
11818
11819 /*
11820 * Check special key names.
11821 */
11822 regmatch->rm_ic = TRUE; /* ignore case here */
11823 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11824 {
11825 name_buf[0] = '<';
11826 STRCPY(name_buf + 1, str);
11827 STRCAT(name_buf, ">");
11828
11829 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11830 {
11831 if (loop == 0)
11832 num_term++;
11833 else
11834 (*file)[count++] = vim_strsave(name_buf);
11835 }
11836 }
11837 }
11838 if (loop == 0)
11839 {
11840 if (num_normal > 0)
11841 *num_file = num_normal;
11842 else if (num_term > 0)
11843 *num_file = num_term;
11844 else
11845 return OK;
11846 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11847 if (*file == NULL)
11848 {
11849 *file = (char_u **)"";
11850 return FAIL;
11851 }
11852 }
11853 }
11854 return OK;
11855}
11856
11857 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011858ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859{
11860 char_u *var = NULL; /* init for GCC */
11861 char_u *buf;
11862
11863 *num_file = 0;
11864 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11865 if (*file == NULL)
11866 return FAIL;
11867
11868 /*
11869 * For a terminal key code expand_option_idx is < 0.
11870 */
11871 if (expand_option_idx < 0)
11872 {
11873 var = find_termcode(expand_option_name + 2);
11874 if (var == NULL)
11875 expand_option_idx = findoption(expand_option_name);
11876 }
11877
11878 if (expand_option_idx >= 0)
11879 {
11880 /* put string of option value in NameBuff */
11881 option_value2string(&options[expand_option_idx], expand_option_flags);
11882 var = NameBuff;
11883 }
11884 else if (var == NULL)
11885 var = (char_u *)"";
11886
11887 /* A backslash is required before some characters. This is the reverse of
11888 * what happens in do_set(). */
11889 buf = vim_strsave_escaped(var, escape_chars);
11890
11891 if (buf == NULL)
11892 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011893 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011894 return FAIL;
11895 }
11896
11897#ifdef BACKSLASH_IN_FILENAME
11898 /* For MS-Windows et al. we don't double backslashes at the start and
11899 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011900 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901 if (var[0] == '\\' && var[1] == '\\'
11902 && expand_option_idx >= 0
11903 && (options[expand_option_idx].flags & P_EXPAND)
11904 && vim_isfilec(var[2])
11905 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011906 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907#endif
11908
11909 *file[0] = buf;
11910 *num_file = 1;
11911 return OK;
11912}
11913#endif
11914
11915/*
11916 * Get the value for the numeric or string option *opp in a nice format into
11917 * NameBuff[]. Must not be called with a hidden option!
11918 */
11919 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011920option_value2string(
11921 struct vimoption *opp,
11922 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011923{
11924 char_u *varp;
11925
11926 varp = get_varp_scope(opp, opt_flags);
11927
11928 if (opp->flags & P_NUM)
11929 {
11930 long wc = 0;
11931
11932 if (wc_use_keyname(varp, &wc))
11933 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11934 else if (wc != 0)
11935 STRCPY(NameBuff, transchar((int)wc));
11936 else
11937 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11938 }
11939 else /* P_STRING */
11940 {
11941 varp = *(char_u **)(varp);
11942 if (varp == NULL) /* just in case */
11943 NameBuff[0] = NUL;
11944#ifdef FEAT_CRYPT
11945 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011946 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947 STRCPY(NameBuff, "*****");
11948#endif
11949 else if (opp->flags & P_EXPAND)
11950 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11951 /* Translate 'pastetoggle' into special key names */
11952 else if ((char_u **)opp->var == &p_pt)
11953 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11954 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011955 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956 }
11957}
11958
11959/*
11960 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11961 * printed as a keyname.
11962 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11963 */
11964 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011965wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011966{
11967 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11968 {
11969 *wcp = *(long *)varp;
11970 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11971 return TRUE;
11972 }
11973 return FALSE;
11974}
11975
Bram Moolenaar01615492015-02-03 13:00:38 +010011976#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011978 * Any character has an equivalent 'langmap' character. This is used for
11979 * keyboards that have a special language mode that sends characters above
11980 * 128 (although other characters can be translated too). The "to" field is a
11981 * Vim command character. This avoids having to switch the keyboard back to
11982 * ASCII mode when leaving Insert mode.
11983 *
11984 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11985 * commands.
11986 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11987 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11988 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011989 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011990# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011991/*
11992 * With multi-byte support use growarray for 'langmap' chars >= 256
11993 */
11994typedef struct
11995{
11996 int from;
11997 int to;
11998} langmap_entry_T;
11999
12000static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010012001static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002
12003/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012004 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12005 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012006 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012007 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012008langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012009{
12010 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012011 int a = 0;
12012 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012013
12014 /* Do a binary search for an existing entry. */
12015 while (a != b)
12016 {
12017 int i = (a + b) / 2;
12018 int d = entries[i].from - from;
12019
12020 if (d == 0)
12021 {
12022 entries[i].to = to;
12023 return;
12024 }
12025 if (d < 0)
12026 a = i + 1;
12027 else
12028 b = i;
12029 }
12030
12031 if (ga_grow(&langmap_mapga, 1) != OK)
12032 return; /* out of memory */
12033
12034 /* insert new entry at position "a" */
12035 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12036 mch_memmove(entries + 1, entries,
12037 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12038 ++langmap_mapga.ga_len;
12039 entries[0].from = from;
12040 entries[0].to = to;
12041}
12042
12043/*
12044 * Apply 'langmap' to multi-byte character "c" and return the result.
12045 */
12046 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012047langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012048{
12049 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12050 int a = 0;
12051 int b = langmap_mapga.ga_len;
12052
12053 while (a != b)
12054 {
12055 int i = (a + b) / 2;
12056 int d = entries[i].from - c;
12057
12058 if (d == 0)
12059 return entries[i].to; /* found matching entry */
12060 if (d < 0)
12061 a = i + 1;
12062 else
12063 b = i;
12064 }
12065 return c; /* no entry found, return "c" unmodified */
12066}
12067# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068
12069 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012070langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012071{
12072 int i;
12073
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012074 for (i = 0; i < 256; i++)
12075 langmap_mapchar[i] = i; /* we init with a one-to-one map */
12076# ifdef FEAT_MBYTE
12077 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
12078# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012079}
12080
12081/*
12082 * Called when langmap option is set; the language map can be
12083 * changed at any time!
12084 */
12085 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012086langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087{
12088 char_u *p;
12089 char_u *p2;
12090 int from, to;
12091
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012092#ifdef FEAT_MBYTE
12093 ga_clear(&langmap_mapga); /* clear the previous map first */
12094#endif
12095 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012096
12097 for (p = p_langmap; p[0] != NUL; )
12098 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012099 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012100 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012101 {
12102 if (p2[0] == '\\' && p2[1] != NUL)
12103 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012104 }
12105 if (p2[0] == ';')
12106 ++p2; /* abcd;ABCD form, p2 points to A */
12107 else
12108 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12109 while (p[0])
12110 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012111 if (p[0] == ',')
12112 {
12113 ++p;
12114 break;
12115 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012116 if (p[0] == '\\' && p[1] != NUL)
12117 ++p;
12118#ifdef FEAT_MBYTE
12119 from = (*mb_ptr2char)(p);
12120#else
12121 from = p[0];
12122#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012123 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012124 if (p2 == NULL)
12125 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012126 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012127 if (p[0] != ',')
12128 {
12129 if (p[0] == '\\')
12130 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012131#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012132 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012133#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012134 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012135#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137 }
12138 else
12139 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012140 if (p2[0] != ',')
12141 {
12142 if (p2[0] == '\\')
12143 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012144#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012145 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012147 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012150 }
12151 if (to == NUL)
12152 {
12153 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12154 transchar(from));
12155 return;
12156 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012157
12158#ifdef FEAT_MBYTE
12159 if (from >= 256)
12160 langmap_set_entry(from, to);
12161 else
12162#endif
12163 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164
12165 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012166 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012167 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012169 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170 if (*p == ';')
12171 {
12172 p = p2;
12173 if (p[0] != NUL)
12174 {
12175 if (p[0] != ',')
12176 {
12177 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12178 return;
12179 }
12180 ++p;
12181 }
12182 break;
12183 }
12184 }
12185 }
12186 }
12187}
12188#endif
12189
12190/*
12191 * Return TRUE if format option 'x' is in effect.
12192 * Take care of no formatting when 'paste' is set.
12193 */
12194 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012195has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196{
12197 if (p_paste)
12198 return FALSE;
12199 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12200}
12201
12202/*
12203 * Return TRUE if "x" is present in 'shortmess' option, or
12204 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12205 */
12206 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012207shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012208{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012209 return p_shm != NULL &&
12210 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211 || (vim_strchr(p_shm, 'a') != NULL
12212 && vim_strchr((char_u *)SHM_A, x) != NULL));
12213}
12214
12215/*
12216 * paste_option_changed() - Called after p_paste was set or reset.
12217 */
12218 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012219paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012220{
12221 static int old_p_paste = FALSE;
12222 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012223 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012224#ifdef FEAT_CMDL_INFO
12225 static int save_ru = 0;
12226#endif
12227#ifdef FEAT_RIGHTLEFT
12228 static int save_ri = 0;
12229 static int save_hkmap = 0;
12230#endif
12231 buf_T *buf;
12232
12233 if (p_paste)
12234 {
12235 /*
12236 * Paste switched from off to on.
12237 * Save the current values, so they can be restored later.
12238 */
12239 if (!old_p_paste)
12240 {
12241 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012242 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012243 {
12244 buf->b_p_tw_nopaste = buf->b_p_tw;
12245 buf->b_p_wm_nopaste = buf->b_p_wm;
12246 buf->b_p_sts_nopaste = buf->b_p_sts;
12247 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012248 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012249#ifdef FEAT_VARTABS
12250 if (buf->b_p_vsts_nopaste)
12251 vim_free(buf->b_p_vsts_nopaste);
12252 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12253 ? vim_strsave(buf->b_p_vsts) : NULL;
12254#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012255 }
12256
12257 /* save global options */
12258 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012259 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012260#ifdef FEAT_CMDL_INFO
12261 save_ru = p_ru;
12262#endif
12263#ifdef FEAT_RIGHTLEFT
12264 save_ri = p_ri;
12265 save_hkmap = p_hkmap;
12266#endif
12267 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012268 p_ai_nopaste = p_ai;
12269 p_et_nopaste = p_et;
12270 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012271 p_tw_nopaste = p_tw;
12272 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012273#ifdef FEAT_VARTABS
12274 if (p_vsts_nopaste)
12275 vim_free(p_vsts_nopaste);
12276 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12277#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278 }
12279
12280 /*
12281 * Always set the option values, also when 'paste' is set when it is
12282 * already on.
12283 */
12284 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012285 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012286 {
12287 buf->b_p_tw = 0; /* textwidth is 0 */
12288 buf->b_p_wm = 0; /* wrapmargin is 0 */
12289 buf->b_p_sts = 0; /* softtabstop is 0 */
12290 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012291 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012292#ifdef FEAT_VARTABS
12293 if (buf->b_p_vsts)
12294 free_string_option(buf->b_p_vsts);
12295 buf->b_p_vsts = empty_option;
12296 if (buf->b_p_vsts_array)
12297 vim_free(buf->b_p_vsts_array);
12298 buf->b_p_vsts_array = 0;
12299#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012300 }
12301
12302 /* set global options */
12303 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012304 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306 if (p_ru)
12307 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012308 p_ru = 0; /* no ruler */
12309#endif
12310#ifdef FEAT_RIGHTLEFT
12311 p_ri = 0; /* no reverse insert */
12312 p_hkmap = 0; /* no Hebrew keyboard */
12313#endif
12314 /* set global values for local buffer options */
12315 p_tw = 0;
12316 p_wm = 0;
12317 p_sts = 0;
12318 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012319#ifdef FEAT_VARTABS
12320 if (p_vsts)
12321 free_string_option(p_vsts);
12322 p_vsts = empty_option;
12323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012324 }
12325
12326 /*
12327 * Paste switched from on to off: Restore saved values.
12328 */
12329 else if (old_p_paste)
12330 {
12331 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012332 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012333 {
12334 buf->b_p_tw = buf->b_p_tw_nopaste;
12335 buf->b_p_wm = buf->b_p_wm_nopaste;
12336 buf->b_p_sts = buf->b_p_sts_nopaste;
12337 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012338 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012339#ifdef FEAT_VARTABS
12340 if (buf->b_p_vsts)
12341 free_string_option(buf->b_p_vsts);
12342 buf->b_p_vsts = buf->b_p_vsts_nopaste
12343 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12344 if (buf->b_p_vsts_array)
12345 vim_free(buf->b_p_vsts_array);
12346 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12347 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12348 else
12349 buf->b_p_vsts_array = 0;
12350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012351 }
12352
12353 /* restore global options */
12354 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012355 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012356#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012357 if (p_ru != save_ru)
12358 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012359 p_ru = save_ru;
12360#endif
12361#ifdef FEAT_RIGHTLEFT
12362 p_ri = save_ri;
12363 p_hkmap = save_hkmap;
12364#endif
12365 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012366 p_ai = p_ai_nopaste;
12367 p_et = p_et_nopaste;
12368 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012369 p_tw = p_tw_nopaste;
12370 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012371#ifdef FEAT_VARTABS
12372 if (p_vsts)
12373 free_string_option(p_vsts);
12374 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012376 }
12377
12378 old_p_paste = p_paste;
12379}
12380
12381/*
12382 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12383 *
12384 * Reset 'compatible' and set the values for options that didn't get set yet
12385 * to the Vim defaults.
12386 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012387 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012388 */
12389 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012390vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012391{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012392 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012393 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012394 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012395
12396 if (!option_was_set((char_u *)"cp"))
12397 {
12398 p_cp = FALSE;
12399 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12400 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12401 set_option_default(opt_idx, OPT_FREE, FALSE);
12402 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012403 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012404 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012405
12406 if (fname != NULL)
12407 {
12408 p = vim_getenv(envname, &dofree);
12409 if (p == NULL)
12410 {
12411 /* Set $MYVIMRC to the first vimrc file found. */
12412 p = FullName_save(fname, FALSE);
12413 if (p != NULL)
12414 {
12415 vim_setenv(envname, p);
12416 vim_free(p);
12417 }
12418 }
12419 else if (dofree)
12420 vim_free(p);
12421 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422}
12423
12424/*
12425 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12426 */
12427 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012428change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012429{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012430 int opt_idx;
12431
Bram Moolenaar071d4272004-06-13 20:20:40 +000012432 if (p_cp != on)
12433 {
12434 p_cp = on;
12435 compatible_set();
12436 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012437 opt_idx = findoption((char_u *)"cp");
12438 if (opt_idx >= 0)
12439 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440}
12441
12442/*
12443 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012444 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445 */
12446 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012447option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012448{
12449 int idx;
12450
12451 idx = findoption(name);
12452 if (idx < 0) /* unknown option */
12453 return FALSE;
12454 if (options[idx].flags & P_WAS_SET)
12455 return TRUE;
12456 return FALSE;
12457}
12458
12459/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012460 * Reset the flag indicating option "name" was set.
12461 */
12462 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012463reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012464{
12465 int idx = findoption(name);
12466
12467 if (idx >= 0)
12468 options[idx].flags &= ~P_WAS_SET;
12469}
12470
12471/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472 * compatible_set() - Called when 'compatible' has been set or unset.
12473 *
12474 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12475 * flag) to a Vi compatible value.
12476 * When 'compatible' is unset: Set all options that have a different default
12477 * for Vim (without the P_VI_DEF flag) to that default.
12478 */
12479 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012480compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012481{
12482 int opt_idx;
12483
12484 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12485 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12486 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12487 set_option_default(opt_idx, OPT_FREE, p_cp);
12488 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012489 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012490}
12491
12492#ifdef FEAT_LINEBREAK
12493
12494# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12495 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012496 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012497# endif
12498
12499/*
12500 * fill_breakat_flags() -- called when 'breakat' changes value.
12501 */
12502 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012503fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012504{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012505 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012506 int i;
12507
12508 for (i = 0; i < 256; i++)
12509 breakat_flags[i] = FALSE;
12510
12511 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012512 for (p = p_breakat; *p; p++)
12513 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012514}
12515
12516# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012517 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012518# endif
12519
12520#endif
12521
12522/*
12523 * Check an option that can be a range of string values.
12524 *
12525 * Return OK for correct value, FAIL otherwise.
12526 * Empty is always OK.
12527 */
12528 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012529check_opt_strings(
12530 char_u *val,
12531 char **values,
12532 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012533{
12534 return opt_strings_flags(val, values, NULL, list);
12535}
12536
12537/*
12538 * Handle an option that can be a range of string values.
12539 * Set a flag in "*flagp" for each string present.
12540 *
12541 * Return OK for correct value, FAIL otherwise.
12542 * Empty is always OK.
12543 */
12544 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012545opt_strings_flags(
12546 char_u *val, /* new value */
12547 char **values, /* array of valid string values */
12548 unsigned *flagp,
12549 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012550{
12551 int i;
12552 int len;
12553 unsigned new_flags = 0;
12554
12555 while (*val)
12556 {
12557 for (i = 0; ; ++i)
12558 {
12559 if (values[i] == NULL) /* val not found in values[] */
12560 return FAIL;
12561
12562 len = (int)STRLEN(values[i]);
12563 if (STRNCMP(values[i], val, len) == 0
12564 && ((list && val[len] == ',') || val[len] == NUL))
12565 {
12566 val += len + (val[len] == ',');
12567 new_flags |= (1 << i);
12568 break; /* check next item in val list */
12569 }
12570 }
12571 }
12572 if (flagp != NULL)
12573 *flagp = new_flags;
12574
12575 return OK;
12576}
12577
12578/*
12579 * Read the 'wildmode' option, fill wim_flags[].
12580 */
12581 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012582check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012583{
12584 char_u new_wim_flags[4];
12585 char_u *p;
12586 int i;
12587 int idx = 0;
12588
12589 for (i = 0; i < 4; ++i)
12590 new_wim_flags[i] = 0;
12591
12592 for (p = p_wim; *p; ++p)
12593 {
12594 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12595 ;
12596 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12597 return FAIL;
12598 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12599 new_wim_flags[idx] |= WIM_LONGEST;
12600 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12601 new_wim_flags[idx] |= WIM_FULL;
12602 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12603 new_wim_flags[idx] |= WIM_LIST;
12604 else
12605 return FAIL;
12606 p += i;
12607 if (*p == NUL)
12608 break;
12609 if (*p == ',')
12610 {
12611 if (idx == 3)
12612 return FAIL;
12613 ++idx;
12614 }
12615 }
12616
12617 /* fill remaining entries with last flag */
12618 while (idx < 3)
12619 {
12620 new_wim_flags[idx + 1] = new_wim_flags[idx];
12621 ++idx;
12622 }
12623
12624 /* only when there are no errors, wim_flags[] is changed */
12625 for (i = 0; i < 4; ++i)
12626 wim_flags[i] = new_wim_flags[i];
12627 return OK;
12628}
12629
12630/*
12631 * Check if backspacing over something is allowed.
12632 */
12633 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012634can_bs(
12635 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012636{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012637#ifdef FEAT_JOB_CHANNEL
12638 if (what == BS_START && bt_prompt(curbuf))
12639 return FALSE;
12640#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012641 switch (*p_bs)
12642 {
12643 case '2': return TRUE;
12644 case '1': return (what != BS_START);
12645 case '0': return FALSE;
12646 }
12647 return vim_strchr(p_bs, what) != NULL;
12648}
12649
12650/*
12651 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12652 * the file must be considered changed when the value is different.
12653 */
12654 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012655save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012656{
12657 buf->b_start_ffc = *buf->b_p_ff;
12658 buf->b_start_eol = buf->b_p_eol;
12659#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012660 buf->b_start_bomb = buf->b_p_bomb;
12661
Bram Moolenaar071d4272004-06-13 20:20:40 +000012662 /* Only use free/alloc when necessary, they take time. */
12663 if (buf->b_start_fenc == NULL
12664 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12665 {
12666 vim_free(buf->b_start_fenc);
12667 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12668 }
12669#endif
12670}
12671
12672/*
12673 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12674 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012675 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12676 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012677 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012678 * When "ignore_empty" is true don't consider a new, empty buffer to be
12679 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012680 */
12681 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012682file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012683{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012684 /* In a buffer that was never loaded the options are not valid. */
12685 if (buf->b_flags & BF_NEVERLOADED)
12686 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012687 if (ignore_empty
12688 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012689 && buf->b_ml.ml_line_count == 1
12690 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12691 return FALSE;
12692 if (buf->b_start_ffc != *buf->b_p_ff)
12693 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012694 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012695 return TRUE;
12696#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012697 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12698 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012699 if (buf->b_start_fenc == NULL)
12700 return (*buf->b_p_fenc != NUL);
12701 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12702#else
12703 return FALSE;
12704#endif
12705}
12706
12707/*
12708 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12709 */
12710 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012711check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012712{
12713 return check_opt_strings(p, p_ff_values, FALSE);
12714}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012715
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012716#ifdef FEAT_VARTABS
12717
12718/*
12719 * Set the integer values corresponding to the string setting of 'vartabstop'.
12720 */
12721 int
12722tabstop_set(char_u *var, int **array)
12723{
12724 int valcount = 1;
12725 int t;
12726 char_u *cp;
12727
12728 if ((!var[0] || (var[0] == '0' && !var[1])))
12729 {
12730 *array = NULL;
12731 return TRUE;
12732 }
12733
12734 for (cp = var; *cp; ++cp)
12735 {
12736 if (cp == var || *(cp - 1) == ',')
12737 {
12738 char_u *end;
12739 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12740 {
12741 if (cp != end)
12742 EMSG(_(e_positive));
12743 else
12744 EMSG(_(e_invarg));
12745 return FALSE;
12746 }
12747 }
12748
12749 if (VIM_ISDIGIT(*cp))
12750 continue;
12751 if (*cp == ',' && cp > var && *(cp - 1) != ',')
12752 {
12753 ++valcount;
12754 continue;
12755 }
12756 EMSG(_(e_invarg));
12757 return FALSE;
12758 }
12759
12760 *array = (int *) alloc((unsigned) ((valcount + 1) * sizeof(int)));
12761 (*array)[0] = valcount;
12762
12763 t = 1;
12764 for (cp = var; *cp;)
12765 {
12766 (*array)[t++] = atoi((char *)cp);
12767 while (*cp && *cp != ',')
12768 ++cp;
12769 if (*cp)
12770 ++cp;
12771 }
12772
12773 return TRUE;
12774}
12775
12776/*
12777 * Calculate the number of screen spaces a tab will occupy.
12778 * If "vts" is set then the tab widths are taken from that array,
12779 * otherwise the value of ts is used.
12780 */
12781 int
12782tabstop_padding(colnr_T col, int ts_arg, int *vts)
12783{
12784 int ts = ts_arg == 0 ? 8 : ts_arg;
12785 int tabcount;
12786 colnr_T tabcol = 0;
12787 int t;
12788 int padding = 0;
12789
12790 if (vts == NULL || vts[0] == 0)
12791 return ts - (col % ts);
12792
12793 tabcount = vts[0];
12794
12795 for (t = 1; t <= tabcount; ++t)
12796 {
12797 tabcol += vts[t];
12798 if (tabcol > col)
12799 {
12800 padding = (int)(tabcol - col);
12801 break;
12802 }
12803 }
12804 if (t > tabcount)
12805 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12806
12807 return padding;
12808}
12809
12810/*
12811 * Find the size of the tab that covers a particular column.
12812 */
12813 int
12814tabstop_at(colnr_T col, int ts, int *vts)
12815{
12816 int tabcount;
12817 colnr_T tabcol = 0;
12818 int t;
12819 int tab_size = 0;
12820
12821 if (vts == 0 || vts[0] == 0)
12822 return ts;
12823
12824 tabcount = vts[0];
12825 for (t = 1; t <= tabcount; ++t)
12826 {
12827 tabcol += vts[t];
12828 if (tabcol > col)
12829 {
12830 tab_size = vts[t];
12831 break;
12832 }
12833 }
12834 if (t > tabcount)
12835 tab_size = vts[tabcount];
12836
12837 return tab_size;
12838}
12839
12840/*
12841 * Find the column on which a tab starts.
12842 */
12843 colnr_T
12844tabstop_start(colnr_T col, int ts, int *vts)
12845{
12846 int tabcount;
12847 colnr_T tabcol = 0;
12848 int t;
12849 int excess;
12850
Bram Moolenaar0119a592018-06-24 23:53:28 +020012851 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012852 return (col / ts) * ts;
12853
12854 tabcount = vts[0];
12855 for (t = 1; t <= tabcount; ++t)
12856 {
12857 tabcol += vts[t];
12858 if (tabcol > col)
12859 return tabcol - vts[t];
12860 }
12861
12862 excess = tabcol % vts[tabcount];
12863 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12864}
12865
12866/*
12867 * Find the number of tabs and spaces necessary to get from one column
12868 * to another.
12869 */
12870 void
12871tabstop_fromto(
12872 colnr_T start_col,
12873 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012874 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012875 int *vts,
12876 int *ntabs,
12877 int *nspcs)
12878{
12879 int spaces = end_col - start_col;
12880 colnr_T tabcol = 0;
12881 int padding = 0;
12882 int tabcount;
12883 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012884 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012885
Bram Moolenaar0119a592018-06-24 23:53:28 +020012886 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012887 {
12888 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012889 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012890
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012891 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012892 if (spaces >= initspc)
12893 {
12894 spaces -= initspc;
12895 tabs++;
12896 }
12897 tabs += spaces / ts;
12898 spaces -= (spaces / ts) * ts;
12899
12900 *ntabs = tabs;
12901 *nspcs = spaces;
12902 return;
12903 }
12904
12905 /* Find the padding needed to reach the next tabstop. */
12906 tabcount = vts[0];
12907 for (t = 1; t <= tabcount; ++t)
12908 {
12909 tabcol += vts[t];
12910 if (tabcol > start_col)
12911 {
12912 padding = (int)(tabcol - start_col);
12913 break;
12914 }
12915 }
12916 if (t > tabcount)
12917 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12918
12919 /* If the space needed is less than the padding no tabs can be used. */
12920 if (spaces < padding)
12921 {
12922 *ntabs = 0;
12923 *nspcs = spaces;
12924 return;
12925 }
12926
12927 *ntabs = 1;
12928 spaces -= padding;
12929
12930 /* At least one tab has been used. See if any more will fit. */
12931 while (spaces != 0 && ++t <= tabcount)
12932 {
12933 padding = vts[t];
12934 if (spaces < padding)
12935 {
12936 *nspcs = spaces;
12937 return;
12938 }
12939 ++*ntabs;
12940 spaces -= padding;
12941 }
12942
12943 *ntabs += spaces / vts[tabcount];
12944 *nspcs = spaces % vts[tabcount];
12945}
12946
12947/*
12948 * See if two tabstop arrays contain the same values.
12949 */
12950 int
12951tabstop_eq(int *ts1, int *ts2)
12952{
12953 int t;
12954
12955 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
12956 return FALSE;
12957 if (ts1 == ts2)
12958 return TRUE;
12959 if (ts1[0] != ts2[0])
12960 return FALSE;
12961
12962 for (t = 1; t <= ts1[0]; ++t)
12963 if (ts1[t] != ts2[t])
12964 return FALSE;
12965
12966 return TRUE;
12967}
12968
12969/*
12970 * Copy a tabstop array, allocating space for the new array.
12971 */
12972 int *
12973tabstop_copy(int *oldts)
12974{
12975 int *newts;
12976 int t;
12977
12978 if (oldts == 0)
12979 return 0;
12980
12981 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
12982 for (t = 0; t <= oldts[0]; ++t)
12983 newts[t] = oldts[t];
12984
12985 return newts;
12986}
12987
12988/*
12989 * Return a count of the number of tabstops.
12990 */
12991 int
12992tabstop_count(int *ts)
12993{
12994 return ts != NULL ? ts[0] : 0;
12995}
12996
12997/*
12998 * Return the first tabstop, or 8 if there are no tabstops defined.
12999 */
13000 int
13001tabstop_first(int *ts)
13002{
13003 return ts != NULL ? ts[1] : 8;
13004}
13005
13006#endif
13007
Bram Moolenaar14f24742012-08-08 18:01:05 +020013008/*
13009 * Return the effective shiftwidth value for current buffer, using the
13010 * 'tabstop' value when 'shiftwidth' is zero.
13011 */
13012 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013013get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013014{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013015 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020013016}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013017
13018/*
13019 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013020 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013021 */
13022 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013023get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013024{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013025 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013026}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013027
13028/*
13029 * Check matchpairs option for "*initc".
13030 * If there is a match set "*initc" to the matching character and "*findc" to
13031 * the opposite character. Set "*backwards" to the direction.
13032 * When "switchit" is TRUE swap the direction.
13033 */
13034 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013035find_mps_values(
13036 int *initc,
13037 int *findc,
13038 int *backwards,
13039 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013040{
13041 char_u *ptr;
13042
13043 ptr = curbuf->b_p_mps;
13044 while (*ptr != NUL)
13045 {
13046#ifdef FEAT_MBYTE
13047 if (has_mbyte)
13048 {
13049 char_u *prev;
13050
13051 if (mb_ptr2char(ptr) == *initc)
13052 {
13053 if (switchit)
13054 {
13055 *findc = *initc;
13056 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13057 *backwards = TRUE;
13058 }
13059 else
13060 {
13061 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13062 *backwards = FALSE;
13063 }
13064 return;
13065 }
13066 prev = ptr;
13067 ptr += mb_ptr2len(ptr) + 1;
13068 if (mb_ptr2char(ptr) == *initc)
13069 {
13070 if (switchit)
13071 {
13072 *findc = *initc;
13073 *initc = mb_ptr2char(prev);
13074 *backwards = FALSE;
13075 }
13076 else
13077 {
13078 *findc = mb_ptr2char(prev);
13079 *backwards = TRUE;
13080 }
13081 return;
13082 }
13083 ptr += mb_ptr2len(ptr);
13084 }
13085 else
13086#endif
13087 {
13088 if (*ptr == *initc)
13089 {
13090 if (switchit)
13091 {
13092 *backwards = TRUE;
13093 *findc = *initc;
13094 *initc = ptr[2];
13095 }
13096 else
13097 {
13098 *backwards = FALSE;
13099 *findc = ptr[2];
13100 }
13101 return;
13102 }
13103 ptr += 2;
13104 if (*ptr == *initc)
13105 {
13106 if (switchit)
13107 {
13108 *backwards = FALSE;
13109 *findc = *initc;
13110 *initc = ptr[-2];
13111 }
13112 else
13113 {
13114 *backwards = TRUE;
13115 *findc = ptr[-2];
13116 }
13117 return;
13118 }
13119 ++ptr;
13120 }
13121 if (*ptr == ',')
13122 ++ptr;
13123 }
13124}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013125
13126#if defined(FEAT_LINEBREAK) || defined(PROTO)
13127/*
13128 * This is called when 'breakindentopt' is changed and when a window is
13129 * initialized.
13130 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013131 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013132briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013133{
13134 char_u *p;
13135 int bri_shift = 0;
13136 long bri_min = 20;
13137 int bri_sbr = FALSE;
13138
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013139 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013140 while (*p != NUL)
13141 {
13142 if (STRNCMP(p, "shift:", 6) == 0
13143 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13144 {
13145 p += 6;
13146 bri_shift = getdigits(&p);
13147 }
13148 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13149 {
13150 p += 4;
13151 bri_min = getdigits(&p);
13152 }
13153 else if (STRNCMP(p, "sbr", 3) == 0)
13154 {
13155 p += 3;
13156 bri_sbr = TRUE;
13157 }
13158 if (*p != ',' && *p != NUL)
13159 return FAIL;
13160 if (*p == ',')
13161 ++p;
13162 }
13163
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013164 wp->w_p_brishift = bri_shift;
13165 wp->w_p_brimin = bri_min;
13166 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013167
13168 return OK;
13169}
13170#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013171
13172/*
13173 * Get the local or global value of 'backupcopy'.
13174 */
13175 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013176get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013177{
13178 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13179}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013180
13181#if defined(FEAT_SIGNS) || defined(PROTO)
13182/*
13183 * Return TRUE when window "wp" has a column to draw signs in.
13184 */
13185 int
13186signcolumn_on(win_T *wp)
13187{
13188 if (*wp->w_p_scl == 'n')
13189 return FALSE;
13190 if (*wp->w_p_scl == 'y')
13191 return TRUE;
13192 return (wp->w_buffer->b_signlist != NULL
13193# ifdef FEAT_NETBEANS_INTG
13194 || wp->w_buffer->b_has_sign_column
13195# endif
13196 );
13197}
13198#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013199
13200#if defined(FEAT_EVAL) || defined(PROTO)
13201/*
13202 * Get window or buffer local options.
13203 */
13204 dict_T *
13205get_winbuf_options(int bufopt)
13206{
13207 dict_T *d;
13208 int opt_idx;
13209
13210 d = dict_alloc();
13211 if (d == NULL)
13212 return NULL;
13213
13214 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13215 {
13216 struct vimoption *opt = &options[opt_idx];
13217
13218 if ((bufopt && (opt->indir & PV_BUF))
13219 || (!bufopt && (opt->indir & PV_WIN)))
13220 {
13221 char_u *varp = get_varp(opt);
13222
13223 if (varp != NULL)
13224 {
13225 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013226 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013227 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013228 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013229 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013230 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013231 }
13232 }
13233 }
13234
13235 return d;
13236}
13237#endif