blob: 50d42ebf7da503798a57079b578d1e5fbd85deaa [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 Moolenaarc4da1132017-07-15 19:39:43 +02003000 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
3001#ifdef FEAT_VIMINFO
3002 (char_u *)&p_viminfofile, PV_NONE,
3003 {(char_u *)"", (char_u *)0L}
3004#else
3005 (char_u *)NULL, PV_NONE,
3006 {(char_u *)0L, (char_u *)0L}
3007#endif
3008 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003009 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
3010 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011#ifdef FEAT_VIRTUALEDIT
3012 (char_u *)&p_ve, PV_NONE,
3013 {(char_u *)"", (char_u *)""}
3014#else
3015 (char_u *)NULL, PV_NONE,
3016 {(char_u *)0L, (char_u *)0L}
3017#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003018 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3020 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 {"w300", NULL, P_NUM|P_VI_DEF,
3023 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 {"w1200", NULL, P_NUM|P_VI_DEF,
3026 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003027 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"w9600", NULL, P_NUM|P_VI_DEF,
3029 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003030 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 {"warn", NULL, P_BOOL|P_VI_DEF,
3032 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003033 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3035 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003037 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003039 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 {"wildchar", "wc", P_NUM|P_VIM,
3041 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003042 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3043 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003044 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003046 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003047 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048#ifdef FEAT_WILDIGN
3049 (char_u *)&p_wig, PV_NONE,
3050#else
3051 (char_u *)NULL, PV_NONE,
3052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003053 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003054 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3055 (char_u *)&p_wic, PV_NONE,
3056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3058#ifdef FEAT_WILDMENU
3059 (char_u *)&p_wmnu, PV_NONE,
3060#else
3061 (char_u *)NULL, PV_NONE,
3062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003064 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003066 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003067 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3068#ifdef FEAT_CMDL_COMPL
3069 (char_u *)&p_wop, PV_NONE,
3070 {(char_u *)"", (char_u *)0L}
3071#else
3072 (char_u *)NULL, PV_NONE,
3073 {(char_u *)NULL, (char_u *)0L}
3074#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003075 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3077#ifdef FEAT_WAK
3078 (char_u *)&p_wak, PV_NONE,
3079 {(char_u *)"menu", (char_u *)0L}
3080#else
3081 (char_u *)NULL, PV_NONE,
3082 {(char_u *)NULL, (char_u *)0L}
3083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003086 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003087 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003090 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003093 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003094 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003095 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003096 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003099 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003102 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003103 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003104#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003105 (char_u *)&p_winptydll, PV_NONE, {
3106# ifdef _WIN64
3107 (char_u *)"winpty64.dll",
3108# else
3109 (char_u *)"winpty32.dll",
3110# endif
3111 (char_u *)0L}
3112#else
3113 (char_u *)NULL, PV_NONE,
3114 {(char_u *)0L, (char_u *)0L}
3115#endif
3116 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003119 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3121 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003122 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3124 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003125 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3127 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003128 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 {"write", NULL, P_BOOL|P_VI_DEF,
3130 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003131 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 {"writeany", "wa", P_BOOL|P_VI_DEF,
3133 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003134 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3136 (char_u *)&p_wb, PV_NONE,
3137 {
3138#ifdef FEAT_WRITEBACKUP
3139 (char_u *)TRUE,
3140#else
3141 (char_u *)FALSE,
3142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003143 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 {"writedelay", "wd", P_NUM|P_VI_DEF,
3145 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003146 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147
3148/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003149#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003151 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152
3153 p_term("t_AB", T_CAB)
3154 p_term("t_AF", T_CAF)
3155 p_term("t_AL", T_CAL)
3156 p_term("t_al", T_AL)
3157 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003158 p_term("t_BE", T_BE)
3159 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 p_term("t_cd", T_CD)
3161 p_term("t_ce", T_CE)
3162 p_term("t_cl", T_CL)
3163 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003164 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_Co", T_CCO)
3166 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003167 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 p_term("t_da", T_DA)
3171 p_term("t_db", T_DB)
3172 p_term("t_DL", T_CDL)
3173 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003174 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003175 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003177 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178 p_term("t_IE", T_CIE)
3179 p_term("t_IS", T_CIS)
3180 p_term("t_ke", T_KE)
3181 p_term("t_ks", T_KS)
3182 p_term("t_le", T_LE)
3183 p_term("t_mb", T_MB)
3184 p_term("t_md", T_MD)
3185 p_term("t_me", T_ME)
3186 p_term("t_mr", T_MR)
3187 p_term("t_ms", T_MS)
3188 p_term("t_nd", T_ND)
3189 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003190 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003191 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003192 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003194 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195 p_term("t_RV", T_CRV)
3196 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003197 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003199 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003200 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003201 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003203 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003205 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206 p_term("t_te", T_TE)
3207 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003208 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003209 p_term("t_ts", T_TS)
3210 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211 p_term("t_ue", T_UE)
3212 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003213 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003214 p_term("t_vb", T_VB)
3215 p_term("t_ve", T_VE)
3216 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003217 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 p_term("t_vs", T_VS)
3219 p_term("t_WP", T_CWP)
3220 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003221 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222 p_term("t_xs", T_XS)
3223 p_term("t_ZH", T_CZH)
3224 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003225 p_term("t_8f", T_8F)
3226 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227
3228/* terminal key codes are not in here */
3229
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003230 /* end marker */
3231 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232};
3233
3234#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3235
3236#ifdef FEAT_MBYTE
3237static char *(p_ambw_values[]) = {"single", "double", NULL};
3238#endif
3239static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003240static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003242#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003243static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003244#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003245#ifdef FEAT_CMDL_COMPL
3246static char *(p_wop_values[]) = {"tagfile", NULL};
3247#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248#ifdef FEAT_WAK
3249static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3250#endif
3251static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3253static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255#ifdef FEAT_BROWSE
3256static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003259static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003261static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003262static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3264#ifdef FEAT_FOLDING
3265static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003266# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003268# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269 NULL};
3270static char *(p_fcl_values[]) = {"all", NULL};
3271#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003272#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003273static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003274#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003275#ifdef FEAT_SIGNS
3276static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3277#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static void set_option_default(int, int opt_flags, int compatible);
3280static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003281static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003282static char_u *term_bg_default(void);
3283static void did_set_option(int opt_idx, int opt_flags, int new_value);
3284static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003286static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003288static char_u *option_expand(int opt_idx, char_u *val);
3289static void didset_options(void);
3290static void didset_options2(void);
3291static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003292#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003294#else
3295# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3296#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003297static void set_string_option_global(int opt_idx, char_u **varp);
3298static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3299static 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);
3300static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003301#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003303#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003307#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003308static char_u *did_set_spell_option(int is_spellfile);
3309static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003310#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003311#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003313#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003314static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3315static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3316static void check_redraw(long_u flags);
3317static int findoption(char_u *);
3318static int find_key_option(char_u *);
3319static void showoptions(int all, int opt_flags);
3320static int optval_default(struct vimoption *, char_u *varp);
3321static void showoneopt(struct vimoption *, int opt_flags);
3322static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3323static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3324static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3325static int istermoption(struct vimoption *);
3326static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3327static char_u *get_varp(struct vimoption *);
3328static void option_value2string(struct vimoption *, int opt_flags);
3329static void check_winopt(winopt_T *wop);
3330static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003332static void langmap_init(void);
3333static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003335static void paste_option_changed(void);
3336static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003338static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003340static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3341static int check_opt_strings(char_u *val, char **values, int);
3342static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003343#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003344static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346
3347/*
3348 * Initialize the options, first part.
3349 *
3350 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003351 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352 */
3353 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003354set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355{
3356 char_u *p;
3357 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003358 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359
3360#ifdef FEAT_LANGMAP
3361 langmap_init();
3362#endif
3363
3364 /* Be Vi compatible by default */
3365 p_cp = TRUE;
3366
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003367 /* Use POSIX compatibility when $VIM_POSIX is set. */
3368 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003369 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003370 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003371 set_string_default("shm", (char_u *)"A");
3372 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003373
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 /*
3375 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003376 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003378 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003379#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003380 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003382 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383# endif
3384#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003385 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003386 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387
3388#ifdef FEAT_WILDIGN
3389 /*
3390 * Set the default for 'backupskip' to include environment variables for
3391 * temp files.
3392 */
3393 {
3394# ifdef UNIX
3395 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3396# else
3397 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3398# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003399 int len;
3400 garray_T ga;
3401 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402
3403 ga_init2(&ga, 1, 100);
3404 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3405 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003406 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407# ifdef UNIX
3408 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003409# ifdef MACOS_X
3410 p = (char_u *)"/private/tmp";
3411# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003413# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 else
3415# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003416 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 if (p != NULL && *p != NUL)
3418 {
3419 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003420 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421 if (ga_grow(&ga, len) == OK)
3422 {
3423 if (ga.ga_len > 0)
3424 STRCAT(ga.ga_data, ",");
3425 STRCAT(ga.ga_data, p);
3426 add_pathsep(ga.ga_data);
3427 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428 ga.ga_len += len;
3429 }
3430 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003431 if (mustfree)
3432 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 }
3434 if (ga.ga_data != NULL)
3435 {
3436 set_string_default("bsk", ga.ga_data);
3437 vim_free(ga.ga_data);
3438 }
3439 }
3440#endif
3441
3442 /*
3443 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3444 */
3445 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003446 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003448#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3449 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3450#endif
3451 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003453 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003454 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455#else
3456# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003457 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003458 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003460 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461# endif
3462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003464 opt_idx = findoption((char_u *)"maxmem");
3465 if (opt_idx >= 0)
3466 {
3467#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003468 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3469 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003470#endif
3471 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3472 }
3473 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474 }
3475
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476#ifdef FEAT_SEARCHPATH
3477 {
3478 char_u *cdpath;
3479 char_u *buf;
3480 int i;
3481 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003482 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483
3484 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003485 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 if (cdpath != NULL)
3487 {
3488 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3489 if (buf != NULL)
3490 {
3491 buf[0] = ','; /* start with ",", current dir first */
3492 j = 1;
3493 for (i = 0; cdpath[i] != NUL; ++i)
3494 {
3495 if (vim_ispathlistsep(cdpath[i]))
3496 buf[j++] = ',';
3497 else
3498 {
3499 if (cdpath[i] == ' ' || cdpath[i] == ',')
3500 buf[j++] = '\\';
3501 buf[j++] = cdpath[i];
3502 }
3503 }
3504 buf[j] = NUL;
3505 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003506 if (opt_idx >= 0)
3507 {
3508 options[opt_idx].def_val[VI_DEFAULT] = buf;
3509 options[opt_idx].flags |= P_DEF_ALLOCED;
3510 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003511 else
3512 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003514 if (mustfree)
3515 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003516 }
3517 }
3518#endif
3519
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003520#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521 /* Set print encoding on platforms that don't default to latin1 */
3522 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003523# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524 (char_u *)"cp1252"
3525# else
3526# ifdef VMS
3527 (char_u *)"dec-mcs"
3528# else
3529# ifdef EBCDIC
3530 (char_u *)"ebcdic-uk"
3531# else
3532# ifdef MAC
3533 (char_u *)"mac-roman"
3534# else /* HPUX */
3535 (char_u *)"hp-roman8"
3536# endif
3537# endif
3538# endif
3539# endif
3540 );
3541#endif
3542
3543#ifdef FEAT_POSTSCRIPT
3544 /* 'printexpr' must be allocated to be able to evaluate it. */
3545 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003546# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003547 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003548# else
3549# ifdef VMS
3550 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3551
3552# else
3553 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3554# endif
3555# endif
3556 );
3557#endif
3558
3559 /*
3560 * Set all the options (except the terminal options) to their default
3561 * value. Also set the global value for local options.
3562 */
3563 set_options_default(0);
3564
Bram Moolenaar07268702018-03-01 21:57:32 +01003565#ifdef CLEAN_RUNTIMEPATH
3566 if (clean_arg)
3567 {
3568 opt_idx = findoption((char_u *)"runtimepath");
3569 if (opt_idx >= 0)
3570 {
3571 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3572 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3573 }
3574 opt_idx = findoption((char_u *)"packpath");
3575 if (opt_idx >= 0)
3576 {
3577 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3578 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3579 }
3580 }
3581#endif
3582
Bram Moolenaar071d4272004-06-13 20:20:40 +00003583#ifdef FEAT_GUI
3584 if (found_reverse_arg)
3585 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3586#endif
3587
3588 curbuf->b_p_initialized = TRUE;
3589 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003590 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003591 check_buf_options(curbuf);
3592 check_win_options(curwin);
3593 check_options();
3594
3595 /* Must be before option_expand(), because that one needs vim_isIDc() */
3596 didset_options();
3597
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003598#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003599 /* Use the current chartab for the generic chartab. This is not in
3600 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003601 init_spell_chartab();
3602#endif
3603
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 /*
3605 * Expand environment variables and things like "~" for the defaults.
3606 * If option_expand() returns non-NULL the variable is expanded. This can
3607 * only happen for non-indirect options.
3608 * Also set the default to the expanded value, so ":set" does not list
3609 * them.
3610 * Don't set the P_ALLOCED flag, because we don't want to free the
3611 * default.
3612 */
3613 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3614 {
3615 if ((options[opt_idx].flags & P_GETTEXT)
3616 && options[opt_idx].var != NULL)
3617 p = (char_u *)_(*(char **)options[opt_idx].var);
3618 else
3619 p = option_expand(opt_idx, NULL);
3620 if (p != NULL && (p = vim_strsave(p)) != NULL)
3621 {
3622 *(char_u **)options[opt_idx].var = p;
3623 /* VIMEXP
3624 * Defaults for all expanded options are currently the same for Vi
3625 * and Vim. When this changes, add some code here! Also need to
3626 * split P_DEF_ALLOCED in two.
3627 */
3628 if (options[opt_idx].flags & P_DEF_ALLOCED)
3629 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3630 options[opt_idx].def_val[VI_DEFAULT] = p;
3631 options[opt_idx].flags |= P_DEF_ALLOCED;
3632 }
3633 }
3634
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635 save_file_ff(curbuf); /* Buffer is unchanged */
3636
Bram Moolenaar071d4272004-06-13 20:20:40 +00003637#if defined(FEAT_ARABIC)
3638 /* Detect use of mlterm.
3639 * Mlterm is a terminal emulator akin to xterm that has some special
3640 * abilities (bidi namely).
3641 * NOTE: mlterm's author is being asked to 'set' a variable
3642 * instead of an environment variable due to inheritance.
3643 */
3644 if (mch_getenv((char_u *)"MLTERM") != NULL)
3645 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3646#endif
3647
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003648 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649
3650#ifdef FEAT_MBYTE
3651# if defined(WIN3264) && defined(FEAT_GETTEXT)
3652 /*
3653 * If $LANG isn't set, try to get a good value for it. This makes the
3654 * right language be used automatically. Don't do this for English.
3655 */
3656 if (mch_getenv((char_u *)"LANG") == NULL)
3657 {
3658 char buf[20];
3659
3660 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3661 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3662 * only the first two. */
3663 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3664 (LPTSTR)buf, 20);
3665 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3666 {
3667 /* There are a few exceptions (probably more) */
3668 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3669 STRCPY(buf, "zh_TW");
3670 else if (STRNICMP(buf, "chs", 3) == 0
3671 || STRNICMP(buf, "zhc", 3) == 0)
3672 STRCPY(buf, "zh_CN");
3673 else if (STRNICMP(buf, "jp", 2) == 0)
3674 STRCPY(buf, "ja");
3675 else
3676 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003677 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678 }
3679 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003680# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003681# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003682 /* Moved to os_mac_conv.c to avoid dependency problems. */
3683 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003684# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685# endif
3686
3687 /* enc_locale() will try to find the encoding of the current locale. */
3688 p = enc_locale();
3689 if (p != NULL)
3690 {
3691 char_u *save_enc;
3692
3693 /* Try setting 'encoding' and check if the value is valid.
3694 * If not, go back to the default "latin1". */
3695 save_enc = p_enc;
3696 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003697 if (STRCMP(p_enc, "gb18030") == 0)
3698 {
3699 /* We don't support "gb18030", but "cp936" is a good substitute
3700 * for practical purposes, thus use that. It's not an alias to
3701 * still support conversion between gb18030 and utf-8. */
3702 p_enc = vim_strsave((char_u *)"cp936");
3703 vim_free(p);
3704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 if (mb_init() == NULL)
3706 {
3707 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003708 if (opt_idx >= 0)
3709 {
3710 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3711 options[opt_idx].flags |= P_DEF_ALLOCED;
3712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713
Bram Moolenaard0573012017-10-28 21:11:06 +02003714#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003715 if (STRCMP(p_enc, "latin1") == 0
3716# ifdef FEAT_MBYTE
3717 || enc_utf8
3718# endif
3719 )
3720 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003721 /* Adjust the default for 'isprint' and 'iskeyword' to match
3722 * latin1. Also set the defaults for when 'nocompatible' is
3723 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003724 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003725 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003726 set_string_option_direct((char_u *)"isk", -1,
3727 ISK_LATIN1, OPT_FREE, SID_NONE);
3728 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003729 if (opt_idx >= 0)
3730 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003731 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003732 if (opt_idx >= 0)
3733 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003734 (void)init_chartab();
3735 }
3736#endif
3737
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738# if defined(WIN3264) && !defined(FEAT_GUI)
3739 /* Win32 console: When GetACP() returns a different value from
3740 * GetConsoleCP() set 'termencoding'. */
3741 if (GetACP() != GetConsoleCP())
3742 {
3743 char buf[50];
3744
3745 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3746 p_tenc = vim_strsave((char_u *)buf);
3747 if (p_tenc != NULL)
3748 {
3749 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003750 if (opt_idx >= 0)
3751 {
3752 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3753 options[opt_idx].flags |= P_DEF_ALLOCED;
3754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755 convert_setup(&input_conv, p_tenc, p_enc);
3756 convert_setup(&output_conv, p_enc, p_tenc);
3757 }
3758 else
3759 p_tenc = empty_option;
3760 }
3761# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003762# if defined(WIN3264) && defined(FEAT_MBYTE)
3763 /* $HOME may have characters in active code page. */
3764 init_homedir();
3765# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 }
3767 else
3768 {
3769 vim_free(p_enc);
3770 p_enc = save_enc;
3771 }
3772 }
3773#endif
3774
3775#ifdef FEAT_MULTI_LANG
3776 /* Set the default for 'helplang'. */
3777 set_helplang_default(get_mess_lang());
3778#endif
3779}
3780
3781/*
3782 * Set an option to its default value.
3783 * This does not take care of side effects!
3784 */
3785 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003786set_option_default(
3787 int opt_idx,
3788 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3789 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790{
3791 char_u *varp; /* pointer to variable for current option */
3792 int dvi; /* index in def_val[] */
3793 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003794 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3796
3797 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3798 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003799 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800 {
3801 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3802 if (flags & P_STRING)
3803 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003804 /* Use set_string_option_direct() for local options to handle
3805 * freeing and allocating the value. */
3806 if (options[opt_idx].indir != PV_NONE)
3807 set_string_option_direct(NULL, opt_idx,
3808 options[opt_idx].def_val[dvi], opt_flags, 0);
3809 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003811 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3812 free_string_option(*(char_u **)(varp));
3813 *(char_u **)varp = options[opt_idx].def_val[dvi];
3814 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 }
3816 }
3817 else if (flags & P_NUM)
3818 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003819 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 win_comp_scroll(curwin);
3821 else
3822 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003823 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824 /* May also set global value for local option. */
3825 if (both)
3826 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3827 *(long *)varp;
3828 }
3829 }
3830 else /* P_BOOL */
3831 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003832 /* the cast to long is required for Manx C, long_i is needed for
3833 * MSVC */
3834 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003835#ifdef UNIX
3836 /* 'modeline' defaults to off for root */
3837 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3838 *(int *)varp = FALSE;
3839#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003840 /* May also set global value for local option. */
3841 if (both)
3842 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3843 *(int *)varp;
3844 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003845
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003846 /* The default value is not insecure. */
3847 flagsp = insecure_flag(opt_idx, opt_flags);
3848 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003849 }
3850
3851#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003852 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853#endif
3854}
3855
3856/*
3857 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003858 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859 */
3860 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003861set_options_default(
3862 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863{
3864 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003866 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867
3868 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003869 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003870#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003871 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003872 || (TRUE
3873# if defined(FEAT_MBYTE)
3874 && options[i].var != (char_u *)&p_enc
3875# endif
3876# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003877 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003878 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003879# endif
3880 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003881#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003882 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883 set_option_default(i, opt_flags, p_cp);
3884
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003886 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003888#ifdef FEAT_CINDENT
3889 parse_cino(curbuf);
3890#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891}
3892
3893/*
3894 * Set the Vi-default value of a string option.
3895 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003896 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003898 static void
3899set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900{
3901 char_u *p;
3902 int opt_idx;
3903
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003904 if (escape && vim_strchr(val, ' ') != NULL)
3905 p = vim_strsave_escaped(val, (char_u *)" ");
3906 else
3907 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 if (p != NULL) /* we don't want a NULL */
3909 {
3910 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003911 if (opt_idx >= 0)
3912 {
3913 if (options[opt_idx].flags & P_DEF_ALLOCED)
3914 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3915 options[opt_idx].def_val[VI_DEFAULT] = p;
3916 options[opt_idx].flags |= P_DEF_ALLOCED;
3917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 }
3919}
3920
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003921 void
3922set_string_default(char *name, char_u *val)
3923{
3924 set_string_default_esc(name, val, FALSE);
3925}
3926
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927/*
3928 * Set the Vi-default value of a number option.
3929 * Used for 'lines' and 'columns'.
3930 */
3931 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003932set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003934 int opt_idx;
3935
3936 opt_idx = findoption((char_u *)name);
3937 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003938 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939}
3940
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003941#if defined(EXITFREE) || defined(PROTO)
3942/*
3943 * Free all options.
3944 */
3945 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003946free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003947{
3948 int i;
3949
3950 for (i = 0; !istermoption(&options[i]); i++)
3951 {
3952 if (options[i].indir == PV_NONE)
3953 {
3954 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003955 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003956 free_string_option(*(char_u **)options[i].var);
3957 if (options[i].flags & P_DEF_ALLOCED)
3958 free_string_option(options[i].def_val[VI_DEFAULT]);
3959 }
3960 else if (options[i].var != VAR_WIN
3961 && (options[i].flags & P_STRING))
3962 /* buffer-local option: free global value */
3963 free_string_option(*(char_u **)options[i].var);
3964 }
3965}
3966#endif
3967
3968
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969/*
3970 * Initialize the options, part two: After getting Rows and Columns and
3971 * setting 'term'.
3972 */
3973 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003974set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003976 int idx;
3977
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003979 * 'scroll' defaults to half the window height. The stored default is zero,
3980 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003982 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003983 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003984 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 comp_col();
3986
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003987 /*
3988 * 'window' is only for backwards compatibility with Vi.
3989 * Default is Rows - 1.
3990 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003991 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003992 p_window = Rows - 1;
3993 set_number_default("window", Rows - 1);
3994
Bram Moolenaarf740b292006-02-16 22:11:02 +00003995 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003996#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003997 /*
3998 * If 'background' wasn't set by the user, try guessing the value,
3999 * depending on the terminal name. Only need to check for terminals
4000 * with a dark background, that can handle color.
4001 */
4002 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004003 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4004 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004006 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004007 /* don't mark it as set, when starting the GUI it may be
4008 * changed again */
4009 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004010 }
4011#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004012
4013#ifdef CURSOR_SHAPE
4014 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4015#endif
4016#ifdef FEAT_MOUSESHAPE
4017 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4018#endif
4019#ifdef FEAT_PRINTER
4020 (void)parse_printoptions(); /* parse 'printoptions' default value */
4021#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022}
4023
4024/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004025 * Return "dark" or "light" depending on the kind of terminal.
4026 * This is just guessing! Recognized are:
4027 * "linux" Linux console
4028 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004029 * "cygwin.*" Cygwin shell
4030 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004031 * We also check the COLORFGBG environment variable, which is set by
4032 * rxvt and derivatives. This variable contains either two or three
4033 * values separated by semicolons; we want the last value in either
4034 * case. If this value is 0-6 or 8, our background is dark.
4035 */
4036 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004037term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004038{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004039#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004040 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004041 return (char_u *)"dark";
4042#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004043 char_u *p;
4044
Bram Moolenaarf740b292006-02-16 22:11:02 +00004045 if (STRCMP(T_NAME, "linux") == 0
4046 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004047 || STRNCMP(T_NAME, "cygwin", 6) == 0
4048 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004049 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4050 && (p = vim_strrchr(p, ';')) != NULL
4051 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4052 && p[2] == NUL))
4053 return (char_u *)"dark";
4054 return (char_u *)"light";
4055#endif
4056}
4057
4058/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 * Initialize the options, part three: After reading the .vimrc
4060 */
4061 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004062set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004064#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065/*
4066 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4067 * This is done after other initializations, where 'shell' might have been
4068 * set, but only if they have not been set before.
4069 */
4070 char_u *p;
4071 int idx_srr;
4072 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 int idx_sp;
4075 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004076# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077
4078 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004079 if (idx_srr < 0)
4080 do_srr = FALSE;
4081 else
4082 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004085 if (idx_sp < 0)
4086 do_sp = FALSE;
4087 else
4088 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004090 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 if (p != NULL)
4092 {
4093 /*
4094 * Default for p_sp is "| tee", for p_srr is ">".
4095 * For known shells it is changed here to include stderr.
4096 */
4097 if ( fnamecmp(p, "csh") == 0
4098 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004099# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 || fnamecmp(p, "csh.exe") == 0
4101 || fnamecmp(p, "tcsh.exe") == 0
4102# endif
4103 )
4104 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004105# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 if (do_sp)
4107 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004110# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004112# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4114 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004115# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 if (do_srr)
4117 {
4118 p_srr = (char_u *)">&";
4119 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4120 }
4121 }
4122 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004123 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 if ( fnamecmp(p, "sh") == 0
4125 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004126 || fnamecmp(p, "mksh") == 0
4127 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004129 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004131 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004132# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 || fnamecmp(p, "cmd") == 0
4134 || fnamecmp(p, "sh.exe") == 0
4135 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004136 || fnamecmp(p, "mksh.exe") == 0
4137 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004139 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 || fnamecmp(p, "bash.exe") == 0
4141 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004143 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004145# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 if (do_sp)
4147 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004148# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004150# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004152# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4154 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004155# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 if (do_srr)
4157 {
4158 p_srr = (char_u *)">%s 2>&1";
4159 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4160 }
4161 }
4162 vim_free(p);
4163 }
4164#endif
4165
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004166#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004167 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004168 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4169 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170 * This is done after other initializations, where 'shell' might have been
4171 * set, but only if they have not been set before. Default for p_shcf is
4172 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004173 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004175 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 {
4177 int idx3;
4178
4179 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004180 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004181 {
4182 p_shcf = (char_u *)"-c";
4183 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4184 }
4185
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186 /* Somehow Win32 requires the quotes around the redirection too */
4187 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004188 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189 {
4190 p_sxq = (char_u *)"\"";
4191 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4192 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004194 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4195 {
4196 int idx3;
4197
4198 /*
4199 * cmd.exe on Windows will strip the first and last double quote given
4200 * on the command line, e.g. most of the time things like:
4201 * cmd /c "my path/to/echo" "my args to echo"
4202 * become:
4203 * my path/to/echo" "my args to echo
4204 * when executed.
4205 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004206 * To avoid this, set shellxquote to surround the command in
4207 * parenthesis. This appears to make most commands work, without
4208 * breaking commands that worked previously, such as
4209 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004210 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004211 idx3 = findoption((char_u *)"sxq");
4212 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4213 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004214 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004215 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4216 }
4217
Bram Moolenaara64ba222012-02-12 23:23:31 +01004218 idx3 = findoption((char_u *)"shcf");
4219 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4220 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004221 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004222 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4223 }
4224 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225#endif
4226
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004227 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004228 {
4229 int idx_ffs = findoption((char_u *)"ffs");
4230
4231 /* Apply the first entry of 'fileformats' to the initial buffer. */
4232 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4233 set_fileformat(default_fileformat(), OPT_LOCAL);
4234 }
4235
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236#ifdef FEAT_TITLE
4237 set_title_defaults();
4238#endif
4239}
4240
4241#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4242/*
4243 * When 'helplang' is still at its default value, set it to "lang".
4244 * Only the first two characters of "lang" are used.
4245 */
4246 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004247set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248{
4249 int idx;
4250
4251 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4252 return;
4253 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004254 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004255 {
4256 if (options[idx].flags & P_ALLOCED)
4257 free_string_option(p_hlg);
4258 p_hlg = vim_strsave(lang);
4259 if (p_hlg == NULL)
4260 p_hlg = empty_option;
4261 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004262 {
4263 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4264 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4265 {
4266 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4267 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4268 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004269 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004270 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004271 options[idx].flags |= P_ALLOCED;
4272 }
4273}
4274#endif
4275
4276#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004277static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004278
4279 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004280gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004281{
4282 if (gui_get_lightness(gui.back_pixel) < 127)
4283 return (char_u *)"dark";
4284 return (char_u *)"light";
4285}
4286
4287/*
4288 * Option initializations that can only be done after opening the GUI window.
4289 */
4290 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004291init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004292{
4293 /* Set the 'background' option according to the lightness of the
4294 * background color, unless the user has set it already. */
4295 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4296 {
4297 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4298 highlight_changed();
4299 }
4300}
4301#endif
4302
4303#ifdef FEAT_TITLE
4304/*
4305 * 'title' and 'icon' only default to true if they have not been set or reset
4306 * in .vimrc and we can read the old value.
4307 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4308 * they can be reset. This reduces startup time when using X on a remote
4309 * machine.
4310 */
4311 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004312set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004313{
4314 int idx1;
4315 long val;
4316
4317 /*
4318 * If GUI is (going to be) used, we can always set the window title and
4319 * icon name. Saves a bit of time, because the X11 display server does
4320 * not need to be contacted.
4321 */
4322 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004323 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004324 {
4325#ifdef FEAT_GUI
4326 if (gui.starting || gui.in_use)
4327 val = TRUE;
4328 else
4329#endif
4330 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004331 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004332 p_title = val;
4333 }
4334 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004335 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004336 {
4337#ifdef FEAT_GUI
4338 if (gui.starting || gui.in_use)
4339 val = TRUE;
4340 else
4341#endif
4342 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004343 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004344 p_icon = val;
4345 }
4346}
4347#endif
4348
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004349#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004350 static void
4351trigger_optionsset_string(
4352 int opt_idx,
4353 int opt_flags,
4354 char_u *oldval,
4355 char_u *newval)
4356{
4357 if (oldval != NULL && newval != NULL)
4358 {
4359 char_u buf_type[7];
4360
4361 sprintf((char *)buf_type, "%s",
4362 (opt_flags & OPT_LOCAL) ? "local" : "global");
4363 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4364 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4365 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4366 apply_autocmds(EVENT_OPTIONSET,
4367 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4368 reset_v_option_vars();
4369 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004370}
4371#endif
4372
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373/*
4374 * Parse 'arg' for option settings.
4375 *
4376 * 'arg' may be IObuff, but only when no errors can be present and option
4377 * does not need to be expanded with option_expand().
4378 * "opt_flags":
4379 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004380 * OPT_GLOBAL for ":setglobal"
4381 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004383 * OPT_WINONLY to only set window-local options
4384 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 *
4386 * returns FAIL if an error is detected, OK otherwise
4387 */
4388 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004389do_set(
4390 char_u *arg, /* option string (may be written to!) */
4391 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392{
4393 int opt_idx;
4394 char_u *errmsg;
4395 char_u errbuf[80];
4396 char_u *startarg;
4397 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4398 int nextchar; /* next non-white char after option name */
4399 int afterchar; /* character just after option name */
4400 int len;
4401 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004402 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 int key;
4404 long_u flags; /* flags for current option */
4405 char_u *varp = NULL; /* pointer to variable for current option */
4406 int did_show = FALSE; /* already showed one value */
4407 int adding; /* "opt+=arg" */
4408 int prepending; /* "opt^=arg" */
4409 int removing; /* "opt-=arg" */
4410 int cp_val = 0;
4411 char_u key_name[2];
4412
4413 if (*arg == NUL)
4414 {
4415 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004416 did_show = TRUE;
4417 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004418 }
4419
4420 while (*arg != NUL) /* loop to process all options */
4421 {
4422 errmsg = NULL;
4423 startarg = arg; /* remember for error message */
4424
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004425 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4426 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004427 {
4428 /*
4429 * ":set all" show all options.
4430 * ":set all&" set all options to their default value.
4431 */
4432 arg += 3;
4433 if (*arg == '&')
4434 {
4435 ++arg;
4436 /* Only for :set command set global value of local options. */
4437 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004438 didset_options();
4439 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004440 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004441 }
4442 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004443 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004444 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004445 did_show = TRUE;
4446 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004447 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004448 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004449 {
4450 showoptions(2, opt_flags);
4451 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004452 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004453 arg += 7;
4454 }
4455 else
4456 {
4457 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004458 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004459 {
4460 prefix = 0;
4461 arg += 2;
4462 }
4463 else if (STRNCMP(arg, "inv", 3) == 0)
4464 {
4465 prefix = 2;
4466 arg += 3;
4467 }
4468
4469 /* find end of name */
4470 key = 0;
4471 if (*arg == '<')
4472 {
4473 nextchar = 0;
4474 opt_idx = -1;
4475 /* look out for <t_>;> */
4476 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4477 len = 5;
4478 else
4479 {
4480 len = 1;
4481 while (arg[len] != NUL && arg[len] != '>')
4482 ++len;
4483 }
4484 if (arg[len] != '>')
4485 {
4486 errmsg = e_invarg;
4487 goto skip;
4488 }
4489 arg[len] = NUL; /* put NUL after name */
4490 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4491 opt_idx = findoption(arg + 1);
4492 arg[len++] = '>'; /* restore '>' */
4493 if (opt_idx == -1)
4494 key = find_key_option(arg + 1);
4495 }
4496 else
4497 {
4498 len = 0;
4499 /*
4500 * The two characters after "t_" may not be alphanumeric.
4501 */
4502 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4503 len = 4;
4504 else
4505 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4506 ++len;
4507 nextchar = arg[len];
4508 arg[len] = NUL; /* put NUL after name */
4509 opt_idx = findoption(arg);
4510 arg[len] = nextchar; /* restore nextchar */
4511 if (opt_idx == -1)
4512 key = find_key_option(arg);
4513 }
4514
4515 /* remember character after option name */
4516 afterchar = arg[len];
4517
4518 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004519 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004520 ++len;
4521
4522 adding = FALSE;
4523 prepending = FALSE;
4524 removing = FALSE;
4525 if (arg[len] != NUL && arg[len + 1] == '=')
4526 {
4527 if (arg[len] == '+')
4528 {
4529 adding = TRUE; /* "+=" */
4530 ++len;
4531 }
4532 else if (arg[len] == '^')
4533 {
4534 prepending = TRUE; /* "^=" */
4535 ++len;
4536 }
4537 else if (arg[len] == '-')
4538 {
4539 removing = TRUE; /* "-=" */
4540 ++len;
4541 }
4542 }
4543 nextchar = arg[len];
4544
4545 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4546 {
4547 errmsg = (char_u *)N_("E518: Unknown option");
4548 goto skip;
4549 }
4550
4551 if (opt_idx >= 0)
4552 {
4553 if (options[opt_idx].var == NULL) /* hidden option: skip */
4554 {
4555 /* Only give an error message when requesting the value of
4556 * a hidden option, ignore setting it. */
4557 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4558 && (!(options[opt_idx].flags & P_BOOL)
4559 || nextchar == '?'))
4560 errmsg = (char_u *)N_("E519: Option not supported");
4561 goto skip;
4562 }
4563
4564 flags = options[opt_idx].flags;
4565 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4566 }
4567 else
4568 {
4569 flags = P_STRING;
4570 if (key < 0)
4571 {
4572 key_name[0] = KEY2TERMCAP0(key);
4573 key_name[1] = KEY2TERMCAP1(key);
4574 }
4575 else
4576 {
4577 key_name[0] = KS_KEY;
4578 key_name[1] = (key & 0xff);
4579 }
4580 }
4581
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004582 /* Skip all options that are not window-local (used when showing
4583 * an already loaded buffer in a window). */
4584 if ((opt_flags & OPT_WINONLY)
4585 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4586 goto skip;
4587
Bram Moolenaara3227e22006-03-08 21:32:40 +00004588 /* Skip all options that are window-local (used for :vimgrep). */
4589 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4590 && options[opt_idx].var == VAR_WIN)
4591 goto skip;
4592
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004593 /* Disallow changing some options from modelines. */
4594 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004595 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004596 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004597 {
4598 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4599 goto skip;
4600 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004601#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004602 /* In diff mode some options are overruled. This avoids that
4603 * 'foldmethod' becomes "marker" instead of "diff" and that
4604 * "wrap" gets set. */
4605 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004606 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004607 && (
4608#ifdef FEAT_FOLDING
4609 options[opt_idx].indir == PV_FDM ||
4610#endif
4611 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004612 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004613#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004614 }
4615
4616#ifdef HAVE_SANDBOX
4617 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004618 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619 {
4620 errmsg = (char_u *)_(e_sandbox);
4621 goto skip;
4622 }
4623#endif
4624
4625 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4626 {
4627 arg += len;
4628 cp_val = p_cp;
4629 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4630 {
4631 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4632 {
4633 cp_val = FALSE;
4634 arg += 3;
4635 }
4636 else /* "opt&vi": set to Vi default */
4637 {
4638 cp_val = TRUE;
4639 arg += 2;
4640 }
4641 }
4642 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004643 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004644 {
4645 errmsg = e_trailing;
4646 goto skip;
4647 }
4648 }
4649
4650 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004651 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4652 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004653 */
4654 if (nextchar == '?'
4655 || (prefix == 1
4656 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4657 && !(flags & P_BOOL)))
4658 {
4659 /*
4660 * print value
4661 */
4662 if (did_show)
4663 msg_putchar('\n'); /* cursor below last one */
4664 else
4665 {
4666 gotocmdline(TRUE); /* cursor at status line */
4667 did_show = TRUE; /* remember that we did a line */
4668 }
4669 if (opt_idx >= 0)
4670 {
4671 showoneopt(&options[opt_idx], opt_flags);
4672#ifdef FEAT_EVAL
4673 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004674 {
4675 /* Mention where the option was last set. */
4676 if (varp == options[opt_idx].var)
4677 last_set_msg(options[opt_idx].scriptID);
4678 else if ((int)options[opt_idx].indir & PV_WIN)
4679 last_set_msg(curwin->w_p_scriptID[
4680 (int)options[opt_idx].indir & PV_MASK]);
4681 else if ((int)options[opt_idx].indir & PV_BUF)
4682 last_set_msg(curbuf->b_p_scriptID[
4683 (int)options[opt_idx].indir & PV_MASK]);
4684 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004685#endif
4686 }
4687 else
4688 {
4689 char_u *p;
4690
4691 p = find_termcode(key_name);
4692 if (p == NULL)
4693 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004694 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004695 goto skip;
4696 }
4697 else
4698 (void)show_one_termcode(key_name, p, TRUE);
4699 }
4700 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004701 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004702 errmsg = e_trailing;
4703 }
4704 else
4705 {
4706 if (flags & P_BOOL) /* boolean */
4707 {
4708 if (nextchar == '=' || nextchar == ':')
4709 {
4710 errmsg = e_invarg;
4711 goto skip;
4712 }
4713
4714 /*
4715 * ":set opt!": invert
4716 * ":set opt&": reset to default value
4717 * ":set opt<": reset to global value
4718 */
4719 if (nextchar == '!')
4720 value = *(int *)(varp) ^ 1;
4721 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004722 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004723 ((flags & P_VI_DEF) || cp_val)
4724 ? VI_DEFAULT : VIM_DEFAULT];
4725 else if (nextchar == '<')
4726 {
4727 /* For 'autoread' -1 means to use global value. */
4728 if ((int *)varp == &curbuf->b_p_ar
4729 && opt_flags == OPT_LOCAL)
4730 value = -1;
4731 else
4732 value = *(int *)get_varp_scope(&(options[opt_idx]),
4733 OPT_GLOBAL);
4734 }
4735 else
4736 {
4737 /*
4738 * ":set invopt": invert
4739 * ":set opt" or ":set noopt": set or reset
4740 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004741 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004742 {
4743 errmsg = e_trailing;
4744 goto skip;
4745 }
4746 if (prefix == 2) /* inv */
4747 value = *(int *)(varp) ^ 1;
4748 else
4749 value = prefix;
4750 }
4751
4752 errmsg = set_bool_option(opt_idx, varp, (int)value,
4753 opt_flags);
4754 }
4755 else /* numeric or string */
4756 {
4757 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4758 || prefix != 1)
4759 {
4760 errmsg = e_invarg;
4761 goto skip;
4762 }
4763
4764 if (flags & P_NUM) /* numeric */
4765 {
4766 /*
4767 * Different ways to set a number option:
4768 * & set to default value
4769 * < set to global value
4770 * <xx> accept special key codes for 'wildchar'
4771 * c accept any non-digit for 'wildchar'
4772 * [-]0-9 set number
4773 * other error
4774 */
4775 ++arg;
4776 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004777 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004778 ((flags & P_VI_DEF) || cp_val)
4779 ? VI_DEFAULT : VIM_DEFAULT];
4780 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004781 {
4782 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4783 * use the global value. */
4784 if ((long *)varp == &curbuf->b_p_ul
4785 && opt_flags == OPT_LOCAL)
4786 value = NO_LOCAL_UNDOLEVEL;
4787 else
4788 value = *(long *)get_varp_scope(
4789 &(options[opt_idx]), OPT_GLOBAL);
4790 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004791 else if (((long *)varp == &p_wc
4792 || (long *)varp == &p_wcm)
4793 && (*arg == '<'
4794 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004795 || (*arg != NUL
4796 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004797 && !VIM_ISDIGIT(*arg))))
4798 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004799 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004800 if (value == 0 && (long *)varp != &p_wcm)
4801 {
4802 errmsg = e_invarg;
4803 goto skip;
4804 }
4805 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004806 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4807 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004808 /* Allow negative (for 'undolevels'), octal and
4809 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004810 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4811 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004812 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004813 {
4814 errmsg = e_invarg;
4815 goto skip;
4816 }
4817 }
4818 else
4819 {
4820 errmsg = (char_u *)N_("E521: Number required after =");
4821 goto skip;
4822 }
4823
4824 if (adding)
4825 value = *(long *)varp + value;
4826 if (prepending)
4827 value = *(long *)varp * value;
4828 if (removing)
4829 value = *(long *)varp - value;
4830 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004831 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832 }
4833 else if (opt_idx >= 0) /* string */
4834 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004835 char_u *save_arg = NULL;
4836 char_u *s = NULL;
4837 char_u *oldval = NULL; /* previous value if *varp */
4838 char_u *newval;
4839 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004840#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004841 char_u *saved_origval = NULL;
4842 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004843#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004844 unsigned newlen;
4845 int comma;
4846 int bs;
4847 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004848 was allocated */
4849
4850 /* When using ":set opt=val" for a global option
4851 * with a local value the local value will be
4852 * reset, use the global value here. */
4853 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004854 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004855 varp = options[opt_idx].var;
4856
4857 /* The old value is kept until we are sure that the
4858 * new value is valid. */
4859 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004860
4861 /* When setting the local value of a global
4862 * option, the old value may be the global value. */
4863 if (((int)options[opt_idx].indir & PV_BOTH)
4864 && (opt_flags & OPT_LOCAL))
4865 origval = *(char_u **)get_varp(
4866 &options[opt_idx]);
4867 else
4868 origval = oldval;
4869
Bram Moolenaar071d4272004-06-13 20:20:40 +00004870 if (nextchar == '&') /* set to default val */
4871 {
4872 newval = options[opt_idx].def_val[
4873 ((flags & P_VI_DEF) || cp_val)
4874 ? VI_DEFAULT : VIM_DEFAULT];
4875 if ((char_u **)varp == &p_bg)
4876 {
4877 /* guess the value of 'background' */
4878#ifdef FEAT_GUI
4879 if (gui.in_use)
4880 newval = gui_bg_default();
4881 else
4882#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004883 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004884 }
4885
4886 /* expand environment variables and ~ (since the
4887 * default value was already expanded, only
4888 * required when an environment variable was set
4889 * later */
4890 if (newval == NULL)
4891 newval = empty_option;
4892 else
4893 {
4894 s = option_expand(opt_idx, newval);
4895 if (s == NULL)
4896 s = newval;
4897 newval = vim_strsave(s);
4898 }
4899 new_value_alloced = TRUE;
4900 }
4901 else if (nextchar == '<') /* set to global val */
4902 {
4903 newval = vim_strsave(*(char_u **)get_varp_scope(
4904 &(options[opt_idx]), OPT_GLOBAL));
4905 new_value_alloced = TRUE;
4906 }
4907 else
4908 {
4909 ++arg; /* jump to after the '=' or ':' */
4910
4911 /*
4912 * Set 'keywordprg' to ":help" if an empty
4913 * value was passed to :set by the user.
4914 * Misuse errbuf[] for the resulting string.
4915 */
4916 if (varp == (char_u *)&p_kp
4917 && (*arg == NUL || *arg == ' '))
4918 {
4919 STRCPY(errbuf, ":help");
4920 save_arg = arg;
4921 arg = errbuf;
4922 }
4923 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004924 * Convert 'backspace' number to string, for
4925 * adding, prepending and removing string.
4926 */
4927 else if (varp == (char_u *)&p_bs
4928 && VIM_ISDIGIT(**(char_u **)varp))
4929 {
4930 i = getdigits((char_u **)varp);
4931 switch (i)
4932 {
4933 case 0:
4934 *(char_u **)varp = empty_option;
4935 break;
4936 case 1:
4937 *(char_u **)varp = vim_strsave(
4938 (char_u *)"indent,eol");
4939 break;
4940 case 2:
4941 *(char_u **)varp = vim_strsave(
4942 (char_u *)"indent,eol,start");
4943 break;
4944 }
4945 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004946 if (origval == oldval)
4947 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004948 oldval = *(char_u **)varp;
4949 }
4950 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004951 * Convert 'whichwrap' number to string, for
4952 * backwards compatibility with Vim 3.0.
4953 * Misuse errbuf[] for the resulting string.
4954 */
4955 else if (varp == (char_u *)&p_ww
4956 && VIM_ISDIGIT(*arg))
4957 {
4958 *errbuf = NUL;
4959 i = getdigits(&arg);
4960 if (i & 1)
4961 STRCAT(errbuf, "b,");
4962 if (i & 2)
4963 STRCAT(errbuf, "s,");
4964 if (i & 4)
4965 STRCAT(errbuf, "h,l,");
4966 if (i & 8)
4967 STRCAT(errbuf, "<,>,");
4968 if (i & 16)
4969 STRCAT(errbuf, "[,],");
4970 if (*errbuf != NUL) /* remove trailing , */
4971 errbuf[STRLEN(errbuf) - 1] = NUL;
4972 save_arg = arg;
4973 arg = errbuf;
4974 }
4975 /*
4976 * Remove '>' before 'dir' and 'bdir', for
4977 * backwards compatibility with version 3.0
4978 */
4979 else if ( *arg == '>'
4980 && (varp == (char_u *)&p_dir
4981 || varp == (char_u *)&p_bdir))
4982 {
4983 ++arg;
4984 }
4985
Bram Moolenaar071d4272004-06-13 20:20:40 +00004986 /*
4987 * Copy the new string into allocated memory.
4988 * Can't use set_string_option_direct(), because
4989 * we need to remove the backslashes.
4990 */
4991 /* get a bit too much */
4992 newlen = (unsigned)STRLEN(arg) + 1;
4993 if (adding || prepending || removing)
4994 newlen += (unsigned)STRLEN(origval) + 1;
4995 newval = alloc(newlen);
4996 if (newval == NULL) /* out of mem, don't change */
4997 break;
4998 s = newval;
4999
5000 /*
5001 * Copy the string, skip over escaped chars.
5002 * For MS-DOS and WIN32 backslashes before normal
5003 * file name characters are not removed, and keep
5004 * backslash at start, for "\\machine\path", but
5005 * do remove it for "\\\\machine\\path".
5006 * The reverse is found in ExpandOldSetting().
5007 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005008 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005009 {
5010 if (*arg == '\\' && arg[1] != NUL
5011#ifdef BACKSLASH_IN_FILENAME
5012 && !((flags & P_EXPAND)
5013 && vim_isfilec(arg[1])
5014 && (arg[1] != '\\'
5015 || (s == newval
5016 && arg[2] != '\\')))
5017#endif
5018 )
5019 ++arg; /* remove backslash */
5020#ifdef FEAT_MBYTE
5021 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005022 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005023 {
5024 /* copy multibyte char */
5025 mch_memmove(s, arg, (size_t)i);
5026 arg += i;
5027 s += i;
5028 }
5029 else
5030#endif
5031 *s++ = *arg++;
5032 }
5033 *s = NUL;
5034
5035 /*
5036 * Expand environment variables and ~.
5037 * Don't do it when adding without inserting a
5038 * comma.
5039 */
5040 if (!(adding || prepending || removing)
5041 || (flags & P_COMMA))
5042 {
5043 s = option_expand(opt_idx, newval);
5044 if (s != NULL)
5045 {
5046 vim_free(newval);
5047 newlen = (unsigned)STRLEN(s) + 1;
5048 if (adding || prepending || removing)
5049 newlen += (unsigned)STRLEN(origval) + 1;
5050 newval = alloc(newlen);
5051 if (newval == NULL)
5052 break;
5053 STRCPY(newval, s);
5054 }
5055 }
5056
5057 /* locate newval[] in origval[] when removing it
5058 * and when adding to avoid duplicates */
5059 i = 0; /* init for GCC */
5060 if (removing || (flags & P_NODUP))
5061 {
5062 i = (int)STRLEN(newval);
5063 bs = 0;
5064 for (s = origval; *s; ++s)
5065 {
5066 if ((!(flags & P_COMMA)
5067 || s == origval
5068 || (s[-1] == ',' && !(bs & 1)))
5069 && STRNCMP(s, newval, i) == 0
5070 && (!(flags & P_COMMA)
5071 || s[i] == ','
5072 || s[i] == NUL))
5073 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005074 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005075 * even number of backslashes or a single
5076 * backslash preceded by a comma before it
5077 * is recognized as a separator */
5078 if ((s > origval + 1
5079 && s[-1] == '\\'
5080 && s[-2] != ',')
5081 || (s == origval + 1
5082 && s[-1] == '\\'))
5083
Bram Moolenaar071d4272004-06-13 20:20:40 +00005084 ++bs;
5085 else
5086 bs = 0;
5087 }
5088
5089 /* do not add if already there */
5090 if ((adding || prepending) && *s)
5091 {
5092 prepending = FALSE;
5093 adding = FALSE;
5094 STRCPY(newval, origval);
5095 }
5096 }
5097
5098 /* concatenate the two strings; add a ',' if
5099 * needed */
5100 if (adding || prepending)
5101 {
5102 comma = ((flags & P_COMMA) && *origval != NUL
5103 && *newval != NUL);
5104 if (adding)
5105 {
5106 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005107 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005108 if (comma && i > 1
5109 && (flags & P_ONECOMMA) == P_ONECOMMA
5110 && origval[i - 1] == ','
5111 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005112 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 mch_memmove(newval + i + comma, newval,
5114 STRLEN(newval) + 1);
5115 mch_memmove(newval, origval, (size_t)i);
5116 }
5117 else
5118 {
5119 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005120 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121 }
5122 if (comma)
5123 newval[i] = ',';
5124 }
5125
5126 /* Remove newval[] from origval[]. (Note: "i" has
5127 * been set above and is used here). */
5128 if (removing)
5129 {
5130 STRCPY(newval, origval);
5131 if (*s)
5132 {
5133 /* may need to remove a comma */
5134 if (flags & P_COMMA)
5135 {
5136 if (s == origval)
5137 {
5138 /* include comma after string */
5139 if (s[i] == ',')
5140 ++i;
5141 }
5142 else
5143 {
5144 /* include comma before string */
5145 --s;
5146 ++i;
5147 }
5148 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005149 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005150 }
5151 }
5152
5153 if (flags & P_FLAGLIST)
5154 {
5155 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005156 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005157 {
5158 /* if options have P_FLAGLIST and
5159 * P_ONECOMMA such as 'whichwrap' */
5160 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005161 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005162 if (*s != ',' && *(s + 1) == ','
5163 && vim_strchr(s + 2, *s) != NULL)
5164 {
5165 /* Remove the duplicated value and
5166 * the next comma. */
5167 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005168 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005169 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005171 else
5172 {
5173 if ((!(flags & P_COMMA) || *s != ',')
5174 && vim_strchr(s + 1, *s) != NULL)
5175 {
5176 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005177 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005178 }
5179 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005180 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005181 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182 }
5183
5184 if (save_arg != NULL) /* number for 'whichwrap' */
5185 arg = save_arg;
5186 new_value_alloced = TRUE;
5187 }
5188
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005189 /*
5190 * Set the new value.
5191 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 *(char_u **)(varp) = newval;
5193
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005194#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005195 if (!starting
5196# ifdef FEAT_CRYPT
5197 && options[opt_idx].indir != PV_KEY
5198# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005199 && origval != NULL && newval != NULL)
5200 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005201 /* origval may be freed by
5202 * did_set_string_option(), make a copy. */
5203 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005204 /* newval (and varp) may become invalid if the
5205 * buffer is closed by autocommands. */
5206 saved_newval = vim_strsave(newval);
5207 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005208#endif
5209
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005211 * ":set" on local options. Note: when setting 'syntax'
5212 * or 'filetype' autocommands may be triggered that can
5213 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005214 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5215 new_value_alloced, oldval, errbuf, opt_flags);
5216
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005217#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005218 if (errmsg == NULL)
5219 trigger_optionsset_string(opt_idx, opt_flags,
5220 saved_origval, saved_newval);
5221 vim_free(saved_origval);
5222 vim_free(saved_newval);
5223#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005224 /* If error detected, print the error message. */
5225 if (errmsg != NULL)
5226 goto skip;
5227 }
5228 else /* key code option */
5229 {
5230 char_u *p;
5231
5232 if (nextchar == '&')
5233 {
5234 if (add_termcap_entry(key_name, TRUE) == FAIL)
5235 errmsg = (char_u *)N_("E522: Not found in termcap");
5236 }
5237 else
5238 {
5239 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005240 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005241 if (*p == '\\' && p[1] != NUL)
5242 ++p;
5243 nextchar = *p;
5244 *p = NUL;
5245 add_termcode(key_name, arg, FALSE);
5246 *p = nextchar;
5247 }
5248 if (full_screen)
5249 ttest(FALSE);
5250 redraw_all_later(CLEAR);
5251 }
5252 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005253
Bram Moolenaar071d4272004-06-13 20:20:40 +00005254 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005255 did_set_option(opt_idx, opt_flags,
5256 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005257 }
5258
5259skip:
5260 /*
5261 * Advance to next argument.
5262 * - skip until a blank found, taking care of backslashes
5263 * - skip blanks
5264 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5265 */
5266 for (i = 0; i < 2 ; ++i)
5267 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005268 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005269 if (*arg++ == '\\' && *arg != NUL)
5270 ++arg;
5271 arg = skipwhite(arg);
5272 if (*arg != '=')
5273 break;
5274 }
5275 }
5276
5277 if (errmsg != NULL)
5278 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005279 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005280 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005281 if (i + (arg - startarg) < IOSIZE)
5282 {
5283 /* append the argument with the error */
5284 STRCAT(IObuff, ": ");
5285 mch_memmove(IObuff + i, startarg, (arg - startarg));
5286 IObuff[i + (arg - startarg)] = NUL;
5287 }
5288 /* make sure all characters are printable */
5289 trans_characters(IObuff, IOSIZE);
5290
5291 ++no_wait_return; /* wait_return done later */
5292 emsg(IObuff); /* show error highlighted */
5293 --no_wait_return;
5294
5295 return FAIL;
5296 }
5297
5298 arg = skipwhite(arg);
5299 }
5300
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005301theend:
5302 if (silent_mode && did_show)
5303 {
5304 /* After displaying option values in silent mode. */
5305 silent_mode = FALSE;
5306 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5307 msg_putchar('\n');
5308 cursor_on(); /* msg_start() switches it off */
5309 out_flush();
5310 silent_mode = TRUE;
5311 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5312 }
5313
Bram Moolenaar071d4272004-06-13 20:20:40 +00005314 return OK;
5315}
5316
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005317/*
5318 * Call this when an option has been given a new value through a user command.
5319 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5320 */
5321 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005322did_set_option(
5323 int opt_idx,
5324 int opt_flags, /* possibly with OPT_MODELINE */
5325 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005326{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005327 long_u *p;
5328
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005329 options[opt_idx].flags |= P_WAS_SET;
5330
5331 /* When an option is set in the sandbox, from a modeline or in secure mode
5332 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005333 * flag. */
5334 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005335 if (secure
5336#ifdef HAVE_SANDBOX
5337 || sandbox != 0
5338#endif
5339 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005340 *p = *p | P_INSECURE;
5341 else if (new_value)
5342 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005343}
5344
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005346illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005347{
5348 if (errbuf == NULL)
5349 return (char_u *)"";
5350 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005351 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352 return errbuf;
5353}
5354
5355/*
5356 * Convert a key name or string into a key value.
5357 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005358 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005360 int
5361string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362{
5363 if (*arg == '<')
5364 return find_key_option(arg + 1);
5365 if (*arg == '^')
5366 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005367 if (multi_byte)
5368 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369 return *arg;
5370}
5371
5372#ifdef FEAT_CMDWIN
5373/*
5374 * Check value of 'cedit' and set cedit_key.
5375 * Returns NULL if value is OK, error message otherwise.
5376 */
5377 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005378check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379{
5380 int n;
5381
5382 if (*p_cedit == NUL)
5383 cedit_key = -1;
5384 else
5385 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005386 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387 if (vim_isprintc(n))
5388 return e_invarg;
5389 cedit_key = n;
5390 }
5391 return NULL;
5392}
5393#endif
5394
5395#ifdef FEAT_TITLE
5396/*
5397 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5398 * maketitle() to create and display it.
5399 * When switching the title or icon off, call mch_restore_title() to get
5400 * the old value back.
5401 */
5402 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005403did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005404{
5405 if (starting != NO_SCREEN
5406#ifdef FEAT_GUI
5407 && !gui.starting
5408#endif
5409 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005410 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005411}
5412#endif
5413
5414/*
5415 * set_options_bin - called when 'bin' changes value.
5416 */
5417 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005418set_options_bin(
5419 int oldval,
5420 int newval,
5421 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005422{
5423 /*
5424 * The option values that are changed when 'bin' changes are
5425 * copied when 'bin is set and restored when 'bin' is reset.
5426 */
5427 if (newval)
5428 {
5429 if (!oldval) /* switched on */
5430 {
5431 if (!(opt_flags & OPT_GLOBAL))
5432 {
5433 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5434 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5435 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5436 curbuf->b_p_et_nobin = curbuf->b_p_et;
5437 }
5438 if (!(opt_flags & OPT_LOCAL))
5439 {
5440 p_tw_nobin = p_tw;
5441 p_wm_nobin = p_wm;
5442 p_ml_nobin = p_ml;
5443 p_et_nobin = p_et;
5444 }
5445 }
5446
5447 if (!(opt_flags & OPT_GLOBAL))
5448 {
5449 curbuf->b_p_tw = 0; /* no automatic line wrap */
5450 curbuf->b_p_wm = 0; /* no automatic line wrap */
5451 curbuf->b_p_ml = 0; /* no modelines */
5452 curbuf->b_p_et = 0; /* no expandtab */
5453 }
5454 if (!(opt_flags & OPT_LOCAL))
5455 {
5456 p_tw = 0;
5457 p_wm = 0;
5458 p_ml = FALSE;
5459 p_et = FALSE;
5460 p_bin = TRUE; /* needed when called for the "-b" argument */
5461 }
5462 }
5463 else if (oldval) /* switched off */
5464 {
5465 if (!(opt_flags & OPT_GLOBAL))
5466 {
5467 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5468 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5469 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5470 curbuf->b_p_et = curbuf->b_p_et_nobin;
5471 }
5472 if (!(opt_flags & OPT_LOCAL))
5473 {
5474 p_tw = p_tw_nobin;
5475 p_wm = p_wm_nobin;
5476 p_ml = p_ml_nobin;
5477 p_et = p_et_nobin;
5478 }
5479 }
5480}
5481
5482#ifdef FEAT_VIMINFO
5483/*
5484 * Find the parameter represented by the given character (eg ', :, ", or /),
5485 * and return its associated value in the 'viminfo' string.
5486 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005487 * If the parameter is not specified in the string or there is no following
5488 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005489 */
5490 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005491get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492{
5493 char_u *p;
5494
5495 p = find_viminfo_parameter(type);
5496 if (p != NULL && VIM_ISDIGIT(*p))
5497 return atoi((char *)p);
5498 return -1;
5499}
5500
5501/*
5502 * Find the parameter represented by the given character (eg ''', ':', '"', or
5503 * '/') in the 'viminfo' option and return a pointer to the string after it.
5504 * Return NULL if the parameter is not specified in the string.
5505 */
5506 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005507find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508{
5509 char_u *p;
5510
5511 for (p = p_viminfo; *p; ++p)
5512 {
5513 if (*p == type)
5514 return p + 1;
5515 if (*p == 'n') /* 'n' is always the last one */
5516 break;
5517 p = vim_strchr(p, ','); /* skip until next ',' */
5518 if (p == NULL) /* hit the end without finding parameter */
5519 break;
5520 }
5521 return NULL;
5522}
5523#endif
5524
5525/*
5526 * Expand environment variables for some string options.
5527 * These string options cannot be indirect!
5528 * If "val" is NULL expand the current value of the option.
5529 * Return pointer to NameBuff, or NULL when not expanded.
5530 */
5531 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005532option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533{
5534 /* if option doesn't need expansion nothing to do */
5535 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5536 return NULL;
5537
5538 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5539 * expand_env() would truncate the string. */
5540 if (val != NULL && STRLEN(val) > MAXPATHL)
5541 return NULL;
5542
5543 if (val == NULL)
5544 val = *(char_u **)options[opt_idx].var;
5545
5546 /*
5547 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5548 * Escape spaces when expanding 'tags', they are used to separate file
5549 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005550 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551 */
5552 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005553 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005554#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005555 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5556#endif
5557 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5559 return NULL;
5560
5561 return NameBuff;
5562}
5563
5564/*
5565 * After setting various option values: recompute variables that depend on
5566 * option values.
5567 */
5568 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005569didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570{
5571 /* initialize the table for 'iskeyword' et.al. */
5572 (void)init_chartab();
5573
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005574#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005578 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005579#ifdef FEAT_SESSION
5580 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5581 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5582#endif
5583#ifdef FEAT_FOLDING
5584 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5585#endif
5586 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005587 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588#ifdef FEAT_VIRTUALEDIT
5589 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5590#endif
5591#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5592 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5593#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005594#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005595 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005596 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005597 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005598 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005600#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5601 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5602#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005603#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5605#endif
5606#ifdef FEAT_CMDWIN
5607 /* set cedit_key */
5608 (void)check_cedit();
5609#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005610#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005611 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005612#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005613#ifdef FEAT_LINEBREAK
5614 /* initialize the table for 'breakat'. */
5615 fill_breakat_flags();
5616#endif
5617
5618}
5619
5620/*
5621 * More side effects of setting options.
5622 */
5623 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005624didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005625{
5626 /* Initialize the highlight_attr[] table. */
5627 (void)highlight_changed();
5628
5629 /* Parse default for 'wildmode' */
5630 check_opt_wim();
5631
5632 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005633 /* Parse default for 'fillchars'. */
5634 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005635
5636#ifdef FEAT_CLIPBOARD
5637 /* Parse default for 'clipboard' */
5638 (void)check_clipboard_option();
5639#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005640#ifdef FEAT_VARTABS
5641 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5642 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5643#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005644}
5645
5646/*
5647 * Check for string options that are NULL (normally only termcap options).
5648 */
5649 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005650check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651{
5652 int opt_idx;
5653
5654 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5655 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5656 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5657}
5658
5659/*
5660 * Check string options in a buffer for NULL value.
5661 */
5662 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005663check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665 check_string_option(&buf->b_p_bh);
5666 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667#ifdef FEAT_MBYTE
5668 check_string_option(&buf->b_p_fenc);
5669#endif
5670 check_string_option(&buf->b_p_ff);
5671#ifdef FEAT_FIND_ID
5672 check_string_option(&buf->b_p_def);
5673 check_string_option(&buf->b_p_inc);
5674# ifdef FEAT_EVAL
5675 check_string_option(&buf->b_p_inex);
5676# endif
5677#endif
5678#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5679 check_string_option(&buf->b_p_inde);
5680 check_string_option(&buf->b_p_indk);
5681#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005682#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5683 check_string_option(&buf->b_p_bexpr);
5684#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005685#if defined(FEAT_CRYPT)
5686 check_string_option(&buf->b_p_cm);
5687#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005688 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005689#if defined(FEAT_EVAL)
5690 check_string_option(&buf->b_p_fex);
5691#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005692#ifdef FEAT_CRYPT
5693 check_string_option(&buf->b_p_key);
5694#endif
5695 check_string_option(&buf->b_p_kp);
5696 check_string_option(&buf->b_p_mps);
5697 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005698 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699 check_string_option(&buf->b_p_isk);
5700#ifdef FEAT_COMMENTS
5701 check_string_option(&buf->b_p_com);
5702#endif
5703#ifdef FEAT_FOLDING
5704 check_string_option(&buf->b_p_cms);
5705#endif
5706 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005707#ifdef FEAT_TEXTOBJ
5708 check_string_option(&buf->b_p_qe);
5709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710#ifdef FEAT_SYN_HL
5711 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005712 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005713#endif
5714#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005715 check_string_option(&buf->b_s.b_p_spc);
5716 check_string_option(&buf->b_s.b_p_spf);
5717 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005718#endif
5719#ifdef FEAT_SEARCHPATH
5720 check_string_option(&buf->b_p_sua);
5721#endif
5722#ifdef FEAT_CINDENT
5723 check_string_option(&buf->b_p_cink);
5724 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005725 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5729 check_string_option(&buf->b_p_cinw);
5730#endif
5731#ifdef FEAT_INS_EXPAND
5732 check_string_option(&buf->b_p_cpt);
5733#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005734#ifdef FEAT_COMPL_FUNC
5735 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005736 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005737#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005738#ifdef FEAT_KEYMAP
5739 check_string_option(&buf->b_p_keymap);
5740#endif
5741#ifdef FEAT_QUICKFIX
5742 check_string_option(&buf->b_p_gp);
5743 check_string_option(&buf->b_p_mp);
5744 check_string_option(&buf->b_p_efm);
5745#endif
5746 check_string_option(&buf->b_p_ep);
5747 check_string_option(&buf->b_p_path);
5748 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005749 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005750#ifdef FEAT_INS_EXPAND
5751 check_string_option(&buf->b_p_dict);
5752 check_string_option(&buf->b_p_tsr);
5753#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005754#ifdef FEAT_LISP
5755 check_string_option(&buf->b_p_lw);
5756#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005757 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005758#ifdef FEAT_MBYTE
5759 check_string_option(&buf->b_p_menc);
5760#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005761#ifdef FEAT_VARTABS
5762 check_string_option(&buf->b_p_vsts);
5763 check_string_option(&buf->b_p_vts);
5764#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765}
5766
5767/*
5768 * Free the string allocated for an option.
5769 * Checks for the string being empty_option. This may happen if we're out of
5770 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5771 * check_options().
5772 * Does NOT check for P_ALLOCED flag!
5773 */
5774 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005775free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776{
5777 if (p != empty_option)
5778 vim_free(p);
5779}
5780
5781 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005782clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783{
5784 if (*pp != empty_option)
5785 vim_free(*pp);
5786 *pp = empty_option;
5787}
5788
5789 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005790check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005791{
5792 if (*pp == NULL)
5793 *pp = empty_option;
5794}
5795
5796/*
5797 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5798 */
5799 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005800set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005801{
5802 int opt_idx;
5803
5804 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5805 if (options[opt_idx].var == (char_u *)p)
5806 {
5807 options[opt_idx].flags |= P_ALLOCED;
5808 return;
5809 }
5810 return; /* cannot happen: didn't find it! */
5811}
5812
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005813#if defined(FEAT_EVAL) || defined(PROTO)
5814/*
5815 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5816 * Return FALSE when it wasn't.
5817 * Return -1 for an unknown option.
5818 */
5819 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005820was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005821{
5822 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005823 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005824
5825 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005826 {
5827 flagp = insecure_flag(idx, opt_flags);
5828 return (*flagp & P_INSECURE) != 0;
5829 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005830 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005831 return -1;
5832}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833
5834/*
5835 * Get a pointer to the flags used for the P_INSECURE flag of option
5836 * "opt_idx". For some local options a local flags field is used.
5837 */
5838 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005839insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005840{
5841 if (opt_flags & OPT_LOCAL)
5842 switch ((int)options[opt_idx].indir)
5843 {
5844#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005845 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005846#endif
5847#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005848# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005849 case PV_FDE: return &curwin->w_p_fde_flags;
5850 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005851# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005852# ifdef FEAT_BEVAL
5853 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5854# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005855# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005856 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005857# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005858 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005859# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005860 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005861# endif
5862#endif
5863 }
5864
5865 /* Nothing special, return global flags field. */
5866 return &options[opt_idx].flags;
5867}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005868#endif
5869
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005870#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005871static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005872
5873/*
5874 * Redraw the window title and/or tab page text later.
5875 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005876static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005877{
5878 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005879 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005880}
5881#endif
5882
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883/*
5884 * Set a string option to a new value (without checking the effect).
5885 * The string is copied into allocated memory.
5886 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005887 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005888 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 */
5890 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005891set_string_option_direct(
5892 char_u *name,
5893 int opt_idx,
5894 char_u *val,
5895 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5896 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897{
5898 char_u *s;
5899 char_u **varp;
5900 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005901 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005902
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005905 idx = findoption(name);
5906 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005907 {
5908 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005909 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 }
5913
Bram Moolenaar89d40322006-08-29 15:30:07 +00005914 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005915 return;
5916
5917 s = vim_strsave(val);
5918 if (s != NULL)
5919 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005920 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005922 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923 free_string_option(*varp);
5924 *varp = s;
5925
5926 /* For buffer/window local option may also set the global value. */
5927 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005928 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929
Bram Moolenaar89d40322006-08-29 15:30:07 +00005930 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005931
5932 /* When setting both values of a global option with a local value,
5933 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005934 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935 {
5936 free_string_option(*varp);
5937 *varp = empty_option;
5938 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005939# ifdef FEAT_EVAL
5940 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005941 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005942 set_sid == 0 ? current_SID : set_sid);
5943# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944 }
5945}
5946
5947/*
5948 * Set global value for string option when it's a local option.
5949 */
5950 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005951set_string_option_global(
5952 int opt_idx, /* option index */
5953 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005954{
5955 char_u **p, *s;
5956
5957 /* the global value is always allocated */
5958 if (options[opt_idx].var == VAR_WIN)
5959 p = (char_u **)GLOBAL_WO(varp);
5960 else
5961 p = (char_u **)options[opt_idx].var;
5962 if (options[opt_idx].indir != PV_NONE
5963 && p != varp
5964 && (s = vim_strsave(*varp)) != NULL)
5965 {
5966 free_string_option(*p);
5967 *p = s;
5968 }
5969}
5970
5971/*
5972 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005973 *
5974 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005976 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005977set_string_option(
5978 int opt_idx,
5979 char_u *value,
5980 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005981{
5982 char_u *s;
5983 char_u **varp;
5984 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005985#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005986 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005988#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005989 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990
5991 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005992 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993
5994 s = vim_strsave(value);
5995 if (s != NULL)
5996 {
5997 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5998 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005999 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000 ? OPT_GLOBAL : OPT_LOCAL)
6001 : opt_flags);
6002 oldval = *varp;
6003 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006004
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006005#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006006 if (!starting
6007# ifdef FEAT_CRYPT
6008 && options[opt_idx].indir != PV_KEY
6009# endif
6010 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006011 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006012 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006013 saved_newval = vim_strsave(s);
6014 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006015#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006016 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6017 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006018 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006019
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006020#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006021 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006022 if (r == NULL)
6023 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006024 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006025 vim_free(saved_oldval);
6026 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006027#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006028 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006029 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006030}
6031
6032/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006033 * Return TRUE if "val" is a valid 'filetype' name.
6034 * Also used for 'syntax' and 'keymap'.
6035 */
6036 static int
6037valid_filetype(char_u *val)
6038{
6039 char_u *s;
6040
6041 for (s = val; *s != NUL; ++s)
6042 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6043 return FALSE;
6044 return TRUE;
6045}
6046
6047/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048 * Handle string options that need some action to perform when changed.
6049 * Returns NULL for success, or an error message for an error.
6050 */
6051 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006052did_set_string_option(
6053 int opt_idx, /* index in options[] table */
6054 char_u **varp, /* pointer to the option variable */
6055 int new_value_alloced, /* new value was allocated */
6056 char_u *oldval, /* previous value of the option */
6057 char_u *errbuf, /* buffer for errors, or NULL */
6058 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006059{
6060 char_u *errmsg = NULL;
6061 char_u *s, *p;
6062 int did_chartab = FALSE;
6063 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006064 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006065#ifdef FEAT_GUI
6066 /* set when changing an option that only requires a redraw in the GUI */
6067 int redraw_gui_only = FALSE;
6068#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006069 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006070#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6071 int did_swaptcap = FALSE;
6072#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073
6074 /* Get the global option to compare with, otherwise we would have to check
6075 * two values for all local options. */
6076 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6077
6078 /* Disallow changing some options from secure mode */
6079 if ((secure
6080#ifdef HAVE_SANDBOX
6081 || sandbox != 0
6082#endif
6083 ) && (options[opt_idx].flags & P_SECURE))
6084 {
6085 errmsg = e_secure;
6086 }
6087
Bram Moolenaar7554da42016-11-25 22:04:13 +01006088 /* Check for a "normal" directory or file name in some options. Disallow a
6089 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006090 * are often illegal in a file name. Be more permissive if "secure" is off.
6091 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006092 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006093 && vim_strpbrk(*varp, (char_u *)(secure
6094 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006095 || ((options[opt_idx].flags & P_NDNAME)
6096 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006097 {
6098 errmsg = e_invarg;
6099 }
6100
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101 /* 'term' */
6102 else if (varp == &T_NAME)
6103 {
6104 if (T_NAME[0] == NUL)
6105 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6106#ifdef FEAT_GUI
6107 if (gui.in_use)
6108 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6109 else if (term_is_gui(T_NAME))
6110 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6111#endif
6112 else if (set_termname(T_NAME) == FAIL)
6113 errmsg = (char_u *)N_("E522: Not found in termcap");
6114 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006115 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 /* Screen colors may have changed. */
6117 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006118
6119 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6120 * P_ALLOCED flag on 'term'. */
6121 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006122 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006123 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 }
6125
6126 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006127 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006129 char_u *bkc = p_bkc;
6130 unsigned int *flags = &bkc_flags;
6131
6132 if (opt_flags & OPT_LOCAL)
6133 {
6134 bkc = curbuf->b_p_bkc;
6135 flags = &curbuf->b_bkc_flags;
6136 }
6137
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006138 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6139 /* make the local value empty: use the global value */
6140 *flags = 0;
6141 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006143 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6144 errmsg = e_invarg;
6145 if ((((int)*flags & BKC_AUTO) != 0)
6146 + (((int)*flags & BKC_YES) != 0)
6147 + (((int)*flags & BKC_NO) != 0) != 1)
6148 {
6149 /* Must have exactly one of "auto", "yes" and "no". */
6150 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6151 errmsg = e_invarg;
6152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006153 }
6154 }
6155
6156 /* 'backupext' and 'patchmode' */
6157 else if (varp == &p_bex || varp == &p_pm)
6158 {
6159 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6160 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6161 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6162 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006163#ifdef FEAT_LINEBREAK
6164 /* 'breakindentopt' */
6165 else if (varp == &curwin->w_p_briopt)
6166 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006167 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006168 errmsg = e_invarg;
6169 }
6170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006171
6172 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006173 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006174 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006175 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006176 */
6177 else if ( varp == &p_isi
6178 || varp == &(curbuf->b_p_isk)
6179 || varp == &p_isp
6180 || varp == &p_isf)
6181 {
6182 if (init_chartab() == FAIL)
6183 {
6184 did_chartab = TRUE; /* need to restore it below */
6185 errmsg = e_invarg; /* error in value */
6186 }
6187 }
6188
6189 /* 'helpfile' */
6190 else if (varp == &p_hf)
6191 {
6192 /* May compute new values for $VIM and $VIMRUNTIME */
6193 if (didset_vim)
6194 {
6195 vim_setenv((char_u *)"VIM", (char_u *)"");
6196 didset_vim = FALSE;
6197 }
6198 if (didset_vimruntime)
6199 {
6200 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6201 didset_vimruntime = FALSE;
6202 }
6203 }
6204
Bram Moolenaar1a384422010-07-14 19:53:30 +02006205#ifdef FEAT_SYN_HL
6206 /* 'colorcolumn' */
6207 else if (varp == &curwin->w_p_cc)
6208 errmsg = check_colorcolumn(curwin);
6209#endif
6210
Bram Moolenaar071d4272004-06-13 20:20:40 +00006211#ifdef FEAT_MULTI_LANG
6212 /* 'helplang' */
6213 else if (varp == &p_hlg)
6214 {
6215 /* Check for "", "ab", "ab,cd", etc. */
6216 for (s = p_hlg; *s != NUL; s += 3)
6217 {
6218 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6219 {
6220 errmsg = e_invarg;
6221 break;
6222 }
6223 if (s[2] == NUL)
6224 break;
6225 }
6226 }
6227#endif
6228
6229 /* 'highlight' */
6230 else if (varp == &p_hl)
6231 {
6232 if (highlight_changed() == FAIL)
6233 errmsg = e_invarg; /* invalid flags */
6234 }
6235
6236 /* 'nrformats' */
6237 else if (gvarp == &p_nf)
6238 {
6239 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6240 errmsg = e_invarg;
6241 }
6242
6243#ifdef FEAT_SESSION
6244 /* 'sessionoptions' */
6245 else if (varp == &p_ssop)
6246 {
6247 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6248 errmsg = e_invarg;
6249 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6250 {
6251 /* Don't allow both "sesdir" and "curdir". */
6252 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6253 errmsg = e_invarg;
6254 }
6255 }
6256 /* 'viewoptions' */
6257 else if (varp == &p_vop)
6258 {
6259 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6260 errmsg = e_invarg;
6261 }
6262#endif
6263
6264 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265 else if (varp == &p_sbo)
6266 {
6267 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6268 errmsg = e_invarg;
6269 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006270
6271 /* 'ambiwidth' */
6272#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006273 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006274 {
6275 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6276 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006277 else if (set_chars_option(&p_lcs) != NULL)
6278 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006279 else if (set_chars_option(&p_fcs) != NULL)
6280 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006281 }
6282#endif
6283
6284 /* 'background' */
6285 else if (varp == &p_bg)
6286 {
6287 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6288 {
6289#ifdef FEAT_EVAL
6290 int dark = (*p_bg == 'd');
6291#endif
6292
6293 init_highlight(FALSE, FALSE);
6294
6295#ifdef FEAT_EVAL
6296 if (dark != (*p_bg == 'd')
6297 && get_var_value((char_u *)"g:colors_name") != NULL)
6298 {
6299 /* The color scheme must have set 'background' back to another
6300 * value, that's not what we want here. Disable the color
6301 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006302 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 free_string_option(p_bg);
6304 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6305 check_string_option(&p_bg);
6306 init_highlight(FALSE, FALSE);
6307 }
6308#endif
6309 }
6310 else
6311 errmsg = e_invarg;
6312 }
6313
6314 /* 'wildmode' */
6315 else if (varp == &p_wim)
6316 {
6317 if (check_opt_wim() == FAIL)
6318 errmsg = e_invarg;
6319 }
6320
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006321#ifdef FEAT_CMDL_COMPL
6322 /* 'wildoptions' */
6323 else if (varp == &p_wop)
6324 {
6325 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6326 errmsg = e_invarg;
6327 }
6328#endif
6329
Bram Moolenaar071d4272004-06-13 20:20:40 +00006330#ifdef FEAT_WAK
6331 /* 'winaltkeys' */
6332 else if (varp == &p_wak)
6333 {
6334 if (*p_wak == NUL
6335 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6336 errmsg = e_invarg;
6337# ifdef FEAT_MENU
6338# ifdef FEAT_GUI_MOTIF
6339 else if (gui.in_use)
6340 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6341# else
6342# ifdef FEAT_GUI_GTK
6343 else if (gui.in_use)
6344 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6345# endif
6346# endif
6347# endif
6348 }
6349#endif
6350
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 /* 'eventignore' */
6352 else if (varp == &p_ei)
6353 {
6354 if (check_ei() == FAIL)
6355 errmsg = e_invarg;
6356 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357
6358#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006359 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6360 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6361 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006362 {
6363 if (gvarp == &p_fenc)
6364 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006365 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006366 errmsg = e_modifiable;
6367 else if (vim_strchr(*varp, ',') != NULL)
6368 /* No comma allowed in 'fileencoding'; catches confusing it
6369 * with 'fileencodings'. */
6370 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006372 {
6373# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006375 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006376# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006377 /* Add 'fileencoding' to the swap file. */
6378 ml_setflags(curbuf);
6379 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 }
6381 if (errmsg == NULL)
6382 {
6383 /* canonize the value, so that STRCMP() can be used on it */
6384 p = enc_canonize(*varp);
6385 if (p != NULL)
6386 {
6387 vim_free(*varp);
6388 *varp = p;
6389 }
6390 if (varp == &p_enc)
6391 {
6392 errmsg = mb_init();
6393# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006394 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006395# endif
6396 }
6397 }
6398
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006399# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6401 {
6402 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6403 if (STRCMP(p_tenc, "utf-8") != 0)
6404 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6405 }
6406# endif
6407
6408 if (errmsg == NULL)
6409 {
6410# ifdef FEAT_KEYMAP
6411 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6412 * (with another encoding). */
6413 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6414 (void)keymap_init();
6415# endif
6416
6417 /* When 'termencoding' is not empty and 'encoding' changes or when
6418 * 'termencoding' changes, need to setup for keyboard input and
6419 * display output conversion. */
6420 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6421 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006422 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6423 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6424 {
6425 EMSG3(_("E950: Cannot convert between %s and %s"),
6426 p_tenc, p_enc);
6427 errmsg = e_invarg;
6428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006429 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006430
6431# if defined(WIN3264) && defined(FEAT_MBYTE)
6432 /* $HOME may have characters in active code page. */
6433 if (varp == &p_enc)
6434 init_homedir();
6435# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006436 }
6437 }
6438#endif
6439
6440#if defined(FEAT_POSTSCRIPT)
6441 else if (varp == &p_penc)
6442 {
6443 /* Canonize printencoding if VIM standard one */
6444 p = enc_canonize(p_penc);
6445 if (p != NULL)
6446 {
6447 vim_free(p_penc);
6448 p_penc = p;
6449 }
6450 else
6451 {
6452 /* Ensure lower case and '-' for '_' */
6453 for (s = p_penc; *s != NUL; s++)
6454 {
6455 if (*s == '_')
6456 *s = '-';
6457 else
6458 *s = TOLOWER_ASC(*s);
6459 }
6460 }
6461 }
6462#endif
6463
Bram Moolenaar9372a112005-12-06 19:59:18 +00006464#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006465 else if (varp == &p_imak)
6466 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006467 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468 errmsg = e_invarg;
6469 }
6470#endif
6471
6472#ifdef FEAT_KEYMAP
6473 else if (varp == &curbuf->b_p_keymap)
6474 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006475 if (!valid_filetype(*varp))
6476 errmsg = e_invarg;
6477 else
6478 /* load or unload key mapping tables */
6479 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480
Bram Moolenaarfab06232009-03-04 03:13:35 +00006481 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006482 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006483 if (*curbuf->b_p_keymap != NUL)
6484 {
6485 /* Installed a new keymap, switch on using it. */
6486 curbuf->b_p_iminsert = B_IMODE_LMAP;
6487 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6488 curbuf->b_p_imsearch = B_IMODE_LMAP;
6489 }
6490 else
6491 {
6492 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6493 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6494 curbuf->b_p_iminsert = B_IMODE_NONE;
6495 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6496 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6497 }
6498 if ((opt_flags & OPT_LOCAL) == 0)
6499 {
6500 set_iminsert_global();
6501 set_imsearch_global();
6502 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006503 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006504 }
6505 }
6506#endif
6507
6508 /* 'fileformat' */
6509 else if (gvarp == &p_ff)
6510 {
6511 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6512 errmsg = e_modifiable;
6513 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6514 errmsg = e_invarg;
6515 else
6516 {
6517 /* may also change 'textmode' */
6518 if (get_fileformat(curbuf) == EOL_DOS)
6519 curbuf->b_p_tx = TRUE;
6520 else
6521 curbuf->b_p_tx = FALSE;
6522#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006523 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006524#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006525 /* update flag in swap file */
6526 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006527 /* Redraw needed when switching to/from "mac": a CR in the text
6528 * will be displayed differently. */
6529 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6530 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006531 }
6532 }
6533
6534 /* 'fileformats' */
6535 else if (varp == &p_ffs)
6536 {
6537 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6538 errmsg = e_invarg;
6539 else
6540 {
6541 /* also change 'textauto' */
6542 if (*p_ffs == NUL)
6543 p_ta = FALSE;
6544 else
6545 p_ta = TRUE;
6546 }
6547 }
6548
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006549#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006550 /* 'cryptkey' */
6551 else if (gvarp == &p_key)
6552 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006553# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554 /* Make sure the ":set" command doesn't show the new value in the
6555 * history. */
6556 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006557# endif
6558 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6559 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006560 ml_set_crypt_key(curbuf, oldval,
6561 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006562 }
6563
6564 else if (gvarp == &p_cm)
6565 {
6566 if (opt_flags & OPT_LOCAL)
6567 p = curbuf->b_p_cm;
6568 else
6569 p = p_cm;
6570 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6571 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006572 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006573 errmsg = e_invarg;
6574 else
6575 {
6576 /* When setting the global value to empty, make it "zip". */
6577 if (*p_cm == NUL)
6578 {
6579 if (new_value_alloced)
6580 free_string_option(p_cm);
6581 p_cm = vim_strsave((char_u *)"zip");
6582 new_value_alloced = TRUE;
6583 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006584 /* When using ":set cm=name" the local value is going to be empty.
6585 * Do that here, otherwise the crypt functions will still use the
6586 * local value. */
6587 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6588 {
6589 free_string_option(curbuf->b_p_cm);
6590 curbuf->b_p_cm = empty_option;
6591 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006592
6593 /* Need to update the swapfile when the effective method changed.
6594 * Set "s" to the effective old value, "p" to the effective new
6595 * method and compare. */
6596 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6597 s = p_cm; /* was previously using the global value */
6598 else
6599 s = oldval;
6600 if (*curbuf->b_p_cm == NUL)
6601 p = p_cm; /* is now using the global value */
6602 else
6603 p = curbuf->b_p_cm;
6604 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006605 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006606
6607 /* If the global value changes need to update the swapfile for all
6608 * buffers using that value. */
6609 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6610 {
6611 buf_T *buf;
6612
Bram Moolenaar29323592016-07-24 22:04:11 +02006613 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006614 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006615 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006616 }
6617 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 }
6619#endif
6620
6621 /* 'matchpairs' */
6622 else if (gvarp == &p_mps)
6623 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006624#ifdef FEAT_MBYTE
6625 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006626 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006627 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006629 int x2 = -1;
6630 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006631
6632 if (*p != NUL)
6633 p += mb_ptr2len(p);
6634 if (*p != NUL)
6635 x2 = *p++;
6636 if (*p != NUL)
6637 {
6638 x3 = mb_ptr2char(p);
6639 p += mb_ptr2len(p);
6640 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006641 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006642 {
6643 errmsg = e_invarg;
6644 break;
6645 }
6646 if (*p == NUL)
6647 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006648 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006649 }
6650 else
6651#endif
6652 {
6653 /* Check for "x:y,x:y" */
6654 for (p = *varp; *p != NUL; p += 4)
6655 {
6656 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6657 {
6658 errmsg = e_invarg;
6659 break;
6660 }
6661 if (p[3] == NUL)
6662 break;
6663 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006664 }
6665 }
6666
6667#ifdef FEAT_COMMENTS
6668 /* 'comments' */
6669 else if (gvarp == &p_com)
6670 {
6671 for (s = *varp; *s; )
6672 {
6673 while (*s && *s != ':')
6674 {
6675 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6676 && !VIM_ISDIGIT(*s) && *s != '-')
6677 {
6678 errmsg = illegal_char(errbuf, *s);
6679 break;
6680 }
6681 ++s;
6682 }
6683 if (*s++ == NUL)
6684 errmsg = (char_u *)N_("E524: Missing colon");
6685 else if (*s == ',' || *s == NUL)
6686 errmsg = (char_u *)N_("E525: Zero length string");
6687 if (errmsg != NULL)
6688 break;
6689 while (*s && *s != ',')
6690 {
6691 if (*s == '\\' && s[1] != NUL)
6692 ++s;
6693 ++s;
6694 }
6695 s = skip_to_option_part(s);
6696 }
6697 }
6698#endif
6699
6700 /* 'listchars' */
6701 else if (varp == &p_lcs)
6702 {
6703 errmsg = set_chars_option(varp);
6704 }
6705
Bram Moolenaar071d4272004-06-13 20:20:40 +00006706 /* 'fillchars' */
6707 else if (varp == &p_fcs)
6708 {
6709 errmsg = set_chars_option(varp);
6710 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006711
6712#ifdef FEAT_CMDWIN
6713 /* 'cedit' */
6714 else if (varp == &p_cedit)
6715 {
6716 errmsg = check_cedit();
6717 }
6718#endif
6719
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006720 /* 'verbosefile' */
6721 else if (varp == &p_vfile)
6722 {
6723 verbose_stop();
6724 if (*p_vfile != NUL && verbose_open() == FAIL)
6725 errmsg = e_invarg;
6726 }
6727
Bram Moolenaar071d4272004-06-13 20:20:40 +00006728#ifdef FEAT_VIMINFO
6729 /* 'viminfo' */
6730 else if (varp == &p_viminfo)
6731 {
6732 for (s = p_viminfo; *s;)
6733 {
6734 /* Check it's a valid character */
6735 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6736 {
6737 errmsg = illegal_char(errbuf, *s);
6738 break;
6739 }
6740 if (*s == 'n') /* name is always last one */
6741 {
6742 break;
6743 }
6744 else if (*s == 'r') /* skip until next ',' */
6745 {
6746 while (*++s && *s != ',')
6747 ;
6748 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006749 else if (*s == '%')
6750 {
6751 /* optional number */
6752 while (vim_isdigit(*++s))
6753 ;
6754 }
6755 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 ++s; /* no extra chars */
6757 else /* must have a number */
6758 {
6759 while (vim_isdigit(*++s))
6760 ;
6761
6762 if (!VIM_ISDIGIT(*(s - 1)))
6763 {
6764 if (errbuf != NULL)
6765 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006766 sprintf((char *)errbuf,
6767 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768 transchar_byte(*(s - 1)));
6769 errmsg = errbuf;
6770 }
6771 else
6772 errmsg = (char_u *)"";
6773 break;
6774 }
6775 }
6776 if (*s == ',')
6777 ++s;
6778 else if (*s)
6779 {
6780 if (errbuf != NULL)
6781 errmsg = (char_u *)N_("E527: Missing comma");
6782 else
6783 errmsg = (char_u *)"";
6784 break;
6785 }
6786 }
6787 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6788 errmsg = (char_u *)N_("E528: Must specify a ' value");
6789 }
6790#endif /* FEAT_VIMINFO */
6791
6792 /* terminal options */
6793 else if (istermoption(&options[opt_idx]) && full_screen)
6794 {
6795 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6796 if (varp == &T_CCO)
6797 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006798 int colors = atoi((char *)T_CCO);
6799
6800 /* Only reinitialize colors if t_Co value has really changed to
6801 * avoid expensive reload of colorscheme if t_Co is set to the
6802 * same value multiple times. */
6803 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006804 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006805 t_colors = colors;
6806 if (t_colors <= 1)
6807 {
6808 if (new_value_alloced)
6809 vim_free(T_CCO);
6810 T_CCO = empty_option;
6811 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006812#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6813 if (is_term_win32())
6814 {
6815 swap_tcap();
6816 did_swaptcap = TRUE;
6817 }
6818#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006819 /* We now have a different color setup, initialize it again. */
6820 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 }
6823 ttest(FALSE);
6824 if (varp == &T_ME)
6825 {
6826 out_str(T_ME);
6827 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006828#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 /* Since t_me has been set, this probably means that the user
6830 * wants to use this as default colors. Need to reset default
6831 * background/foreground colors. */
6832 mch_set_normal_colors();
6833#endif
6834 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006835 if (varp == &T_BE && termcap_active)
6836 {
6837 if (*T_BE == NUL)
6838 /* When clearing t_BE we assume the user no longer wants
6839 * bracketed paste, thus disable it by writing t_BD. */
6840 out_str(T_BD);
6841 else
6842 out_str(T_BE);
6843 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844 }
6845
6846#ifdef FEAT_LINEBREAK
6847 /* 'showbreak' */
6848 else if (varp == &p_sbr)
6849 {
6850 for (s = p_sbr; *s; )
6851 {
6852 if (ptr2cells(s) != 1)
6853 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006854 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006855 }
6856 }
6857#endif
6858
6859#ifdef FEAT_GUI
6860 /* 'guifont' */
6861 else if (varp == &p_guifont)
6862 {
6863 if (gui.in_use)
6864 {
6865 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006866# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006867 /*
6868 * Put up a font dialog and let the user select a new value.
6869 * If this is cancelled go back to the old value but don't
6870 * give an error message.
6871 */
6872 if (STRCMP(p, "*") == 0)
6873 {
6874 p = gui_mch_font_dialog(oldval);
6875
6876 if (new_value_alloced)
6877 free_string_option(p_guifont);
6878
6879 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6880 new_value_alloced = TRUE;
6881 }
6882# endif
6883 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6884 {
6885# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6886 if (STRCMP(p_guifont, "*") == 0)
6887 {
6888 /* Dialog was cancelled: Keep the old value without giving
6889 * an error message. */
6890 if (new_value_alloced)
6891 free_string_option(p_guifont);
6892 p_guifont = vim_strsave(oldval);
6893 new_value_alloced = TRUE;
6894 }
6895 else
6896# endif
6897 errmsg = (char_u *)N_("E596: Invalid font(s)");
6898 }
6899 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006900 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006901 }
6902# ifdef FEAT_XFONTSET
6903 else if (varp == &p_guifontset)
6904 {
6905 if (STRCMP(p_guifontset, "*") == 0)
6906 errmsg = (char_u *)N_("E597: can't select fontset");
6907 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6908 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006909 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 }
6911# endif
6912# ifdef FEAT_MBYTE
6913 else if (varp == &p_guifontwide)
6914 {
6915 if (STRCMP(p_guifontwide, "*") == 0)
6916 errmsg = (char_u *)N_("E533: can't select wide font");
6917 else if (gui_get_wide_font() == FAIL)
6918 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006919 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920 }
6921# endif
6922#endif
6923
6924#ifdef CURSOR_SHAPE
6925 /* 'guicursor' */
6926 else if (varp == &p_guicursor)
6927 errmsg = parse_shape_opt(SHAPE_CURSOR);
6928#endif
6929
6930#ifdef FEAT_MOUSESHAPE
6931 /* 'mouseshape' */
6932 else if (varp == &p_mouseshape)
6933 {
6934 errmsg = parse_shape_opt(SHAPE_MOUSE);
6935 update_mouseshape(-1);
6936 }
6937#endif
6938
6939#ifdef FEAT_PRINTER
6940 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006941 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006942# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006943 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006944 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006945# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946#endif
6947
6948#ifdef FEAT_LANGMAP
6949 /* 'langmap' */
6950 else if (varp == &p_langmap)
6951 langmap_set();
6952#endif
6953
6954#ifdef FEAT_LINEBREAK
6955 /* 'breakat' */
6956 else if (varp == &p_breakat)
6957 fill_breakat_flags();
6958#endif
6959
6960#ifdef FEAT_TITLE
6961 /* 'titlestring' and 'iconstring' */
6962 else if (varp == &p_titlestring || varp == &p_iconstring)
6963 {
6964# ifdef FEAT_STL_OPT
6965 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6966
6967 /* NULL => statusline syntax */
6968 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6969 stl_syntax |= flagval;
6970 else
6971 stl_syntax &= ~flagval;
6972# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006973 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974 }
6975#endif
6976
6977#ifdef FEAT_GUI
6978 /* 'guioptions' */
6979 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006980 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006981 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006982 redraw_gui_only = TRUE;
6983 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006984#endif
6985
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006986#if defined(FEAT_GUI_TABLINE)
6987 /* 'guitablabel' */
6988 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006989 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006990 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006991 redraw_gui_only = TRUE;
6992 }
6993 /* 'guitabtooltip' */
6994 else if (varp == &p_gtt)
6995 {
6996 redraw_gui_only = TRUE;
6997 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006998#endif
6999
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7001 /* 'ttymouse' */
7002 else if (varp == &p_ttym)
7003 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007004 /* Switch the mouse off before changing the escape sequences used for
7005 * that. */
7006 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7008 errmsg = e_invarg;
7009 else
7010 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007011 if (termcap_active)
7012 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013 }
7014#endif
7015
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016 /* 'selection' */
7017 else if (varp == &p_sel)
7018 {
7019 if (*p_sel == NUL
7020 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7021 errmsg = e_invarg;
7022 }
7023
7024 /* 'selectmode' */
7025 else if (varp == &p_slm)
7026 {
7027 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7028 errmsg = e_invarg;
7029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030
7031#ifdef FEAT_BROWSE
7032 /* 'browsedir' */
7033 else if (varp == &p_bsdir)
7034 {
7035 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7036 && !mch_isdir(p_bsdir))
7037 errmsg = e_invarg;
7038 }
7039#endif
7040
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 /* 'keymodel' */
7042 else if (varp == &p_km)
7043 {
7044 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7045 errmsg = e_invarg;
7046 else
7047 {
7048 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7049 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7050 }
7051 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052
7053 /* 'mousemodel' */
7054 else if (varp == &p_mousem)
7055 {
7056 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7057 errmsg = e_invarg;
7058#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7059 else if (*p_mousem != *oldval)
7060 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7061 * to create or delete the popup menus. */
7062 gui_motif_update_mousemodel(root_menu);
7063#endif
7064 }
7065
7066 /* 'switchbuf' */
7067 else if (varp == &p_swb)
7068 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007069 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 errmsg = e_invarg;
7071 }
7072
7073 /* 'debug' */
7074 else if (varp == &p_debug)
7075 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007076 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 errmsg = e_invarg;
7078 }
7079
7080 /* 'display' */
7081 else if (varp == &p_dy)
7082 {
7083 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7084 errmsg = e_invarg;
7085 else
7086 (void)init_chartab();
7087
7088 }
7089
Bram Moolenaar071d4272004-06-13 20:20:40 +00007090 /* 'eadirection' */
7091 else if (varp == &p_ead)
7092 {
7093 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7094 errmsg = e_invarg;
7095 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096
7097#ifdef FEAT_CLIPBOARD
7098 /* 'clipboard' */
7099 else if (varp == &p_cb)
7100 errmsg = check_clipboard_option();
7101#endif
7102
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007103#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007104 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7105 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007106 else if (varp == &(curwin->w_s->b_p_spl)
7107 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007108 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007109 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007110 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007111 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007112 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007113 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007114 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007115 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007116 /* 'spellsuggest' */
7117 else if (varp == &p_sps)
7118 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007119 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007120 errmsg = e_invarg;
7121 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007122 /* 'mkspellmem' */
7123 else if (varp == &p_msm)
7124 {
7125 if (spell_check_msm() != OK)
7126 errmsg = e_invarg;
7127 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007128#endif
7129
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130 /* When 'bufhidden' is set, check for valid value. */
7131 else if (gvarp == &p_bh)
7132 {
7133 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7134 errmsg = e_invarg;
7135 }
7136
7137 /* When 'buftype' is set, check for valid value. */
7138 else if (gvarp == &p_bt)
7139 {
7140 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7141 errmsg = e_invarg;
7142 else
7143 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144 if (curwin->w_status_height)
7145 {
7146 curwin->w_redr_status = TRUE;
7147 redraw_later(VALID);
7148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007149 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007150#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007151 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153 }
7154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007155
7156#ifdef FEAT_STL_OPT
7157 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007158 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007159 {
7160 int wid;
7161
7162 if (varp == &p_ruf) /* reset ru_wid first */
7163 ru_wid = 0;
7164 s = *varp;
7165 if (varp == &p_ruf && *s == '%')
7166 {
7167 /* set ru_wid if 'ruf' starts with "%99(" */
7168 if (*++s == '-') /* ignore a '-' */
7169 s++;
7170 wid = getdigits(&s);
7171 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7172 ru_wid = wid;
7173 else
7174 errmsg = check_stl_option(p_ruf);
7175 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007176 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007177 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007178 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007179 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180 comp_col();
7181 }
7182#endif
7183
7184#ifdef FEAT_INS_EXPAND
7185 /* check if it is a valid value for 'complete' -- Acevedo */
7186 else if (gvarp == &p_cpt)
7187 {
7188 for (s = *varp; *s;)
7189 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007190 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191 s++;
7192 if (!*s)
7193 break;
7194 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7195 {
7196 errmsg = illegal_char(errbuf, *s);
7197 break;
7198 }
7199 if (*++s != NUL && *s != ',' && *s != ' ')
7200 {
7201 if (s[-1] == 'k' || s[-1] == 's')
7202 {
7203 /* skip optional filename after 'k' and 's' */
7204 while (*s && *s != ',' && *s != ' ')
7205 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007206 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007207 ++s;
7208 ++s;
7209 }
7210 }
7211 else
7212 {
7213 if (errbuf != NULL)
7214 {
7215 sprintf((char *)errbuf,
7216 _("E535: Illegal character after <%c>"),
7217 *--s);
7218 errmsg = errbuf;
7219 }
7220 else
7221 errmsg = (char_u *)"";
7222 break;
7223 }
7224 }
7225 }
7226 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007227
7228 /* 'completeopt' */
7229 else if (varp == &p_cot)
7230 {
7231 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7232 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007233 else
7234 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007236#endif /* FEAT_INS_EXPAND */
7237
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007238#ifdef FEAT_SIGNS
7239 /* 'signcolumn' */
7240 else if (varp == &curwin->w_p_scl)
7241 {
7242 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7243 errmsg = e_invarg;
7244 }
7245#endif
7246
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247
7248#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007249 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007250 else if (varp == &p_toolbar)
7251 {
7252 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7253 &toolbar_flags, TRUE) != OK)
7254 errmsg = e_invarg;
7255 else
7256 {
7257 out_flush();
7258 gui_mch_show_toolbar((toolbar_flags &
7259 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7260 }
7261 }
7262#endif
7263
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007264#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265 /* 'toolbariconsize': GTK+ 2 only */
7266 else if (varp == &p_tbis)
7267 {
7268 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7269 errmsg = e_invarg;
7270 else
7271 {
7272 out_flush();
7273 gui_mch_show_toolbar((toolbar_flags &
7274 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7275 }
7276 }
7277#endif
7278
7279 /* 'pastetoggle': translate key codes like in a mapping */
7280 else if (varp == &p_pt)
7281 {
7282 if (*p_pt)
7283 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007284 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285 if (p != NULL)
7286 {
7287 if (new_value_alloced)
7288 free_string_option(p_pt);
7289 p_pt = p;
7290 new_value_alloced = TRUE;
7291 }
7292 }
7293 }
7294
7295 /* 'backspace' */
7296 else if (varp == &p_bs)
7297 {
7298 if (VIM_ISDIGIT(*p_bs))
7299 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007300 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301 errmsg = e_invarg;
7302 }
7303 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7304 errmsg = e_invarg;
7305 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007306 else if (varp == &p_bo)
7307 {
7308 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7309 errmsg = e_invarg;
7310 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007312 /* 'tagcase' */
7313 else if (gvarp == &p_tc)
7314 {
7315 unsigned int *flags;
7316
7317 if (opt_flags & OPT_LOCAL)
7318 {
7319 p = curbuf->b_p_tc;
7320 flags = &curbuf->b_tc_flags;
7321 }
7322 else
7323 {
7324 p = p_tc;
7325 flags = &tc_flags;
7326 }
7327
7328 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7329 /* make the local value empty: use the global value */
7330 *flags = 0;
7331 else if (*p == NUL
7332 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7333 errmsg = e_invarg;
7334 }
7335
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007336#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007337 /* 'casemap' */
7338 else if (varp == &p_cmp)
7339 {
7340 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7341 errmsg = e_invarg;
7342 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344
7345#ifdef FEAT_DIFF
7346 /* 'diffopt' */
7347 else if (varp == &p_dip)
7348 {
7349 if (diffopt_changed() == FAIL)
7350 errmsg = e_invarg;
7351 }
7352#endif
7353
7354#ifdef FEAT_FOLDING
7355 /* 'foldmethod' */
7356 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7357 {
7358 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7359 || *curwin->w_p_fdm == NUL)
7360 errmsg = e_invarg;
7361 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007362 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007363 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007364 if (foldmethodIsDiff(curwin))
7365 newFoldLevel();
7366 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007367 }
7368# ifdef FEAT_EVAL
7369 /* 'foldexpr' */
7370 else if (varp == &curwin->w_p_fde)
7371 {
7372 if (foldmethodIsExpr(curwin))
7373 foldUpdateAll(curwin);
7374 }
7375# endif
7376 /* 'foldmarker' */
7377 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7378 {
7379 p = vim_strchr(*varp, ',');
7380 if (p == NULL)
7381 errmsg = (char_u *)N_("E536: comma required");
7382 else if (p == *varp || p[1] == NUL)
7383 errmsg = e_invarg;
7384 else if (foldmethodIsMarker(curwin))
7385 foldUpdateAll(curwin);
7386 }
7387 /* 'commentstring' */
7388 else if (gvarp == &p_cms)
7389 {
7390 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7391 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7392 }
7393 /* 'foldopen' */
7394 else if (varp == &p_fdo)
7395 {
7396 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7397 errmsg = e_invarg;
7398 }
7399 /* 'foldclose' */
7400 else if (varp == &p_fcl)
7401 {
7402 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7403 errmsg = e_invarg;
7404 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007405 /* 'foldignore' */
7406 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7407 {
7408 if (foldmethodIsIndent(curwin))
7409 foldUpdateAll(curwin);
7410 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007411#endif
7412
7413#ifdef FEAT_VIRTUALEDIT
7414 /* 'virtualedit' */
7415 else if (varp == &p_ve)
7416 {
7417 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7418 errmsg = e_invarg;
7419 else if (STRCMP(p_ve, oldval) != 0)
7420 {
7421 /* Recompute cursor position in case the new 've' setting
7422 * changes something. */
7423 validate_virtcol();
7424 coladvance(curwin->w_virtcol);
7425 }
7426 }
7427#endif
7428
7429#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7430 else if (varp == &p_csqf)
7431 {
7432 if (p_csqf != NULL)
7433 {
7434 p = p_csqf;
7435 while (*p != NUL)
7436 {
7437 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7438 || p[1] == NUL
7439 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7440 || (p[2] != NUL && p[2] != ','))
7441 {
7442 errmsg = e_invarg;
7443 break;
7444 }
7445 else if (p[2] == NUL)
7446 break;
7447 else
7448 p += 3;
7449 }
7450 }
7451 }
7452#endif
7453
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007454#ifdef FEAT_CINDENT
7455 /* 'cinoptions' */
7456 else if (gvarp == &p_cino)
7457 {
7458 /* TODO: recognize errors */
7459 parse_cino(curbuf);
7460 }
7461#endif
7462
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007463#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007464 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007465 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007466 {
7467 if (!gui_mch_set_rendering_options(p_rop))
7468 errmsg = e_invarg;
7469 }
7470#endif
7471
Bram Moolenaard0b51382016-11-04 15:23:45 +01007472 else if (gvarp == &p_ft)
7473 {
7474 if (!valid_filetype(*varp))
7475 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007476 else
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007477 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007478 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007479
7480#ifdef FEAT_SYN_HL
7481 else if (gvarp == &p_syn)
7482 {
7483 if (!valid_filetype(*varp))
7484 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007485 else
7486 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007487 }
7488#endif
7489
Bram Moolenaar825680f2017-07-22 17:04:02 +02007490#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007491 /* 'termwinkey' */
7492 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007493 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007494 if (*curwin->w_p_twk != NUL
7495 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007496 errmsg = e_invarg;
7497 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007498 /* 'termwinsize' */
7499 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007500 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007501 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007502 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007503 p = skipdigits(curwin->w_p_tws);
7504 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007505 || (*p != 'x' && *p != '*')
7506 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007507 errmsg = e_invarg;
7508 }
7509 }
7510#endif
7511
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007512#ifdef FEAT_VARTABS
7513 /* 'varsofttabstop' */
7514 else if (varp == &(curbuf->b_p_vsts))
7515 {
7516 char_u *cp;
7517
7518 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7519 {
7520 if (curbuf->b_p_vsts_array)
7521 {
7522 vim_free(curbuf->b_p_vsts_array);
7523 curbuf->b_p_vsts_array = 0;
7524 }
7525 }
7526 else
7527 {
7528 for (cp = *varp; *cp; ++cp)
7529 {
7530 if (vim_isdigit(*cp))
7531 continue;
7532 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7533 continue;
7534 errmsg = e_invarg;
7535 break;
7536 }
7537 if (errmsg == NULL)
7538 {
7539 int *oldarray = curbuf->b_p_vsts_array;
7540 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7541 {
7542 if (oldarray)
7543 vim_free(oldarray);
7544 }
7545 else
7546 errmsg = e_invarg;
7547 }
7548 }
7549 }
7550
7551 /* 'vartabstop' */
7552 else if (varp == &(curbuf->b_p_vts))
7553 {
7554 char_u *cp;
7555
7556 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7557 {
7558 if (curbuf->b_p_vts_array)
7559 {
7560 vim_free(curbuf->b_p_vts_array);
7561 curbuf->b_p_vts_array = NULL;
7562 }
7563 }
7564 else
7565 {
7566 for (cp = *varp; *cp; ++cp)
7567 {
7568 if (vim_isdigit(*cp))
7569 continue;
7570 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7571 continue;
7572 errmsg = e_invarg;
7573 break;
7574 }
7575 if (errmsg == NULL)
7576 {
7577 int *oldarray = curbuf->b_p_vts_array;
7578 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7579 {
7580 if (oldarray)
7581 vim_free(oldarray);
7582#ifdef FEAT_FOLDING
7583 if (foldmethodIsIndent(curwin))
7584 foldUpdateAll(curwin);
7585#endif /* FEAT_FOLDING */
7586 }
7587 else
7588 errmsg = e_invarg;
7589 }
7590 }
7591 }
7592#endif
7593
Bram Moolenaar071d4272004-06-13 20:20:40 +00007594 /* Options that are a list of flags. */
7595 else
7596 {
7597 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007598 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007599 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007600 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007602 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007603 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007604 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007605 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007606#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007607 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007608 p = (char_u *)COCU_ALL;
7609#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007610 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007611 {
7612#ifdef FEAT_MOUSE
7613 p = (char_u *)MOUSE_ALL;
7614#else
7615 if (*p_mouse != NUL)
7616 errmsg = (char_u *)N_("E538: No mouse support");
7617#endif
7618 }
7619#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007620 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621 p = (char_u *)GO_ALL;
7622#endif
7623 if (p != NULL)
7624 {
7625 for (s = *varp; *s; ++s)
7626 if (vim_strchr(p, *s) == NULL)
7627 {
7628 errmsg = illegal_char(errbuf, *s);
7629 break;
7630 }
7631 }
7632 }
7633
7634 /*
7635 * If error detected, restore the previous value.
7636 */
7637 if (errmsg != NULL)
7638 {
7639 if (new_value_alloced)
7640 free_string_option(*varp);
7641 *varp = oldval;
7642 /*
7643 * When resetting some values, need to act on it.
7644 */
7645 if (did_chartab)
7646 (void)init_chartab();
7647 if (varp == &p_hl)
7648 (void)highlight_changed();
7649 }
7650 else
7651 {
7652#ifdef FEAT_EVAL
7653 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007654 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007655#endif
7656 /*
7657 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007658 * Use "free_oldval", because recursiveness may change the flags under
7659 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007661 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662 free_string_option(oldval);
7663 if (new_value_alloced)
7664 options[opt_idx].flags |= P_ALLOCED;
7665 else
7666 options[opt_idx].flags &= ~P_ALLOCED;
7667
7668 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007669 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670 {
7671 /* global option with local value set to use global value; free
7672 * the local value and make it empty */
7673 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7674 free_string_option(*(char_u **)p);
7675 *(char_u **)p = empty_option;
7676 }
7677
7678 /* May set global value for local option. */
7679 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7680 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007681
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007682 /*
7683 * Trigger the autocommand only after setting the flags.
7684 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007685#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007686 /* When 'syntax' is set, load the syntax of that name */
7687 if (varp == &(curbuf->b_p_syn))
7688 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007689 static int syn_recursive = 0;
7690
7691 ++syn_recursive;
7692 // Only pass TRUE for "force" when the value changed or not used
7693 // recursively, to avoid endless recurrence.
7694 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7695 value_changed || syn_recursive == 1, curbuf);
7696 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007697 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007698#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007699 else if (varp == &(curbuf->b_p_ft))
7700 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007701 /* 'filetype' is set, trigger the FileType autocommand.
7702 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007703 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007704 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007705 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007706 static int ft_recursive = 0;
7707
7708 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007709 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007710 // Only pass TRUE for "force" when the value changed or not
7711 // used recursively, to avoid endless recurrence.
7712 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7713 value_changed || ft_recursive == 1, curbuf);
7714 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007715 /* Just in case the old "curbuf" is now invalid. */
7716 if (varp != &(curbuf->b_p_ft))
7717 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007718 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007719 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007720#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007721 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007722 {
7723 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007724 char_u *q = curwin->w_s->b_p_spl;
7725
7726 /* Skip the first name if it is "cjk". */
7727 if (STRNCMP(q, "cjk,", 4) == 0)
7728 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007729
7730 /*
7731 * Source the spell/LANG.vim in 'runtimepath'.
7732 * They could set 'spellcapcheck' depending on the language.
7733 * Use the first name in 'spelllang' up to '_region' or
7734 * '.encoding'.
7735 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007736 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007737 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7738 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007739 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007740 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007741 }
7742#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007743 }
7744
7745#ifdef FEAT_MOUSE
7746 if (varp == &p_mouse)
7747 {
7748# ifdef FEAT_MOUSE_TTY
7749 if (*p_mouse == NUL)
7750 mch_setmouse(FALSE); /* switch mouse off */
7751 else
7752# endif
7753 setmouse(); /* in case 'mouse' changed */
7754 }
7755#endif
7756
Bram Moolenaar913077c2012-03-28 19:59:04 +02007757 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007758 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007759 curwin->w_set_curswant = TRUE;
7760
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007761#ifdef FEAT_GUI
7762 /* check redraw when it's not a GUI option or the GUI is active. */
7763 if (!redraw_gui_only || gui.in_use)
7764#endif
7765 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007767#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7768 if (did_swaptcap)
7769 {
7770 if (t_colors < 256)
7771 p_tgc = 0;
7772 set_termname((char_u *)"win32");
7773 init_highlight(TRUE, FALSE);
7774 }
7775#endif
7776
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777 return errmsg;
7778}
7779
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007780#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007781/*
7782 * Simple int comparison function for use with qsort()
7783 */
7784 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007785int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007786{
7787 return *(const int *)a - *(const int *)b;
7788}
7789
7790/*
7791 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7792 * Returns error message, NULL if it's OK.
7793 */
7794 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007795check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007796{
7797 char_u *s;
7798 int col;
7799 int count = 0;
7800 int color_cols[256];
7801 int i;
7802 int j = 0;
7803
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007804 if (wp->w_buffer == NULL)
7805 return NULL; /* buffer was closed */
7806
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007807 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007808 {
7809 if (*s == '-' || *s == '+')
7810 {
7811 /* -N and +N: add to 'textwidth' */
7812 col = (*s == '-') ? -1 : 1;
7813 ++s;
7814 if (!VIM_ISDIGIT(*s))
7815 return e_invarg;
7816 col = col * getdigits(&s);
7817 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007818 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007819 col += wp->w_buffer->b_p_tw;
7820 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007821 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007822 }
7823 else if (VIM_ISDIGIT(*s))
7824 col = getdigits(&s);
7825 else
7826 return e_invarg;
7827 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007828skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007829 if (*s == NUL)
7830 break;
7831 if (*s != ',')
7832 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007833 if (*++s == NUL)
7834 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007835 }
7836
7837 vim_free(wp->w_p_cc_cols);
7838 if (count == 0)
7839 wp->w_p_cc_cols = NULL;
7840 else
7841 {
7842 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7843 if (wp->w_p_cc_cols != NULL)
7844 {
7845 /* sort the columns for faster usage on screen redraw inside
7846 * win_line() */
7847 qsort(color_cols, count, sizeof(int), int_cmp);
7848
7849 for (i = 0; i < count; ++i)
7850 /* skip duplicates */
7851 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7852 wp->w_p_cc_cols[j++] = color_cols[i];
7853 wp->w_p_cc_cols[j] = -1; /* end marker */
7854 }
7855 }
7856
7857 return NULL; /* no error */
7858}
7859#endif
7860
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861/*
7862 * Handle setting 'listchars' or 'fillchars'.
7863 * Returns error message, NULL if it's OK.
7864 */
7865 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007866set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007867{
7868 int round, i, len, entries;
7869 char_u *p, *s;
7870 int c1, c2 = 0;
7871 struct charstab
7872 {
7873 int *cp;
7874 char *name;
7875 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876 static struct charstab filltab[] =
7877 {
7878 {&fill_stl, "stl"},
7879 {&fill_stlnc, "stlnc"},
7880 {&fill_vert, "vert"},
7881 {&fill_fold, "fold"},
7882 {&fill_diff, "diff"},
7883 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884 static struct charstab lcstab[] =
7885 {
7886 {&lcs_eol, "eol"},
7887 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007888 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007890 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007891 {&lcs_tab2, "tab"},
7892 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007893#ifdef FEAT_CONCEAL
7894 {&lcs_conceal, "conceal"},
7895#else
7896 {NULL, "conceal"},
7897#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 };
7899 struct charstab *tab;
7900
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902 {
7903 tab = lcstab;
7904 entries = sizeof(lcstab) / sizeof(struct charstab);
7905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906 else
7907 {
7908 tab = filltab;
7909 entries = sizeof(filltab) / sizeof(struct charstab);
7910 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911
7912 /* first round: check for valid value, second round: assign values */
7913 for (round = 0; round <= 1; ++round)
7914 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007915 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916 {
7917 /* After checking that the value is valid: set defaults: space for
7918 * 'fillchars', NUL for 'listchars' */
7919 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007920 if (tab[i].cp != NULL)
7921 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007922 if (varp == &p_lcs)
7923 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924 else
7925 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926 }
7927 p = *varp;
7928 while (*p)
7929 {
7930 for (i = 0; i < entries; ++i)
7931 {
7932 len = (int)STRLEN(tab[i].name);
7933 if (STRNCMP(p, tab[i].name, len) == 0
7934 && p[len] == ':'
7935 && p[len + 1] != NUL)
7936 {
7937 s = p + len + 1;
7938#ifdef FEAT_MBYTE
7939 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007940 if (mb_char2cells(c1) > 1)
7941 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007942#else
7943 c1 = *s++;
7944#endif
7945 if (tab[i].cp == &lcs_tab2)
7946 {
7947 if (*s == NUL)
7948 continue;
7949#ifdef FEAT_MBYTE
7950 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007951 if (mb_char2cells(c2) > 1)
7952 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953#else
7954 c2 = *s++;
7955#endif
7956 }
7957 if (*s == ',' || *s == NUL)
7958 {
7959 if (round)
7960 {
7961 if (tab[i].cp == &lcs_tab2)
7962 {
7963 lcs_tab1 = c1;
7964 lcs_tab2 = c2;
7965 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007966 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 *(tab[i].cp) = c1;
7968
7969 }
7970 p = s;
7971 break;
7972 }
7973 }
7974 }
7975
7976 if (i == entries)
7977 return e_invarg;
7978 if (*p == ',')
7979 ++p;
7980 }
7981 }
7982
7983 return NULL; /* no error */
7984}
7985
7986#ifdef FEAT_STL_OPT
7987/*
7988 * Check validity of options with the 'statusline' format.
7989 * Return error message or NULL.
7990 */
7991 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007992check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993{
7994 int itemcnt = 0;
7995 int groupdepth = 0;
7996 static char_u errbuf[80];
7997
7998 while (*s && itemcnt < STL_MAX_ITEM)
7999 {
8000 /* Check for valid keys after % sequences */
8001 while (*s && *s != '%')
8002 s++;
8003 if (!*s)
8004 break;
8005 s++;
8006 if (*s != '%' && *s != ')')
8007 ++itemcnt;
8008 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8009 {
8010 s++;
8011 continue;
8012 }
8013 if (*s == ')')
8014 {
8015 s++;
8016 if (--groupdepth < 0)
8017 break;
8018 continue;
8019 }
8020 if (*s == '-')
8021 s++;
8022 while (VIM_ISDIGIT(*s))
8023 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008024 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025 continue;
8026 if (*s == '.')
8027 {
8028 s++;
8029 while (*s && VIM_ISDIGIT(*s))
8030 s++;
8031 }
8032 if (*s == '(')
8033 {
8034 groupdepth++;
8035 continue;
8036 }
8037 if (vim_strchr(STL_ALL, *s) == NULL)
8038 {
8039 return illegal_char(errbuf, *s);
8040 }
8041 if (*s == '{')
8042 {
8043 s++;
8044 while (*s != '}' && *s)
8045 s++;
8046 if (*s != '}')
8047 return (char_u *)N_("E540: Unclosed expression sequence");
8048 }
8049 }
8050 if (itemcnt >= STL_MAX_ITEM)
8051 return (char_u *)N_("E541: too many items");
8052 if (groupdepth != 0)
8053 return (char_u *)N_("E542: unbalanced groups");
8054 return NULL;
8055}
8056#endif
8057
8058#ifdef FEAT_CLIPBOARD
8059/*
8060 * Extract the items in the 'clipboard' option and set global values.
8061 */
8062 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008063check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008065 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008066 int new_autoselect_star = FALSE;
8067 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008068 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008069 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 regprog_T *new_exclude_prog = NULL;
8071 char_u *errmsg = NULL;
8072 char_u *p;
8073
8074 for (p = p_cb; *p != NUL; )
8075 {
8076 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8077 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008078 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008079 p += 7;
8080 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008081 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008082 && (p[11] == ',' || p[11] == NUL))
8083 {
8084 new_unnamed |= CLIP_UNNAMED_PLUS;
8085 p += 11;
8086 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008088 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008089 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008090 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 p += 10;
8092 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008093 else if (STRNCMP(p, "autoselectplus", 14) == 0
8094 && (p[14] == ',' || p[14] == NUL))
8095 {
8096 new_autoselect_plus = TRUE;
8097 p += 14;
8098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008100 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101 {
8102 new_autoselectml = TRUE;
8103 p += 12;
8104 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008105 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8106 {
8107 new_html = TRUE;
8108 p += 4;
8109 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008110 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8111 {
8112 p += 8;
8113 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8114 if (new_exclude_prog == NULL)
8115 errmsg = e_invarg;
8116 break;
8117 }
8118 else
8119 {
8120 errmsg = e_invarg;
8121 break;
8122 }
8123 if (*p == ',')
8124 ++p;
8125 }
8126 if (errmsg == NULL)
8127 {
8128 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008129 clip_autoselect_star = new_autoselect_star;
8130 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008132 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008133 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008135#ifdef FEAT_GUI_GTK
8136 if (gui.in_use)
8137 {
8138 gui_gtk_set_selection_targets();
8139 gui_gtk_set_dnd_targets();
8140 }
8141#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 }
8143 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008144 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145
8146 return errmsg;
8147}
8148#endif
8149
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008150#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008151 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008152did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008153{
8154 char_u *errmsg = NULL;
8155 win_T *wp;
8156 int l;
8157
8158 if (is_spellfile)
8159 {
8160 l = (int)STRLEN(curwin->w_s->b_p_spf);
8161 if (l > 0 && (l < 4
8162 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8163 errmsg = e_invarg;
8164 }
8165
8166 if (errmsg == NULL)
8167 {
8168 FOR_ALL_WINDOWS(wp)
8169 if (wp->w_buffer == curbuf && wp->w_p_spell)
8170 {
8171 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008172 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008173 }
8174 }
8175 return errmsg;
8176}
8177
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008178/*
8179 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8180 * Return error message when failed, NULL when OK.
8181 */
8182 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008183compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008184{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008185 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008186 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008187
Bram Moolenaar860cae12010-06-05 23:22:07 +02008188 if (*synblock->b_p_spc == NUL)
8189 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008190 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008191 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008192 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008193 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008194 if (re != NULL)
8195 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008196 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008197 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008198 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008199 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008200 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008201 return e_invarg;
8202 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008203 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008204 }
8205
Bram Moolenaar473de612013-06-08 18:19:48 +02008206 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008207 return NULL;
8208}
8209#endif
8210
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008211#if defined(FEAT_EVAL) || defined(PROTO)
8212/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008213 * Set the scriptID for an option, taking care of setting the buffer- or
8214 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008215 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008216 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008217set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008218{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008219 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8220 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008221
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008222 /* Remember where the option was set. For local options need to do that
8223 * in the buffer or window structure. */
8224 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008225 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008226 if (both || (opt_flags & OPT_LOCAL))
8227 {
8228 if (indir & PV_BUF)
8229 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8230 else if (indir & PV_WIN)
8231 curwin->w_p_scriptID[indir & PV_MASK] = id;
8232 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008233}
8234#endif
8235
Bram Moolenaar071d4272004-06-13 20:20:40 +00008236/*
8237 * Set the value of a boolean option, and take care of side effects.
8238 * Returns NULL for success, or an error message for an error.
8239 */
8240 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008241set_bool_option(
8242 int opt_idx, /* index in options[] table */
8243 char_u *varp, /* pointer to the option variable */
8244 int value, /* new value */
8245 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246{
8247 int old_value = *(int *)varp;
8248
Bram Moolenaar071d4272004-06-13 20:20:40 +00008249 /* Disallow changing some options from secure mode */
8250 if ((secure
8251#ifdef HAVE_SANDBOX
8252 || sandbox != 0
8253#endif
8254 ) && (options[opt_idx].flags & P_SECURE))
8255 return e_secure;
8256
8257 *(int *)varp = value; /* set the new value */
8258#ifdef FEAT_EVAL
8259 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008260 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261#endif
8262
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008263#ifdef FEAT_GUI
8264 need_mouse_correct = TRUE;
8265#endif
8266
Bram Moolenaar071d4272004-06-13 20:20:40 +00008267 /* May set global value for local option. */
8268 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8269 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8270
8271 /*
8272 * Handle side effects of changing a bool option.
8273 */
8274
8275 /* 'compatible' */
8276 if ((int *)varp == &p_cp)
8277 {
8278 compatible_set();
8279 }
8280
Bram Moolenaar920694c2016-08-21 17:45:02 +02008281#ifdef FEAT_LANGMAP
8282 if ((int *)varp == &p_lrm)
8283 /* 'langremap' -> !'langnoremap' */
8284 p_lnr = !p_lrm;
8285 else if ((int *)varp == &p_lnr)
8286 /* 'langnoremap' -> !'langremap' */
8287 p_lrm = !p_lnr;
8288#endif
8289
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008290#ifdef FEAT_PERSISTENT_UNDO
8291 /* 'undofile' */
8292 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8293 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008294 /* Only take action when the option was set. When reset we do not
8295 * delete the undo file, the option may be set again without making
8296 * any changes in between. */
8297 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008298 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008299 char_u hash[UNDO_HASH_SIZE];
8300 buf_T *save_curbuf = curbuf;
8301
Bram Moolenaar29323592016-07-24 22:04:11 +02008302 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008303 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008304 /* When 'undofile' is set globally: for every buffer, otherwise
8305 * only for the current buffer: Try to read in the undofile,
8306 * if one exists, the buffer wasn't changed and the buffer was
8307 * loaded */
8308 if ((curbuf == save_curbuf
8309 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8310 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8311 {
8312 u_compute_hash(hash);
8313 u_read_undo(NULL, hash, curbuf->b_fname);
8314 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008315 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008316 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008317 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008318 }
8319#endif
8320
Bram Moolenaar071d4272004-06-13 20:20:40 +00008321 else if ((int *)varp == &curbuf->b_p_ro)
8322 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008323 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8325 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008326
8327 /* when 'readonly' is set may give W10 again */
8328 if (curbuf->b_p_ro)
8329 curbuf->b_did_warn = FALSE;
8330
Bram Moolenaar071d4272004-06-13 20:20:40 +00008331#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008332 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008333#endif
8334 }
8335
Bram Moolenaar9c449722010-07-20 18:44:27 +02008336#ifdef FEAT_GUI
8337 else if ((int *)varp == &p_mh)
8338 {
8339 if (!p_mh)
8340 gui_mch_mousehide(FALSE);
8341 }
8342#endif
8343
Bram Moolenaara539df02010-08-01 14:35:05 +02008344 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008346 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008347# ifdef FEAT_TERMINAL
8348 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008349 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8350 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008351 {
8352 curbuf->b_p_ma = FALSE;
8353 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8354 }
8355# endif
8356# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008357 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008358# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008359 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008360#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361 /* when 'endofline' is changed, redraw the window title */
8362 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008363 {
8364 redraw_titles();
8365 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008366 /* when 'fixeol' is changed, redraw the window title */
8367 else if ((int *)varp == &curbuf->b_p_fixeol)
8368 {
8369 redraw_titles();
8370 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008371# ifdef FEAT_MBYTE
8372 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008373 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008374 {
8375 redraw_titles();
8376 }
8377# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378#endif
8379
8380 /* when 'bin' is set also set some other options */
8381 else if ((int *)varp == &curbuf->b_p_bin)
8382 {
8383 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8384#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008385 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386#endif
8387 }
8388
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389 /* when 'buflisted' changes, trigger autocommands */
8390 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8391 {
8392 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8393 NULL, NULL, TRUE, curbuf);
8394 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008395
8396 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8397 else if ((int *)varp == &curbuf->b_p_swf)
8398 {
8399 if (curbuf->b_p_swf && p_uc)
8400 ml_open_file(curbuf); /* create the swap file */
8401 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008402 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8403 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404 mf_close_file(curbuf, TRUE); /* remove the swap file */
8405 }
8406
8407 /* when 'terse' is set change 'shortmess' */
8408 else if ((int *)varp == &p_terse)
8409 {
8410 char_u *p;
8411
8412 p = vim_strchr(p_shm, SHM_SEARCH);
8413
8414 /* insert 's' in p_shm */
8415 if (p_terse && p == NULL)
8416 {
8417 STRCPY(IObuff, p_shm);
8418 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008419 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420 }
8421 /* remove 's' from p_shm */
8422 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008423 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424 }
8425
8426 /* when 'paste' is set or reset also change other options */
8427 else if ((int *)varp == &p_paste)
8428 {
8429 paste_option_changed();
8430 }
8431
8432 /* when 'insertmode' is set from an autocommand need to do work here */
8433 else if ((int *)varp == &p_im)
8434 {
8435 if (p_im)
8436 {
8437 if ((State & INSERT) == 0)
8438 need_start_insertmode = TRUE;
8439 stop_insert_mode = FALSE;
8440 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008441 /* only reset if it was set previously */
8442 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443 {
8444 need_start_insertmode = FALSE;
8445 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008446 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 clear_cmdline = TRUE; /* remove "(insert)" */
8448 restart_edit = 0;
8449 }
8450 }
8451
8452 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8453 else if ((int *)varp == &p_ic && p_hls)
8454 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008455 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008456 }
8457
8458#ifdef FEAT_SEARCH_EXTRA
8459 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8460 else if ((int *)varp == &p_hls)
8461 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008462 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008463 }
8464#endif
8465
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8467 * at the end of normal_cmd() */
8468 else if ((int *)varp == &curwin->w_p_scb)
8469 {
8470 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008471 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008472 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008473 curwin->w_scbind_pos = curwin->w_topline;
8474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008476
Bram Moolenaar4033c552017-09-16 20:54:51 +02008477#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478 /* There can be only one window with 'previewwindow' set. */
8479 else if ((int *)varp == &curwin->w_p_pvw)
8480 {
8481 if (curwin->w_p_pvw)
8482 {
8483 win_T *win;
8484
Bram Moolenaar29323592016-07-24 22:04:11 +02008485 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486 if (win->w_p_pvw && win != curwin)
8487 {
8488 curwin->w_p_pvw = FALSE;
8489 return (char_u *)N_("E590: A preview window already exists");
8490 }
8491 }
8492 }
8493#endif
8494
8495 /* when 'textmode' is set or reset also change 'fileformat' */
8496 else if ((int *)varp == &curbuf->b_p_tx)
8497 {
8498 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8499 }
8500
8501 /* when 'textauto' is set or reset also change 'fileformats' */
8502 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008503 set_string_option_direct((char_u *)"ffs", -1,
8504 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008505 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506
8507 /*
8508 * When 'lisp' option changes include/exclude '-' in
8509 * keyword characters.
8510 */
8511#ifdef FEAT_LISP
8512 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8513 {
8514 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8515 }
8516#endif
8517
8518#ifdef FEAT_TITLE
8519 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008520 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008522 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008523 }
8524#endif
8525
8526 else if ((int *)varp == &curbuf->b_changed)
8527 {
8528 if (!value)
8529 save_file_ff(curbuf); /* Buffer is unchanged */
8530#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008531 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008534 }
8535
8536#ifdef BACKSLASH_IN_FILENAME
8537 else if ((int *)varp == &p_ssl)
8538 {
8539 if (p_ssl)
8540 {
8541 psepc = '/';
8542 psepcN = '\\';
8543 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008544 }
8545 else
8546 {
8547 psepc = '\\';
8548 psepcN = '/';
8549 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008550 }
8551
8552 /* need to adjust the file name arguments and buffer names. */
8553 buflist_slash_adjust();
8554 alist_slash_adjust();
8555# ifdef FEAT_EVAL
8556 scriptnames_slash_adjust();
8557# endif
8558 }
8559#endif
8560
8561 /* If 'wrap' is set, set w_leftcol to zero. */
8562 else if ((int *)varp == &curwin->w_p_wrap)
8563 {
8564 if (curwin->w_p_wrap)
8565 curwin->w_leftcol = 0;
8566 }
8567
Bram Moolenaar071d4272004-06-13 20:20:40 +00008568 else if ((int *)varp == &p_ea)
8569 {
8570 if (p_ea && !old_value)
8571 win_equal(curwin, FALSE, 0);
8572 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008573
8574 else if ((int *)varp == &p_wiv)
8575 {
8576 /*
8577 * When 'weirdinvert' changed, set/reset 't_xs'.
8578 * Then set 'weirdinvert' according to value of 't_xs'.
8579 */
8580 if (p_wiv && !old_value)
8581 T_XS = (char_u *)"y";
8582 else if (!p_wiv && old_value)
8583 T_XS = empty_option;
8584 p_wiv = (*T_XS != NUL);
8585 }
8586
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008587#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 else if ((int *)varp == &p_beval)
8589 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008590 if (!balloonEvalForTerm)
8591 {
8592 if (p_beval && !old_value)
8593 gui_mch_enable_beval_area(balloonEval);
8594 else if (!p_beval && old_value)
8595 gui_mch_disable_beval_area(balloonEval);
8596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008597 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008598#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008599#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008600 else if ((int *)varp == &p_bevalterm)
8601 {
8602 mch_bevalterm_changed();
8603 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008604#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008606#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008607 else if ((int *)varp == &p_acd)
8608 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008609 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008610 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008611 }
8612#endif
8613
8614#ifdef FEAT_DIFF
8615 /* 'diff' */
8616 else if ((int *)varp == &curwin->w_p_diff)
8617 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008618 /* May add or remove the buffer from the list of diff buffers. */
8619 diff_buf_adjust(curwin);
8620# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008621 if (foldmethodIsDiff(curwin))
8622 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008623# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 }
8625#endif
8626
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008627#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 /* 'imdisable' */
8629 else if ((int *)varp == &p_imdisable)
8630 {
8631 /* Only de-activate it here, it will be enabled when changing mode. */
8632 if (p_imdisable)
8633 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008634 else if (State & INSERT)
8635 /* When the option is set from an autocommand, it may need to take
8636 * effect right away. */
8637 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638 }
8639#endif
8640
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008641#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008642 /* 'spell' */
8643 else if ((int *)varp == &curwin->w_p_spell)
8644 {
8645 if (curwin->w_p_spell)
8646 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008647 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008648 if (errmsg != NULL)
8649 EMSG(_(errmsg));
8650 }
8651 }
8652#endif
8653
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654#ifdef FEAT_FKMAP
8655 else if ((int *)varp == &p_altkeymap)
8656 {
8657 if (old_value != p_altkeymap)
8658 {
8659 if (!p_altkeymap)
8660 {
8661 p_hkmap = p_fkmap;
8662 p_fkmap = 0;
8663 }
8664 else
8665 {
8666 p_fkmap = p_hkmap;
8667 p_hkmap = 0;
8668 }
8669 (void)init_chartab();
8670 }
8671 }
8672
8673 /*
8674 * In case some second language keymapping options have changed, check
8675 * and correct the setting in a consistent way.
8676 */
8677
8678 /*
8679 * If hkmap or fkmap are set, reset Arabic keymapping.
8680 */
8681 if ((p_hkmap || p_fkmap) && p_altkeymap)
8682 {
8683 p_altkeymap = p_fkmap;
8684# ifdef FEAT_ARABIC
8685 curwin->w_p_arab = FALSE;
8686# endif
8687 (void)init_chartab();
8688 }
8689
8690 /*
8691 * If hkmap set, reset Farsi keymapping.
8692 */
8693 if (p_hkmap && p_altkeymap)
8694 {
8695 p_altkeymap = 0;
8696 p_fkmap = 0;
8697# ifdef FEAT_ARABIC
8698 curwin->w_p_arab = FALSE;
8699# endif
8700 (void)init_chartab();
8701 }
8702
8703 /*
8704 * If fkmap set, reset Hebrew keymapping.
8705 */
8706 if (p_fkmap && !p_altkeymap)
8707 {
8708 p_altkeymap = 1;
8709 p_hkmap = 0;
8710# ifdef FEAT_ARABIC
8711 curwin->w_p_arab = FALSE;
8712# endif
8713 (void)init_chartab();
8714 }
8715#endif
8716
8717#ifdef FEAT_ARABIC
8718 if ((int *)varp == &curwin->w_p_arab)
8719 {
8720 if (curwin->w_p_arab)
8721 {
8722 /*
8723 * 'arabic' is set, handle various sub-settings.
8724 */
8725 if (!p_tbidi)
8726 {
8727 /* set rightleft mode */
8728 if (!curwin->w_p_rl)
8729 {
8730 curwin->w_p_rl = TRUE;
8731 changed_window_setting();
8732 }
8733
8734 /* Enable Arabic shaping (major part of what Arabic requires) */
8735 if (!p_arshape)
8736 {
8737 p_arshape = TRUE;
8738 redraw_later_clear();
8739 }
8740 }
8741
8742 /* Arabic requires a utf-8 encoding, inform the user if its not
8743 * set. */
8744 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008745 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008746 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8747
Bram Moolenaar8820b482017-03-16 17:23:31 +01008748 msg_source(HL_ATTR(HLF_W));
8749 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008750#ifdef FEAT_EVAL
8751 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8752#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754
8755# ifdef FEAT_MBYTE
8756 /* set 'delcombine' */
8757 p_deco = TRUE;
8758# endif
8759
8760# ifdef FEAT_KEYMAP
8761 /* Force-set the necessary keymap for arabic */
8762 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8763 OPT_LOCAL);
8764# endif
8765# ifdef FEAT_FKMAP
8766 p_altkeymap = 0;
8767 p_hkmap = 0;
8768 p_fkmap = 0;
8769 (void)init_chartab();
8770# endif
8771 }
8772 else
8773 {
8774 /*
8775 * 'arabic' is reset, handle various sub-settings.
8776 */
8777 if (!p_tbidi)
8778 {
8779 /* reset rightleft mode */
8780 if (curwin->w_p_rl)
8781 {
8782 curwin->w_p_rl = FALSE;
8783 changed_window_setting();
8784 }
8785
8786 /* 'arabicshape' isn't reset, it is a global option and
8787 * another window may still need it "on". */
8788 }
8789
8790 /* 'delcombine' isn't reset, it is a global option and another
8791 * window may still want it "on". */
8792
8793# ifdef FEAT_KEYMAP
8794 /* Revert to the default keymap */
8795 curbuf->b_p_iminsert = B_IMODE_NONE;
8796 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8797# endif
8798 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008799 }
8800
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008801#endif
8802
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008803#ifdef FEAT_TERMGUICOLORS
8804 /* 'termguicolors' */
8805 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008806 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008807# ifdef FEAT_VTP
8808 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8809 if (!has_vtp_working())
8810 {
8811 p_tgc = 0;
8812 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8813 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008814 if (is_term_win32())
8815 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008816# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008817# ifdef FEAT_GUI
8818 if (!gui.in_use && !gui.starting)
8819# endif
8820 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008821# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008822 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008823 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008824 {
8825 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008826 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008827 init_highlight(TRUE, FALSE);
8828 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008829# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008830 }
8831#endif
8832
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833 /*
8834 * End of handling side effects for bool options.
8835 */
8836
Bram Moolenaar53744302015-07-17 17:38:22 +02008837 /* after handling side effects, call autocommand */
8838
Bram Moolenaar071d4272004-06-13 20:20:40 +00008839 options[opt_idx].flags |= P_WAS_SET;
8840
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008841#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008842 if (!starting)
8843 {
8844 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008845 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8846 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8847 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008848 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8849 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8850 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8851 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8852 reset_v_option_vars();
8853 }
8854#endif
8855
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008857 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008858 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008859 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008860 check_redraw(options[opt_idx].flags);
8861
8862 return NULL;
8863}
8864
8865/*
8866 * Set the value of a number option, and take care of side effects.
8867 * Returns NULL for success, or an error message for an error.
8868 */
8869 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008870set_num_option(
8871 int opt_idx, /* index in options[] table */
8872 char_u *varp, /* pointer to the option variable */
8873 long value, /* new value */
8874 char_u *errbuf, /* buffer for error messages */
8875 size_t errbuflen, /* length of "errbuf" */
8876 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008877 OPT_MODELINE */
8878{
8879 char_u *errmsg = NULL;
8880 long old_value = *(long *)varp;
8881 long old_Rows = Rows; /* remember old Rows */
8882 long old_Columns = Columns; /* remember old Columns */
8883 long *pp = (long *)varp;
8884
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008885 /* Disallow changing some options from secure mode. */
8886 if ((secure
8887#ifdef HAVE_SANDBOX
8888 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008890 ) && (options[opt_idx].flags & P_SECURE))
8891 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008892
8893 *pp = value;
8894#ifdef FEAT_EVAL
8895 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008896 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008897#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008898#ifdef FEAT_GUI
8899 need_mouse_correct = TRUE;
8900#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901
Bram Moolenaar14f24742012-08-08 18:01:05 +02008902 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008903 {
8904 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008905#ifdef FEAT_VARTABS
8906 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8907 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8908 ? tabstop_first(curbuf->b_p_vts_array)
8909 : curbuf->b_p_ts;
8910#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008912#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 }
8914
8915 /*
8916 * Number options that need some action when changed
8917 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918 if (pp == &p_wh || pp == &p_hh)
8919 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008920 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 if (p_wh < 1)
8922 {
8923 errmsg = e_positive;
8924 p_wh = 1;
8925 }
8926 if (p_wmh > p_wh)
8927 {
8928 errmsg = e_winheight;
8929 p_wh = p_wmh;
8930 }
8931 if (p_hh < 0)
8932 {
8933 errmsg = e_positive;
8934 p_hh = 0;
8935 }
8936
8937 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008938 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 {
8940 if (pp == &p_wh && curwin->w_height < p_wh)
8941 win_setheight((int)p_wh);
8942 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8943 win_setheight((int)p_hh);
8944 }
8945 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946 else if (pp == &p_wmh)
8947 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008948 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008949 if (p_wmh < 0)
8950 {
8951 errmsg = e_positive;
8952 p_wmh = 0;
8953 }
8954 if (p_wmh > p_wh)
8955 {
8956 errmsg = e_winheight;
8957 p_wmh = p_wh;
8958 }
8959 win_setminheight();
8960 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008961 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008962 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008963 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008964 if (p_wiw < 1)
8965 {
8966 errmsg = e_positive;
8967 p_wiw = 1;
8968 }
8969 if (p_wmw > p_wiw)
8970 {
8971 errmsg = e_winwidth;
8972 p_wiw = p_wmw;
8973 }
8974
8975 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008976 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008977 win_setwidth((int)p_wiw);
8978 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008979 else if (pp == &p_wmw)
8980 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008981 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008982 if (p_wmw < 0)
8983 {
8984 errmsg = e_positive;
8985 p_wmw = 0;
8986 }
8987 if (p_wmw > p_wiw)
8988 {
8989 errmsg = e_winwidth;
8990 p_wmw = p_wiw;
8991 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008992 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995 /* (re)set last window status line */
8996 else if (pp == &p_ls)
8997 {
8998 last_status(FALSE);
8999 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009000
9001 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009002 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009003 {
9004 shell_new_rows(); /* recompute window positions and heights */
9005 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009006
9007#ifdef FEAT_GUI
9008 else if (pp == &p_linespace)
9009 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009010 /* Recompute gui.char_height and resize the Vim window to keep the
9011 * same number of lines. */
9012 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009013 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014 }
9015#endif
9016
9017#ifdef FEAT_FOLDING
9018 /* 'foldlevel' */
9019 else if (pp == &curwin->w_p_fdl)
9020 {
9021 if (curwin->w_p_fdl < 0)
9022 curwin->w_p_fdl = 0;
9023 newFoldLevel();
9024 }
9025
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009026 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009027 else if (pp == &curwin->w_p_fml)
9028 {
9029 foldUpdateAll(curwin);
9030 }
9031
9032 /* 'foldnestmax' */
9033 else if (pp == &curwin->w_p_fdn)
9034 {
9035 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9036 foldUpdateAll(curwin);
9037 }
9038
9039 /* 'foldcolumn' */
9040 else if (pp == &curwin->w_p_fdc)
9041 {
9042 if (curwin->w_p_fdc < 0)
9043 {
9044 errmsg = e_positive;
9045 curwin->w_p_fdc = 0;
9046 }
9047 else if (curwin->w_p_fdc > 12)
9048 {
9049 errmsg = e_invarg;
9050 curwin->w_p_fdc = 12;
9051 }
9052 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009053#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009055#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056 /* 'shiftwidth' or 'tabstop' */
9057 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9058 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009059# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009060 if (foldmethodIsIndent(curwin))
9061 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009062# endif
9063# ifdef FEAT_CINDENT
9064 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9065 * parse 'cinoptions'. */
9066 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9067 parse_cino(curbuf);
9068# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009071
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009072#ifdef FEAT_MBYTE
9073 /* 'maxcombine' */
9074 else if (pp == &p_mco)
9075 {
9076 if (p_mco > MAX_MCO)
9077 p_mco = MAX_MCO;
9078 else if (p_mco < 0)
9079 p_mco = 0;
9080 screenclear(); /* will re-allocate the screen */
9081 }
9082#endif
9083
Bram Moolenaar071d4272004-06-13 20:20:40 +00009084 else if (pp == &curbuf->b_p_iminsert)
9085 {
9086 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9087 {
9088 errmsg = e_invarg;
9089 curbuf->b_p_iminsert = B_IMODE_NONE;
9090 }
9091 p_iminsert = curbuf->b_p_iminsert;
9092 if (termcap_active) /* don't do this in the alternate screen */
9093 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009094#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009095 /* Show/unshow value of 'keymap' in status lines. */
9096 status_redraw_curbuf();
9097#endif
9098 }
9099
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009100#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9101 /* 'imstyle' */
9102 else if (pp == &p_imst)
9103 {
9104 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9105 errmsg = e_invarg;
9106 }
9107#endif
9108
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009109 else if (pp == &p_window)
9110 {
9111 if (p_window < 1)
9112 p_window = 1;
9113 else if (p_window >= Rows)
9114 p_window = Rows - 1;
9115 }
9116
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 else if (pp == &curbuf->b_p_imsearch)
9118 {
9119 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9120 {
9121 errmsg = e_invarg;
9122 curbuf->b_p_imsearch = B_IMODE_NONE;
9123 }
9124 p_imsearch = curbuf->b_p_imsearch;
9125 }
9126
9127#ifdef FEAT_TITLE
9128 /* if 'titlelen' has changed, redraw the title */
9129 else if (pp == &p_titlelen)
9130 {
9131 if (p_titlelen < 0)
9132 {
9133 errmsg = e_positive;
9134 p_titlelen = 85;
9135 }
9136 if (starting != NO_SCREEN && old_value != p_titlelen)
9137 need_maketitle = TRUE;
9138 }
9139#endif
9140
9141 /* if p_ch changed value, change the command line height */
9142 else if (pp == &p_ch)
9143 {
9144 if (p_ch < 1)
9145 {
9146 errmsg = e_positive;
9147 p_ch = 1;
9148 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009149 if (p_ch > Rows - min_rows() + 1)
9150 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009151
9152 /* Only compute the new window layout when startup has been
9153 * completed. Otherwise the frame sizes may be wrong. */
9154 if (p_ch != old_value && full_screen
9155#ifdef FEAT_GUI
9156 && !gui.starting
9157#endif
9158 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009159 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009160 }
9161
9162 /* when 'updatecount' changes from zero to non-zero, open swap files */
9163 else if (pp == &p_uc)
9164 {
9165 if (p_uc < 0)
9166 {
9167 errmsg = e_positive;
9168 p_uc = 100;
9169 }
9170 if (p_uc && !old_value)
9171 ml_open_files();
9172 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009173#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009174 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009175 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009176 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009177 {
9178 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009179 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009180 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009181 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009182 {
9183 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009184 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009185 }
9186 }
9187#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009188#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009189 else if (pp == &p_mzq)
9190 mzvim_reset_timer();
9191#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009193#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9194 /* 'pyxversion' */
9195 else if (pp == &p_pyx)
9196 {
9197 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9198 errmsg = e_invarg;
9199 }
9200#endif
9201
Bram Moolenaar071d4272004-06-13 20:20:40 +00009202 /* sync undo before 'undolevels' changes */
9203 else if (pp == &p_ul)
9204 {
9205 /* use the old value, otherwise u_sync() may not work properly */
9206 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009207 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208 p_ul = value;
9209 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009210 else if (pp == &curbuf->b_p_ul)
9211 {
9212 /* use the old value, otherwise u_sync() may not work properly */
9213 curbuf->b_p_ul = old_value;
9214 u_sync(TRUE);
9215 curbuf->b_p_ul = value;
9216 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009218#ifdef FEAT_LINEBREAK
9219 /* 'numberwidth' must be positive */
9220 else if (pp == &curwin->w_p_nuw)
9221 {
9222 if (curwin->w_p_nuw < 1)
9223 {
9224 errmsg = e_positive;
9225 curwin->w_p_nuw = 1;
9226 }
9227 if (curwin->w_p_nuw > 10)
9228 {
9229 errmsg = e_invarg;
9230 curwin->w_p_nuw = 10;
9231 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009232 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009233 }
9234#endif
9235
Bram Moolenaar1a384422010-07-14 19:53:30 +02009236 else if (pp == &curbuf->b_p_tw)
9237 {
9238 if (curbuf->b_p_tw < 0)
9239 {
9240 errmsg = e_positive;
9241 curbuf->b_p_tw = 0;
9242 }
9243#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009244 {
9245 win_T *wp;
9246 tabpage_T *tp;
9247
9248 FOR_ALL_TAB_WINDOWS(tp, wp)
9249 check_colorcolumn(wp);
9250 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009251#endif
9252 }
9253
Bram Moolenaar071d4272004-06-13 20:20:40 +00009254 /*
9255 * Check the bounds for numeric options here
9256 */
9257 if (Rows < min_rows() && full_screen)
9258 {
9259 if (errbuf != NULL)
9260 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009261 vim_snprintf((char *)errbuf, errbuflen,
9262 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009263 errmsg = errbuf;
9264 }
9265 Rows = min_rows();
9266 }
9267 if (Columns < MIN_COLUMNS && full_screen)
9268 {
9269 if (errbuf != NULL)
9270 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009271 vim_snprintf((char *)errbuf, errbuflen,
9272 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009273 errmsg = errbuf;
9274 }
9275 Columns = MIN_COLUMNS;
9276 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009277 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279 /*
9280 * If the screen (shell) height has been changed, assume it is the
9281 * physical screenheight.
9282 */
9283 if (old_Rows != Rows || old_Columns != Columns)
9284 {
9285 /* Changing the screen size is not allowed while updating the screen. */
9286 if (updating_screen)
9287 *pp = old_value;
9288 else if (full_screen
9289#ifdef FEAT_GUI
9290 && !gui.starting
9291#endif
9292 )
9293 set_shellsize((int)Columns, (int)Rows, TRUE);
9294 else
9295 {
9296 /* Postpone the resizing; check the size and cmdline position for
9297 * messages. */
9298 check_shellsize();
9299 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9300 cmdline_row = Rows - p_ch;
9301 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009302 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009303 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304 }
9305
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306 if (curbuf->b_p_ts <= 0)
9307 {
9308 errmsg = e_positive;
9309 curbuf->b_p_ts = 8;
9310 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009311 if (p_tm < 0)
9312 {
9313 errmsg = e_positive;
9314 p_tm = 0;
9315 }
9316 if ((curwin->w_p_scr <= 0
9317 || (curwin->w_p_scr > curwin->w_height
9318 && curwin->w_height > 0))
9319 && full_screen)
9320 {
9321 if (pp == &(curwin->w_p_scr))
9322 {
9323 if (curwin->w_p_scr != 0)
9324 errmsg = e_scroll;
9325 win_comp_scroll(curwin);
9326 }
9327 /* If 'scroll' became invalid because of a side effect silently adjust
9328 * it. */
9329 else if (curwin->w_p_scr <= 0)
9330 curwin->w_p_scr = 1;
9331 else /* curwin->w_p_scr > curwin->w_height */
9332 curwin->w_p_scr = curwin->w_height;
9333 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009334 if (p_hi < 0)
9335 {
9336 errmsg = e_positive;
9337 p_hi = 0;
9338 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009339 else if (p_hi > 10000)
9340 {
9341 errmsg = e_invarg;
9342 p_hi = 10000;
9343 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009344 if (p_re < 0 || p_re > 2)
9345 {
9346 errmsg = e_invarg;
9347 p_re = 0;
9348 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009349 if (p_report < 0)
9350 {
9351 errmsg = e_positive;
9352 p_report = 1;
9353 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009354 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355 {
9356 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9357 p_sj = Rows / 2;
9358 else
9359 {
9360 errmsg = e_scroll;
9361 p_sj = 1;
9362 }
9363 }
9364 if (p_so < 0 && full_screen)
9365 {
9366 errmsg = e_scroll;
9367 p_so = 0;
9368 }
9369 if (p_siso < 0 && full_screen)
9370 {
9371 errmsg = e_positive;
9372 p_siso = 0;
9373 }
9374#ifdef FEAT_CMDWIN
9375 if (p_cwh < 1)
9376 {
9377 errmsg = e_positive;
9378 p_cwh = 1;
9379 }
9380#endif
9381 if (p_ut < 0)
9382 {
9383 errmsg = e_positive;
9384 p_ut = 2000;
9385 }
9386 if (p_ss < 0)
9387 {
9388 errmsg = e_positive;
9389 p_ss = 0;
9390 }
9391
9392 /* May set global value for local option. */
9393 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9394 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9395
9396 options[opt_idx].flags |= P_WAS_SET;
9397
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009398#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009399 if (!starting && errmsg == NULL)
9400 {
9401 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009402 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9403 vim_snprintf((char *)buf_new, 10, "%ld", value);
9404 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009405 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9406 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9407 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9408 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9409 reset_v_option_vars();
9410 }
9411#endif
9412
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009414 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009415 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009416 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009417 check_redraw(options[opt_idx].flags);
9418
9419 return errmsg;
9420}
9421
9422/*
9423 * Called after an option changed: check if something needs to be redrawn.
9424 */
9425 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009426check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427{
9428 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009429 int doclear = (flags & P_RCLR) == P_RCLR;
9430 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009431
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9433 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009434
9435 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9436 changed_window_setting();
9437 if (flags & P_RBUF)
9438 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009439 if (flags & P_RWINONLY)
9440 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009441 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009442 redraw_all_later(CLEAR);
9443 else if (all)
9444 redraw_all_later(NOT_VALID);
9445}
9446
9447/*
9448 * Find index for option 'arg'.
9449 * Return -1 if not found.
9450 */
9451 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009452findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009453{
9454 int opt_idx;
9455 char *s, *p;
9456 static short quick_tab[27] = {0, 0}; /* quick access table */
9457 int is_term_opt;
9458
9459 /*
9460 * For first call: Initialize the quick-access table.
9461 * It contains the index for the first option that starts with a certain
9462 * letter. There are 26 letters, plus the first "t_" option.
9463 */
9464 if (quick_tab[1] == 0)
9465 {
9466 p = options[0].fullname;
9467 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9468 {
9469 if (s[0] != p[0])
9470 {
9471 if (s[0] == 't' && s[1] == '_')
9472 quick_tab[26] = opt_idx;
9473 else
9474 quick_tab[CharOrdLow(s[0])] = opt_idx;
9475 }
9476 p = s;
9477 }
9478 }
9479
9480 /*
9481 * Check for name starting with an illegal character.
9482 */
9483#ifdef EBCDIC
9484 if (!islower(arg[0]))
9485#else
9486 if (arg[0] < 'a' || arg[0] > 'z')
9487#endif
9488 return -1;
9489
9490 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9491 if (is_term_opt)
9492 opt_idx = quick_tab[26];
9493 else
9494 opt_idx = quick_tab[CharOrdLow(arg[0])];
9495 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9496 {
9497 if (STRCMP(arg, s) == 0) /* match full name */
9498 break;
9499 }
9500 if (s == NULL && !is_term_opt)
9501 {
9502 opt_idx = quick_tab[CharOrdLow(arg[0])];
9503 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9504 {
9505 s = options[opt_idx].shortname;
9506 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9507 break;
9508 s = NULL;
9509 }
9510 }
9511 if (s == NULL)
9512 opt_idx = -1;
9513 return opt_idx;
9514}
9515
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009516#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009517/*
9518 * Get the value for an option.
9519 *
9520 * Returns:
9521 * Number or Toggle option: 1, *numval gets value.
9522 * String option: 0, *stringval gets allocated string.
9523 * Hidden Number or Toggle option: -1.
9524 * hidden String option: -2.
9525 * unknown option: -3.
9526 */
9527 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009528get_option_value(
9529 char_u *name,
9530 long *numval,
9531 char_u **stringval, /* NULL when only checking existence */
9532 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009533{
9534 int opt_idx;
9535 char_u *varp;
9536
9537 opt_idx = findoption(name);
9538 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009539 {
9540 int key;
9541
9542 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9543 && (key = find_key_option(name)) != 0)
9544 {
9545 char_u key_name[2];
9546 char_u *p;
9547
9548 if (key < 0)
9549 {
9550 key_name[0] = KEY2TERMCAP0(key);
9551 key_name[1] = KEY2TERMCAP1(key);
9552 }
9553 else
9554 {
9555 key_name[0] = KS_KEY;
9556 key_name[1] = (key & 0xff);
9557 }
9558 p = find_termcode(key_name);
9559 if (p != NULL)
9560 {
9561 if (stringval != NULL)
9562 *stringval = vim_strsave(p);
9563 return 0;
9564 }
9565 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009566 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568
9569 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9570
9571 if (options[opt_idx].flags & P_STRING)
9572 {
9573 if (varp == NULL) /* hidden option */
9574 return -2;
9575 if (stringval != NULL)
9576 {
9577#ifdef FEAT_CRYPT
9578 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009579 if ((char_u **)varp == &curbuf->b_p_key
9580 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009581 *stringval = vim_strsave((char_u *)"*****");
9582 else
9583#endif
9584 *stringval = vim_strsave(*(char_u **)(varp));
9585 }
9586 return 0;
9587 }
9588
9589 if (varp == NULL) /* hidden option */
9590 return -1;
9591 if (options[opt_idx].flags & P_NUM)
9592 *numval = *(long *)varp;
9593 else
9594 {
9595 /* Special case: 'modified' is b_changed, but we also want to consider
9596 * it set when 'ff' or 'fenc' changed. */
9597 if ((int *)varp == &curbuf->b_changed)
9598 *numval = curbufIsChanged();
9599 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009600 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009601 }
9602 return 1;
9603}
9604#endif
9605
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009606#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009607/*
9608 * Returns the option attributes and its value. Unlike the above function it
9609 * will return either global value or local value of the option depending on
9610 * what was requested, but it will never return global value if it was
9611 * requested to return local one and vice versa. Neither it will return
9612 * buffer-local value if it was requested to return window-local one.
9613 *
9614 * Pretends that option is absent if it is not present in the requested scope
9615 * (i.e. has no global, window-local or buffer-local value depending on
9616 * opt_type). Uses
9617 *
9618 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009619 * 0 hidden or unknown option, also option that does not have requested
9620 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009621 * see SOPT_* in vim.h for other flags
9622 *
9623 * Possible opt_type values: see SREQ_* in vim.h
9624 */
9625 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009626get_option_value_strict(
9627 char_u *name,
9628 long *numval,
9629 char_u **stringval, /* NULL when only obtaining attributes */
9630 int opt_type,
9631 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009632{
9633 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009634 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009635 struct vimoption *p;
9636 int r = 0;
9637
9638 opt_idx = findoption(name);
9639 if (opt_idx < 0)
9640 return 0;
9641
9642 p = &(options[opt_idx]);
9643
9644 /* Hidden option */
9645 if (p->var == NULL)
9646 return 0;
9647
9648 if (p->flags & P_BOOL)
9649 r |= SOPT_BOOL;
9650 else if (p->flags & P_NUM)
9651 r |= SOPT_NUM;
9652 else if (p->flags & P_STRING)
9653 r |= SOPT_STRING;
9654
9655 if (p->indir == PV_NONE)
9656 {
9657 if (opt_type == SREQ_GLOBAL)
9658 r |= SOPT_GLOBAL;
9659 else
9660 return 0; /* Did not request global-only option */
9661 }
9662 else
9663 {
9664 if (p->indir & PV_BOTH)
9665 r |= SOPT_GLOBAL;
9666 else if (opt_type == SREQ_GLOBAL)
9667 return 0; /* Requested global option */
9668
9669 if (p->indir & PV_WIN)
9670 {
9671 if (opt_type == SREQ_BUF)
9672 return 0; /* Did not request window-local option */
9673 else
9674 r |= SOPT_WIN;
9675 }
9676 else if (p->indir & PV_BUF)
9677 {
9678 if (opt_type == SREQ_WIN)
9679 return 0; /* Did not request buffer-local option */
9680 else
9681 r |= SOPT_BUF;
9682 }
9683 }
9684
9685 if (stringval == NULL)
9686 return r;
9687
9688 if (opt_type == SREQ_GLOBAL)
9689 varp = p->var;
9690 else
9691 {
9692 if (opt_type == SREQ_BUF)
9693 {
9694 /* Special case: 'modified' is b_changed, but we also want to
9695 * consider it set when 'ff' or 'fenc' changed. */
9696 if (p->indir == PV_MOD)
9697 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009698 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009699 varp = NULL;
9700 }
9701#ifdef FEAT_CRYPT
9702 else if (p->indir == PV_KEY)
9703 {
9704 /* never return the value of the crypt key */
9705 *stringval = NULL;
9706 varp = NULL;
9707 }
9708#endif
9709 else
9710 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009711 buf_T *save_curbuf = curbuf;
9712
9713 // only getting a pointer, no need to use aucmd_prepbuf()
9714 curbuf = (buf_T *)from;
9715 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009716 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009717 curbuf = save_curbuf;
9718 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009719 }
9720 }
9721 else if (opt_type == SREQ_WIN)
9722 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009723 win_T *save_curwin = curwin;
9724
9725 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009726 curbuf = curwin->w_buffer;
9727 varp = get_varp(p);
9728 curwin = save_curwin;
9729 curbuf = curwin->w_buffer;
9730 }
9731 if (varp == p->var)
9732 return (r | SOPT_UNSET);
9733 }
9734
9735 if (varp != NULL)
9736 {
9737 if (p->flags & P_STRING)
9738 *stringval = vim_strsave(*(char_u **)(varp));
9739 else if (p->flags & P_NUM)
9740 *numval = *(long *) varp;
9741 else
9742 *numval = *(int *)varp;
9743 }
9744
9745 return r;
9746}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009747
9748/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009749 * Iterate over options. First argument is a pointer to a pointer to a
9750 * structure inside options[] array, second is option type like in the above
9751 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009752 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009753 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009754 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009755 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009756 * first argument to NULL.
9757 *
9758 * Returns full option name for current option on each call.
9759 */
9760 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009761option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009762{
9763 struct vimoption *ret = NULL;
9764 do
9765 {
9766 if (*option == NULL)
9767 *option = (void *) options;
9768 else if (((struct vimoption *) (*option))->fullname == NULL)
9769 {
9770 *option = NULL;
9771 return NULL;
9772 }
9773 else
9774 *option = (void *) (((struct vimoption *) (*option)) + 1);
9775
9776 ret = ((struct vimoption *) (*option));
9777
9778 /* Hidden option */
9779 if (ret->var == NULL)
9780 {
9781 ret = NULL;
9782 continue;
9783 }
9784
9785 switch (opt_type)
9786 {
9787 case SREQ_GLOBAL:
9788 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9789 ret = NULL;
9790 break;
9791 case SREQ_BUF:
9792 if (!(ret->indir & PV_BUF))
9793 ret = NULL;
9794 break;
9795 case SREQ_WIN:
9796 if (!(ret->indir & PV_WIN))
9797 ret = NULL;
9798 break;
9799 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009800 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009801 return NULL;
9802 }
9803 }
9804 while (ret == NULL);
9805
9806 return (char_u *)ret->fullname;
9807}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009808#endif
9809
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810/*
9811 * Set the value of option "name".
9812 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009813 *
9814 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009815 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009816 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009817set_option_value(
9818 char_u *name,
9819 long number,
9820 char_u *string,
9821 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009822{
9823 int opt_idx;
9824 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009825 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009826
9827 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009828 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009829 {
9830 int key;
9831
9832 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9833 && (key = find_key_option(name)) != 0)
9834 {
9835 char_u key_name[2];
9836
9837 if (key < 0)
9838 {
9839 key_name[0] = KEY2TERMCAP0(key);
9840 key_name[1] = KEY2TERMCAP1(key);
9841 }
9842 else
9843 {
9844 key_name[0] = KS_KEY;
9845 key_name[1] = (key & 0xff);
9846 }
9847 add_termcode(key_name, string, FALSE);
9848 if (full_screen)
9849 ttest(FALSE);
9850 redraw_all_later(CLEAR);
9851 return NULL;
9852 }
9853
Bram Moolenaar071d4272004-06-13 20:20:40 +00009854 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009855 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856 else
9857 {
9858 flags = options[opt_idx].flags;
9859#ifdef HAVE_SANDBOX
9860 /* Disallow changing some options in the sandbox */
9861 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009862 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009863 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009864 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009865 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009866#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009867 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009868 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009869 else
9870 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009871 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009872 if (varp != NULL) /* hidden option is not changed */
9873 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009874 if (number == 0 && string != NULL)
9875 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009876 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009877
9878 /* Either we are given a string or we are setting option
9879 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009880 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009881 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009882 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009883 {
9884 /* There's another character after zeros or the string
9885 * is empty. In both cases, we are trying to set a
9886 * num option using a string. */
9887 EMSG3(_("E521: Number required: &%s = '%s'"),
9888 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009889 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009890
9891 }
9892 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009893 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009894 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009895 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009896 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009897 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009898 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 }
9900 }
9901 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009902 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009903}
9904
9905/*
9906 * Get the terminal code for a terminal option.
9907 * Returns NULL when not found.
9908 */
9909 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009910get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009911{
9912 int opt_idx;
9913 char_u *varp;
9914
9915 if (tname[0] != 't' || tname[1] != '_' ||
9916 tname[2] == NUL || tname[3] == NUL)
9917 return NULL;
9918 if ((opt_idx = findoption(tname)) >= 0)
9919 {
9920 varp = get_varp(&(options[opt_idx]));
9921 if (varp != NULL)
9922 varp = *(char_u **)(varp);
9923 return varp;
9924 }
9925 return find_termcode(tname + 2);
9926}
9927
9928 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009929get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009930{
9931 int i;
9932
9933 i = findoption((char_u *)"hl");
9934 if (i >= 0)
9935 return options[i].def_val[VI_DEFAULT];
9936 return (char_u *)NULL;
9937}
9938
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009939#if defined(FEAT_MBYTE) || defined(PROTO)
9940 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009941get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009942{
9943 int i;
9944
9945 i = findoption((char_u *)"enc");
9946 if (i >= 0)
9947 return options[i].def_val[VI_DEFAULT];
9948 return (char_u *)NULL;
9949}
9950#endif
9951
Bram Moolenaar071d4272004-06-13 20:20:40 +00009952/*
9953 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9954 */
9955 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009956find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957{
9958 int key;
9959 int modifiers;
9960
9961 /*
9962 * Don't use get_special_key_code() for t_xx, we don't want it to call
9963 * add_termcap_entry().
9964 */
9965 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9966 key = TERMCAP2KEY(arg[2], arg[3]);
9967 else
9968 {
9969 --arg; /* put arg at the '<' */
9970 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009971 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972 if (modifiers) /* can't handle modifiers here */
9973 key = 0;
9974 }
9975 return key;
9976}
9977
9978/*
9979 * if 'all' == 0: show changed options
9980 * if 'all' == 1: show all normal options
9981 * if 'all' == 2: show all terminal options
9982 */
9983 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009984showoptions(
9985 int all,
9986 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987{
9988 struct vimoption *p;
9989 int col;
9990 int isterm;
9991 char_u *varp;
9992 struct vimoption **items;
9993 int item_count;
9994 int run;
9995 int row, rows;
9996 int cols;
9997 int i;
9998 int len;
9999
10000#define INC 20
10001#define GAP 3
10002
10003 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10004 PARAM_COUNT));
10005 if (items == NULL)
10006 return;
10007
10008 /* Highlight title */
10009 if (all == 2)
10010 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
10011 else if (opt_flags & OPT_GLOBAL)
10012 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
10013 else if (opt_flags & OPT_LOCAL)
10014 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
10015 else
10016 MSG_PUTS_TITLE(_("\n--- Options ---"));
10017
10018 /*
10019 * do the loop two times:
10020 * 1. display the short items
10021 * 2. display the long items (only strings and numbers)
10022 */
10023 for (run = 1; run <= 2 && !got_int; ++run)
10024 {
10025 /*
10026 * collect the items in items[]
10027 */
10028 item_count = 0;
10029 for (p = &options[0]; p->fullname != NULL; p++)
10030 {
10031 varp = NULL;
10032 isterm = istermoption(p);
10033 if (opt_flags != 0)
10034 {
10035 if (p->indir != PV_NONE && !isterm)
10036 varp = get_varp_scope(p, opt_flags);
10037 }
10038 else
10039 varp = get_varp(p);
10040 if (varp != NULL
10041 && ((all == 2 && isterm)
10042 || (all == 1 && !isterm)
10043 || (all == 0 && !optval_default(p, varp))))
10044 {
10045 if (p->flags & P_BOOL)
10046 len = 1; /* a toggle option fits always */
10047 else
10048 {
10049 option_value2string(p, opt_flags);
10050 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10051 }
10052 if ((len <= INC - GAP && run == 1) ||
10053 (len > INC - GAP && run == 2))
10054 items[item_count++] = p;
10055 }
10056 }
10057
10058 /*
10059 * display the items
10060 */
10061 if (run == 1)
10062 {
10063 cols = (Columns + GAP - 3) / INC;
10064 if (cols == 0)
10065 cols = 1;
10066 rows = (item_count + cols - 1) / cols;
10067 }
10068 else /* run == 2 */
10069 rows = item_count;
10070 for (row = 0; row < rows && !got_int; ++row)
10071 {
10072 msg_putchar('\n'); /* go to next line */
10073 if (got_int) /* 'q' typed in more */
10074 break;
10075 col = 0;
10076 for (i = row; i < item_count; i += rows)
10077 {
10078 msg_col = col; /* make columns */
10079 showoneopt(items[i], opt_flags);
10080 col += INC;
10081 }
10082 out_flush();
10083 ui_breakcheck();
10084 }
10085 }
10086 vim_free(items);
10087}
10088
10089/*
10090 * Return TRUE if option "p" has its default value.
10091 */
10092 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010093optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010094{
10095 int dvi;
10096
10097 if (varp == NULL)
10098 return TRUE; /* hidden option is always at default */
10099 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10100 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010101 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010102 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010103 /* the cast to long is required for Manx C, long_i is
10104 * needed for MSVC */
10105 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010106 /* P_STRING */
10107 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10108}
10109
10110/*
10111 * showoneopt: show the value of one option
10112 * must not be called with a hidden option!
10113 */
10114 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010115showoneopt(
10116 struct vimoption *p,
10117 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010119 char_u *varp;
10120 int save_silent = silent_mode;
10121
10122 silent_mode = FALSE;
10123 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124
10125 varp = get_varp_scope(p, opt_flags);
10126
10127 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10128 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10129 ? !curbufIsChanged() : !*(int *)varp))
10130 MSG_PUTS("no");
10131 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10132 MSG_PUTS("--");
10133 else
10134 MSG_PUTS(" ");
10135 MSG_PUTS(p->fullname);
10136 if (!(p->flags & P_BOOL))
10137 {
10138 msg_putchar('=');
10139 /* put value string in NameBuff */
10140 option_value2string(p, opt_flags);
10141 msg_outtrans(NameBuff);
10142 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010143
10144 silent_mode = save_silent;
10145 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146}
10147
10148/*
10149 * Write modified options as ":set" commands to a file.
10150 *
10151 * There are three values for "opt_flags":
10152 * OPT_GLOBAL: Write global option values and fresh values of
10153 * buffer-local options (used for start of a session
10154 * file).
10155 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10156 * curwin (used for a vimrc file).
10157 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10158 * and local values for window-local options of
10159 * curwin. Local values are also written when at the
10160 * default value, because a modeline or autocommand
10161 * may have set them when doing ":edit file" and the
10162 * user has set them back at the default or fresh
10163 * value.
10164 * When "local_only" is TRUE, don't write fresh
10165 * values, only local values (for ":mkview").
10166 * (fresh value = value used for a new buffer or window for a local option).
10167 *
10168 * Return FAIL on error, OK otherwise.
10169 */
10170 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010171makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172{
10173 struct vimoption *p;
10174 char_u *varp; /* currently used value */
10175 char_u *varp_fresh; /* local value */
10176 char_u *varp_local = NULL; /* fresh value */
10177 char *cmd;
10178 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010179 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180
10181 /*
10182 * The options that don't have a default (terminal name, columns, lines)
10183 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010184 * Do the loop over "options[]" twice: once for options with the
10185 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010187 for (pri = 1; pri >= 0; --pri)
10188 {
10189 for (p = &options[0]; !istermoption(p); p++)
10190 if (!(p->flags & P_NO_MKRC)
10191 && !istermoption(p)
10192 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 {
10194 /* skip global option when only doing locals */
10195 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10196 continue;
10197
10198 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10199 * file, they are always buffer-specific. */
10200 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10201 continue;
10202
10203 /* Global values are only written when not at the default value. */
10204 varp = get_varp_scope(p, opt_flags);
10205 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10206 continue;
10207
10208 round = 2;
10209 if (p->indir != PV_NONE)
10210 {
10211 if (p->var == VAR_WIN)
10212 {
10213 /* skip window-local option when only doing globals */
10214 if (!(opt_flags & OPT_LOCAL))
10215 continue;
10216 /* When fresh value of window-local option is not at the
10217 * default, need to write it too. */
10218 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10219 {
10220 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10221 if (!optval_default(p, varp_fresh))
10222 {
10223 round = 1;
10224 varp_local = varp;
10225 varp = varp_fresh;
10226 }
10227 }
10228 }
10229 }
10230
10231 /* Round 1: fresh value for window-local options.
10232 * Round 2: other values */
10233 for ( ; round <= 2; varp = varp_local, ++round)
10234 {
10235 if (round == 1 || (opt_flags & OPT_GLOBAL))
10236 cmd = "set";
10237 else
10238 cmd = "setlocal";
10239
10240 if (p->flags & P_BOOL)
10241 {
10242 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10243 return FAIL;
10244 }
10245 else if (p->flags & P_NUM)
10246 {
10247 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10248 return FAIL;
10249 }
10250 else /* P_STRING */
10251 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010252 int do_endif = FALSE;
10253
Bram Moolenaar071d4272004-06-13 20:20:40 +000010254 /* Don't set 'syntax' and 'filetype' again if the value is
10255 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010256 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010257#if defined(FEAT_SYN_HL)
10258 p->indir == PV_SYN ||
10259#endif
10260 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 {
10262 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10263 *(char_u **)(varp)) < 0
10264 || put_eol(fd) < 0)
10265 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010266 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267 }
10268 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10269 (p->flags & P_EXPAND) != 0) == FAIL)
10270 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010271 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272 {
10273 if (put_line(fd, "endif") == FAIL)
10274 return FAIL;
10275 }
10276 }
10277 }
10278 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010279 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280 return OK;
10281}
10282
10283#if defined(FEAT_FOLDING) || defined(PROTO)
10284/*
10285 * Generate set commands for the local fold options only. Used when
10286 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10287 */
10288 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010289makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290{
10291 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10292# ifdef FEAT_EVAL
10293 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10294 == FAIL
10295# endif
10296 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10297 == FAIL
10298 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10299 == FAIL
10300 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10301 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10302 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10303 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10304 )
10305 return FAIL;
10306
10307 return OK;
10308}
10309#endif
10310
10311 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010312put_setstring(
10313 FILE *fd,
10314 char *cmd,
10315 char *name,
10316 char_u **valuep,
10317 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318{
10319 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010320 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321
10322 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10323 return FAIL;
10324 if (*valuep != NULL)
10325 {
10326 /* Output 'pastetoggle' as key names. For other
10327 * options some characters have to be escaped with
10328 * CTRL-V or backslash */
10329 if (valuep == &p_pt)
10330 {
10331 s = *valuep;
10332 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010333 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334 return FAIL;
10335 }
10336 else if (expand)
10337 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010338 buf = alloc(MAXPATHL);
10339 if (buf == NULL)
10340 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10342 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010343 {
10344 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010346 }
10347 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348 }
10349 else if (put_escstr(fd, *valuep, 2) == FAIL)
10350 return FAIL;
10351 }
10352 if (put_eol(fd) < 0)
10353 return FAIL;
10354 return OK;
10355}
10356
10357 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010358put_setnum(
10359 FILE *fd,
10360 char *cmd,
10361 char *name,
10362 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363{
10364 long wc;
10365
10366 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10367 return FAIL;
10368 if (wc_use_keyname((char_u *)valuep, &wc))
10369 {
10370 /* print 'wildchar' and 'wildcharm' as a key name */
10371 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10372 return FAIL;
10373 }
10374 else if (fprintf(fd, "%ld", *valuep) < 0)
10375 return FAIL;
10376 if (put_eol(fd) < 0)
10377 return FAIL;
10378 return OK;
10379}
10380
10381 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010382put_setbool(
10383 FILE *fd,
10384 char *cmd,
10385 char *name,
10386 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387{
Bram Moolenaar893de922007-10-02 18:40:57 +000010388 if (value < 0) /* global/local option using global value */
10389 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010390 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10391 || put_eol(fd) < 0)
10392 return FAIL;
10393 return OK;
10394}
10395
10396/*
10397 * Clear all the terminal options.
10398 * If the option has been allocated, free the memory.
10399 * Terminal options are never hidden or indirect.
10400 */
10401 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010402clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404 /*
10405 * Reset a few things before clearing the old options. This may cause
10406 * outputting a few things that the terminal doesn't understand, but the
10407 * screen will be cleared later, so this is OK.
10408 */
10409#ifdef FEAT_MOUSE_TTY
10410 mch_setmouse(FALSE); /* switch mouse off */
10411#endif
10412#ifdef FEAT_TITLE
10413 mch_restore_title(3); /* restore window titles */
10414#endif
10415#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10416 /* When starting the GUI close the display opened for the clipboard.
10417 * After restoring the title, because that will need the display. */
10418 if (gui.starting)
10419 clear_xterm_clip();
10420#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010421 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010422
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010423 free_termoptions();
10424}
10425
10426 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010427free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010428{
10429 struct vimoption *p;
10430
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431 for (p = &options[0]; p->fullname != NULL; p++)
10432 if (istermoption(p))
10433 {
10434 if (p->flags & P_ALLOCED)
10435 free_string_option(*(char_u **)(p->var));
10436 if (p->flags & P_DEF_ALLOCED)
10437 free_string_option(p->def_val[VI_DEFAULT]);
10438 *(char_u **)(p->var) = empty_option;
10439 p->def_val[VI_DEFAULT] = empty_option;
10440 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10441 }
10442 clear_termcodes();
10443}
10444
10445/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010446 * Free the string for one term option, if it was allocated.
10447 * Set the string to empty_option and clear allocated flag.
10448 * "var" points to the option value.
10449 */
10450 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010451free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010452{
10453 struct vimoption *p;
10454
10455 for (p = &options[0]; p->fullname != NULL; p++)
10456 if (p->var == var)
10457 {
10458 if (p->flags & P_ALLOCED)
10459 free_string_option(*(char_u **)(p->var));
10460 *(char_u **)(p->var) = empty_option;
10461 p->flags &= ~P_ALLOCED;
10462 break;
10463 }
10464}
10465
10466/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467 * Set the terminal option defaults to the current value.
10468 * Used after setting the terminal name.
10469 */
10470 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010471set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472{
10473 struct vimoption *p;
10474
10475 for (p = &options[0]; p->fullname != NULL; p++)
10476 {
10477 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10478 {
10479 if (p->flags & P_DEF_ALLOCED)
10480 {
10481 free_string_option(p->def_val[VI_DEFAULT]);
10482 p->flags &= ~P_DEF_ALLOCED;
10483 }
10484 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10485 if (p->flags & P_ALLOCED)
10486 {
10487 p->flags |= P_DEF_ALLOCED;
10488 p->flags &= ~P_ALLOCED; /* don't free the value now */
10489 }
10490 }
10491 }
10492}
10493
10494/*
10495 * return TRUE if 'p' starts with 't_'
10496 */
10497 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010498istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499{
10500 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10501}
10502
10503/*
10504 * Compute columns for ruler and shown command. 'sc_col' is also used to
10505 * decide what the maximum length of a message on the status line can be.
10506 * If there is a status line for the last window, 'sc_col' is independent
10507 * of 'ru_col'.
10508 */
10509
10510#define COL_RULER 17 /* columns needed by standard ruler */
10511
10512 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010513comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010514{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010515#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010516 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010517
10518 sc_col = 0;
10519 ru_col = 0;
10520 if (p_ru)
10521 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010522# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010524# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010525 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010526# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527 /* no last status line, adjust sc_col */
10528 if (!last_has_status)
10529 sc_col = ru_col;
10530 }
10531 if (p_sc)
10532 {
10533 sc_col += SHOWCMD_COLS;
10534 if (!p_ru || last_has_status) /* no need for separating space */
10535 ++sc_col;
10536 }
10537 sc_col = Columns - sc_col;
10538 ru_col = Columns - ru_col;
10539 if (sc_col <= 0) /* screen too narrow, will become a mess */
10540 sc_col = 1;
10541 if (ru_col <= 0)
10542 ru_col = 1;
10543#else
10544 sc_col = Columns;
10545 ru_col = Columns;
10546#endif
10547}
10548
10549/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010550 * Unset local option value, similar to ":set opt<".
10551 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010552 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010553unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010554{
10555 struct vimoption *p;
10556 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010557 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010558
10559 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010560 if (opt_idx < 0)
10561 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010562 p = &(options[opt_idx]);
10563
10564 switch ((int)p->indir)
10565 {
10566 /* global option with local value: use local value if it's been set */
10567 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010568 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010569 break;
10570 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010571 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010572 break;
10573 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010574 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010575 break;
10576 case PV_AR:
10577 buf->b_p_ar = -1;
10578 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010579 case PV_BKC:
10580 clear_string_option(&buf->b_p_bkc);
10581 buf->b_bkc_flags = 0;
10582 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010583 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010584 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010585 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010586 case PV_TC:
10587 clear_string_option(&buf->b_p_tc);
10588 buf->b_tc_flags = 0;
10589 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010590#ifdef FEAT_FIND_ID
10591 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010592 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010593 break;
10594 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010595 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010596 break;
10597#endif
10598#ifdef FEAT_INS_EXPAND
10599 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010600 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010601 break;
10602 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010603 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010604 break;
10605#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010606 case PV_FP:
10607 clear_string_option(&buf->b_p_fp);
10608 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010609#ifdef FEAT_QUICKFIX
10610 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010611 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010612 break;
10613 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010614 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010615 break;
10616 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010617 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010618 break;
10619#endif
10620#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10621 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010622 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010623 break;
10624#endif
10625#if defined(FEAT_CRYPT)
10626 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010627 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010628 break;
10629#endif
10630#ifdef FEAT_STL_OPT
10631 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010632 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010633 break;
10634#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010635 case PV_UL:
10636 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10637 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010638#ifdef FEAT_LISP
10639 case PV_LW:
10640 clear_string_option(&buf->b_p_lw);
10641 break;
10642#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010643#ifdef FEAT_MBYTE
10644 case PV_MENC:
10645 clear_string_option(&buf->b_p_menc);
10646 break;
10647#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010648 }
10649}
10650
10651/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652 * Get pointer to option variable, depending on local or global scope.
10653 */
10654 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010655get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010656{
10657 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10658 {
10659 if (p->var == VAR_WIN)
10660 return (char_u *)GLOBAL_WO(get_varp(p));
10661 return p->var;
10662 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010663 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010664 {
10665 switch ((int)p->indir)
10666 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010667 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010669 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10670 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10671 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010672#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010673 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10674 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10675 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010676 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010677 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010678 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010680 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10681 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010682#endif
10683#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010684 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10685 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010687#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10688 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10689#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010690#if defined(FEAT_CRYPT)
10691 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10692#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010693#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010694 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010695#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010696 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010697#ifdef FEAT_LISP
10698 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10699#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010700 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010701#ifdef FEAT_MBYTE
10702 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704 }
10705 return NULL; /* "cannot happen" */
10706 }
10707 return get_varp(p);
10708}
10709
10710/*
10711 * Get pointer to option variable.
10712 */
10713 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010714get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715{
10716 /* hidden option, always return NULL */
10717 if (p->var == NULL)
10718 return NULL;
10719
10720 switch ((int)p->indir)
10721 {
10722 case PV_NONE: return p->var;
10723
10724 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010725 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010727 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010728 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010729 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010731 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010733 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010735 case PV_TC: return *curbuf->b_p_tc != NUL
10736 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010737 case PV_BKC: return *curbuf->b_p_bkc != NUL
10738 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010740 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010742 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10744#endif
10745#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010746 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010747 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010748 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010749 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10750#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010751 case PV_FP: return *curbuf->b_p_fp != NUL
10752 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010754 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010756 case PV_GP: return *curbuf->b_p_gp != NUL
10757 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10758 case PV_MP: return *curbuf->b_p_mp != NUL
10759 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010761#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10762 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10763 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10764#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010765#if defined(FEAT_CRYPT)
10766 case PV_CM: return *curbuf->b_p_cm != NUL
10767 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10768#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010769#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010770 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010771 ? (char_u *)&(curwin->w_p_stl) : p->var;
10772#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010773 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10774 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010775#ifdef FEAT_LISP
10776 case PV_LW: return *curbuf->b_p_lw != NUL
10777 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10778#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010779#ifdef FEAT_MBYTE
10780 case PV_MENC: return *curbuf->b_p_menc != NUL
10781 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783
10784#ifdef FEAT_ARABIC
10785 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10786#endif
10787 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010788#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010789 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10790#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010791#ifdef FEAT_SYN_HL
10792 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10793 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010794 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796#ifdef FEAT_DIFF
10797 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10798#endif
10799#ifdef FEAT_FOLDING
10800 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10801 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10802 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10803 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10804 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10805 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10806 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10807# ifdef FEAT_EVAL
10808 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10809 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10810# endif
10811 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10812#endif
10813 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010814 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010815#ifdef FEAT_LINEBREAK
10816 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10817#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010819 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010820#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10822#endif
10823#ifdef FEAT_RIGHTLEFT
10824 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10825 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10826#endif
10827 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10828 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10829#ifdef FEAT_LINEBREAK
10830 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010831 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10832 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010835 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010836#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010837 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10838 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10839#endif
10840#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010841 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10842 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10843 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010844#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845
10846 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10847 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10848#ifdef FEAT_MBYTE
10849 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10852 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10854 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10855#ifdef FEAT_CINDENT
10856 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10857 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10858 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10859#endif
10860#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10861 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10862#endif
10863#ifdef FEAT_COMMENTS
10864 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10865#endif
10866#ifdef FEAT_FOLDING
10867 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10868#endif
10869#ifdef FEAT_INS_EXPAND
10870 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10871#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010872#ifdef FEAT_COMPL_FUNC
10873 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010874 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010877 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10879#ifdef FEAT_MBYTE
10880 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10881#endif
10882 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010885 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010886 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10887 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10888 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10889 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10890#ifdef FEAT_FIND_ID
10891# ifdef FEAT_EVAL
10892 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10893# endif
10894#endif
10895#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10896 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10897 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10898#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010899#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010900 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10901#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902#ifdef FEAT_CRYPT
10903 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10904#endif
10905#ifdef FEAT_LISP
10906 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10907#endif
10908 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10909 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10910 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10911 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10912 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010914#ifdef FEAT_TEXTOBJ
10915 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10916#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010917 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10918#ifdef FEAT_SMARTINDENT
10919 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10920#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10923#ifdef FEAT_SEARCHPATH
10924 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10925#endif
10926 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10927#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010928 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010929 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10930#endif
10931#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010932 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10933 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10934 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935#endif
10936 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10937 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10938 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10939 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010940#ifdef FEAT_PERSISTENT_UNDO
10941 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10942#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10944#ifdef FEAT_KEYMAP
10945 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10946#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010947#ifdef FEAT_SIGNS
10948 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10949#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020010950#ifdef FEAT_VARTABS
10951 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
10952 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
10953#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010954 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010955 }
10956 /* always return a valid pointer to avoid a crash! */
10957 return (char_u *)&(curbuf->b_p_wm);
10958}
10959
10960/*
10961 * Get the value of 'equalprg', either the buffer-local one or the global one.
10962 */
10963 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010964get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010965{
10966 if (*curbuf->b_p_ep == NUL)
10967 return p_ep;
10968 return curbuf->b_p_ep;
10969}
10970
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971/*
10972 * Copy options from one window to another.
10973 * Used when splitting a window.
10974 */
10975 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010976win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010977{
10978 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10979 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10980# ifdef FEAT_RIGHTLEFT
10981# ifdef FEAT_FKMAP
10982 /* Is this right? */
10983 wp_to->w_farsi = wp_from->w_farsi;
10984# endif
10985# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010986#if defined(FEAT_LINEBREAK)
10987 briopt_check(wp_to);
10988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990
10991/*
10992 * Copy the options from one winopt_T to another.
10993 * Doesn't free the old option values in "to", use clear_winopt() for that.
10994 * The 'scroll' option is not copied, because it depends on the window height.
10995 * The 'previewwindow' option is reset, there can be only one preview window.
10996 */
10997 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010998copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010999{
11000#ifdef FEAT_ARABIC
11001 to->wo_arab = from->wo_arab;
11002#endif
11003 to->wo_list = from->wo_list;
11004 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011005 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011006#ifdef FEAT_LINEBREAK
11007 to->wo_nuw = from->wo_nuw;
11008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011009#ifdef FEAT_RIGHTLEFT
11010 to->wo_rl = from->wo_rl;
11011 to->wo_rlc = vim_strsave(from->wo_rlc);
11012#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011013#ifdef FEAT_STL_OPT
11014 to->wo_stl = vim_strsave(from->wo_stl);
11015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011016 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011017#ifdef FEAT_DIFF
11018 to->wo_wrap_save = from->wo_wrap_save;
11019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020#ifdef FEAT_LINEBREAK
11021 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011022 to->wo_bri = from->wo_bri;
11023 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011026 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011027 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011028 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011029#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011030 to->wo_spell = from->wo_spell;
11031#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011032#ifdef FEAT_SYN_HL
11033 to->wo_cuc = from->wo_cuc;
11034 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011035 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011036#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011037#ifdef FEAT_DIFF
11038 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011039 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011040#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011041#ifdef FEAT_CONCEAL
11042 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011043 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011044#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011045#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011046 to->wo_twk = vim_strsave(from->wo_twk);
11047 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011048#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011049#ifdef FEAT_FOLDING
11050 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011051 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011052 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011053 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054 to->wo_fdi = vim_strsave(from->wo_fdi);
11055 to->wo_fml = from->wo_fml;
11056 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011057 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011058 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011059 to->wo_fdm_save = from->wo_diff_saved
11060 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011061 to->wo_fdn = from->wo_fdn;
11062# ifdef FEAT_EVAL
11063 to->wo_fde = vim_strsave(from->wo_fde);
11064 to->wo_fdt = vim_strsave(from->wo_fdt);
11065# endif
11066 to->wo_fmr = vim_strsave(from->wo_fmr);
11067#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011068#ifdef FEAT_SIGNS
11069 to->wo_scl = vim_strsave(from->wo_scl);
11070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011071 check_winopt(to); /* don't want NULL pointers */
11072}
11073
11074/*
11075 * Check string options in a window for a NULL value.
11076 */
11077 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011078check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079{
11080 check_winopt(&win->w_onebuf_opt);
11081 check_winopt(&win->w_allbuf_opt);
11082}
11083
11084/*
11085 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11086 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011087 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011088check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089{
11090#ifdef FEAT_FOLDING
11091 check_string_option(&wop->wo_fdi);
11092 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011093 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011094# ifdef FEAT_EVAL
11095 check_string_option(&wop->wo_fde);
11096 check_string_option(&wop->wo_fdt);
11097# endif
11098 check_string_option(&wop->wo_fmr);
11099#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011100#ifdef FEAT_SIGNS
11101 check_string_option(&wop->wo_scl);
11102#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103#ifdef FEAT_RIGHTLEFT
11104 check_string_option(&wop->wo_rlc);
11105#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011106#ifdef FEAT_STL_OPT
11107 check_string_option(&wop->wo_stl);
11108#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011109#ifdef FEAT_SYN_HL
11110 check_string_option(&wop->wo_cc);
11111#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011112#ifdef FEAT_CONCEAL
11113 check_string_option(&wop->wo_cocu);
11114#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011115#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011116 check_string_option(&wop->wo_twk);
11117 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011118#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011119#ifdef FEAT_LINEBREAK
11120 check_string_option(&wop->wo_briopt);
11121#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122}
11123
11124/*
11125 * Free the allocated memory inside a winopt_T.
11126 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011127 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011128clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129{
11130#ifdef FEAT_FOLDING
11131 clear_string_option(&wop->wo_fdi);
11132 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011133 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011134# ifdef FEAT_EVAL
11135 clear_string_option(&wop->wo_fde);
11136 clear_string_option(&wop->wo_fdt);
11137# endif
11138 clear_string_option(&wop->wo_fmr);
11139#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011140#ifdef FEAT_SIGNS
11141 clear_string_option(&wop->wo_scl);
11142#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011143#ifdef FEAT_LINEBREAK
11144 clear_string_option(&wop->wo_briopt);
11145#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011146#ifdef FEAT_RIGHTLEFT
11147 clear_string_option(&wop->wo_rlc);
11148#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011149#ifdef FEAT_STL_OPT
11150 clear_string_option(&wop->wo_stl);
11151#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011152#ifdef FEAT_SYN_HL
11153 clear_string_option(&wop->wo_cc);
11154#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011155#ifdef FEAT_CONCEAL
11156 clear_string_option(&wop->wo_cocu);
11157#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011158#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011159 clear_string_option(&wop->wo_twk);
11160 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011161#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162}
11163
11164/*
11165 * Copy global option values to local options for one buffer.
11166 * Used when creating a new buffer and sometimes when entering a buffer.
11167 * flags:
11168 * BCO_ENTER We will enter the buf buffer.
11169 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11170 * appropriate.
11171 * BCO_NOHELP Don't copy the values to a help buffer.
11172 */
11173 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011174buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011175{
11176 int should_copy = TRUE;
11177 char_u *save_p_isk = NULL; /* init for GCC */
11178 int dont_do_help;
11179 int did_isk = FALSE;
11180
11181 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011182 * Skip this when the option defaults have not been set yet. Happens when
11183 * main() allocates the first buffer.
11184 */
11185 if (p_cpo != NULL)
11186 {
11187 /*
11188 * Always copy when entering and 'cpo' contains 'S'.
11189 * Don't copy when already initialized.
11190 * Don't copy when 'cpo' contains 's' and not entering.
11191 * 'S' BCO_ENTER initialized 's' should_copy
11192 * yes yes X X TRUE
11193 * yes no yes X FALSE
11194 * no X yes X FALSE
11195 * X no no yes FALSE
11196 * X no no no TRUE
11197 * no yes no X TRUE
11198 */
11199 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11200 && (buf->b_p_initialized
11201 || (!(flags & BCO_ENTER)
11202 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11203 should_copy = FALSE;
11204
11205 if (should_copy || (flags & BCO_ALWAYS))
11206 {
11207 /* Don't copy the options specific to a help buffer when
11208 * BCO_NOHELP is given or the options were initialized already
11209 * (jumping back to a help file with CTRL-T or CTRL-O) */
11210 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11211 || buf->b_p_initialized;
11212 if (dont_do_help) /* don't free b_p_isk */
11213 {
11214 save_p_isk = buf->b_p_isk;
11215 buf->b_p_isk = NULL;
11216 }
11217 /*
11218 * Always free the allocated strings.
11219 * If not already initialized, set 'readonly' and copy 'fileformat'.
11220 */
11221 if (!buf->b_p_initialized)
11222 {
11223 free_buf_options(buf, TRUE);
11224 buf->b_p_ro = FALSE; /* don't copy readonly */
11225 buf->b_p_tx = p_tx;
11226#ifdef FEAT_MBYTE
11227 buf->b_p_fenc = vim_strsave(p_fenc);
11228#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011229 switch (*p_ffs)
11230 {
11231 case 'm':
11232 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11233 case 'd':
11234 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11235 case 'u':
11236 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11237 default:
11238 buf->b_p_ff = vim_strsave(p_ff);
11239 }
11240 if (buf->b_p_ff != NULL)
11241 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242 buf->b_p_bh = empty_option;
11243 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011244 }
11245 else
11246 free_buf_options(buf, FALSE);
11247
11248 buf->b_p_ai = p_ai;
11249 buf->b_p_ai_nopaste = p_ai_nopaste;
11250 buf->b_p_sw = p_sw;
11251 buf->b_p_tw = p_tw;
11252 buf->b_p_tw_nopaste = p_tw_nopaste;
11253 buf->b_p_tw_nobin = p_tw_nobin;
11254 buf->b_p_wm = p_wm;
11255 buf->b_p_wm_nopaste = p_wm_nopaste;
11256 buf->b_p_wm_nobin = p_wm_nobin;
11257 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011258#ifdef FEAT_MBYTE
11259 buf->b_p_bomb = p_bomb;
11260#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011261 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011262 buf->b_p_et = p_et;
11263 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011264 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265 buf->b_p_ml = p_ml;
11266 buf->b_p_ml_nobin = p_ml_nobin;
11267 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011268 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269#ifdef FEAT_INS_EXPAND
11270 buf->b_p_cpt = vim_strsave(p_cpt);
11271#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011272#ifdef FEAT_COMPL_FUNC
11273 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011274 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011276 buf->b_p_sts = p_sts;
11277 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011278#ifdef FEAT_VARTABS
11279 buf->b_p_vsts = vim_strsave(p_vsts);
11280 if (p_vsts && p_vsts != empty_option)
11281 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11282 else
11283 buf->b_p_vsts_array = 0;
11284 buf->b_p_vsts_nopaste = p_vsts_nopaste
11285 ? vim_strsave(p_vsts_nopaste) : NULL;
11286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011287 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288#ifdef FEAT_COMMENTS
11289 buf->b_p_com = vim_strsave(p_com);
11290#endif
11291#ifdef FEAT_FOLDING
11292 buf->b_p_cms = vim_strsave(p_cms);
11293#endif
11294 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011295 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011296 buf->b_p_nf = vim_strsave(p_nf);
11297 buf->b_p_mps = vim_strsave(p_mps);
11298#ifdef FEAT_SMARTINDENT
11299 buf->b_p_si = p_si;
11300#endif
11301 buf->b_p_ci = p_ci;
11302#ifdef FEAT_CINDENT
11303 buf->b_p_cin = p_cin;
11304 buf->b_p_cink = vim_strsave(p_cink);
11305 buf->b_p_cino = vim_strsave(p_cino);
11306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011307 /* Don't copy 'filetype', it must be detected */
11308 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011309 buf->b_p_pi = p_pi;
11310#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11311 buf->b_p_cinw = vim_strsave(p_cinw);
11312#endif
11313#ifdef FEAT_LISP
11314 buf->b_p_lisp = p_lisp;
11315#endif
11316#ifdef FEAT_SYN_HL
11317 /* Don't copy 'syntax', it must be set */
11318 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011319 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011320 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011321#endif
11322#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011323 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011324 (void)compile_cap_prog(&buf->b_s);
11325 buf->b_s.b_p_spf = vim_strsave(p_spf);
11326 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011327#endif
11328#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11329 buf->b_p_inde = vim_strsave(p_inde);
11330 buf->b_p_indk = vim_strsave(p_indk);
11331#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011332 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011333#if defined(FEAT_EVAL)
11334 buf->b_p_fex = vim_strsave(p_fex);
11335#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011336#ifdef FEAT_CRYPT
11337 buf->b_p_key = vim_strsave(p_key);
11338#endif
11339#ifdef FEAT_SEARCHPATH
11340 buf->b_p_sua = vim_strsave(p_sua);
11341#endif
11342#ifdef FEAT_KEYMAP
11343 buf->b_p_keymap = vim_strsave(p_keymap);
11344 buf->b_kmap_state |= KEYMAP_INIT;
11345#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011346#ifdef FEAT_TERMINAL
11347 buf->b_p_twsl = p_twsl;
11348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349 /* This isn't really an option, but copying the langmap and IME
11350 * state from the current buffer is better than resetting it. */
11351 buf->b_p_iminsert = p_iminsert;
11352 buf->b_p_imsearch = p_imsearch;
11353
11354 /* options that are normally global but also have a local value
11355 * are not copied, start using the global value */
11356 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011357 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011358 buf->b_p_bkc = empty_option;
11359 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360#ifdef FEAT_QUICKFIX
11361 buf->b_p_gp = empty_option;
11362 buf->b_p_mp = empty_option;
11363 buf->b_p_efm = empty_option;
11364#endif
11365 buf->b_p_ep = empty_option;
11366 buf->b_p_kp = empty_option;
11367 buf->b_p_path = empty_option;
11368 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011369 buf->b_p_tc = empty_option;
11370 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371#ifdef FEAT_FIND_ID
11372 buf->b_p_def = empty_option;
11373 buf->b_p_inc = empty_option;
11374# ifdef FEAT_EVAL
11375 buf->b_p_inex = vim_strsave(p_inex);
11376# endif
11377#endif
11378#ifdef FEAT_INS_EXPAND
11379 buf->b_p_dict = empty_option;
11380 buf->b_p_tsr = empty_option;
11381#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011382#ifdef FEAT_TEXTOBJ
11383 buf->b_p_qe = vim_strsave(p_qe);
11384#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011385#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11386 buf->b_p_bexpr = empty_option;
11387#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011388#if defined(FEAT_CRYPT)
11389 buf->b_p_cm = empty_option;
11390#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011391#ifdef FEAT_PERSISTENT_UNDO
11392 buf->b_p_udf = p_udf;
11393#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011394#ifdef FEAT_LISP
11395 buf->b_p_lw = empty_option;
11396#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011397#ifdef FEAT_MBYTE
11398 buf->b_p_menc = empty_option;
11399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400
11401 /*
11402 * Don't copy the options set by ex_help(), use the saved values,
11403 * when going from a help buffer to a non-help buffer.
11404 * Don't touch these at all when BCO_NOHELP is used and going from
11405 * or to a help buffer.
11406 */
11407 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011408 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011409 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011410#ifdef FEAT_VARTABS
11411 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11412 tabstop_set(p_vts, &buf->b_p_vts_array);
11413 else
11414 buf->b_p_vts_array = NULL;
11415#endif
11416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011417 else
11418 {
11419 buf->b_p_isk = vim_strsave(p_isk);
11420 did_isk = TRUE;
11421 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011422#ifdef FEAT_VARTABS
11423 buf->b_p_vts = vim_strsave(p_vts);
11424 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11425 tabstop_set(p_vts, &buf->b_p_vts_array);
11426 else
11427 buf->b_p_vts_array = NULL;
11428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011429 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011430 if (buf->b_p_bt[0] == 'h')
11431 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011432 buf->b_p_ma = p_ma;
11433 }
11434 }
11435
11436 /*
11437 * When the options should be copied (ignoring BCO_ALWAYS), set the
11438 * flag that indicates that the options have been initialized.
11439 */
11440 if (should_copy)
11441 buf->b_p_initialized = TRUE;
11442 }
11443
11444 check_buf_options(buf); /* make sure we don't have NULLs */
11445 if (did_isk)
11446 (void)buf_init_chartab(buf, FALSE);
11447}
11448
11449/*
11450 * Reset the 'modifiable' option and its default value.
11451 */
11452 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011453reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011454{
11455 int opt_idx;
11456
11457 curbuf->b_p_ma = FALSE;
11458 p_ma = FALSE;
11459 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011460 if (opt_idx >= 0)
11461 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011462}
11463
11464/*
11465 * Set the global value for 'iminsert' to the local value.
11466 */
11467 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011468set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011469{
11470 p_iminsert = curbuf->b_p_iminsert;
11471}
11472
11473/*
11474 * Set the global value for 'imsearch' to the local value.
11475 */
11476 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011477set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478{
11479 p_imsearch = curbuf->b_p_imsearch;
11480}
11481
11482#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11483static int expand_option_idx = -1;
11484static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11485static int expand_option_flags = 0;
11486
11487 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011488set_context_in_set_cmd(
11489 expand_T *xp,
11490 char_u *arg,
11491 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011492{
11493 int nextchar;
11494 long_u flags = 0; /* init for GCC */
11495 int opt_idx = 0; /* init for GCC */
11496 char_u *p;
11497 char_u *s;
11498 int is_term_option = FALSE;
11499 int key;
11500
11501 expand_option_flags = opt_flags;
11502
11503 xp->xp_context = EXPAND_SETTINGS;
11504 if (*arg == NUL)
11505 {
11506 xp->xp_pattern = arg;
11507 return;
11508 }
11509 p = arg + STRLEN(arg) - 1;
11510 if (*p == ' ' && *(p - 1) != '\\')
11511 {
11512 xp->xp_pattern = p + 1;
11513 return;
11514 }
11515 while (p > arg)
11516 {
11517 s = p;
11518 /* count number of backslashes before ' ' or ',' */
11519 if (*p == ' ' || *p == ',')
11520 {
11521 while (s > arg && *(s - 1) == '\\')
11522 --s;
11523 }
11524 /* break at a space with an even number of backslashes */
11525 if (*p == ' ' && ((p - s) & 1) == 0)
11526 {
11527 ++p;
11528 break;
11529 }
11530 --p;
11531 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011532 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533 {
11534 xp->xp_context = EXPAND_BOOL_SETTINGS;
11535 p += 2;
11536 }
11537 if (STRNCMP(p, "inv", 3) == 0)
11538 {
11539 xp->xp_context = EXPAND_BOOL_SETTINGS;
11540 p += 3;
11541 }
11542 xp->xp_pattern = arg = p;
11543 if (*arg == '<')
11544 {
11545 while (*p != '>')
11546 if (*p++ == NUL) /* expand terminal option name */
11547 return;
11548 key = get_special_key_code(arg + 1);
11549 if (key == 0) /* unknown name */
11550 {
11551 xp->xp_context = EXPAND_NOTHING;
11552 return;
11553 }
11554 nextchar = *++p;
11555 is_term_option = TRUE;
11556 expand_option_name[2] = KEY2TERMCAP0(key);
11557 expand_option_name[3] = KEY2TERMCAP1(key);
11558 }
11559 else
11560 {
11561 if (p[0] == 't' && p[1] == '_')
11562 {
11563 p += 2;
11564 if (*p != NUL)
11565 ++p;
11566 if (*p == NUL)
11567 return; /* expand option name */
11568 nextchar = *++p;
11569 is_term_option = TRUE;
11570 expand_option_name[2] = p[-2];
11571 expand_option_name[3] = p[-1];
11572 }
11573 else
11574 {
11575 /* Allow * wildcard */
11576 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11577 p++;
11578 if (*p == NUL)
11579 return;
11580 nextchar = *p;
11581 *p = NUL;
11582 opt_idx = findoption(arg);
11583 *p = nextchar;
11584 if (opt_idx == -1 || options[opt_idx].var == NULL)
11585 {
11586 xp->xp_context = EXPAND_NOTHING;
11587 return;
11588 }
11589 flags = options[opt_idx].flags;
11590 if (flags & P_BOOL)
11591 {
11592 xp->xp_context = EXPAND_NOTHING;
11593 return;
11594 }
11595 }
11596 }
11597 /* handle "-=" and "+=" */
11598 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11599 {
11600 ++p;
11601 nextchar = '=';
11602 }
11603 if ((nextchar != '=' && nextchar != ':')
11604 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11605 {
11606 xp->xp_context = EXPAND_UNSUCCESSFUL;
11607 return;
11608 }
11609 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11610 {
11611 xp->xp_context = EXPAND_OLD_SETTING;
11612 if (is_term_option)
11613 expand_option_idx = -1;
11614 else
11615 expand_option_idx = opt_idx;
11616 xp->xp_pattern = p + 1;
11617 return;
11618 }
11619 xp->xp_context = EXPAND_NOTHING;
11620 if (is_term_option || (flags & P_NUM))
11621 return;
11622
11623 xp->xp_pattern = p + 1;
11624
11625 if (flags & P_EXPAND)
11626 {
11627 p = options[opt_idx].var;
11628 if (p == (char_u *)&p_bdir
11629 || p == (char_u *)&p_dir
11630 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011631 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011632 || p == (char_u *)&p_rtp
11633#ifdef FEAT_SEARCHPATH
11634 || p == (char_u *)&p_cdpath
11635#endif
11636#ifdef FEAT_SESSION
11637 || p == (char_u *)&p_vdir
11638#endif
11639 )
11640 {
11641 xp->xp_context = EXPAND_DIRECTORIES;
11642 if (p == (char_u *)&p_path
11643#ifdef FEAT_SEARCHPATH
11644 || p == (char_u *)&p_cdpath
11645#endif
11646 )
11647 xp->xp_backslash = XP_BS_THREE;
11648 else
11649 xp->xp_backslash = XP_BS_ONE;
11650 }
11651 else
11652 {
11653 xp->xp_context = EXPAND_FILES;
11654 /* for 'tags' need three backslashes for a space */
11655 if (p == (char_u *)&p_tags)
11656 xp->xp_backslash = XP_BS_THREE;
11657 else
11658 xp->xp_backslash = XP_BS_ONE;
11659 }
11660 }
11661
11662 /* For an option that is a list of file names, find the start of the
11663 * last file name. */
11664 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11665 {
11666 /* count number of backslashes before ' ' or ',' */
11667 if (*p == ' ' || *p == ',')
11668 {
11669 s = p;
11670 while (s > xp->xp_pattern && *(s - 1) == '\\')
11671 --s;
11672 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11673 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11674 {
11675 xp->xp_pattern = p + 1;
11676 break;
11677 }
11678 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011679
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011680#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011681 /* for 'spellsuggest' start at "file:" */
11682 if (options[opt_idx].var == (char_u *)&p_sps
11683 && STRNCMP(p, "file:", 5) == 0)
11684 {
11685 xp->xp_pattern = p + 5;
11686 break;
11687 }
11688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689 }
11690
11691 return;
11692}
11693
11694 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011695ExpandSettings(
11696 expand_T *xp,
11697 regmatch_T *regmatch,
11698 int *num_file,
11699 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011700{
11701 int num_normal = 0; /* Nr of matching non-term-code settings */
11702 int num_term = 0; /* Nr of matching terminal code settings */
11703 int opt_idx;
11704 int match;
11705 int count = 0;
11706 char_u *str;
11707 int loop;
11708 int is_term_opt;
11709 char_u name_buf[MAX_KEY_NAME_LEN];
11710 static char *(names[]) = {"all", "termcap"};
11711 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11712
11713 /* do this loop twice:
11714 * loop == 0: count the number of matching options
11715 * loop == 1: copy the matching options into allocated memory
11716 */
11717 for (loop = 0; loop <= 1; ++loop)
11718 {
11719 regmatch->rm_ic = ic;
11720 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11721 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011722 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11723 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011724 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11725 {
11726 if (loop == 0)
11727 num_normal++;
11728 else
11729 (*file)[count++] = vim_strsave((char_u *)names[match]);
11730 }
11731 }
11732 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11733 opt_idx++)
11734 {
11735 if (options[opt_idx].var == NULL)
11736 continue;
11737 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11738 && !(options[opt_idx].flags & P_BOOL))
11739 continue;
11740 is_term_opt = istermoption(&options[opt_idx]);
11741 if (is_term_opt && num_normal > 0)
11742 continue;
11743 match = FALSE;
11744 if (vim_regexec(regmatch, str, (colnr_T)0)
11745 || (options[opt_idx].shortname != NULL
11746 && vim_regexec(regmatch,
11747 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11748 match = TRUE;
11749 else if (is_term_opt)
11750 {
11751 name_buf[0] = '<';
11752 name_buf[1] = 't';
11753 name_buf[2] = '_';
11754 name_buf[3] = str[2];
11755 name_buf[4] = str[3];
11756 name_buf[5] = '>';
11757 name_buf[6] = NUL;
11758 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11759 {
11760 match = TRUE;
11761 str = name_buf;
11762 }
11763 }
11764 if (match)
11765 {
11766 if (loop == 0)
11767 {
11768 if (is_term_opt)
11769 num_term++;
11770 else
11771 num_normal++;
11772 }
11773 else
11774 (*file)[count++] = vim_strsave(str);
11775 }
11776 }
11777 /*
11778 * Check terminal key codes, these are not in the option table
11779 */
11780 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11781 {
11782 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11783 {
11784 if (!isprint(str[0]) || !isprint(str[1]))
11785 continue;
11786
11787 name_buf[0] = 't';
11788 name_buf[1] = '_';
11789 name_buf[2] = str[0];
11790 name_buf[3] = str[1];
11791 name_buf[4] = NUL;
11792
11793 match = FALSE;
11794 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11795 match = TRUE;
11796 else
11797 {
11798 name_buf[0] = '<';
11799 name_buf[1] = 't';
11800 name_buf[2] = '_';
11801 name_buf[3] = str[0];
11802 name_buf[4] = str[1];
11803 name_buf[5] = '>';
11804 name_buf[6] = NUL;
11805
11806 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11807 match = TRUE;
11808 }
11809 if (match)
11810 {
11811 if (loop == 0)
11812 num_term++;
11813 else
11814 (*file)[count++] = vim_strsave(name_buf);
11815 }
11816 }
11817
11818 /*
11819 * Check special key names.
11820 */
11821 regmatch->rm_ic = TRUE; /* ignore case here */
11822 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11823 {
11824 name_buf[0] = '<';
11825 STRCPY(name_buf + 1, str);
11826 STRCAT(name_buf, ">");
11827
11828 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11829 {
11830 if (loop == 0)
11831 num_term++;
11832 else
11833 (*file)[count++] = vim_strsave(name_buf);
11834 }
11835 }
11836 }
11837 if (loop == 0)
11838 {
11839 if (num_normal > 0)
11840 *num_file = num_normal;
11841 else if (num_term > 0)
11842 *num_file = num_term;
11843 else
11844 return OK;
11845 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11846 if (*file == NULL)
11847 {
11848 *file = (char_u **)"";
11849 return FAIL;
11850 }
11851 }
11852 }
11853 return OK;
11854}
11855
11856 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011857ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011858{
11859 char_u *var = NULL; /* init for GCC */
11860 char_u *buf;
11861
11862 *num_file = 0;
11863 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11864 if (*file == NULL)
11865 return FAIL;
11866
11867 /*
11868 * For a terminal key code expand_option_idx is < 0.
11869 */
11870 if (expand_option_idx < 0)
11871 {
11872 var = find_termcode(expand_option_name + 2);
11873 if (var == NULL)
11874 expand_option_idx = findoption(expand_option_name);
11875 }
11876
11877 if (expand_option_idx >= 0)
11878 {
11879 /* put string of option value in NameBuff */
11880 option_value2string(&options[expand_option_idx], expand_option_flags);
11881 var = NameBuff;
11882 }
11883 else if (var == NULL)
11884 var = (char_u *)"";
11885
11886 /* A backslash is required before some characters. This is the reverse of
11887 * what happens in do_set(). */
11888 buf = vim_strsave_escaped(var, escape_chars);
11889
11890 if (buf == NULL)
11891 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011892 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893 return FAIL;
11894 }
11895
11896#ifdef BACKSLASH_IN_FILENAME
11897 /* For MS-Windows et al. we don't double backslashes at the start and
11898 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011899 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900 if (var[0] == '\\' && var[1] == '\\'
11901 && expand_option_idx >= 0
11902 && (options[expand_option_idx].flags & P_EXPAND)
11903 && vim_isfilec(var[2])
11904 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011905 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906#endif
11907
11908 *file[0] = buf;
11909 *num_file = 1;
11910 return OK;
11911}
11912#endif
11913
11914/*
11915 * Get the value for the numeric or string option *opp in a nice format into
11916 * NameBuff[]. Must not be called with a hidden option!
11917 */
11918 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011919option_value2string(
11920 struct vimoption *opp,
11921 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922{
11923 char_u *varp;
11924
11925 varp = get_varp_scope(opp, opt_flags);
11926
11927 if (opp->flags & P_NUM)
11928 {
11929 long wc = 0;
11930
11931 if (wc_use_keyname(varp, &wc))
11932 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11933 else if (wc != 0)
11934 STRCPY(NameBuff, transchar((int)wc));
11935 else
11936 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11937 }
11938 else /* P_STRING */
11939 {
11940 varp = *(char_u **)(varp);
11941 if (varp == NULL) /* just in case */
11942 NameBuff[0] = NUL;
11943#ifdef FEAT_CRYPT
11944 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011945 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011946 STRCPY(NameBuff, "*****");
11947#endif
11948 else if (opp->flags & P_EXPAND)
11949 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11950 /* Translate 'pastetoggle' into special key names */
11951 else if ((char_u **)opp->var == &p_pt)
11952 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11953 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011954 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 }
11956}
11957
11958/*
11959 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11960 * printed as a keyname.
11961 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11962 */
11963 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011964wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965{
11966 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11967 {
11968 *wcp = *(long *)varp;
11969 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11970 return TRUE;
11971 }
11972 return FALSE;
11973}
11974
Bram Moolenaar01615492015-02-03 13:00:38 +010011975#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011977 * Any character has an equivalent 'langmap' character. This is used for
11978 * keyboards that have a special language mode that sends characters above
11979 * 128 (although other characters can be translated too). The "to" field is a
11980 * Vim command character. This avoids having to switch the keyboard back to
11981 * ASCII mode when leaving Insert mode.
11982 *
11983 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11984 * commands.
11985 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11986 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11987 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011988 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011989# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011990/*
11991 * With multi-byte support use growarray for 'langmap' chars >= 256
11992 */
11993typedef struct
11994{
11995 int from;
11996 int to;
11997} langmap_entry_T;
11998
11999static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010012000static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001
12002/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012003 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12004 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012005 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012006 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012007langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012008{
12009 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012010 int a = 0;
12011 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012012
12013 /* Do a binary search for an existing entry. */
12014 while (a != b)
12015 {
12016 int i = (a + b) / 2;
12017 int d = entries[i].from - from;
12018
12019 if (d == 0)
12020 {
12021 entries[i].to = to;
12022 return;
12023 }
12024 if (d < 0)
12025 a = i + 1;
12026 else
12027 b = i;
12028 }
12029
12030 if (ga_grow(&langmap_mapga, 1) != OK)
12031 return; /* out of memory */
12032
12033 /* insert new entry at position "a" */
12034 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12035 mch_memmove(entries + 1, entries,
12036 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12037 ++langmap_mapga.ga_len;
12038 entries[0].from = from;
12039 entries[0].to = to;
12040}
12041
12042/*
12043 * Apply 'langmap' to multi-byte character "c" and return the result.
12044 */
12045 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012046langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012047{
12048 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12049 int a = 0;
12050 int b = langmap_mapga.ga_len;
12051
12052 while (a != b)
12053 {
12054 int i = (a + b) / 2;
12055 int d = entries[i].from - c;
12056
12057 if (d == 0)
12058 return entries[i].to; /* found matching entry */
12059 if (d < 0)
12060 a = i + 1;
12061 else
12062 b = i;
12063 }
12064 return c; /* no entry found, return "c" unmodified */
12065}
12066# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012067
12068 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012069langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070{
12071 int i;
12072
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012073 for (i = 0; i < 256; i++)
12074 langmap_mapchar[i] = i; /* we init with a one-to-one map */
12075# ifdef FEAT_MBYTE
12076 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
12077# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078}
12079
12080/*
12081 * Called when langmap option is set; the language map can be
12082 * changed at any time!
12083 */
12084 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012085langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086{
12087 char_u *p;
12088 char_u *p2;
12089 int from, to;
12090
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012091#ifdef FEAT_MBYTE
12092 ga_clear(&langmap_mapga); /* clear the previous map first */
12093#endif
12094 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095
12096 for (p = p_langmap; p[0] != NUL; )
12097 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012098 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012099 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100 {
12101 if (p2[0] == '\\' && p2[1] != NUL)
12102 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 }
12104 if (p2[0] == ';')
12105 ++p2; /* abcd;ABCD form, p2 points to A */
12106 else
12107 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12108 while (p[0])
12109 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012110 if (p[0] == ',')
12111 {
12112 ++p;
12113 break;
12114 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115 if (p[0] == '\\' && p[1] != NUL)
12116 ++p;
12117#ifdef FEAT_MBYTE
12118 from = (*mb_ptr2char)(p);
12119#else
12120 from = p[0];
12121#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012122 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123 if (p2 == NULL)
12124 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012125 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012126 if (p[0] != ',')
12127 {
12128 if (p[0] == '\\')
12129 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012130#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012131 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012132#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012133 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012134#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012135 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 }
12137 else
12138 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012139 if (p2[0] != ',')
12140 {
12141 if (p2[0] == '\\')
12142 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012144 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012145#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012146 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 }
12150 if (to == NUL)
12151 {
12152 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12153 transchar(from));
12154 return;
12155 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012156
12157#ifdef FEAT_MBYTE
12158 if (from >= 256)
12159 langmap_set_entry(from, to);
12160 else
12161#endif
12162 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163
12164 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012165 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012166 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012168 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012169 if (*p == ';')
12170 {
12171 p = p2;
12172 if (p[0] != NUL)
12173 {
12174 if (p[0] != ',')
12175 {
12176 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12177 return;
12178 }
12179 ++p;
12180 }
12181 break;
12182 }
12183 }
12184 }
12185 }
12186}
12187#endif
12188
12189/*
12190 * Return TRUE if format option 'x' is in effect.
12191 * Take care of no formatting when 'paste' is set.
12192 */
12193 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012194has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012195{
12196 if (p_paste)
12197 return FALSE;
12198 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12199}
12200
12201/*
12202 * Return TRUE if "x" is present in 'shortmess' option, or
12203 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12204 */
12205 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012206shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012207{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012208 return p_shm != NULL &&
12209 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012210 || (vim_strchr(p_shm, 'a') != NULL
12211 && vim_strchr((char_u *)SHM_A, x) != NULL));
12212}
12213
12214/*
12215 * paste_option_changed() - Called after p_paste was set or reset.
12216 */
12217 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012218paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012219{
12220 static int old_p_paste = FALSE;
12221 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012222 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012223#ifdef FEAT_CMDL_INFO
12224 static int save_ru = 0;
12225#endif
12226#ifdef FEAT_RIGHTLEFT
12227 static int save_ri = 0;
12228 static int save_hkmap = 0;
12229#endif
12230 buf_T *buf;
12231
12232 if (p_paste)
12233 {
12234 /*
12235 * Paste switched from off to on.
12236 * Save the current values, so they can be restored later.
12237 */
12238 if (!old_p_paste)
12239 {
12240 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012241 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242 {
12243 buf->b_p_tw_nopaste = buf->b_p_tw;
12244 buf->b_p_wm_nopaste = buf->b_p_wm;
12245 buf->b_p_sts_nopaste = buf->b_p_sts;
12246 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012247 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012248#ifdef FEAT_VARTABS
12249 if (buf->b_p_vsts_nopaste)
12250 vim_free(buf->b_p_vsts_nopaste);
12251 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12252 ? vim_strsave(buf->b_p_vsts) : NULL;
12253#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254 }
12255
12256 /* save global options */
12257 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012258 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259#ifdef FEAT_CMDL_INFO
12260 save_ru = p_ru;
12261#endif
12262#ifdef FEAT_RIGHTLEFT
12263 save_ri = p_ri;
12264 save_hkmap = p_hkmap;
12265#endif
12266 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012267 p_ai_nopaste = p_ai;
12268 p_et_nopaste = p_et;
12269 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270 p_tw_nopaste = p_tw;
12271 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012272#ifdef FEAT_VARTABS
12273 if (p_vsts_nopaste)
12274 vim_free(p_vsts_nopaste);
12275 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12276#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277 }
12278
12279 /*
12280 * Always set the option values, also when 'paste' is set when it is
12281 * already on.
12282 */
12283 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012284 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012285 {
12286 buf->b_p_tw = 0; /* textwidth is 0 */
12287 buf->b_p_wm = 0; /* wrapmargin is 0 */
12288 buf->b_p_sts = 0; /* softtabstop is 0 */
12289 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012290 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012291#ifdef FEAT_VARTABS
12292 if (buf->b_p_vsts)
12293 free_string_option(buf->b_p_vsts);
12294 buf->b_p_vsts = empty_option;
12295 if (buf->b_p_vsts_array)
12296 vim_free(buf->b_p_vsts_array);
12297 buf->b_p_vsts_array = 0;
12298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012299 }
12300
12301 /* set global options */
12302 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012303 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012304#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305 if (p_ru)
12306 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012307 p_ru = 0; /* no ruler */
12308#endif
12309#ifdef FEAT_RIGHTLEFT
12310 p_ri = 0; /* no reverse insert */
12311 p_hkmap = 0; /* no Hebrew keyboard */
12312#endif
12313 /* set global values for local buffer options */
12314 p_tw = 0;
12315 p_wm = 0;
12316 p_sts = 0;
12317 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012318#ifdef FEAT_VARTABS
12319 if (p_vsts)
12320 free_string_option(p_vsts);
12321 p_vsts = empty_option;
12322#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012323 }
12324
12325 /*
12326 * Paste switched from on to off: Restore saved values.
12327 */
12328 else if (old_p_paste)
12329 {
12330 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012331 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012332 {
12333 buf->b_p_tw = buf->b_p_tw_nopaste;
12334 buf->b_p_wm = buf->b_p_wm_nopaste;
12335 buf->b_p_sts = buf->b_p_sts_nopaste;
12336 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012337 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012338#ifdef FEAT_VARTABS
12339 if (buf->b_p_vsts)
12340 free_string_option(buf->b_p_vsts);
12341 buf->b_p_vsts = buf->b_p_vsts_nopaste
12342 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12343 if (buf->b_p_vsts_array)
12344 vim_free(buf->b_p_vsts_array);
12345 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12346 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12347 else
12348 buf->b_p_vsts_array = 0;
12349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012350 }
12351
12352 /* restore global options */
12353 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012354 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012355#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012356 if (p_ru != save_ru)
12357 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012358 p_ru = save_ru;
12359#endif
12360#ifdef FEAT_RIGHTLEFT
12361 p_ri = save_ri;
12362 p_hkmap = save_hkmap;
12363#endif
12364 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012365 p_ai = p_ai_nopaste;
12366 p_et = p_et_nopaste;
12367 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012368 p_tw = p_tw_nopaste;
12369 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012370#ifdef FEAT_VARTABS
12371 if (p_vsts)
12372 free_string_option(p_vsts);
12373 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012375 }
12376
12377 old_p_paste = p_paste;
12378}
12379
12380/*
12381 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12382 *
12383 * Reset 'compatible' and set the values for options that didn't get set yet
12384 * to the Vim defaults.
12385 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012386 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012387 */
12388 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012389vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012390{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012391 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012392 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012393 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012394
12395 if (!option_was_set((char_u *)"cp"))
12396 {
12397 p_cp = FALSE;
12398 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12399 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12400 set_option_default(opt_idx, OPT_FREE, FALSE);
12401 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012402 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012403 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012404
12405 if (fname != NULL)
12406 {
12407 p = vim_getenv(envname, &dofree);
12408 if (p == NULL)
12409 {
12410 /* Set $MYVIMRC to the first vimrc file found. */
12411 p = FullName_save(fname, FALSE);
12412 if (p != NULL)
12413 {
12414 vim_setenv(envname, p);
12415 vim_free(p);
12416 }
12417 }
12418 else if (dofree)
12419 vim_free(p);
12420 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421}
12422
12423/*
12424 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12425 */
12426 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012427change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012428{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012429 int opt_idx;
12430
Bram Moolenaar071d4272004-06-13 20:20:40 +000012431 if (p_cp != on)
12432 {
12433 p_cp = on;
12434 compatible_set();
12435 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012436 opt_idx = findoption((char_u *)"cp");
12437 if (opt_idx >= 0)
12438 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012439}
12440
12441/*
12442 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012443 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012444 */
12445 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012446option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012447{
12448 int idx;
12449
12450 idx = findoption(name);
12451 if (idx < 0) /* unknown option */
12452 return FALSE;
12453 if (options[idx].flags & P_WAS_SET)
12454 return TRUE;
12455 return FALSE;
12456}
12457
12458/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012459 * Reset the flag indicating option "name" was set.
12460 */
12461 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012462reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012463{
12464 int idx = findoption(name);
12465
12466 if (idx >= 0)
12467 options[idx].flags &= ~P_WAS_SET;
12468}
12469
12470/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012471 * compatible_set() - Called when 'compatible' has been set or unset.
12472 *
12473 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12474 * flag) to a Vi compatible value.
12475 * When 'compatible' is unset: Set all options that have a different default
12476 * for Vim (without the P_VI_DEF flag) to that default.
12477 */
12478 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012479compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012480{
12481 int opt_idx;
12482
12483 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12484 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12485 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12486 set_option_default(opt_idx, OPT_FREE, p_cp);
12487 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012488 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012489}
12490
12491#ifdef FEAT_LINEBREAK
12492
12493# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12494 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012495 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012496# endif
12497
12498/*
12499 * fill_breakat_flags() -- called when 'breakat' changes value.
12500 */
12501 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012502fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012503{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012504 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012505 int i;
12506
12507 for (i = 0; i < 256; i++)
12508 breakat_flags[i] = FALSE;
12509
12510 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012511 for (p = p_breakat; *p; p++)
12512 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012513}
12514
12515# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012516 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012517# endif
12518
12519#endif
12520
12521/*
12522 * Check an option that can be a range of string values.
12523 *
12524 * Return OK for correct value, FAIL otherwise.
12525 * Empty is always OK.
12526 */
12527 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012528check_opt_strings(
12529 char_u *val,
12530 char **values,
12531 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012532{
12533 return opt_strings_flags(val, values, NULL, list);
12534}
12535
12536/*
12537 * Handle an option that can be a range of string values.
12538 * Set a flag in "*flagp" for each string present.
12539 *
12540 * Return OK for correct value, FAIL otherwise.
12541 * Empty is always OK.
12542 */
12543 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012544opt_strings_flags(
12545 char_u *val, /* new value */
12546 char **values, /* array of valid string values */
12547 unsigned *flagp,
12548 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012549{
12550 int i;
12551 int len;
12552 unsigned new_flags = 0;
12553
12554 while (*val)
12555 {
12556 for (i = 0; ; ++i)
12557 {
12558 if (values[i] == NULL) /* val not found in values[] */
12559 return FAIL;
12560
12561 len = (int)STRLEN(values[i]);
12562 if (STRNCMP(values[i], val, len) == 0
12563 && ((list && val[len] == ',') || val[len] == NUL))
12564 {
12565 val += len + (val[len] == ',');
12566 new_flags |= (1 << i);
12567 break; /* check next item in val list */
12568 }
12569 }
12570 }
12571 if (flagp != NULL)
12572 *flagp = new_flags;
12573
12574 return OK;
12575}
12576
12577/*
12578 * Read the 'wildmode' option, fill wim_flags[].
12579 */
12580 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012581check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012582{
12583 char_u new_wim_flags[4];
12584 char_u *p;
12585 int i;
12586 int idx = 0;
12587
12588 for (i = 0; i < 4; ++i)
12589 new_wim_flags[i] = 0;
12590
12591 for (p = p_wim; *p; ++p)
12592 {
12593 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12594 ;
12595 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12596 return FAIL;
12597 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12598 new_wim_flags[idx] |= WIM_LONGEST;
12599 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12600 new_wim_flags[idx] |= WIM_FULL;
12601 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12602 new_wim_flags[idx] |= WIM_LIST;
12603 else
12604 return FAIL;
12605 p += i;
12606 if (*p == NUL)
12607 break;
12608 if (*p == ',')
12609 {
12610 if (idx == 3)
12611 return FAIL;
12612 ++idx;
12613 }
12614 }
12615
12616 /* fill remaining entries with last flag */
12617 while (idx < 3)
12618 {
12619 new_wim_flags[idx + 1] = new_wim_flags[idx];
12620 ++idx;
12621 }
12622
12623 /* only when there are no errors, wim_flags[] is changed */
12624 for (i = 0; i < 4; ++i)
12625 wim_flags[i] = new_wim_flags[i];
12626 return OK;
12627}
12628
12629/*
12630 * Check if backspacing over something is allowed.
12631 */
12632 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012633can_bs(
12634 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012635{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012636#ifdef FEAT_JOB_CHANNEL
12637 if (what == BS_START && bt_prompt(curbuf))
12638 return FALSE;
12639#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012640 switch (*p_bs)
12641 {
12642 case '2': return TRUE;
12643 case '1': return (what != BS_START);
12644 case '0': return FALSE;
12645 }
12646 return vim_strchr(p_bs, what) != NULL;
12647}
12648
12649/*
12650 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12651 * the file must be considered changed when the value is different.
12652 */
12653 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012654save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012655{
12656 buf->b_start_ffc = *buf->b_p_ff;
12657 buf->b_start_eol = buf->b_p_eol;
12658#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012659 buf->b_start_bomb = buf->b_p_bomb;
12660
Bram Moolenaar071d4272004-06-13 20:20:40 +000012661 /* Only use free/alloc when necessary, they take time. */
12662 if (buf->b_start_fenc == NULL
12663 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12664 {
12665 vim_free(buf->b_start_fenc);
12666 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12667 }
12668#endif
12669}
12670
12671/*
12672 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12673 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012674 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12675 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012676 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012677 * When "ignore_empty" is true don't consider a new, empty buffer to be
12678 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012679 */
12680 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012681file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012682{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012683 /* In a buffer that was never loaded the options are not valid. */
12684 if (buf->b_flags & BF_NEVERLOADED)
12685 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012686 if (ignore_empty
12687 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012688 && buf->b_ml.ml_line_count == 1
12689 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12690 return FALSE;
12691 if (buf->b_start_ffc != *buf->b_p_ff)
12692 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012693 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012694 return TRUE;
12695#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012696 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12697 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012698 if (buf->b_start_fenc == NULL)
12699 return (*buf->b_p_fenc != NUL);
12700 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12701#else
12702 return FALSE;
12703#endif
12704}
12705
12706/*
12707 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12708 */
12709 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012710check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012711{
12712 return check_opt_strings(p, p_ff_values, FALSE);
12713}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012714
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012715#ifdef FEAT_VARTABS
12716
12717/*
12718 * Set the integer values corresponding to the string setting of 'vartabstop'.
12719 */
12720 int
12721tabstop_set(char_u *var, int **array)
12722{
12723 int valcount = 1;
12724 int t;
12725 char_u *cp;
12726
12727 if ((!var[0] || (var[0] == '0' && !var[1])))
12728 {
12729 *array = NULL;
12730 return TRUE;
12731 }
12732
12733 for (cp = var; *cp; ++cp)
12734 {
12735 if (cp == var || *(cp - 1) == ',')
12736 {
12737 char_u *end;
12738 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12739 {
12740 if (cp != end)
12741 EMSG(_(e_positive));
12742 else
12743 EMSG(_(e_invarg));
12744 return FALSE;
12745 }
12746 }
12747
12748 if (VIM_ISDIGIT(*cp))
12749 continue;
12750 if (*cp == ',' && cp > var && *(cp - 1) != ',')
12751 {
12752 ++valcount;
12753 continue;
12754 }
12755 EMSG(_(e_invarg));
12756 return FALSE;
12757 }
12758
12759 *array = (int *) alloc((unsigned) ((valcount + 1) * sizeof(int)));
12760 (*array)[0] = valcount;
12761
12762 t = 1;
12763 for (cp = var; *cp;)
12764 {
12765 (*array)[t++] = atoi((char *)cp);
12766 while (*cp && *cp != ',')
12767 ++cp;
12768 if (*cp)
12769 ++cp;
12770 }
12771
12772 return TRUE;
12773}
12774
12775/*
12776 * Calculate the number of screen spaces a tab will occupy.
12777 * If "vts" is set then the tab widths are taken from that array,
12778 * otherwise the value of ts is used.
12779 */
12780 int
12781tabstop_padding(colnr_T col, int ts_arg, int *vts)
12782{
12783 int ts = ts_arg == 0 ? 8 : ts_arg;
12784 int tabcount;
12785 colnr_T tabcol = 0;
12786 int t;
12787 int padding = 0;
12788
12789 if (vts == NULL || vts[0] == 0)
12790 return ts - (col % ts);
12791
12792 tabcount = vts[0];
12793
12794 for (t = 1; t <= tabcount; ++t)
12795 {
12796 tabcol += vts[t];
12797 if (tabcol > col)
12798 {
12799 padding = (int)(tabcol - col);
12800 break;
12801 }
12802 }
12803 if (t > tabcount)
12804 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12805
12806 return padding;
12807}
12808
12809/*
12810 * Find the size of the tab that covers a particular column.
12811 */
12812 int
12813tabstop_at(colnr_T col, int ts, int *vts)
12814{
12815 int tabcount;
12816 colnr_T tabcol = 0;
12817 int t;
12818 int tab_size = 0;
12819
12820 if (vts == 0 || vts[0] == 0)
12821 return ts;
12822
12823 tabcount = vts[0];
12824 for (t = 1; t <= tabcount; ++t)
12825 {
12826 tabcol += vts[t];
12827 if (tabcol > col)
12828 {
12829 tab_size = vts[t];
12830 break;
12831 }
12832 }
12833 if (t > tabcount)
12834 tab_size = vts[tabcount];
12835
12836 return tab_size;
12837}
12838
12839/*
12840 * Find the column on which a tab starts.
12841 */
12842 colnr_T
12843tabstop_start(colnr_T col, int ts, int *vts)
12844{
12845 int tabcount;
12846 colnr_T tabcol = 0;
12847 int t;
12848 int excess;
12849
Bram Moolenaar0119a592018-06-24 23:53:28 +020012850 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012851 return (col / ts) * ts;
12852
12853 tabcount = vts[0];
12854 for (t = 1; t <= tabcount; ++t)
12855 {
12856 tabcol += vts[t];
12857 if (tabcol > col)
12858 return tabcol - vts[t];
12859 }
12860
12861 excess = tabcol % vts[tabcount];
12862 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12863}
12864
12865/*
12866 * Find the number of tabs and spaces necessary to get from one column
12867 * to another.
12868 */
12869 void
12870tabstop_fromto(
12871 colnr_T start_col,
12872 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012873 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012874 int *vts,
12875 int *ntabs,
12876 int *nspcs)
12877{
12878 int spaces = end_col - start_col;
12879 colnr_T tabcol = 0;
12880 int padding = 0;
12881 int tabcount;
12882 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012883 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012884
Bram Moolenaar0119a592018-06-24 23:53:28 +020012885 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012886 {
12887 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012888 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012889
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012890 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012891 if (spaces >= initspc)
12892 {
12893 spaces -= initspc;
12894 tabs++;
12895 }
12896 tabs += spaces / ts;
12897 spaces -= (spaces / ts) * ts;
12898
12899 *ntabs = tabs;
12900 *nspcs = spaces;
12901 return;
12902 }
12903
12904 /* Find the padding needed to reach the next tabstop. */
12905 tabcount = vts[0];
12906 for (t = 1; t <= tabcount; ++t)
12907 {
12908 tabcol += vts[t];
12909 if (tabcol > start_col)
12910 {
12911 padding = (int)(tabcol - start_col);
12912 break;
12913 }
12914 }
12915 if (t > tabcount)
12916 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12917
12918 /* If the space needed is less than the padding no tabs can be used. */
12919 if (spaces < padding)
12920 {
12921 *ntabs = 0;
12922 *nspcs = spaces;
12923 return;
12924 }
12925
12926 *ntabs = 1;
12927 spaces -= padding;
12928
12929 /* At least one tab has been used. See if any more will fit. */
12930 while (spaces != 0 && ++t <= tabcount)
12931 {
12932 padding = vts[t];
12933 if (spaces < padding)
12934 {
12935 *nspcs = spaces;
12936 return;
12937 }
12938 ++*ntabs;
12939 spaces -= padding;
12940 }
12941
12942 *ntabs += spaces / vts[tabcount];
12943 *nspcs = spaces % vts[tabcount];
12944}
12945
12946/*
12947 * See if two tabstop arrays contain the same values.
12948 */
12949 int
12950tabstop_eq(int *ts1, int *ts2)
12951{
12952 int t;
12953
12954 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
12955 return FALSE;
12956 if (ts1 == ts2)
12957 return TRUE;
12958 if (ts1[0] != ts2[0])
12959 return FALSE;
12960
12961 for (t = 1; t <= ts1[0]; ++t)
12962 if (ts1[t] != ts2[t])
12963 return FALSE;
12964
12965 return TRUE;
12966}
12967
12968/*
12969 * Copy a tabstop array, allocating space for the new array.
12970 */
12971 int *
12972tabstop_copy(int *oldts)
12973{
12974 int *newts;
12975 int t;
12976
12977 if (oldts == 0)
12978 return 0;
12979
12980 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
12981 for (t = 0; t <= oldts[0]; ++t)
12982 newts[t] = oldts[t];
12983
12984 return newts;
12985}
12986
12987/*
12988 * Return a count of the number of tabstops.
12989 */
12990 int
12991tabstop_count(int *ts)
12992{
12993 return ts != NULL ? ts[0] : 0;
12994}
12995
12996/*
12997 * Return the first tabstop, or 8 if there are no tabstops defined.
12998 */
12999 int
13000tabstop_first(int *ts)
13001{
13002 return ts != NULL ? ts[1] : 8;
13003}
13004
13005#endif
13006
Bram Moolenaar14f24742012-08-08 18:01:05 +020013007/*
13008 * Return the effective shiftwidth value for current buffer, using the
13009 * 'tabstop' value when 'shiftwidth' is zero.
13010 */
13011 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013012get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013013{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013014 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020013015}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013016
13017/*
13018 * Return the effective softtabstop value for the current buffer, using the
13019 * 'tabstop' value when 'softtabstop' is negative.
13020 */
13021 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013022get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013023{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013024 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013025}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013026
13027/*
13028 * Check matchpairs option for "*initc".
13029 * If there is a match set "*initc" to the matching character and "*findc" to
13030 * the opposite character. Set "*backwards" to the direction.
13031 * When "switchit" is TRUE swap the direction.
13032 */
13033 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013034find_mps_values(
13035 int *initc,
13036 int *findc,
13037 int *backwards,
13038 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013039{
13040 char_u *ptr;
13041
13042 ptr = curbuf->b_p_mps;
13043 while (*ptr != NUL)
13044 {
13045#ifdef FEAT_MBYTE
13046 if (has_mbyte)
13047 {
13048 char_u *prev;
13049
13050 if (mb_ptr2char(ptr) == *initc)
13051 {
13052 if (switchit)
13053 {
13054 *findc = *initc;
13055 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13056 *backwards = TRUE;
13057 }
13058 else
13059 {
13060 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13061 *backwards = FALSE;
13062 }
13063 return;
13064 }
13065 prev = ptr;
13066 ptr += mb_ptr2len(ptr) + 1;
13067 if (mb_ptr2char(ptr) == *initc)
13068 {
13069 if (switchit)
13070 {
13071 *findc = *initc;
13072 *initc = mb_ptr2char(prev);
13073 *backwards = FALSE;
13074 }
13075 else
13076 {
13077 *findc = mb_ptr2char(prev);
13078 *backwards = TRUE;
13079 }
13080 return;
13081 }
13082 ptr += mb_ptr2len(ptr);
13083 }
13084 else
13085#endif
13086 {
13087 if (*ptr == *initc)
13088 {
13089 if (switchit)
13090 {
13091 *backwards = TRUE;
13092 *findc = *initc;
13093 *initc = ptr[2];
13094 }
13095 else
13096 {
13097 *backwards = FALSE;
13098 *findc = ptr[2];
13099 }
13100 return;
13101 }
13102 ptr += 2;
13103 if (*ptr == *initc)
13104 {
13105 if (switchit)
13106 {
13107 *backwards = FALSE;
13108 *findc = *initc;
13109 *initc = ptr[-2];
13110 }
13111 else
13112 {
13113 *backwards = TRUE;
13114 *findc = ptr[-2];
13115 }
13116 return;
13117 }
13118 ++ptr;
13119 }
13120 if (*ptr == ',')
13121 ++ptr;
13122 }
13123}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013124
13125#if defined(FEAT_LINEBREAK) || defined(PROTO)
13126/*
13127 * This is called when 'breakindentopt' is changed and when a window is
13128 * initialized.
13129 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013130 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013131briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013132{
13133 char_u *p;
13134 int bri_shift = 0;
13135 long bri_min = 20;
13136 int bri_sbr = FALSE;
13137
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013138 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013139 while (*p != NUL)
13140 {
13141 if (STRNCMP(p, "shift:", 6) == 0
13142 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13143 {
13144 p += 6;
13145 bri_shift = getdigits(&p);
13146 }
13147 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13148 {
13149 p += 4;
13150 bri_min = getdigits(&p);
13151 }
13152 else if (STRNCMP(p, "sbr", 3) == 0)
13153 {
13154 p += 3;
13155 bri_sbr = TRUE;
13156 }
13157 if (*p != ',' && *p != NUL)
13158 return FAIL;
13159 if (*p == ',')
13160 ++p;
13161 }
13162
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013163 wp->w_p_brishift = bri_shift;
13164 wp->w_p_brimin = bri_min;
13165 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013166
13167 return OK;
13168}
13169#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013170
13171/*
13172 * Get the local or global value of 'backupcopy'.
13173 */
13174 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013175get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013176{
13177 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13178}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013179
13180#if defined(FEAT_SIGNS) || defined(PROTO)
13181/*
13182 * Return TRUE when window "wp" has a column to draw signs in.
13183 */
13184 int
13185signcolumn_on(win_T *wp)
13186{
13187 if (*wp->w_p_scl == 'n')
13188 return FALSE;
13189 if (*wp->w_p_scl == 'y')
13190 return TRUE;
13191 return (wp->w_buffer->b_signlist != NULL
13192# ifdef FEAT_NETBEANS_INTG
13193 || wp->w_buffer->b_has_sign_column
13194# endif
13195 );
13196}
13197#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013198
13199#if defined(FEAT_EVAL) || defined(PROTO)
13200/*
13201 * Get window or buffer local options.
13202 */
13203 dict_T *
13204get_winbuf_options(int bufopt)
13205{
13206 dict_T *d;
13207 int opt_idx;
13208
13209 d = dict_alloc();
13210 if (d == NULL)
13211 return NULL;
13212
13213 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13214 {
13215 struct vimoption *opt = &options[opt_idx];
13216
13217 if ((bufopt && (opt->indir & PV_BUF))
13218 || (!bufopt && (opt->indir & PV_WIN)))
13219 {
13220 char_u *varp = get_varp(opt);
13221
13222 if (varp != NULL)
13223 {
13224 if (opt->flags & P_STRING)
13225 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013226 else if (opt->flags & P_NUM)
13227 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013228 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013229 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013230 }
13231 }
13232 }
13233
13234 return d;
13235}
13236#endif