blob: 2ecdcea649e9917a0cacdb9f3bc32304ff6c6a2f [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 Moolenaara23ccb82006-02-27 00:08:02 +0000185
186/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000187 * Definition of the PV_ values for window-local options.
188 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190#define PV_LIST OPT_WIN(WV_LIST)
191#ifdef FEAT_ARABIC
192# define PV_ARAB OPT_WIN(WV_ARAB)
193#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200194#ifdef FEAT_LINEBREAK
195# define PV_BRI OPT_WIN(WV_BRI)
196# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
197#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000198#ifdef FEAT_DIFF
199# define PV_DIFF OPT_WIN(WV_DIFF)
200#endif
201#ifdef FEAT_FOLDING
202# define PV_FDC OPT_WIN(WV_FDC)
203# define PV_FEN OPT_WIN(WV_FEN)
204# define PV_FDI OPT_WIN(WV_FDI)
205# define PV_FDL OPT_WIN(WV_FDL)
206# define PV_FDM OPT_WIN(WV_FDM)
207# define PV_FML OPT_WIN(WV_FML)
208# define PV_FDN OPT_WIN(WV_FDN)
209# ifdef FEAT_EVAL
210# define PV_FDE OPT_WIN(WV_FDE)
211# define PV_FDT OPT_WIN(WV_FDT)
212# endif
213# define PV_FMR OPT_WIN(WV_FMR)
214#endif
215#ifdef FEAT_LINEBREAK
216# define PV_LBR OPT_WIN(WV_LBR)
217#endif
218#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200219#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000220#ifdef FEAT_LINEBREAK
221# define PV_NUW OPT_WIN(WV_NUW)
222#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200223#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000224# define PV_PVW OPT_WIN(WV_PVW)
225#endif
226#ifdef FEAT_RIGHTLEFT
227# define PV_RL OPT_WIN(WV_RL)
228# define PV_RLC OPT_WIN(WV_RLC)
229#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100230#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000245# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100247#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200248#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200249# define PV_COCU OPT_WIN(WV_COCU)
250# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200252#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200253# define PV_TWK OPT_WIN(WV_TWK)
254# define PV_TWS OPT_WIN(WV_TWS)
255# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200256#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200257#ifdef FEAT_SIGNS
258# define PV_SCL OPT_WIN(WV_SCL)
259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
280#ifdef FEAT_MBYTE
281static int p_bomb;
282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283static char_u *p_bh;
284static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285static int p_bl;
286static int p_ci;
287#ifdef FEAT_CINDENT
288static int p_cin;
289static char_u *p_cink;
290static char_u *p_cino;
291#endif
292#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
293static char_u *p_cinw;
294#endif
295#ifdef FEAT_COMMENTS
296static char_u *p_com;
297#endif
298#ifdef FEAT_FOLDING
299static char_u *p_cms;
300#endif
301#ifdef FEAT_INS_EXPAND
302static char_u *p_cpt;
303#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000304#ifdef FEAT_COMPL_FUNC
305static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000306static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200309static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_et;
311#ifdef FEAT_MBYTE
312static char_u *p_fenc;
313#endif
314static char_u *p_ff;
315static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000316static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static long p_sts;
353#if defined(FEAT_SEARCHPATH)
354static char_u *p_sua;
355#endif
356static long p_sw;
357static int p_swf;
358#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000359static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000361#endif
362#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000363static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000364static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000365static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366#endif
367static long p_ts;
368static long p_tw;
369static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200370#ifdef FEAT_PERSISTENT_UNDO
371static int p_udf;
372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373static long p_wm;
374#ifdef FEAT_KEYMAP
375static char_u *p_keymap;
376#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200377#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200378static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200388static int p_ai_nopaste;
389static int p_et_nopaste;
390static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391static long p_tw_nopaste;
392static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393
394struct vimoption
395{
396 char *fullname; /* full option name */
397 char *shortname; /* permissible abbreviation */
398 long_u flags; /* see below */
399 char_u *var; /* global option: pointer to variable;
400 * window-local option: VAR_WIN;
401 * buffer-local option: global value */
402 idopt_T indir; /* global option: PV_NONE;
403 * local option: indirect option index */
404 char_u *def_val[2]; /* default values for variable (vi and vim) */
405#ifdef FEAT_EVAL
406 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000407# define SCRIPTID_INIT , 0
408#else
409# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410#endif
411};
412
413#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
414#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
415
416/*
417 * Flags
418 */
419#define P_BOOL 0x01 /* the option is boolean */
420#define P_NUM 0x02 /* the option is numeric */
421#define P_STRING 0x04 /* the option is a string */
422#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000423 must use free_string_option() when
424 assigning new value. Not set if default is
425 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
427 never be used for local or hidden options! */
428#define P_NODEFAULT 0x40 /* don't set to default value */
429#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
430 use vim_free() when assigning new value */
431#define P_WAS_SET 0x100 /* option has been set/reset */
432#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
433#define P_VI_DEF 0x400 /* Use Vi default for Vim */
434#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
435
436 /* when option changed, what to display: */
437#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100438#define P_RWIN 0x2000 /* redraw current window and recompute text */
439#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440#define P_RALL 0x6000 /* redraw all windows */
441#define P_RCLR 0x7000 /* clear and redraw all */
442
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200443#define P_COMMA 0x8000 /* comma separated list */
444#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
445 * commas */
446#define P_NODUP 0x20000L /* don't allow duplicate strings */
447#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
450#define P_GETTEXT 0x100000L /* expand default value with _() */
451#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
452#define P_NFNAME 0x400000L /* only normal file name chars allowed */
453#define P_INSECURE 0x800000L /* option was set from a modeline */
454#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100455 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200456#define P_NO_ML 0x2000000L /* not allowed in modeline */
457#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200458 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100460#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000461
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000462#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
463
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000464/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
465 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100466#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000467# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000468#else
469# define ISP_LATIN1 (char_u *)"@,161-255"
470#endif
471
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200472# 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 +0000473
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100474/* Default python version for pyx* commands */
475#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
476# define DEFAULT_PYTHON_VER 0
477#elif defined(FEAT_PYTHON3)
478# define DEFAULT_PYTHON_VER 3
479#elif defined(FEAT_PYTHON)
480# define DEFAULT_PYTHON_VER 2
481#else
482# define DEFAULT_PYTHON_VER 0
483#endif
484
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485/*
486 * options[] is initialized here.
487 * The order of the options MUST be alphabetic for ":set all" and findoption().
488 * All option names MUST start with a lowercase letter (for findoption()).
489 * Exception: "t_" options are at the end.
490 * The options with a NULL variable are 'hidden': a set command for them is
491 * ignored and they are not printed.
492 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100493static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200495 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496#ifdef FEAT_RIGHTLEFT
497 (char_u *)&p_aleph, PV_NONE,
498#else
499 (char_u *)NULL, PV_NONE,
500#endif
501 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100502#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 (char_u *)128L,
504#else
505 (char_u *)224L,
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200509#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 (char_u *)&p_antialias, PV_NONE,
511 {(char_u *)FALSE, (char_u *)FALSE}
512#else
513 (char_u *)NULL, PV_NONE,
514 {(char_u *)FALSE, (char_u *)FALSE}
515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000516 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200517 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518#ifdef FEAT_ARABIC
519 (char_u *)VAR_WIN, PV_ARAB,
520#else
521 (char_u *)NULL, PV_NONE,
522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
525#ifdef FEAT_ARABIC
526 (char_u *)&p_arshape, PV_NONE,
527#else
528 (char_u *)NULL, PV_NONE,
529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000530 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
532#ifdef FEAT_RIGHTLEFT
533 (char_u *)&p_ari, PV_NONE,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
539#ifdef FEAT_FKMAP
540 (char_u *)&p_altkeymap, PV_NONE,
541#else
542 (char_u *)NULL, PV_NONE,
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
546#if defined(FEAT_MBYTE)
547 (char_u *)&p_ambw, PV_NONE,
548 {(char_u *)"single", (char_u *)0L}
549#else
550 (char_u *)NULL, PV_NONE,
551 {(char_u *)0L, (char_u *)0L}
552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100555#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100557 {(char_u *)FALSE, (char_u *)0L}
558#else
559 (char_u *)NULL, PV_NONE,
560 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100562 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autoindent", "ai", P_BOOL|P_VI_DEF,
564 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autoprint", "ap", P_BOOL|P_VI_DEF,
567 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000570 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"autowrite", "aw", P_BOOL|P_VI_DEF,
573 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000574 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"autowriteall","awa", P_BOOL|P_VI_DEF,
576 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
579 (char_u *)&p_bg, PV_NONE,
580 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100581#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 (char_u *)"dark",
583#else
584 (char_u *)"light",
585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200587 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
591 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200593 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200594 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000595#ifdef UNIX
596 {(char_u *)"yes", (char_u *)"auto"}
597#else
598 {(char_u *)"auto", (char_u *)"auto"}
599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200601 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
602 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000605 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606 (char_u *)&p_bex, PV_NONE,
607 {
608#ifdef VMS
609 (char_u *)"_",
610#else
611 (char_u *)"~",
612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200614 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615#ifdef FEAT_WILDIGN
616 (char_u *)&p_bsk, PV_NONE,
617 {(char_u *)"", (char_u *)0L}
618#else
619 (char_u *)NULL, PV_NONE,
620 {(char_u *)0L, (char_u *)0L}
621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000622 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100624#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100626 {(char_u *)600L, (char_u *)0L}
627#else
628 (char_u *)NULL, PV_NONE,
629 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100631 SCRIPTID_INIT},
632 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100633#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100634 (char_u *)&p_beval, PV_NONE,
635 {(char_u *)FALSE, (char_u *)0L}
636#else
637 (char_u *)NULL, PV_NONE,
638 {(char_u *)0L, (char_u *)0L}
639#endif
640 SCRIPTID_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100641 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100642#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100643 (char_u *)&p_bevalterm, PV_NONE,
644 {(char_u *)FALSE, (char_u *)0L}
645#else
646 (char_u *)NULL, PV_NONE,
647 {(char_u *)0L, (char_u *)0L}
648#endif
649 SCRIPTID_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100650 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
651#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
652 (char_u *)&p_bexpr, PV_BEXPR,
653 {(char_u *)"", (char_u *)0L}
654#else
655 (char_u *)NULL, PV_NONE,
656 {(char_u *)0L, (char_u *)0L}
657#endif
658 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659 {"beautify", "bf", P_BOOL|P_VI_DEF,
660 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000661 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200662 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
663 (char_u *)&p_bo, PV_NONE,
664 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
666 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000670 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
672#ifdef FEAT_MBYTE
673 (char_u *)&p_bomb, PV_BOMB,
674#else
675 (char_u *)NULL, PV_NONE,
676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000677 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
679#ifdef FEAT_LINEBREAK
680 (char_u *)&p_breakat, PV_NONE,
681 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)0L, (char_u *)0L}
685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000686 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200687 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
688#ifdef FEAT_LINEBREAK
689 (char_u *)VAR_WIN, PV_BRI,
690 {(char_u *)FALSE, (char_u *)0L}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
695 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200696 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
697 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200698#ifdef FEAT_LINEBREAK
699 (char_u *)VAR_WIN, PV_BRIOPT,
700 {(char_u *)"", (char_u *)NULL}
701#else
702 (char_u *)NULL, PV_NONE,
703 {(char_u *)"", (char_u *)NULL}
704#endif
705 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
707#ifdef FEAT_BROWSE
708 (char_u *)&p_bsdir, PV_NONE,
709 {(char_u *)"last", (char_u *)0L}
710#else
711 (char_u *)NULL, PV_NONE,
712 {(char_u *)0L, (char_u *)0L}
713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000714 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 (char_u *)&p_bh, PV_BH,
717 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
720 (char_u *)&p_bl, PV_BL,
721 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 (char_u *)&p_bt, PV_BT,
725 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200727 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000728#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 (char_u *)&p_cmp, PV_NONE,
730 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000731#else
732 (char_u *)NULL, PV_NONE,
733 {(char_u *)0L, (char_u *)0L}
734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
737#ifdef FEAT_SEARCHPATH
738 (char_u *)&p_cdpath, PV_NONE,
739 {(char_u *)",,", (char_u *)0L}
740#else
741 (char_u *)NULL, PV_NONE,
742 {(char_u *)0L, (char_u *)0L}
743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000744 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745 {"cedit", NULL, P_STRING,
746#ifdef FEAT_CMDWIN
747 (char_u *)&p_cedit, PV_NONE,
748 {(char_u *)"", (char_u *)CTRL_F_STR}
749#else
750 (char_u *)NULL, PV_NONE,
751 {(char_u *)0L, (char_u *)0L}
752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
755#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
756 (char_u *)&p_ccv, PV_NONE,
757 {(char_u *)"", (char_u *)0L}
758#else
759 (char_u *)NULL, PV_NONE,
760 {(char_u *)0L, (char_u *)0L}
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
764#ifdef FEAT_CINDENT
765 (char_u *)&p_cin, PV_CIN,
766#else
767 (char_u *)NULL, PV_NONE,
768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200770 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#ifdef FEAT_CINDENT
772 (char_u *)&p_cink, PV_CINK,
773 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
774#else
775 (char_u *)NULL, PV_NONE,
776 {(char_u *)0L, (char_u *)0L}
777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000778 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200779 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780#ifdef FEAT_CINDENT
781 (char_u *)&p_cino, PV_CINO,
782#else
783 (char_u *)NULL, PV_NONE,
784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000785 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200786 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
788 (char_u *)&p_cinw, PV_CINW,
789 {(char_u *)"if,else,while,do,for,switch",
790 (char_u *)0L}
791#else
792 (char_u *)NULL, PV_NONE,
793 {(char_u *)0L, (char_u *)0L}
794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000795 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200796 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797#ifdef FEAT_CLIPBOARD
798 (char_u *)&p_cb, PV_NONE,
799# ifdef FEAT_XCLIPBOARD
800 {(char_u *)"autoselect,exclude:cons\\|linux",
801 (char_u *)0L}
802# else
803 {(char_u *)"", (char_u *)0L}
804# endif
805#else
806 (char_u *)NULL, PV_NONE,
807 {(char_u *)"", (char_u *)0L}
808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000809 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
811 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000812 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000813 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
814#ifdef FEAT_CMDWIN
815 (char_u *)&p_cwh, PV_NONE,
816#else
817 (char_u *)NULL, PV_NONE,
818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000819 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200820 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200821#ifdef FEAT_SYN_HL
822 (char_u *)VAR_WIN, PV_CC,
823#else
824 (char_u *)NULL, PV_NONE,
825#endif
826 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
828 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200830 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
831 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832#ifdef FEAT_COMMENTS
833 (char_u *)&p_com, PV_COM,
834 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
835 (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000840 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200841 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842#ifdef FEAT_FOLDING
843 (char_u *)&p_cms, PV_CMS,
844 {(char_u *)"/*%s*/", (char_u *)0L}
845#else
846 (char_u *)NULL, PV_NONE,
847 {(char_u *)0L, (char_u *)0L}
848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000849 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000850 /* P_PRI_MKRC isn't needed here, optval_default()
851 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852 {"compatible", "cp", P_BOOL|P_RALL,
853 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000854 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200855 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856#ifdef FEAT_INS_EXPAND
857 (char_u *)&p_cpt, PV_CPT,
858 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
859#else
860 (char_u *)NULL, PV_NONE,
861 {(char_u *)0L, (char_u *)0L}
862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000863 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200864 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200865#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200866 (char_u *)VAR_WIN, PV_COCU,
867 {(char_u *)"", (char_u *)NULL}
868#else
869 (char_u *)NULL, PV_NONE,
870 {(char_u *)NULL, (char_u *)0L}
871#endif
872 SCRIPTID_INIT},
873 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
874#ifdef FEAT_CONCEAL
875 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200876#else
877 (char_u *)NULL, PV_NONE,
878#endif
879 {(char_u *)0L, (char_u *)0L}
880 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000881 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
882#ifdef FEAT_COMPL_FUNC
883 (char_u *)&p_cfu, PV_CFU,
884 {(char_u *)"", (char_u *)0L}
885#else
886 (char_u *)NULL, PV_NONE,
887 {(char_u *)0L, (char_u *)0L}
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200890 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000891#ifdef FEAT_INS_EXPAND
892 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000893 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000894#else
895 (char_u *)NULL, PV_NONE,
896 {(char_u *)0L, (char_u *)0L}
897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"confirm", "cf", P_BOOL|P_VI_DEF,
900#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
901 (char_u *)&p_confirm, PV_NONE,
902#else
903 (char_u *)NULL, PV_NONE,
904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000908 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
910 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
913 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
915 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200916 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200917#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200918 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200919 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200920#else
921 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200922 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200923#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
926#ifdef FEAT_CSCOPE
927 (char_u *)&p_cspc, PV_NONE,
928#else
929 (char_u *)NULL, PV_NONE,
930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000931 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000932 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
933#ifdef FEAT_CSCOPE
934 (char_u *)&p_csprg, PV_NONE,
935 {(char_u *)"cscope", (char_u *)0L}
936#else
937 (char_u *)NULL, PV_NONE,
938 {(char_u *)0L, (char_u *)0L}
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200941 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
943 (char_u *)&p_csqf, PV_NONE,
944 {(char_u *)"", (char_u *)0L}
945#else
946 (char_u *)NULL, PV_NONE,
947 {(char_u *)0L, (char_u *)0L}
948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000949 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200950 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
951#ifdef FEAT_CSCOPE
952 (char_u *)&p_csre, PV_NONE,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
956 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
958#ifdef FEAT_CSCOPE
959 (char_u *)&p_cst, PV_NONE,
960#else
961 (char_u *)NULL, PV_NONE,
962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
965#ifdef FEAT_CSCOPE
966 (char_u *)&p_csto, PV_NONE,
967#else
968 (char_u *)NULL, PV_NONE,
969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000970 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000971 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
972#ifdef FEAT_CSCOPE
973 (char_u *)&p_csverbose, PV_NONE,
974#else
975 (char_u *)NULL, PV_NONE,
976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000977 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200978 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200979 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000981 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
982#ifdef FEAT_SYN_HL
983 (char_u *)VAR_WIN, PV_CUC,
984#else
985 (char_u *)NULL, PV_NONE,
986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100988 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000989#ifdef FEAT_SYN_HL
990 (char_u *)VAR_WIN, PV_CUL,
991#else
992 (char_u *)NULL, PV_NONE,
993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995 {"debug", NULL, P_STRING|P_VI_DEF,
996 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200998 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001000 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001001 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002#else
1003 (char_u *)NULL, PV_NONE,
1004 {(char_u *)NULL, (char_u *)0L}
1005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1008#ifdef FEAT_MBYTE
1009 (char_u *)&p_deco, PV_NONE,
1010#else
1011 (char_u *)NULL, PV_NONE,
1012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001014 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001016 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#else
1018 (char_u *)NULL, PV_NONE,
1019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1022#ifdef FEAT_DIFF
1023 (char_u *)VAR_WIN, PV_DIFF,
1024#else
1025 (char_u *)NULL, PV_NONE,
1026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001028 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1030 (char_u *)&p_dex, PV_NONE,
1031 {(char_u *)"", (char_u *)0L}
1032#else
1033 (char_u *)NULL, PV_NONE,
1034 {(char_u *)0L, (char_u *)0L}
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001037 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1038 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039#ifdef FEAT_DIFF
1040 (char_u *)&p_dip, PV_NONE,
1041 {(char_u *)"filler", (char_u *)NULL}
1042#else
1043 (char_u *)NULL, PV_NONE,
1044 {(char_u *)"", (char_u *)NULL}
1045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1048#ifdef FEAT_DIGRAPHS
1049 (char_u *)&p_dg, PV_NONE,
1050#else
1051 (char_u *)NULL, PV_NONE,
1052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001054 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1055 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001058 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001060 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 (char_u *)&p_ead, PV_NONE,
1063 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1066 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001068 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1069#if defined(FEAT_MBYTE)
1070 (char_u *)&p_emoji, PV_NONE,
1071 {(char_u *)TRUE, (char_u *)0L}
1072#else
1073 (char_u *)NULL, PV_NONE,
1074 {(char_u *)0L, (char_u *)0L}
1075#endif
1076 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001077 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078#ifdef FEAT_MBYTE
1079 (char_u *)&p_enc, PV_NONE,
1080 {(char_u *)ENC_DFLT, (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)0L, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1087 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1090 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001091 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001093 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1096 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1099#ifdef FEAT_QUICKFIX
1100 (char_u *)&p_ef, PV_NONE,
1101 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)NULL, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001107 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001109 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111#else
1112 (char_u *)NULL, PV_NONE,
1113 {(char_u *)NULL, (char_u *)0L}
1114#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"esckeys", "ek", P_BOOL|P_VIM,
1117 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 (char_u *)&p_ei, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1123 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1126 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1129 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130#ifdef FEAT_MBYTE
1131 (char_u *)&p_fenc, PV_FENC,
1132 {(char_u *)"", (char_u *)0L}
1133#else
1134 (char_u *)NULL, PV_NONE,
1135 {(char_u *)0L, (char_u *)0L}
1136#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001137 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001138 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139#ifdef FEAT_MBYTE
1140 (char_u *)&p_fencs, PV_NONE,
1141 {(char_u *)"ucs-bom", (char_u *)0L}
1142#else
1143 (char_u *)NULL, PV_NONE,
1144 {(char_u *)0L, (char_u *)0L}
1145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1148 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001151 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1154 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001155 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1156 (char_u *)&p_fic, PV_NONE,
1157 {
1158#ifdef CASE_INSENSITIVE_FILENAME
1159 (char_u *)TRUE,
1160#else
1161 (char_u *)FALSE,
1162#endif
1163 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001164 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 (char_u *)&p_ft, PV_FT,
1166 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001168 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 (char_u *)&p_fcs, PV_NONE,
1170 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001172 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1173 (char_u *)&p_fixeol, PV_FIXEOL,
1174 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001175 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1176#ifdef FEAT_FKMAP
1177 (char_u *)&p_fkmap, PV_NONE,
1178#else
1179 (char_u *)NULL, PV_NONE,
1180#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"flash", "fl", P_BOOL|P_VI_DEF,
1183 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001185 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001186#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001188 {(char_u *)"", (char_u *)0L}
1189#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 (char_u *)NULL, PV_NONE,
1191 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001192#endif
1193 SCRIPTID_INIT},
1194 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1195#ifdef FEAT_FOLDING
1196 (char_u *)VAR_WIN, PV_FDC,
1197 {(char_u *)FALSE, (char_u *)0L}
1198#else
1199 (char_u *)NULL, PV_NONE,
1200 {(char_u *)NULL, (char_u *)0L}
1201#endif
1202 SCRIPTID_INIT},
1203 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1204#ifdef FEAT_FOLDING
1205 (char_u *)VAR_WIN, PV_FEN,
1206 {(char_u *)TRUE, (char_u *)0L}
1207#else
1208 (char_u *)NULL, PV_NONE,
1209 {(char_u *)NULL, (char_u *)0L}
1210#endif
1211 SCRIPTID_INIT},
1212 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1213#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1214 (char_u *)VAR_WIN, PV_FDE,
1215 {(char_u *)"0", (char_u *)NULL}
1216#else
1217 (char_u *)NULL, PV_NONE,
1218 {(char_u *)NULL, (char_u *)0L}
1219#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001222#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001224 {(char_u *)"#", (char_u *)NULL}
1225#else
1226 (char_u *)NULL, PV_NONE,
1227 {(char_u *)NULL, (char_u *)0L}
1228#endif
1229 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001230 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001231#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001233 {(char_u *)0L, (char_u *)0L}
1234#else
1235 (char_u *)NULL, PV_NONE,
1236 {(char_u *)NULL, (char_u *)0L}
1237#endif
1238 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001239 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001240#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001242 {(char_u *)-1L, (char_u *)0L}
1243#else
1244 (char_u *)NULL, PV_NONE,
1245 {(char_u *)NULL, (char_u *)0L}
1246#endif
1247 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001248 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001249 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001250#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254 (char_u *)NULL, PV_NONE,
1255 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257 SCRIPTID_INIT},
1258 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1259#ifdef FEAT_FOLDING
1260 (char_u *)VAR_WIN, PV_FDM,
1261 {(char_u *)"manual", (char_u *)NULL}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)NULL, (char_u *)0L}
1265#endif
1266 SCRIPTID_INIT},
1267 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1268#ifdef FEAT_FOLDING
1269 (char_u *)VAR_WIN, PV_FML,
1270 {(char_u *)1L, (char_u *)0L}
1271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)NULL, (char_u *)0L}
1274#endif
1275 SCRIPTID_INIT},
1276 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1277#ifdef FEAT_FOLDING
1278 (char_u *)VAR_WIN, PV_FDN,
1279 {(char_u *)20L, (char_u *)0L}
1280#else
1281 (char_u *)NULL, PV_NONE,
1282 {(char_u *)NULL, (char_u *)0L}
1283#endif
1284 SCRIPTID_INIT},
1285 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1286#ifdef FEAT_FOLDING
1287 (char_u *)&p_fdo, PV_NONE,
1288 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1289 (char_u *)0L}
1290#else
1291 (char_u *)NULL, PV_NONE,
1292 {(char_u *)NULL, (char_u *)0L}
1293#endif
1294 SCRIPTID_INIT},
1295 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1296#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1297 (char_u *)VAR_WIN, PV_FDT,
1298 {(char_u *)"foldtext()", (char_u *)NULL}
1299#else
1300 (char_u *)NULL, PV_NONE,
1301 {(char_u *)NULL, (char_u *)0L}
1302#endif
1303 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001304 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001305#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001306 (char_u *)&p_fex, PV_FEX,
1307 {(char_u *)"", (char_u *)0L}
1308#else
1309 (char_u *)NULL, PV_NONE,
1310 {(char_u *)0L, (char_u *)0L}
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1314 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001315 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1316 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001317 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1318 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1320 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001322 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001323 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001324 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1325#ifdef HAVE_FSYNC
1326 (char_u *)&p_fs, PV_NONE,
1327 {(char_u *)TRUE, (char_u *)0L}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)FALSE, (char_u *)0L}
1331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1334 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336 {"graphic", "gr", P_BOOL|P_VI_DEF,
1337 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001338 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001339 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340#ifdef FEAT_QUICKFIX
1341 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001342 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343#else
1344 (char_u *)NULL, PV_NONE,
1345 {(char_u *)NULL, (char_u *)0L}
1346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1349#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001350 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351 {
1352# ifdef WIN3264
1353 /* may be changed to "grep -n" in os_win32.c */
1354 (char_u *)"findstr /n",
1355# else
1356# ifdef UNIX
1357 /* Add an extra file name so that grep will always
1358 * insert a file name in the match line. */
1359 (char_u *)"grep -n $* /dev/null",
1360# else
1361# ifdef VMS
1362 (char_u *)"SEARCH/NUMBERS ",
1363# else
1364 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001365# endif
1366# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001368 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369#else
1370 (char_u *)NULL, PV_NONE,
1371 {(char_u *)NULL, (char_u *)0L}
1372#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001374 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375#ifdef CURSOR_SHAPE
1376 (char_u *)&p_guicursor, PV_NONE,
1377 {
1378# ifdef FEAT_GUI
1379 (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 +01001380# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1382# endif
1383 (char_u *)0L}
1384#else
1385 (char_u *)NULL, PV_NONE,
1386 {(char_u *)NULL, (char_u *)0L}
1387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001389 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390#ifdef FEAT_GUI
1391 (char_u *)&p_guifont, PV_NONE,
1392 {(char_u *)"", (char_u *)0L}
1393#else
1394 (char_u *)NULL, PV_NONE,
1395 {(char_u *)NULL, (char_u *)0L}
1396#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001398 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1400 (char_u *)&p_guifontset, PV_NONE,
1401 {(char_u *)"", (char_u *)0L}
1402#else
1403 (char_u *)NULL, PV_NONE,
1404 {(char_u *)NULL, (char_u *)0L}
1405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001407 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1409 (char_u *)&p_guifontwide, PV_NONE,
1410 {(char_u *)"", (char_u *)0L}
1411#else
1412 (char_u *)NULL, PV_NONE,
1413 {(char_u *)NULL, (char_u *)0L}
1414#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001415 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001417#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 (char_u *)&p_ghr, PV_NONE,
1419#else
1420 (char_u *)NULL, PV_NONE,
1421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001422 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001424#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001426# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001427 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001429 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430# endif
1431#else
1432 (char_u *)NULL, PV_NONE,
1433 {(char_u *)NULL, (char_u *)0L}
1434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"guipty", NULL, P_BOOL|P_VI_DEF,
1437#if defined(FEAT_GUI)
1438 (char_u *)&p_guipty, PV_NONE,
1439#else
1440 (char_u *)NULL, PV_NONE,
1441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001442 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001443 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001444#if defined(FEAT_GUI_TABLINE)
1445 (char_u *)&p_gtl, PV_NONE,
1446 {(char_u *)"", (char_u *)0L}
1447#else
1448 (char_u *)NULL, PV_NONE,
1449 {(char_u *)NULL, (char_u *)0L}
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001452 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001453#if defined(FEAT_GUI_TABLINE)
1454 (char_u *)&p_gtt, PV_NONE,
1455 {(char_u *)"", (char_u *)0L}
1456#else
1457 (char_u *)NULL, PV_NONE,
1458 {(char_u *)NULL, (char_u *)0L}
1459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1462 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001463 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1465 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001466 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1467 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001471 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472#ifdef FEAT_MULTI_LANG
1473 (char_u *)&p_hlg, PV_NONE,
1474 {(char_u *)"", (char_u *)0L}
1475#else
1476 (char_u *)NULL, PV_NONE,
1477 {(char_u *)0L, (char_u *)0L}
1478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001479 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 {"hidden", "hid", P_BOOL|P_VI_DEF,
1481 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001482 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001483 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001485 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"history", "hi", P_NUM|P_VIM,
1488 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001489 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1491#ifdef FEAT_RIGHTLEFT
1492 (char_u *)&p_hkmap, PV_NONE,
1493#else
1494 (char_u *)NULL, PV_NONE,
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1498#ifdef FEAT_RIGHTLEFT
1499 (char_u *)&p_hkmapp, PV_NONE,
1500#else
1501 (char_u *)NULL, PV_NONE,
1502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1505 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"icon", NULL, P_BOOL|P_VI_DEF,
1508#ifdef FEAT_TITLE
1509 (char_u *)&p_icon, PV_NONE,
1510#else
1511 (char_u *)NULL, PV_NONE,
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"iconstring", NULL, P_STRING|P_VI_DEF,
1515#ifdef FEAT_TITLE
1516 (char_u *)&p_iconstring, PV_NONE,
1517#else
1518 (char_u *)NULL, PV_NONE,
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1522 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001524 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001525#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001526 (char_u *)&p_imaf, PV_NONE,
1527 {(char_u *)"", (char_u *)NULL}
1528# else
1529 (char_u *)NULL, PV_NONE,
1530 {(char_u *)NULL, (char_u *)0L}
1531# endif
1532 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001534#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001535 (char_u *)&p_imak, PV_NONE,
1536#else
1537 (char_u *)NULL, PV_NONE,
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001541#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 (char_u *)&p_imcmdline, PV_NONE,
1543#else
1544 (char_u *)NULL, PV_NONE,
1545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001548#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 (char_u *)&p_imdisable, PV_NONE,
1550#else
1551 (char_u *)NULL, PV_NONE,
1552#endif
1553#ifdef __sgi
1554 {(char_u *)TRUE, (char_u *)0L}
1555#else
1556 {(char_u *)FALSE, (char_u *)0L}
1557#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559 {"iminsert", "imi", P_NUM|P_VI_DEF,
1560 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563 {"imsearch", "ims", P_NUM|P_VI_DEF,
1564 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001565 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001567 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001568#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001569 (char_u *)&p_imsf, PV_NONE,
1570 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001571#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001572 (char_u *)NULL, PV_NONE,
1573 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001574#endif
1575 SCRIPTID_INIT},
1576 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1577#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1578 (char_u *)&p_imst, PV_NONE,
1579 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1580#else
1581 (char_u *)NULL, PV_NONE,
1582 {(char_u *)0L, (char_u *)0L}
1583#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001584 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1586#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001587 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1589#else
1590 (char_u *)NULL, PV_NONE,
1591 {(char_u *)0L, (char_u *)0L}
1592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001593 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1595#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1596 (char_u *)&p_inex, PV_INEX,
1597 {(char_u *)"", (char_u *)0L}
1598#else
1599 (char_u *)NULL, PV_NONE,
1600 {(char_u *)0L, (char_u *)0L}
1601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001602 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1604 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001605 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1607#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1608 (char_u *)&p_inde, PV_INDE,
1609 {(char_u *)"", (char_u *)0L}
1610#else
1611 (char_u *)NULL, PV_NONE,
1612 {(char_u *)0L, (char_u *)0L}
1613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001614 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001615 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1617 (char_u *)&p_indk, PV_INDK,
1618 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1619#else
1620 (char_u *)NULL, PV_NONE,
1621 {(char_u *)0L, (char_u *)0L}
1622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001623 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624 {"infercase", "inf", P_BOOL|P_VI_DEF,
1625 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001626 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1628 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001629 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1631 (char_u *)&p_isf, PV_NONE,
1632 {
1633#ifdef BACKSLASH_IN_FILENAME
1634 /* Excluded are: & and ^ are special in cmd.exe
1635 * ( and ) are used in text separating fnames */
1636 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1637#else
1638# ifdef AMIGA
1639 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1640# else
1641# ifdef VMS
1642 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1643# else /* UNIX et al. */
1644# ifdef EBCDIC
1645 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1646# else
1647 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1648# endif
1649# endif
1650# endif
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1654 (char_u *)&p_isi, PV_NONE,
1655 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001656#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 (char_u *)"@,48-57,_,128-167,224-235",
1658#else
1659# ifdef EBCDIC
1660 /* TODO: EBCDIC Check this! @ == isalpha()*/
1661 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1662 "112-120,128,140-142,156,158,172,"
1663 "174,186,191,203-207,219-225,235-239,"
1664 "251-254",
1665# else
1666 (char_u *)"@,48-57,_,192-255",
1667# endif
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1671 (char_u *)&p_isk, PV_ISK,
1672 {
1673#ifdef EBCDIC
1674 (char_u *)"@,240-249,_",
1675 /* TODO: EBCDIC Check this! @ == isalpha()*/
1676 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1677 "112-120,128,140-142,156,158,172,"
1678 "174,186,191,203-207,219-225,235-239,"
1679 "251-254",
1680#else
1681 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001682# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683 (char_u *)"@,48-57,_,128-167,224-235"
1684# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001685 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686# endif
1687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001688 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1690 (char_u *)&p_isp, PV_NONE,
1691 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001692#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 (char_u *)"@,~-255",
1694#else
1695# ifdef EBCDIC
1696 /* all chars above 63 are printable */
1697 (char_u *)"63-255",
1698# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001699 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700# endif
1701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001702 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1704 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1707#ifdef FEAT_CRYPT
1708 (char_u *)&p_key, PV_KEY,
1709 {(char_u *)"", (char_u *)0L}
1710#else
1711 (char_u *)NULL, PV_NONE,
1712 {(char_u *)0L, (char_u *)0L}
1713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001715 {"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 +00001716#ifdef FEAT_KEYMAP
1717 (char_u *)&p_keymap, PV_KMAP,
1718 {(char_u *)"", (char_u *)0L}
1719#else
1720 (char_u *)NULL, PV_NONE,
1721 {(char_u *)"", (char_u *)0L}
1722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001723 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001724 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001728 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001730#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 (char_u *)":help",
1732#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001733# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001735# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001736# ifdef USEMAN_S
1737 (char_u *)"man -s",
1738# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001740# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741# endif
1742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001744 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745#ifdef FEAT_LANGMAP
1746 (char_u *)&p_langmap, PV_NONE,
1747 {(char_u *)"", /* unmatched } */
1748#else
1749 (char_u *)NULL, PV_NONE,
1750 {(char_u *)NULL,
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001753 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1755 (char_u *)&p_lm, PV_NONE,
1756#else
1757 (char_u *)NULL, PV_NONE,
1758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001760 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1761#ifdef FEAT_LANGMAP
1762 (char_u *)&p_lnr, PV_NONE,
1763#else
1764 (char_u *)NULL, PV_NONE,
1765#endif
1766 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001767 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1768#ifdef FEAT_LANGMAP
1769 (char_u *)&p_lrm, PV_NONE,
1770#else
1771 (char_u *)NULL, PV_NONE,
1772#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001773 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1778 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001779 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1781#ifdef FEAT_LINEBREAK
1782 (char_u *)VAR_WIN, PV_LBR,
1783#else
1784 (char_u *)NULL, PV_NONE,
1785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001786 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1788 (char_u *)&Rows, PV_NONE,
1789 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001790#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 (char_u *)25L,
1792#else
1793 (char_u *)24L,
1794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1797#ifdef FEAT_GUI
1798 (char_u *)&p_linespace, PV_NONE,
1799#else
1800 (char_u *)NULL, PV_NONE,
1801#endif
1802#ifdef FEAT_GUI_W32
1803 {(char_u *)1L, (char_u *)0L}
1804#else
1805 {(char_u *)0L, (char_u *)0L}
1806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"lisp", NULL, P_BOOL|P_VI_DEF,
1809#ifdef FEAT_LISP
1810 (char_u *)&p_lisp, PV_LISP,
1811#else
1812 (char_u *)NULL, PV_NONE,
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001815 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001817 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1819#else
1820 (char_u *)NULL, PV_NONE,
1821 {(char_u *)"", (char_u *)0L}
1822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1825 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001826 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001827 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001829 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1831 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001833 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001834#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001835 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001836 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001837#else
1838 (char_u *)NULL, PV_NONE,
1839 {(char_u *)"", (char_u *)0L}
1840#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001841 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001842 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001843#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001844 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001845 {(char_u *)TRUE, (char_u *)0L}
1846#else
1847 (char_u *)NULL, PV_NONE,
1848 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001849#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"magic", NULL, P_BOOL|P_VI_DEF,
1852 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001854 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855#ifdef FEAT_QUICKFIX
1856 (char_u *)&p_mef, PV_NONE,
1857 {(char_u *)"", (char_u *)0L}
1858#else
1859 (char_u *)NULL, PV_NONE,
1860 {(char_u *)NULL, (char_u *)0L}
1861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001863 {"makeencoding","menc", P_STRING|P_VI_DEF,
1864#ifdef FEAT_MBYTE
1865 (char_u *)&p_menc, PV_MENC,
1866 {(char_u *)"", (char_u *)0L}
1867#else
1868 (char_u *)NULL, PV_NONE,
1869 {(char_u *)0L, (char_u *)0L}
1870#endif
1871 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1873#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001874 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001875# ifdef VMS
1876 {(char_u *)"MMS", (char_u *)0L}
1877# else
1878 {(char_u *)"make", (char_u *)0L}
1879# endif
1880#else
1881 (char_u *)NULL, PV_NONE,
1882 {(char_u *)NULL, (char_u *)0L}
1883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001884 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001885 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"matchtime", "mat", P_NUM|P_VI_DEF,
1890 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001892 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001893#ifdef FEAT_MBYTE
1894 (char_u *)&p_mco, PV_NONE,
1895#else
1896 (char_u *)NULL, PV_NONE,
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1900#ifdef FEAT_EVAL
1901 (char_u *)&p_mfd, PV_NONE,
1902#else
1903 (char_u *)NULL, PV_NONE,
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1907 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"maxmem", "mm", P_NUM|P_VI_DEF,
1910 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1912 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001913 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1914 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1917 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001918 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"menuitems", "mis", P_NUM|P_VI_DEF,
1921#ifdef FEAT_MENU
1922 (char_u *)&p_mis, PV_NONE,
1923#else
1924 (char_u *)NULL, PV_NONE,
1925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"mesg", NULL, P_BOOL|P_VI_DEF,
1928 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001929 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001930 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001931#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001932 (char_u *)&p_msm, PV_NONE,
1933 {(char_u *)"460000,2000,500", (char_u *)0L}
1934#else
1935 (char_u *)NULL, PV_NONE,
1936 {(char_u *)0L, (char_u *)0L}
1937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 {"modeline", "ml", P_BOOL|P_VIM,
1940 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"modelines", "mls", P_NUM|P_VI_DEF,
1943 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1946 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1949 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {"more", NULL, P_BOOL|P_VIM,
1952 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1955 (char_u *)&p_mouse, PV_NONE,
1956 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001957#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 (char_u *)"a",
1959#else
1960 (char_u *)"",
1961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1964#ifdef FEAT_GUI
1965 (char_u *)&p_mousef, PV_NONE,
1966#else
1967 (char_u *)NULL, PV_NONE,
1968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1971#ifdef FEAT_GUI
1972 (char_u *)&p_mh, PV_NONE,
1973#else
1974 (char_u *)NULL, PV_NONE,
1975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001976 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1978 (char_u *)&p_mousem, PV_NONE,
1979 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001980#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 (char_u *)"popup",
1982#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001983# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 (char_u *)"popup_setpos",
1985# else
1986 (char_u *)"extend",
1987# endif
1988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001989 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001990 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991#ifdef FEAT_MOUSESHAPE
1992 (char_u *)&p_mouseshape, PV_NONE,
1993 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1994#else
1995 (char_u *)NULL, PV_NONE,
1996 {(char_u *)NULL, (char_u *)0L}
1997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2000 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002001 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002002 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2003#if defined(DYNAMIC_MZSCHEME)
2004 (char_u *)&p_mzschemedll, PV_NONE,
2005 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2006#else
2007 (char_u *)NULL, PV_NONE,
2008 {(char_u *)"", (char_u *)0L}
2009#endif
2010 SCRIPTID_INIT},
2011 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2012#if defined(DYNAMIC_MZSCHEME)
2013 (char_u *)&p_mzschemegcdll, PV_NONE,
2014 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2015#else
2016 (char_u *)NULL, PV_NONE,
2017 {(char_u *)"", (char_u *)0L}
2018#endif
2019 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002020 {"mzquantum", "mzq", P_NUM,
2021#ifdef FEAT_MZSCHEME
2022 (char_u *)&p_mzq, PV_NONE,
2023#else
2024 (char_u *)NULL, PV_NONE,
2025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002026 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"novice", NULL, P_BOOL|P_VI_DEF,
2028 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002030 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002032 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2035 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002037 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2038#ifdef FEAT_LINEBREAK
2039 (char_u *)VAR_WIN, PV_NUW,
2040#else
2041 (char_u *)NULL, PV_NONE,
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002044 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002045#ifdef FEAT_COMPL_FUNC
2046 (char_u *)&p_ofu, PV_OFU,
2047 {(char_u *)"", (char_u *)0L}
2048#else
2049 (char_u *)NULL, PV_NONE,
2050 {(char_u *)0L, (char_u *)0L}
2051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {"open", NULL, P_BOOL|P_VI_DEF,
2054 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002055 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002056 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002057#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002058 (char_u *)&p_odev, PV_NONE,
2059#else
2060 (char_u *)NULL, PV_NONE,
2061#endif
2062 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002064 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2065 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 {"optimize", "opt", P_BOOL|P_VI_DEF,
2068 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002072 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002073 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2074 |P_SECURE,
2075 (char_u *)&p_pp, PV_NONE,
2076 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"paragraphs", "para", P_STRING|P_VI_DEF,
2079 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002080 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002081 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002082 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2086 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002087 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2089#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2090 (char_u *)&p_pex, PV_NONE,
2091 {(char_u *)"", (char_u *)0L}
2092#else
2093 (char_u *)NULL, PV_NONE,
2094 {(char_u *)0L, (char_u *)0L}
2095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002097 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002099 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002101 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002103#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104 (char_u *)".,,",
2105#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002109 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002110#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002111 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002112 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002113#else
2114 (char_u *)NULL, PV_NONE,
2115 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002116#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002117 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2119 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002121 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002122#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)&p_pvh, PV_NONE,
2124#else
2125 (char_u *)NULL, PV_NONE,
2126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002129#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 (char_u *)VAR_WIN, PV_PVW,
2131#else
2132 (char_u *)NULL, PV_NONE,
2133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002135 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136#ifdef FEAT_PRINTER
2137 (char_u *)&p_pdev, PV_NONE,
2138 {(char_u *)"", (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)NULL, (char_u *)0L}
2142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"printencoding", "penc", P_STRING|P_VI_DEF,
2145#ifdef FEAT_POSTSCRIPT
2146 (char_u *)&p_penc, PV_NONE,
2147 {(char_u *)"", (char_u *)0L}
2148#else
2149 (char_u *)NULL, PV_NONE,
2150 {(char_u *)NULL, (char_u *)0L}
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002153 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154#ifdef FEAT_POSTSCRIPT
2155 (char_u *)&p_pexpr, PV_NONE,
2156 {(char_u *)"", (char_u *)0L}
2157#else
2158 (char_u *)NULL, PV_NONE,
2159 {(char_u *)NULL, (char_u *)0L}
2160#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002161 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162 {"printfont", "pfn", P_STRING|P_VI_DEF,
2163#ifdef FEAT_PRINTER
2164 (char_u *)&p_pfn, PV_NONE,
2165 {
2166# ifdef MSWIN
2167 (char_u *)"Courier_New:h10",
2168# else
2169 (char_u *)"courier",
2170# endif
2171 (char_u *)0L}
2172#else
2173 (char_u *)NULL, PV_NONE,
2174 {(char_u *)NULL, (char_u *)0L}
2175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2178#ifdef FEAT_PRINTER
2179 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002180 /* untranslated to avoid problems when 'encoding'
2181 * is changed */
2182 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183#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 Moolenaar8299df92004-07-10 09:47:34 +00002188 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2189#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2190 (char_u *)&p_pmcs, PV_NONE,
2191 {(char_u *)"", (char_u *)0L}
2192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)NULL, (char_u *)0L}
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002197 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2198#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2199 (char_u *)&p_pmfn, PV_NONE,
2200 {(char_u *)"", (char_u *)0L}
2201#else
2202 (char_u *)NULL, PV_NONE,
2203 {(char_u *)NULL, (char_u *)0L}
2204#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002205 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002206 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207#ifdef FEAT_PRINTER
2208 (char_u *)&p_popt, PV_NONE,
2209 {(char_u *)"", (char_u *)0L}
2210#else
2211 (char_u *)NULL, PV_NONE,
2212 {(char_u *)NULL, (char_u *)0L}
2213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002216 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002217 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002218 {"pumheight", "ph", P_NUM|P_VI_DEF,
2219#ifdef FEAT_INS_EXPAND
2220 (char_u *)&p_ph, PV_NONE,
2221#else
2222 (char_u *)NULL, PV_NONE,
2223#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002224 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002225 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2226#ifdef FEAT_INS_EXPAND
2227 (char_u *)&p_pw, PV_NONE,
2228#else
2229 (char_u *)NULL, PV_NONE,
2230#endif
Bram Moolenaar42443c72018-02-10 18:28:52 +01002231 {(char_u *)15L, (char_u *)15L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002232 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002233#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002234 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002235 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002236#else
2237 (char_u *)NULL, PV_NONE,
2238 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002239#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002240 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002241 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2242#if defined(FEAT_PYTHON3)
2243 (char_u *)&p_py3home, PV_NONE,
2244 {(char_u *)"", (char_u *)0L}
2245#else
2246 (char_u *)NULL, PV_NONE,
2247 {(char_u *)NULL, (char_u *)0L}
2248#endif
2249 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002250 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002251#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002252 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002253 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002254#else
2255 (char_u *)NULL, PV_NONE,
2256 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002257#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002258 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002259 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2260#if defined(FEAT_PYTHON)
2261 (char_u *)&p_pyhome, PV_NONE,
2262 {(char_u *)"", (char_u *)0L}
2263#else
2264 (char_u *)NULL, PV_NONE,
2265 {(char_u *)NULL, (char_u *)0L}
2266#endif
2267 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002268 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2269#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2270 (char_u *)&p_pyx, PV_NONE,
2271#else
2272 (char_u *)NULL, PV_NONE,
2273#endif
2274 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2275 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002276 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2277#ifdef FEAT_TEXTOBJ
2278 (char_u *)&p_qe, PV_QE,
2279 {(char_u *)"\\", (char_u *)0L}
2280#else
2281 (char_u *)NULL, PV_NONE,
2282 {(char_u *)NULL, (char_u *)0L}
2283#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002284 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2286 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"redraw", NULL, P_BOOL|P_VI_DEF,
2289 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002291 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2292#ifdef FEAT_RELTIME
2293 (char_u *)&p_rdt, PV_NONE,
2294#else
2295 (char_u *)NULL, PV_NONE,
2296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002298 {"regexpengine", "re", P_NUM|P_VI_DEF,
2299 (char_u *)&p_re, PV_NONE,
2300 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002301 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2302 (char_u *)VAR_WIN, PV_RNU,
2303 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 {"remap", NULL, P_BOOL|P_VI_DEF,
2305 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002306 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002307 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002308#ifdef FEAT_RENDER_OPTIONS
2309 (char_u *)&p_rop, PV_NONE,
2310 {(char_u *)"", (char_u *)0L}
2311#else
2312 (char_u *)NULL, PV_NONE,
2313 {(char_u *)NULL, (char_u *)0L}
2314#endif
2315 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"report", NULL, P_NUM|P_VI_DEF,
2317 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002318 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2320#ifdef WIN3264
2321 (char_u *)&p_rs, PV_NONE,
2322#else
2323 (char_u *)NULL, PV_NONE,
2324#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002325 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2327#ifdef FEAT_RIGHTLEFT
2328 (char_u *)&p_ri, PV_NONE,
2329#else
2330 (char_u *)NULL, PV_NONE,
2331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2334#ifdef FEAT_RIGHTLEFT
2335 (char_u *)VAR_WIN, PV_RL,
2336#else
2337 (char_u *)NULL, PV_NONE,
2338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2341#ifdef FEAT_RIGHTLEFT
2342 (char_u *)VAR_WIN, PV_RLC,
2343 {(char_u *)"search", (char_u *)NULL}
2344#else
2345 (char_u *)NULL, PV_NONE,
2346 {(char_u *)NULL, (char_u *)0L}
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002349 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002350#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002351 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002352 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002353#else
2354 (char_u *)NULL, PV_NONE,
2355 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002356#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002357 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2359#ifdef FEAT_CMDL_INFO
2360 (char_u *)&p_ru, PV_NONE,
2361#else
2362 (char_u *)NULL, PV_NONE,
2363#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2366#ifdef FEAT_STL_OPT
2367 (char_u *)&p_ruf, PV_NONE,
2368#else
2369 (char_u *)NULL, PV_NONE,
2370#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002372 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2373 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2376 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2378 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002379 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002382 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2384 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2387 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002389 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 (char_u *)&p_sbo, PV_NONE,
2391 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"sections", "sect", P_STRING|P_VI_DEF,
2394 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2396 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2398 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"inclusive", (char_u *)0L}
2403 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002404 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002407 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408#ifdef FEAT_SESSION
2409 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002410 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 (char_u *)0L}
2412#else
2413 (char_u *)NULL, PV_NONE,
2414 {(char_u *)0L, (char_u *)0L}
2415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2418 (char_u *)&p_sh, PV_NONE,
2419 {
2420#ifdef VMS
2421 (char_u *)"-",
2422#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002423# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002425# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427# endif
2428#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2431 (char_u *)&p_shcf, PV_NONE,
2432 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002433#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 (char_u *)"/c",
2435#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2440#ifdef FEAT_QUICKFIX
2441 (char_u *)&p_sp, PV_NONE,
2442 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002443#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445#else
2446 (char_u *)">",
2447#endif
2448 (char_u *)0L}
2449#else
2450 (char_u *)NULL, PV_NONE,
2451 {(char_u *)0L, (char_u *)0L}
2452#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2455 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2458 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2461#ifdef BACKSLASH_IN_FILENAME
2462 (char_u *)&p_ssl, PV_NONE,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002467 {"shelltemp", "stmp", P_BOOL,
2468 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"shelltype", "st", P_NUM|P_VI_DEF,
2471#ifdef AMIGA
2472 (char_u *)&p_st, PV_NONE,
2473#else
2474 (char_u *)NULL, PV_NONE,
2475#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2478 (char_u *)&p_sxq, PV_NONE,
2479 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002480#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 (char_u *)"\"",
2482#else
2483 (char_u *)"",
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002486 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2487 (char_u *)&p_sxe, PV_NONE,
2488 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002489#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002490 (char_u *)"\"&|<>()@^",
2491#else
2492 (char_u *)"",
2493#endif
2494 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2496 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2499 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2502 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)"", (char_u *)"filnxtToO"}
2504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2509#ifdef FEAT_LINEBREAK
2510 (char_u *)&p_sbr, PV_NONE,
2511#else
2512 (char_u *)NULL, PV_NONE,
2513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"showcmd", "sc", P_BOOL|P_VIM,
2516#ifdef FEAT_CMDL_INFO
2517 (char_u *)&p_sc, PV_NONE,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
2521 {(char_u *)FALSE,
2522#ifdef UNIX
2523 (char_u *)FALSE
2524#else
2525 (char_u *)TRUE
2526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2529 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2532 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"showmode", "smd", P_BOOL|P_VIM,
2535 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002537 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002538 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2541 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2544 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002546 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2547#ifdef FEAT_SIGNS
2548 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002549 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002550#else
2551 (char_u *)NULL, PV_NONE,
2552 {(char_u *)NULL, (char_u *)0L}
2553#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002554 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2556 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2559 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2562#ifdef FEAT_SMARTINDENT
2563 (char_u *)&p_si, PV_SI,
2564#else
2565 (char_u *)NULL, PV_NONE,
2566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2569 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2572 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002573 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2575 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002577 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002578#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002579 (char_u *)VAR_WIN, PV_SPELL,
2580#else
2581 (char_u *)NULL, PV_NONE,
2582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002584 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002585#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002586 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002587 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002588#else
2589 (char_u *)NULL, PV_NONE,
2590 {(char_u *)0L, (char_u *)0L}
2591#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002592 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002593 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2594 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002595#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002596 (char_u *)&p_spf, PV_SPF,
2597 {(char_u *)"", (char_u *)0L}
2598#else
2599 (char_u *)NULL, PV_NONE,
2600 {(char_u *)0L, (char_u *)0L}
2601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002602 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002603 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2604 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002605#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002606 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002607 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002608#else
2609 (char_u *)NULL, PV_NONE,
2610 {(char_u *)0L, (char_u *)0L}
2611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002613 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002614#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002615 (char_u *)&p_sps, PV_NONE,
2616 {(char_u *)"best", (char_u *)0L}
2617#else
2618 (char_u *)NULL, PV_NONE,
2619 {(char_u *)0L, (char_u *)0L}
2620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2629 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2632#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002633 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634#else
2635 (char_u *)NULL, PV_NONE,
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002638 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 (char_u *)&p_su, PV_NONE,
2640 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002642 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002643#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 (char_u *)&p_sua, PV_SUA,
2645 {(char_u *)"", (char_u *)0L}
2646#else
2647 (char_u *)NULL, PV_NONE,
2648 {(char_u *)0L, (char_u *)0L}
2649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2652 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"swapsync", "sws", P_STRING|P_VI_DEF,
2655 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002657 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002660 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2661#ifdef FEAT_SYN_HL
2662 (char_u *)&p_smc, PV_SMC,
2663 {(char_u *)3000L, (char_u *)0L}
2664#else
2665 (char_u *)NULL, PV_NONE,
2666 {(char_u *)0L, (char_u *)0L}
2667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002669 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670#ifdef FEAT_SYN_HL
2671 (char_u *)&p_syn, PV_SYN,
2672 {(char_u *)"", (char_u *)0L}
2673#else
2674 (char_u *)NULL, PV_NONE,
2675 {(char_u *)0L, (char_u *)0L}
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002678 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2679#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002680 (char_u *)&p_tal, PV_NONE,
2681#else
2682 (char_u *)NULL, PV_NONE,
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002685 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002686 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2689 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2692 (char_u *)&p_tbs, PV_NONE,
2693#ifdef VMS /* binary searching doesn't appear to work on VMS */
2694 {(char_u *)0L, (char_u *)0L}
2695#else
2696 {(char_u *)TRUE, (char_u *)0L}
2697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002699 {"tagcase", "tc", P_STRING|P_VIM,
2700 (char_u *)&p_tc, PV_TC,
2701 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"taglength", "tl", P_NUM|P_VI_DEF,
2703 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"tagrelative", "tr", P_BOOL|P_VIM,
2706 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002708 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002709 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 {
2711#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2712 (char_u *)"./tags,./TAGS,tags,TAGS",
2713#else
2714 (char_u *)"./tags,tags",
2715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2718 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002720 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002721#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002722 (char_u *)&p_tcldll, PV_NONE,
2723 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002724#else
2725 (char_u *)NULL, PV_NONE,
2726 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002727#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2730 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2733#ifdef FEAT_ARABIC
2734 (char_u *)&p_tbidi, PV_NONE,
2735#else
2736 (char_u *)NULL, PV_NONE,
2737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2740#ifdef FEAT_MBYTE
2741 (char_u *)&p_tenc, PV_NONE,
2742 {(char_u *)"", (char_u *)0L}
2743#else
2744 (char_u *)NULL, PV_NONE,
2745 {(char_u *)0L, (char_u *)0L}
2746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002748 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2749#ifdef FEAT_TERMGUICOLORS
2750 (char_u *)&p_tgc, PV_NONE,
2751 {(char_u *)FALSE, (char_u *)FALSE}
2752#else
2753 (char_u*)NULL, PV_NONE,
2754 {(char_u *)FALSE, (char_u *)FALSE}
2755#endif
2756 SCRIPTID_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002757 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2758#ifdef FEAT_TERMINAL
2759 (char_u *)VAR_WIN, PV_TWK,
2760 {(char_u *)"", (char_u *)NULL}
2761#else
2762 (char_u *)NULL, PV_NONE,
2763 {(char_u *)NULL, (char_u *)0L}
2764#endif
2765 SCRIPTID_INIT},
2766 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2767#ifdef FEAT_TERMINAL
2768 (char_u *)&p_twsl, PV_TWSL,
2769 {(char_u *)10000L, (char_u *)10000L}
2770#else
2771 (char_u *)NULL, PV_NONE,
2772 {(char_u *)NULL, (char_u *)0L}
2773#endif
2774 SCRIPTID_INIT},
2775 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2776#ifdef FEAT_TERMINAL
2777 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002778 {(char_u *)"", (char_u *)NULL}
2779#else
2780 (char_u *)NULL, PV_NONE,
2781 {(char_u *)NULL, (char_u *)0L}
2782#endif
2783 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"terse", NULL, P_BOOL|P_VI_DEF,
2785 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"textauto", "ta", P_BOOL|P_VIM,
2788 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2792 (char_u *)&p_tx, PV_TX,
2793 {
2794#ifdef USE_CRNL
2795 (char_u *)TRUE,
2796#else
2797 (char_u *)FALSE,
2798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002800 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002803 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002805 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806#else
2807 (char_u *)NULL, PV_NONE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2811 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"timeout", "to", P_BOOL|P_VI_DEF,
2814 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2817 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 {"title", NULL, P_BOOL|P_VI_DEF,
2820#ifdef FEAT_TITLE
2821 (char_u *)&p_title, PV_NONE,
2822#else
2823 (char_u *)NULL, PV_NONE,
2824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"titlelen", NULL, P_NUM|P_VI_DEF,
2827#ifdef FEAT_TITLE
2828 (char_u *)&p_titlelen, PV_NONE,
2829#else
2830 (char_u *)NULL, PV_NONE,
2831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002833 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834#ifdef FEAT_TITLE
2835 (char_u *)&p_titleold, PV_NONE,
2836 {(char_u *)N_("Thanks for flying Vim"),
2837 (char_u *)0L}
2838#else
2839 (char_u *)NULL, PV_NONE,
2840 {(char_u *)0L, (char_u *)0L}
2841#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"titlestring", NULL, P_STRING|P_VI_DEF,
2844#ifdef FEAT_TITLE
2845 (char_u *)&p_titlestring, PV_NONE,
2846#else
2847 (char_u *)NULL, PV_NONE,
2848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002850 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002851#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002854#else
2855 (char_u *)NULL, PV_NONE,
2856 {(char_u *)0L, (char_u *)0L}
2857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002860#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002862 {(char_u *)"small", (char_u *)0L}
2863#else
2864 (char_u *)NULL, PV_NONE,
2865 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2869 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2872 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2875 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2878 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2881#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2882 (char_u *)&p_ttym, PV_NONE,
2883#else
2884 (char_u *)NULL, PV_NONE,
2885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2888 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002889 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2891 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002892 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002893 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2894 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002895#ifdef FEAT_PERSISTENT_UNDO
2896 (char_u *)&p_udir, PV_NONE,
2897 {(char_u *)".", (char_u *)0L}
2898#else
2899 (char_u *)NULL, PV_NONE,
2900 {(char_u *)0L, (char_u *)0L}
2901#endif
2902 SCRIPTID_INIT},
2903 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2904#ifdef FEAT_PERSISTENT_UNDO
2905 (char_u *)&p_udf, PV_UDF,
2906#else
2907 (char_u *)NULL, PV_NONE,
2908#endif
2909 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002911 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002913#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 (char_u *)1000L,
2915#else
2916 (char_u *)100L,
2917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002919 {"undoreload", "ur", P_NUM|P_VI_DEF,
2920 (char_u *)&p_ur, PV_NONE,
2921 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"updatecount", "uc", P_NUM|P_VI_DEF,
2923 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"updatetime", "ut", P_NUM|P_VI_DEF,
2926 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"verbose", "vbs", P_NUM|P_VI_DEF,
2929 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002930 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002931 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2932 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002933 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2935#ifdef FEAT_SESSION
2936 (char_u *)&p_vdir, PV_NONE,
2937 {(char_u *)DFLT_VDIR, (char_u *)0L}
2938#else
2939 (char_u *)NULL, PV_NONE,
2940 {(char_u *)0L, (char_u *)0L}
2941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002943 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944#ifdef FEAT_SESSION
2945 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002946 {(char_u *)"folds,options,cursor,curdir",
2947 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948#else
2949 (char_u *)NULL, PV_NONE,
2950 {(char_u *)0L, (char_u *)0L}
2951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002952 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002953 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954#ifdef FEAT_VIMINFO
2955 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002956#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002957 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958#else
2959# ifdef AMIGA
2960 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002961 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002963 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964# endif
2965#endif
2966#else
2967 (char_u *)NULL, PV_NONE,
2968 {(char_u *)0L, (char_u *)0L}
2969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002970 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002971 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2972#ifdef FEAT_VIMINFO
2973 (char_u *)&p_viminfofile, PV_NONE,
2974 {(char_u *)"", (char_u *)0L}
2975#else
2976 (char_u *)NULL, PV_NONE,
2977 {(char_u *)0L, (char_u *)0L}
2978#endif
2979 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002980 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2981 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982#ifdef FEAT_VIRTUALEDIT
2983 (char_u *)&p_ve, PV_NONE,
2984 {(char_u *)"", (char_u *)""}
2985#else
2986 (char_u *)NULL, PV_NONE,
2987 {(char_u *)0L, (char_u *)0L}
2988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002989 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2991 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002992 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 {"w300", NULL, P_NUM|P_VI_DEF,
2994 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002995 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 {"w1200", NULL, P_NUM|P_VI_DEF,
2997 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002998 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 {"w9600", NULL, P_NUM|P_VI_DEF,
3000 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003001 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 {"warn", NULL, P_BOOL|P_VI_DEF,
3003 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003004 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3006 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003007 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003008 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003010 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"wildchar", "wc", P_NUM|P_VIM,
3012 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003013 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3014 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003015 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003017 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003018 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019#ifdef FEAT_WILDIGN
3020 (char_u *)&p_wig, PV_NONE,
3021#else
3022 (char_u *)NULL, PV_NONE,
3023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003025 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3026 (char_u *)&p_wic, PV_NONE,
3027 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3029#ifdef FEAT_WILDMENU
3030 (char_u *)&p_wmnu, PV_NONE,
3031#else
3032 (char_u *)NULL, PV_NONE,
3033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003034 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003035 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003037 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003038 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3039#ifdef FEAT_CMDL_COMPL
3040 (char_u *)&p_wop, PV_NONE,
3041 {(char_u *)"", (char_u *)0L}
3042#else
3043 (char_u *)NULL, PV_NONE,
3044 {(char_u *)NULL, (char_u *)0L}
3045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003046 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3048#ifdef FEAT_WAK
3049 (char_u *)&p_wak, PV_NONE,
3050 {(char_u *)"menu", (char_u *)0L}
3051#else
3052 (char_u *)NULL, PV_NONE,
3053 {(char_u *)NULL, (char_u *)0L}
3054#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003055 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003057 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003058 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003061 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003065 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003066 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003067 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003070 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003073 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003074 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003075#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003076 (char_u *)&p_winptydll, PV_NONE, {
3077# ifdef _WIN64
3078 (char_u *)"winpty64.dll",
3079# else
3080 (char_u *)"winpty32.dll",
3081# endif
3082 (char_u *)0L}
3083#else
3084 (char_u *)NULL, PV_NONE,
3085 {(char_u *)0L, (char_u *)0L}
3086#endif
3087 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003090 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3092 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003093 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3095 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003096 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3098 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003099 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 {"write", NULL, P_BOOL|P_VI_DEF,
3101 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003102 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103 {"writeany", "wa", P_BOOL|P_VI_DEF,
3104 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003105 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3107 (char_u *)&p_wb, PV_NONE,
3108 {
3109#ifdef FEAT_WRITEBACKUP
3110 (char_u *)TRUE,
3111#else
3112 (char_u *)FALSE,
3113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003114 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115 {"writedelay", "wd", P_NUM|P_VI_DEF,
3116 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003117 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118
3119/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003120#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003122 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123
3124 p_term("t_AB", T_CAB)
3125 p_term("t_AF", T_CAF)
3126 p_term("t_AL", T_CAL)
3127 p_term("t_al", T_AL)
3128 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003129 p_term("t_BE", T_BE)
3130 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_cd", T_CD)
3132 p_term("t_ce", T_CE)
3133 p_term("t_cl", T_CL)
3134 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003135 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_Co", T_CCO)
3137 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003138 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_da", T_DA)
3142 p_term("t_db", T_DB)
3143 p_term("t_DL", T_CDL)
3144 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003145 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003146 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003148 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_IE", T_CIE)
3150 p_term("t_IS", T_CIS)
3151 p_term("t_ke", T_KE)
3152 p_term("t_ks", T_KS)
3153 p_term("t_le", T_LE)
3154 p_term("t_mb", T_MB)
3155 p_term("t_md", T_MD)
3156 p_term("t_me", T_ME)
3157 p_term("t_mr", T_MR)
3158 p_term("t_ms", T_MS)
3159 p_term("t_nd", T_ND)
3160 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003161 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003163 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003165 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_RV", T_CRV)
3167 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003168 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003170 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003171 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003172 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003174 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003176 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_te", T_TE)
3178 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003179 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003180 p_term("t_ts", T_TS)
3181 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 p_term("t_ue", T_UE)
3183 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003184 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_vb", T_VB)
3186 p_term("t_ve", T_VE)
3187 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003188 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 p_term("t_vs", T_VS)
3190 p_term("t_WP", T_CWP)
3191 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003192 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 p_term("t_xs", T_XS)
3194 p_term("t_ZH", T_CZH)
3195 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003196 p_term("t_8f", T_8F)
3197 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198
3199/* terminal key codes are not in here */
3200
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003201 /* end marker */
3202 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203};
3204
3205#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3206
3207#ifdef FEAT_MBYTE
3208static char *(p_ambw_values[]) = {"single", "double", NULL};
3209#endif
3210static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003211static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003213#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003214static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003215#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003216#ifdef FEAT_CMDL_COMPL
3217static char *(p_wop_values[]) = {"tagfile", NULL};
3218#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219#ifdef FEAT_WAK
3220static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3221#endif
3222static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3224static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226#ifdef FEAT_BROWSE
3227static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3228#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003230static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003232static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003233static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3235#ifdef FEAT_FOLDING
3236static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003237# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003239# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240 NULL};
3241static char *(p_fcl_values[]) = {"all", NULL};
3242#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003244static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003245#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003246#ifdef FEAT_SIGNS
3247static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003250static void set_option_default(int, int opt_flags, int compatible);
3251static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003252static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003253static char_u *term_bg_default(void);
3254static void did_set_option(int opt_idx, int opt_flags, int new_value);
3255static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003257static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static char_u *option_expand(int opt_idx, char_u *val);
3260static void didset_options(void);
3261static void didset_options2(void);
3262static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003263#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003265#else
3266# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3267#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static void set_string_option_global(int opt_idx, char_u **varp);
3269static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3270static 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);
3271static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003272#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003278#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static char_u *did_set_spell_option(int is_spellfile);
3280static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003281#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003282#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003284#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003285static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3286static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3287static void check_redraw(long_u flags);
3288static int findoption(char_u *);
3289static int find_key_option(char_u *);
3290static void showoptions(int all, int opt_flags);
3291static int optval_default(struct vimoption *, char_u *varp);
3292static void showoneopt(struct vimoption *, int opt_flags);
3293static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3294static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3295static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3296static int istermoption(struct vimoption *);
3297static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3298static char_u *get_varp(struct vimoption *);
3299static void option_value2string(struct vimoption *, int opt_flags);
3300static void check_winopt(winopt_T *wop);
3301static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003303static void langmap_init(void);
3304static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static void paste_option_changed(void);
3307static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003311static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3312static int check_opt_strings(char_u *val, char **values, int);
3313static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003314#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003315static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003316#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317
3318/*
3319 * Initialize the options, first part.
3320 *
3321 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003322 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323 */
3324 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003325set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326{
3327 char_u *p;
3328 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003329 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
3331#ifdef FEAT_LANGMAP
3332 langmap_init();
3333#endif
3334
3335 /* Be Vi compatible by default */
3336 p_cp = TRUE;
3337
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003338 /* Use POSIX compatibility when $VIM_POSIX is set. */
3339 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003340 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003341 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003342 set_string_default("shm", (char_u *)"A");
3343 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003344
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 /*
3346 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003347 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003349 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003350#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003351 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003353 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354# endif
3355#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003356 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003357 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358
3359#ifdef FEAT_WILDIGN
3360 /*
3361 * Set the default for 'backupskip' to include environment variables for
3362 * temp files.
3363 */
3364 {
3365# ifdef UNIX
3366 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3367# else
3368 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3369# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003370 int len;
3371 garray_T ga;
3372 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373
3374 ga_init2(&ga, 1, 100);
3375 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3376 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003377 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378# ifdef UNIX
3379 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003380# ifdef MACOS_X
3381 p = (char_u *)"/private/tmp";
3382# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003384# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385 else
3386# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003387 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 if (p != NULL && *p != NUL)
3389 {
3390 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003391 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 if (ga_grow(&ga, len) == OK)
3393 {
3394 if (ga.ga_len > 0)
3395 STRCAT(ga.ga_data, ",");
3396 STRCAT(ga.ga_data, p);
3397 add_pathsep(ga.ga_data);
3398 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399 ga.ga_len += len;
3400 }
3401 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003402 if (mustfree)
3403 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 }
3405 if (ga.ga_data != NULL)
3406 {
3407 set_string_default("bsk", ga.ga_data);
3408 vim_free(ga.ga_data);
3409 }
3410 }
3411#endif
3412
3413 /*
3414 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3415 */
3416 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003417 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003419#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3420 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3421#endif
3422 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003424 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003425 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426#else
3427# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003428 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003429 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432# endif
3433#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003435 opt_idx = findoption((char_u *)"maxmem");
3436 if (opt_idx >= 0)
3437 {
3438#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003439 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3440 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003441#endif
3442 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3443 }
3444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445 }
3446
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447#ifdef FEAT_SEARCHPATH
3448 {
3449 char_u *cdpath;
3450 char_u *buf;
3451 int i;
3452 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003453 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454
3455 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003456 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457 if (cdpath != NULL)
3458 {
3459 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3460 if (buf != NULL)
3461 {
3462 buf[0] = ','; /* start with ",", current dir first */
3463 j = 1;
3464 for (i = 0; cdpath[i] != NUL; ++i)
3465 {
3466 if (vim_ispathlistsep(cdpath[i]))
3467 buf[j++] = ',';
3468 else
3469 {
3470 if (cdpath[i] == ' ' || cdpath[i] == ',')
3471 buf[j++] = '\\';
3472 buf[j++] = cdpath[i];
3473 }
3474 }
3475 buf[j] = NUL;
3476 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003477 if (opt_idx >= 0)
3478 {
3479 options[opt_idx].def_val[VI_DEFAULT] = buf;
3480 options[opt_idx].flags |= P_DEF_ALLOCED;
3481 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003482 else
3483 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003485 if (mustfree)
3486 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 }
3488 }
3489#endif
3490
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003491#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003492 /* Set print encoding on platforms that don't default to latin1 */
3493 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003494# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495 (char_u *)"cp1252"
3496# else
3497# ifdef VMS
3498 (char_u *)"dec-mcs"
3499# else
3500# ifdef EBCDIC
3501 (char_u *)"ebcdic-uk"
3502# else
3503# ifdef MAC
3504 (char_u *)"mac-roman"
3505# else /* HPUX */
3506 (char_u *)"hp-roman8"
3507# endif
3508# endif
3509# endif
3510# endif
3511 );
3512#endif
3513
3514#ifdef FEAT_POSTSCRIPT
3515 /* 'printexpr' must be allocated to be able to evaluate it. */
3516 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003517# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003518 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519# else
3520# ifdef VMS
3521 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3522
3523# else
3524 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3525# endif
3526# endif
3527 );
3528#endif
3529
3530 /*
3531 * Set all the options (except the terminal options) to their default
3532 * value. Also set the global value for local options.
3533 */
3534 set_options_default(0);
3535
Bram Moolenaar07268702018-03-01 21:57:32 +01003536#ifdef CLEAN_RUNTIMEPATH
3537 if (clean_arg)
3538 {
3539 opt_idx = findoption((char_u *)"runtimepath");
3540 if (opt_idx >= 0)
3541 {
3542 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3543 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3544 }
3545 opt_idx = findoption((char_u *)"packpath");
3546 if (opt_idx >= 0)
3547 {
3548 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3549 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3550 }
3551 }
3552#endif
3553
Bram Moolenaar071d4272004-06-13 20:20:40 +00003554#ifdef FEAT_GUI
3555 if (found_reverse_arg)
3556 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3557#endif
3558
3559 curbuf->b_p_initialized = TRUE;
3560 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003561 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003562 check_buf_options(curbuf);
3563 check_win_options(curwin);
3564 check_options();
3565
3566 /* Must be before option_expand(), because that one needs vim_isIDc() */
3567 didset_options();
3568
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003569#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003570 /* Use the current chartab for the generic chartab. This is not in
3571 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003572 init_spell_chartab();
3573#endif
3574
Bram Moolenaar071d4272004-06-13 20:20:40 +00003575 /*
3576 * Expand environment variables and things like "~" for the defaults.
3577 * If option_expand() returns non-NULL the variable is expanded. This can
3578 * only happen for non-indirect options.
3579 * Also set the default to the expanded value, so ":set" does not list
3580 * them.
3581 * Don't set the P_ALLOCED flag, because we don't want to free the
3582 * default.
3583 */
3584 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3585 {
3586 if ((options[opt_idx].flags & P_GETTEXT)
3587 && options[opt_idx].var != NULL)
3588 p = (char_u *)_(*(char **)options[opt_idx].var);
3589 else
3590 p = option_expand(opt_idx, NULL);
3591 if (p != NULL && (p = vim_strsave(p)) != NULL)
3592 {
3593 *(char_u **)options[opt_idx].var = p;
3594 /* VIMEXP
3595 * Defaults for all expanded options are currently the same for Vi
3596 * and Vim. When this changes, add some code here! Also need to
3597 * split P_DEF_ALLOCED in two.
3598 */
3599 if (options[opt_idx].flags & P_DEF_ALLOCED)
3600 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3601 options[opt_idx].def_val[VI_DEFAULT] = p;
3602 options[opt_idx].flags |= P_DEF_ALLOCED;
3603 }
3604 }
3605
Bram Moolenaar071d4272004-06-13 20:20:40 +00003606 save_file_ff(curbuf); /* Buffer is unchanged */
3607
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608#if defined(FEAT_ARABIC)
3609 /* Detect use of mlterm.
3610 * Mlterm is a terminal emulator akin to xterm that has some special
3611 * abilities (bidi namely).
3612 * NOTE: mlterm's author is being asked to 'set' a variable
3613 * instead of an environment variable due to inheritance.
3614 */
3615 if (mch_getenv((char_u *)"MLTERM") != NULL)
3616 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3617#endif
3618
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003619 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003620
3621#ifdef FEAT_MBYTE
3622# if defined(WIN3264) && defined(FEAT_GETTEXT)
3623 /*
3624 * If $LANG isn't set, try to get a good value for it. This makes the
3625 * right language be used automatically. Don't do this for English.
3626 */
3627 if (mch_getenv((char_u *)"LANG") == NULL)
3628 {
3629 char buf[20];
3630
3631 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3632 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3633 * only the first two. */
3634 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3635 (LPTSTR)buf, 20);
3636 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3637 {
3638 /* There are a few exceptions (probably more) */
3639 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3640 STRCPY(buf, "zh_TW");
3641 else if (STRNICMP(buf, "chs", 3) == 0
3642 || STRNICMP(buf, "zhc", 3) == 0)
3643 STRCPY(buf, "zh_CN");
3644 else if (STRNICMP(buf, "jp", 2) == 0)
3645 STRCPY(buf, "ja");
3646 else
3647 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003648 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649 }
3650 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003651# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003652# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003653 /* Moved to os_mac_conv.c to avoid dependency problems. */
3654 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003655# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003656# endif
3657
3658 /* enc_locale() will try to find the encoding of the current locale. */
3659 p = enc_locale();
3660 if (p != NULL)
3661 {
3662 char_u *save_enc;
3663
3664 /* Try setting 'encoding' and check if the value is valid.
3665 * If not, go back to the default "latin1". */
3666 save_enc = p_enc;
3667 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003668 if (STRCMP(p_enc, "gb18030") == 0)
3669 {
3670 /* We don't support "gb18030", but "cp936" is a good substitute
3671 * for practical purposes, thus use that. It's not an alias to
3672 * still support conversion between gb18030 and utf-8. */
3673 p_enc = vim_strsave((char_u *)"cp936");
3674 vim_free(p);
3675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676 if (mb_init() == NULL)
3677 {
3678 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003679 if (opt_idx >= 0)
3680 {
3681 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3682 options[opt_idx].flags |= P_DEF_ALLOCED;
3683 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684
Bram Moolenaard0573012017-10-28 21:11:06 +02003685#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003686 if (STRCMP(p_enc, "latin1") == 0
3687# ifdef FEAT_MBYTE
3688 || enc_utf8
3689# endif
3690 )
3691 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003692 /* Adjust the default for 'isprint' and 'iskeyword' to match
3693 * latin1. Also set the defaults for when 'nocompatible' is
3694 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003695 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003696 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003697 set_string_option_direct((char_u *)"isk", -1,
3698 ISK_LATIN1, OPT_FREE, SID_NONE);
3699 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (opt_idx >= 0)
3701 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003702 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003703 if (opt_idx >= 0)
3704 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003705 (void)init_chartab();
3706 }
3707#endif
3708
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709# if defined(WIN3264) && !defined(FEAT_GUI)
3710 /* Win32 console: When GetACP() returns a different value from
3711 * GetConsoleCP() set 'termencoding'. */
3712 if (GetACP() != GetConsoleCP())
3713 {
3714 char buf[50];
3715
3716 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3717 p_tenc = vim_strsave((char_u *)buf);
3718 if (p_tenc != NULL)
3719 {
3720 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003721 if (opt_idx >= 0)
3722 {
3723 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3724 options[opt_idx].flags |= P_DEF_ALLOCED;
3725 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726 convert_setup(&input_conv, p_tenc, p_enc);
3727 convert_setup(&output_conv, p_enc, p_tenc);
3728 }
3729 else
3730 p_tenc = empty_option;
3731 }
3732# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003733# if defined(WIN3264) && defined(FEAT_MBYTE)
3734 /* $HOME may have characters in active code page. */
3735 init_homedir();
3736# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 }
3738 else
3739 {
3740 vim_free(p_enc);
3741 p_enc = save_enc;
3742 }
3743 }
3744#endif
3745
3746#ifdef FEAT_MULTI_LANG
3747 /* Set the default for 'helplang'. */
3748 set_helplang_default(get_mess_lang());
3749#endif
3750}
3751
3752/*
3753 * Set an option to its default value.
3754 * This does not take care of side effects!
3755 */
3756 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003757set_option_default(
3758 int opt_idx,
3759 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3760 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761{
3762 char_u *varp; /* pointer to variable for current option */
3763 int dvi; /* index in def_val[] */
3764 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003765 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3767
3768 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3769 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003770 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 {
3772 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3773 if (flags & P_STRING)
3774 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003775 /* Use set_string_option_direct() for local options to handle
3776 * freeing and allocating the value. */
3777 if (options[opt_idx].indir != PV_NONE)
3778 set_string_option_direct(NULL, opt_idx,
3779 options[opt_idx].def_val[dvi], opt_flags, 0);
3780 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003782 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3783 free_string_option(*(char_u **)(varp));
3784 *(char_u **)varp = options[opt_idx].def_val[dvi];
3785 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003786 }
3787 }
3788 else if (flags & P_NUM)
3789 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003790 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 win_comp_scroll(curwin);
3792 else
3793 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003794 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 /* May also set global value for local option. */
3796 if (both)
3797 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3798 *(long *)varp;
3799 }
3800 }
3801 else /* P_BOOL */
3802 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003803 /* the cast to long is required for Manx C, long_i is needed for
3804 * MSVC */
3805 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003806#ifdef UNIX
3807 /* 'modeline' defaults to off for root */
3808 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3809 *(int *)varp = FALSE;
3810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811 /* May also set global value for local option. */
3812 if (both)
3813 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3814 *(int *)varp;
3815 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003816
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003817 /* The default value is not insecure. */
3818 flagsp = insecure_flag(opt_idx, opt_flags);
3819 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 }
3821
3822#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003823 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824#endif
3825}
3826
3827/*
3828 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003829 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830 */
3831 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003832set_options_default(
3833 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834{
3835 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003837 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838
3839 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003840 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003841#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003842 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003843 || (TRUE
3844# if defined(FEAT_MBYTE)
3845 && options[i].var != (char_u *)&p_enc
3846# endif
3847# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003848 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003849 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003850# endif
3851 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003852#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003853 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 set_option_default(i, opt_flags, p_cp);
3855
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003857 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003859#ifdef FEAT_CINDENT
3860 parse_cino(curbuf);
3861#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862}
3863
3864/*
3865 * Set the Vi-default value of a string option.
3866 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003867 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003869 static void
3870set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871{
3872 char_u *p;
3873 int opt_idx;
3874
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003875 if (escape && vim_strchr(val, ' ') != NULL)
3876 p = vim_strsave_escaped(val, (char_u *)" ");
3877 else
3878 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 if (p != NULL) /* we don't want a NULL */
3880 {
3881 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003882 if (opt_idx >= 0)
3883 {
3884 if (options[opt_idx].flags & P_DEF_ALLOCED)
3885 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3886 options[opt_idx].def_val[VI_DEFAULT] = p;
3887 options[opt_idx].flags |= P_DEF_ALLOCED;
3888 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889 }
3890}
3891
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003892 void
3893set_string_default(char *name, char_u *val)
3894{
3895 set_string_default_esc(name, val, FALSE);
3896}
3897
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898/*
3899 * Set the Vi-default value of a number option.
3900 * Used for 'lines' and 'columns'.
3901 */
3902 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003903set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003905 int opt_idx;
3906
3907 opt_idx = findoption((char_u *)name);
3908 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003909 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910}
3911
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003912#if defined(EXITFREE) || defined(PROTO)
3913/*
3914 * Free all options.
3915 */
3916 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003917free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003918{
3919 int i;
3920
3921 for (i = 0; !istermoption(&options[i]); i++)
3922 {
3923 if (options[i].indir == PV_NONE)
3924 {
3925 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003926 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003927 free_string_option(*(char_u **)options[i].var);
3928 if (options[i].flags & P_DEF_ALLOCED)
3929 free_string_option(options[i].def_val[VI_DEFAULT]);
3930 }
3931 else if (options[i].var != VAR_WIN
3932 && (options[i].flags & P_STRING))
3933 /* buffer-local option: free global value */
3934 free_string_option(*(char_u **)options[i].var);
3935 }
3936}
3937#endif
3938
3939
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940/*
3941 * Initialize the options, part two: After getting Rows and Columns and
3942 * setting 'term'.
3943 */
3944 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003945set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003947 int idx;
3948
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003950 * 'scroll' defaults to half the window height. The stored default is zero,
3951 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003953 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003954 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003955 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 comp_col();
3957
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003958 /*
3959 * 'window' is only for backwards compatibility with Vi.
3960 * Default is Rows - 1.
3961 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003962 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003963 p_window = Rows - 1;
3964 set_number_default("window", Rows - 1);
3965
Bram Moolenaarf740b292006-02-16 22:11:02 +00003966 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003967#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003968 /*
3969 * If 'background' wasn't set by the user, try guessing the value,
3970 * depending on the terminal name. Only need to check for terminals
3971 * with a dark background, that can handle color.
3972 */
3973 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003974 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3975 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003977 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003978 /* don't mark it as set, when starting the GUI it may be
3979 * changed again */
3980 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 }
3982#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003983
3984#ifdef CURSOR_SHAPE
3985 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3986#endif
3987#ifdef FEAT_MOUSESHAPE
3988 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3989#endif
3990#ifdef FEAT_PRINTER
3991 (void)parse_printoptions(); /* parse 'printoptions' default value */
3992#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993}
3994
3995/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003996 * Return "dark" or "light" depending on the kind of terminal.
3997 * This is just guessing! Recognized are:
3998 * "linux" Linux console
3999 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004000 * "cygwin.*" Cygwin shell
4001 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004002 * We also check the COLORFGBG environment variable, which is set by
4003 * rxvt and derivatives. This variable contains either two or three
4004 * values separated by semicolons; we want the last value in either
4005 * case. If this value is 0-6 or 8, our background is dark.
4006 */
4007 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004008term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004009{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004010#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004011 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004012 return (char_u *)"dark";
4013#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004014 char_u *p;
4015
Bram Moolenaarf740b292006-02-16 22:11:02 +00004016 if (STRCMP(T_NAME, "linux") == 0
4017 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004018 || STRNCMP(T_NAME, "cygwin", 6) == 0
4019 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004020 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4021 && (p = vim_strrchr(p, ';')) != NULL
4022 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4023 && p[2] == NUL))
4024 return (char_u *)"dark";
4025 return (char_u *)"light";
4026#endif
4027}
4028
4029/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030 * Initialize the options, part three: After reading the .vimrc
4031 */
4032 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004033set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004035#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004036/*
4037 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4038 * This is done after other initializations, where 'shell' might have been
4039 * set, but only if they have not been set before.
4040 */
4041 char_u *p;
4042 int idx_srr;
4043 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004044# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 int idx_sp;
4046 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004047# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048
4049 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004050 if (idx_srr < 0)
4051 do_srr = FALSE;
4052 else
4053 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004056 if (idx_sp < 0)
4057 do_sp = FALSE;
4058 else
4059 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004061 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if (p != NULL)
4063 {
4064 /*
4065 * Default for p_sp is "| tee", for p_srr is ">".
4066 * For known shells it is changed here to include stderr.
4067 */
4068 if ( fnamecmp(p, "csh") == 0
4069 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 || fnamecmp(p, "csh.exe") == 0
4072 || fnamecmp(p, "tcsh.exe") == 0
4073# endif
4074 )
4075 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004076# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 if (do_sp)
4078 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4085 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 if (do_srr)
4088 {
4089 p_srr = (char_u *)">&";
4090 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4091 }
4092 }
4093 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004094 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 if ( fnamecmp(p, "sh") == 0
4096 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004097 || fnamecmp(p, "mksh") == 0
4098 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004100 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004102 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004103# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 || fnamecmp(p, "cmd") == 0
4105 || fnamecmp(p, "sh.exe") == 0
4106 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004107 || fnamecmp(p, "mksh.exe") == 0
4108 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004110 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 || fnamecmp(p, "bash.exe") == 0
4112 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004114 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004116# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 if (do_sp)
4118 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004121# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004123# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4125 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004126# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 if (do_srr)
4128 {
4129 p_srr = (char_u *)">%s 2>&1";
4130 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4131 }
4132 }
4133 vim_free(p);
4134 }
4135#endif
4136
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004137#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004139 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4140 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 * This is done after other initializations, where 'shell' might have been
4142 * set, but only if they have not been set before. Default for p_shcf is
4143 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004144 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004146 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 {
4148 int idx3;
4149
4150 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004151 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152 {
4153 p_shcf = (char_u *)"-c";
4154 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4155 }
4156
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 /* Somehow Win32 requires the quotes around the redirection too */
4158 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004159 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 {
4161 p_sxq = (char_u *)"\"";
4162 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4163 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004165 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4166 {
4167 int idx3;
4168
4169 /*
4170 * cmd.exe on Windows will strip the first and last double quote given
4171 * on the command line, e.g. most of the time things like:
4172 * cmd /c "my path/to/echo" "my args to echo"
4173 * become:
4174 * my path/to/echo" "my args to echo
4175 * when executed.
4176 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004177 * To avoid this, set shellxquote to surround the command in
4178 * parenthesis. This appears to make most commands work, without
4179 * breaking commands that worked previously, such as
4180 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004181 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004182 idx3 = findoption((char_u *)"sxq");
4183 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4184 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004185 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004186 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4187 }
4188
Bram Moolenaara64ba222012-02-12 23:23:31 +01004189 idx3 = findoption((char_u *)"shcf");
4190 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4191 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004192 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004193 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4194 }
4195 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004196#endif
4197
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004198 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004199 {
4200 int idx_ffs = findoption((char_u *)"ffs");
4201
4202 /* Apply the first entry of 'fileformats' to the initial buffer. */
4203 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4204 set_fileformat(default_fileformat(), OPT_LOCAL);
4205 }
4206
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207#ifdef FEAT_TITLE
4208 set_title_defaults();
4209#endif
4210}
4211
4212#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4213/*
4214 * When 'helplang' is still at its default value, set it to "lang".
4215 * Only the first two characters of "lang" are used.
4216 */
4217 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004218set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219{
4220 int idx;
4221
4222 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4223 return;
4224 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004225 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226 {
4227 if (options[idx].flags & P_ALLOCED)
4228 free_string_option(p_hlg);
4229 p_hlg = vim_strsave(lang);
4230 if (p_hlg == NULL)
4231 p_hlg = empty_option;
4232 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004233 {
4234 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4235 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4236 {
4237 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4238 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4239 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242 options[idx].flags |= P_ALLOCED;
4243 }
4244}
4245#endif
4246
4247#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004248static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004249
4250 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004251gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004252{
4253 if (gui_get_lightness(gui.back_pixel) < 127)
4254 return (char_u *)"dark";
4255 return (char_u *)"light";
4256}
4257
4258/*
4259 * Option initializations that can only be done after opening the GUI window.
4260 */
4261 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004262init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004263{
4264 /* Set the 'background' option according to the lightness of the
4265 * background color, unless the user has set it already. */
4266 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4267 {
4268 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4269 highlight_changed();
4270 }
4271}
4272#endif
4273
4274#ifdef FEAT_TITLE
4275/*
4276 * 'title' and 'icon' only default to true if they have not been set or reset
4277 * in .vimrc and we can read the old value.
4278 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4279 * they can be reset. This reduces startup time when using X on a remote
4280 * machine.
4281 */
4282 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004283set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004284{
4285 int idx1;
4286 long val;
4287
4288 /*
4289 * If GUI is (going to be) used, we can always set the window title and
4290 * icon name. Saves a bit of time, because the X11 display server does
4291 * not need to be contacted.
4292 */
4293 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004294 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004295 {
4296#ifdef FEAT_GUI
4297 if (gui.starting || gui.in_use)
4298 val = TRUE;
4299 else
4300#endif
4301 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004302 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 p_title = val;
4304 }
4305 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004306 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004307 {
4308#ifdef FEAT_GUI
4309 if (gui.starting || gui.in_use)
4310 val = TRUE;
4311 else
4312#endif
4313 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004314 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004315 p_icon = val;
4316 }
4317}
4318#endif
4319
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004320#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004321 static void
4322trigger_optionsset_string(
4323 int opt_idx,
4324 int opt_flags,
4325 char_u *oldval,
4326 char_u *newval)
4327{
4328 if (oldval != NULL && newval != NULL)
4329 {
4330 char_u buf_type[7];
4331
4332 sprintf((char *)buf_type, "%s",
4333 (opt_flags & OPT_LOCAL) ? "local" : "global");
4334 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4335 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4336 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4337 apply_autocmds(EVENT_OPTIONSET,
4338 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4339 reset_v_option_vars();
4340 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004341}
4342#endif
4343
Bram Moolenaar071d4272004-06-13 20:20:40 +00004344/*
4345 * Parse 'arg' for option settings.
4346 *
4347 * 'arg' may be IObuff, but only when no errors can be present and option
4348 * does not need to be expanded with option_expand().
4349 * "opt_flags":
4350 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004351 * OPT_GLOBAL for ":setglobal"
4352 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004354 * OPT_WINONLY to only set window-local options
4355 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004356 *
4357 * returns FAIL if an error is detected, OK otherwise
4358 */
4359 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004360do_set(
4361 char_u *arg, /* option string (may be written to!) */
4362 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004363{
4364 int opt_idx;
4365 char_u *errmsg;
4366 char_u errbuf[80];
4367 char_u *startarg;
4368 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4369 int nextchar; /* next non-white char after option name */
4370 int afterchar; /* character just after option name */
4371 int len;
4372 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004373 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374 int key;
4375 long_u flags; /* flags for current option */
4376 char_u *varp = NULL; /* pointer to variable for current option */
4377 int did_show = FALSE; /* already showed one value */
4378 int adding; /* "opt+=arg" */
4379 int prepending; /* "opt^=arg" */
4380 int removing; /* "opt-=arg" */
4381 int cp_val = 0;
4382 char_u key_name[2];
4383
4384 if (*arg == NUL)
4385 {
4386 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004387 did_show = TRUE;
4388 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 }
4390
4391 while (*arg != NUL) /* loop to process all options */
4392 {
4393 errmsg = NULL;
4394 startarg = arg; /* remember for error message */
4395
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004396 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4397 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004398 {
4399 /*
4400 * ":set all" show all options.
4401 * ":set all&" set all options to their default value.
4402 */
4403 arg += 3;
4404 if (*arg == '&')
4405 {
4406 ++arg;
4407 /* Only for :set command set global value of local options. */
4408 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004409 didset_options();
4410 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004411 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004412 }
4413 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004414 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004416 did_show = TRUE;
4417 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004418 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004419 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 {
4421 showoptions(2, opt_flags);
4422 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004423 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004424 arg += 7;
4425 }
4426 else
4427 {
4428 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004429 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004430 {
4431 prefix = 0;
4432 arg += 2;
4433 }
4434 else if (STRNCMP(arg, "inv", 3) == 0)
4435 {
4436 prefix = 2;
4437 arg += 3;
4438 }
4439
4440 /* find end of name */
4441 key = 0;
4442 if (*arg == '<')
4443 {
4444 nextchar = 0;
4445 opt_idx = -1;
4446 /* look out for <t_>;> */
4447 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4448 len = 5;
4449 else
4450 {
4451 len = 1;
4452 while (arg[len] != NUL && arg[len] != '>')
4453 ++len;
4454 }
4455 if (arg[len] != '>')
4456 {
4457 errmsg = e_invarg;
4458 goto skip;
4459 }
4460 arg[len] = NUL; /* put NUL after name */
4461 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4462 opt_idx = findoption(arg + 1);
4463 arg[len++] = '>'; /* restore '>' */
4464 if (opt_idx == -1)
4465 key = find_key_option(arg + 1);
4466 }
4467 else
4468 {
4469 len = 0;
4470 /*
4471 * The two characters after "t_" may not be alphanumeric.
4472 */
4473 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4474 len = 4;
4475 else
4476 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4477 ++len;
4478 nextchar = arg[len];
4479 arg[len] = NUL; /* put NUL after name */
4480 opt_idx = findoption(arg);
4481 arg[len] = nextchar; /* restore nextchar */
4482 if (opt_idx == -1)
4483 key = find_key_option(arg);
4484 }
4485
4486 /* remember character after option name */
4487 afterchar = arg[len];
4488
4489 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004490 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004491 ++len;
4492
4493 adding = FALSE;
4494 prepending = FALSE;
4495 removing = FALSE;
4496 if (arg[len] != NUL && arg[len + 1] == '=')
4497 {
4498 if (arg[len] == '+')
4499 {
4500 adding = TRUE; /* "+=" */
4501 ++len;
4502 }
4503 else if (arg[len] == '^')
4504 {
4505 prepending = TRUE; /* "^=" */
4506 ++len;
4507 }
4508 else if (arg[len] == '-')
4509 {
4510 removing = TRUE; /* "-=" */
4511 ++len;
4512 }
4513 }
4514 nextchar = arg[len];
4515
4516 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4517 {
4518 errmsg = (char_u *)N_("E518: Unknown option");
4519 goto skip;
4520 }
4521
4522 if (opt_idx >= 0)
4523 {
4524 if (options[opt_idx].var == NULL) /* hidden option: skip */
4525 {
4526 /* Only give an error message when requesting the value of
4527 * a hidden option, ignore setting it. */
4528 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4529 && (!(options[opt_idx].flags & P_BOOL)
4530 || nextchar == '?'))
4531 errmsg = (char_u *)N_("E519: Option not supported");
4532 goto skip;
4533 }
4534
4535 flags = options[opt_idx].flags;
4536 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4537 }
4538 else
4539 {
4540 flags = P_STRING;
4541 if (key < 0)
4542 {
4543 key_name[0] = KEY2TERMCAP0(key);
4544 key_name[1] = KEY2TERMCAP1(key);
4545 }
4546 else
4547 {
4548 key_name[0] = KS_KEY;
4549 key_name[1] = (key & 0xff);
4550 }
4551 }
4552
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004553 /* Skip all options that are not window-local (used when showing
4554 * an already loaded buffer in a window). */
4555 if ((opt_flags & OPT_WINONLY)
4556 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4557 goto skip;
4558
Bram Moolenaara3227e22006-03-08 21:32:40 +00004559 /* Skip all options that are window-local (used for :vimgrep). */
4560 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4561 && options[opt_idx].var == VAR_WIN)
4562 goto skip;
4563
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004564 /* Disallow changing some options from modelines. */
4565 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004566 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004567 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004568 {
4569 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4570 goto skip;
4571 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004572#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004573 /* In diff mode some options are overruled. This avoids that
4574 * 'foldmethod' becomes "marker" instead of "diff" and that
4575 * "wrap" gets set. */
4576 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004577 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004578 && (
4579#ifdef FEAT_FOLDING
4580 options[opt_idx].indir == PV_FDM ||
4581#endif
4582 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004583 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004584#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004585 }
4586
4587#ifdef HAVE_SANDBOX
4588 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004589 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004590 {
4591 errmsg = (char_u *)_(e_sandbox);
4592 goto skip;
4593 }
4594#endif
4595
4596 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4597 {
4598 arg += len;
4599 cp_val = p_cp;
4600 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4601 {
4602 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4603 {
4604 cp_val = FALSE;
4605 arg += 3;
4606 }
4607 else /* "opt&vi": set to Vi default */
4608 {
4609 cp_val = TRUE;
4610 arg += 2;
4611 }
4612 }
4613 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004614 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 {
4616 errmsg = e_trailing;
4617 goto skip;
4618 }
4619 }
4620
4621 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004622 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4623 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004624 */
4625 if (nextchar == '?'
4626 || (prefix == 1
4627 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4628 && !(flags & P_BOOL)))
4629 {
4630 /*
4631 * print value
4632 */
4633 if (did_show)
4634 msg_putchar('\n'); /* cursor below last one */
4635 else
4636 {
4637 gotocmdline(TRUE); /* cursor at status line */
4638 did_show = TRUE; /* remember that we did a line */
4639 }
4640 if (opt_idx >= 0)
4641 {
4642 showoneopt(&options[opt_idx], opt_flags);
4643#ifdef FEAT_EVAL
4644 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004645 {
4646 /* Mention where the option was last set. */
4647 if (varp == options[opt_idx].var)
4648 last_set_msg(options[opt_idx].scriptID);
4649 else if ((int)options[opt_idx].indir & PV_WIN)
4650 last_set_msg(curwin->w_p_scriptID[
4651 (int)options[opt_idx].indir & PV_MASK]);
4652 else if ((int)options[opt_idx].indir & PV_BUF)
4653 last_set_msg(curbuf->b_p_scriptID[
4654 (int)options[opt_idx].indir & PV_MASK]);
4655 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004656#endif
4657 }
4658 else
4659 {
4660 char_u *p;
4661
4662 p = find_termcode(key_name);
4663 if (p == NULL)
4664 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004665 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004666 goto skip;
4667 }
4668 else
4669 (void)show_one_termcode(key_name, p, TRUE);
4670 }
4671 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004672 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004673 errmsg = e_trailing;
4674 }
4675 else
4676 {
4677 if (flags & P_BOOL) /* boolean */
4678 {
4679 if (nextchar == '=' || nextchar == ':')
4680 {
4681 errmsg = e_invarg;
4682 goto skip;
4683 }
4684
4685 /*
4686 * ":set opt!": invert
4687 * ":set opt&": reset to default value
4688 * ":set opt<": reset to global value
4689 */
4690 if (nextchar == '!')
4691 value = *(int *)(varp) ^ 1;
4692 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004693 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004694 ((flags & P_VI_DEF) || cp_val)
4695 ? VI_DEFAULT : VIM_DEFAULT];
4696 else if (nextchar == '<')
4697 {
4698 /* For 'autoread' -1 means to use global value. */
4699 if ((int *)varp == &curbuf->b_p_ar
4700 && opt_flags == OPT_LOCAL)
4701 value = -1;
4702 else
4703 value = *(int *)get_varp_scope(&(options[opt_idx]),
4704 OPT_GLOBAL);
4705 }
4706 else
4707 {
4708 /*
4709 * ":set invopt": invert
4710 * ":set opt" or ":set noopt": set or reset
4711 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004712 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004713 {
4714 errmsg = e_trailing;
4715 goto skip;
4716 }
4717 if (prefix == 2) /* inv */
4718 value = *(int *)(varp) ^ 1;
4719 else
4720 value = prefix;
4721 }
4722
4723 errmsg = set_bool_option(opt_idx, varp, (int)value,
4724 opt_flags);
4725 }
4726 else /* numeric or string */
4727 {
4728 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4729 || prefix != 1)
4730 {
4731 errmsg = e_invarg;
4732 goto skip;
4733 }
4734
4735 if (flags & P_NUM) /* numeric */
4736 {
4737 /*
4738 * Different ways to set a number option:
4739 * & set to default value
4740 * < set to global value
4741 * <xx> accept special key codes for 'wildchar'
4742 * c accept any non-digit for 'wildchar'
4743 * [-]0-9 set number
4744 * other error
4745 */
4746 ++arg;
4747 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004748 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004749 ((flags & P_VI_DEF) || cp_val)
4750 ? VI_DEFAULT : VIM_DEFAULT];
4751 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004752 {
4753 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4754 * use the global value. */
4755 if ((long *)varp == &curbuf->b_p_ul
4756 && opt_flags == OPT_LOCAL)
4757 value = NO_LOCAL_UNDOLEVEL;
4758 else
4759 value = *(long *)get_varp_scope(
4760 &(options[opt_idx]), OPT_GLOBAL);
4761 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 else if (((long *)varp == &p_wc
4763 || (long *)varp == &p_wcm)
4764 && (*arg == '<'
4765 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004766 || (*arg != NUL
4767 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004768 && !VIM_ISDIGIT(*arg))))
4769 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004770 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004771 if (value == 0 && (long *)varp != &p_wcm)
4772 {
4773 errmsg = e_invarg;
4774 goto skip;
4775 }
4776 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004777 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4778 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004779 /* Allow negative (for 'undolevels'), octal and
4780 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004781 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4782 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004783 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004784 {
4785 errmsg = e_invarg;
4786 goto skip;
4787 }
4788 }
4789 else
4790 {
4791 errmsg = (char_u *)N_("E521: Number required after =");
4792 goto skip;
4793 }
4794
4795 if (adding)
4796 value = *(long *)varp + value;
4797 if (prepending)
4798 value = *(long *)varp * value;
4799 if (removing)
4800 value = *(long *)varp - value;
4801 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004802 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004803 }
4804 else if (opt_idx >= 0) /* string */
4805 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004806 char_u *save_arg = NULL;
4807 char_u *s = NULL;
4808 char_u *oldval = NULL; /* previous value if *varp */
4809 char_u *newval;
4810 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004811#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004812 char_u *saved_origval = NULL;
4813 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004814#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004815 unsigned newlen;
4816 int comma;
4817 int bs;
4818 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004819 was allocated */
4820
4821 /* When using ":set opt=val" for a global option
4822 * with a local value the local value will be
4823 * reset, use the global value here. */
4824 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004825 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004826 varp = options[opt_idx].var;
4827
4828 /* The old value is kept until we are sure that the
4829 * new value is valid. */
4830 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004831
4832 /* When setting the local value of a global
4833 * option, the old value may be the global value. */
4834 if (((int)options[opt_idx].indir & PV_BOTH)
4835 && (opt_flags & OPT_LOCAL))
4836 origval = *(char_u **)get_varp(
4837 &options[opt_idx]);
4838 else
4839 origval = oldval;
4840
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 if (nextchar == '&') /* set to default val */
4842 {
4843 newval = options[opt_idx].def_val[
4844 ((flags & P_VI_DEF) || cp_val)
4845 ? VI_DEFAULT : VIM_DEFAULT];
4846 if ((char_u **)varp == &p_bg)
4847 {
4848 /* guess the value of 'background' */
4849#ifdef FEAT_GUI
4850 if (gui.in_use)
4851 newval = gui_bg_default();
4852 else
4853#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004854 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004855 }
4856
4857 /* expand environment variables and ~ (since the
4858 * default value was already expanded, only
4859 * required when an environment variable was set
4860 * later */
4861 if (newval == NULL)
4862 newval = empty_option;
4863 else
4864 {
4865 s = option_expand(opt_idx, newval);
4866 if (s == NULL)
4867 s = newval;
4868 newval = vim_strsave(s);
4869 }
4870 new_value_alloced = TRUE;
4871 }
4872 else if (nextchar == '<') /* set to global val */
4873 {
4874 newval = vim_strsave(*(char_u **)get_varp_scope(
4875 &(options[opt_idx]), OPT_GLOBAL));
4876 new_value_alloced = TRUE;
4877 }
4878 else
4879 {
4880 ++arg; /* jump to after the '=' or ':' */
4881
4882 /*
4883 * Set 'keywordprg' to ":help" if an empty
4884 * value was passed to :set by the user.
4885 * Misuse errbuf[] for the resulting string.
4886 */
4887 if (varp == (char_u *)&p_kp
4888 && (*arg == NUL || *arg == ' '))
4889 {
4890 STRCPY(errbuf, ":help");
4891 save_arg = arg;
4892 arg = errbuf;
4893 }
4894 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004895 * Convert 'backspace' number to string, for
4896 * adding, prepending and removing string.
4897 */
4898 else if (varp == (char_u *)&p_bs
4899 && VIM_ISDIGIT(**(char_u **)varp))
4900 {
4901 i = getdigits((char_u **)varp);
4902 switch (i)
4903 {
4904 case 0:
4905 *(char_u **)varp = empty_option;
4906 break;
4907 case 1:
4908 *(char_u **)varp = vim_strsave(
4909 (char_u *)"indent,eol");
4910 break;
4911 case 2:
4912 *(char_u **)varp = vim_strsave(
4913 (char_u *)"indent,eol,start");
4914 break;
4915 }
4916 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004917 if (origval == oldval)
4918 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004919 oldval = *(char_u **)varp;
4920 }
4921 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004922 * Convert 'whichwrap' number to string, for
4923 * backwards compatibility with Vim 3.0.
4924 * Misuse errbuf[] for the resulting string.
4925 */
4926 else if (varp == (char_u *)&p_ww
4927 && VIM_ISDIGIT(*arg))
4928 {
4929 *errbuf = NUL;
4930 i = getdigits(&arg);
4931 if (i & 1)
4932 STRCAT(errbuf, "b,");
4933 if (i & 2)
4934 STRCAT(errbuf, "s,");
4935 if (i & 4)
4936 STRCAT(errbuf, "h,l,");
4937 if (i & 8)
4938 STRCAT(errbuf, "<,>,");
4939 if (i & 16)
4940 STRCAT(errbuf, "[,],");
4941 if (*errbuf != NUL) /* remove trailing , */
4942 errbuf[STRLEN(errbuf) - 1] = NUL;
4943 save_arg = arg;
4944 arg = errbuf;
4945 }
4946 /*
4947 * Remove '>' before 'dir' and 'bdir', for
4948 * backwards compatibility with version 3.0
4949 */
4950 else if ( *arg == '>'
4951 && (varp == (char_u *)&p_dir
4952 || varp == (char_u *)&p_bdir))
4953 {
4954 ++arg;
4955 }
4956
Bram Moolenaar071d4272004-06-13 20:20:40 +00004957 /*
4958 * Copy the new string into allocated memory.
4959 * Can't use set_string_option_direct(), because
4960 * we need to remove the backslashes.
4961 */
4962 /* get a bit too much */
4963 newlen = (unsigned)STRLEN(arg) + 1;
4964 if (adding || prepending || removing)
4965 newlen += (unsigned)STRLEN(origval) + 1;
4966 newval = alloc(newlen);
4967 if (newval == NULL) /* out of mem, don't change */
4968 break;
4969 s = newval;
4970
4971 /*
4972 * Copy the string, skip over escaped chars.
4973 * For MS-DOS and WIN32 backslashes before normal
4974 * file name characters are not removed, and keep
4975 * backslash at start, for "\\machine\path", but
4976 * do remove it for "\\\\machine\\path".
4977 * The reverse is found in ExpandOldSetting().
4978 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004979 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004980 {
4981 if (*arg == '\\' && arg[1] != NUL
4982#ifdef BACKSLASH_IN_FILENAME
4983 && !((flags & P_EXPAND)
4984 && vim_isfilec(arg[1])
4985 && (arg[1] != '\\'
4986 || (s == newval
4987 && arg[2] != '\\')))
4988#endif
4989 )
4990 ++arg; /* remove backslash */
4991#ifdef FEAT_MBYTE
4992 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004993 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004994 {
4995 /* copy multibyte char */
4996 mch_memmove(s, arg, (size_t)i);
4997 arg += i;
4998 s += i;
4999 }
5000 else
5001#endif
5002 *s++ = *arg++;
5003 }
5004 *s = NUL;
5005
5006 /*
5007 * Expand environment variables and ~.
5008 * Don't do it when adding without inserting a
5009 * comma.
5010 */
5011 if (!(adding || prepending || removing)
5012 || (flags & P_COMMA))
5013 {
5014 s = option_expand(opt_idx, newval);
5015 if (s != NULL)
5016 {
5017 vim_free(newval);
5018 newlen = (unsigned)STRLEN(s) + 1;
5019 if (adding || prepending || removing)
5020 newlen += (unsigned)STRLEN(origval) + 1;
5021 newval = alloc(newlen);
5022 if (newval == NULL)
5023 break;
5024 STRCPY(newval, s);
5025 }
5026 }
5027
5028 /* locate newval[] in origval[] when removing it
5029 * and when adding to avoid duplicates */
5030 i = 0; /* init for GCC */
5031 if (removing || (flags & P_NODUP))
5032 {
5033 i = (int)STRLEN(newval);
5034 bs = 0;
5035 for (s = origval; *s; ++s)
5036 {
5037 if ((!(flags & P_COMMA)
5038 || s == origval
5039 || (s[-1] == ',' && !(bs & 1)))
5040 && STRNCMP(s, newval, i) == 0
5041 && (!(flags & P_COMMA)
5042 || s[i] == ','
5043 || s[i] == NUL))
5044 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005045 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005046 * even number of backslashes or a single
5047 * backslash preceded by a comma before it
5048 * is recognized as a separator */
5049 if ((s > origval + 1
5050 && s[-1] == '\\'
5051 && s[-2] != ',')
5052 || (s == origval + 1
5053 && s[-1] == '\\'))
5054
Bram Moolenaar071d4272004-06-13 20:20:40 +00005055 ++bs;
5056 else
5057 bs = 0;
5058 }
5059
5060 /* do not add if already there */
5061 if ((adding || prepending) && *s)
5062 {
5063 prepending = FALSE;
5064 adding = FALSE;
5065 STRCPY(newval, origval);
5066 }
5067 }
5068
5069 /* concatenate the two strings; add a ',' if
5070 * needed */
5071 if (adding || prepending)
5072 {
5073 comma = ((flags & P_COMMA) && *origval != NUL
5074 && *newval != NUL);
5075 if (adding)
5076 {
5077 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005078 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005079 if (comma && i > 1
5080 && (flags & P_ONECOMMA) == P_ONECOMMA
5081 && origval[i - 1] == ','
5082 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005083 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005084 mch_memmove(newval + i + comma, newval,
5085 STRLEN(newval) + 1);
5086 mch_memmove(newval, origval, (size_t)i);
5087 }
5088 else
5089 {
5090 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005091 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005092 }
5093 if (comma)
5094 newval[i] = ',';
5095 }
5096
5097 /* Remove newval[] from origval[]. (Note: "i" has
5098 * been set above and is used here). */
5099 if (removing)
5100 {
5101 STRCPY(newval, origval);
5102 if (*s)
5103 {
5104 /* may need to remove a comma */
5105 if (flags & P_COMMA)
5106 {
5107 if (s == origval)
5108 {
5109 /* include comma after string */
5110 if (s[i] == ',')
5111 ++i;
5112 }
5113 else
5114 {
5115 /* include comma before string */
5116 --s;
5117 ++i;
5118 }
5119 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005120 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121 }
5122 }
5123
5124 if (flags & P_FLAGLIST)
5125 {
5126 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005127 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005128 {
5129 /* if options have P_FLAGLIST and
5130 * P_ONECOMMA such as 'whichwrap' */
5131 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005132 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005133 if (*s != ',' && *(s + 1) == ','
5134 && vim_strchr(s + 2, *s) != NULL)
5135 {
5136 /* Remove the duplicated value and
5137 * the next comma. */
5138 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005139 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005140 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005141 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005142 else
5143 {
5144 if ((!(flags & P_COMMA) || *s != ',')
5145 && vim_strchr(s + 1, *s) != NULL)
5146 {
5147 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005148 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005149 }
5150 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005151 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005153 }
5154
5155 if (save_arg != NULL) /* number for 'whichwrap' */
5156 arg = save_arg;
5157 new_value_alloced = TRUE;
5158 }
5159
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005160 /*
5161 * Set the new value.
5162 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163 *(char_u **)(varp) = newval;
5164
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005165#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005166 if (!starting
5167# ifdef FEAT_CRYPT
5168 && options[opt_idx].indir != PV_KEY
5169# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005170 && origval != NULL && newval != NULL)
5171 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005172 /* origval may be freed by
5173 * did_set_string_option(), make a copy. */
5174 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005175 /* newval (and varp) may become invalid if the
5176 * buffer is closed by autocommands. */
5177 saved_newval = vim_strsave(newval);
5178 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005179#endif
5180
Bram Moolenaar071d4272004-06-13 20:20:40 +00005181 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005182 * ":set" on local options. Note: when setting 'syntax'
5183 * or 'filetype' autocommands may be triggered that can
5184 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5186 new_value_alloced, oldval, errbuf, opt_flags);
5187
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005188#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005189 if (errmsg == NULL)
5190 trigger_optionsset_string(opt_idx, opt_flags,
5191 saved_origval, saved_newval);
5192 vim_free(saved_origval);
5193 vim_free(saved_newval);
5194#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 /* If error detected, print the error message. */
5196 if (errmsg != NULL)
5197 goto skip;
5198 }
5199 else /* key code option */
5200 {
5201 char_u *p;
5202
5203 if (nextchar == '&')
5204 {
5205 if (add_termcap_entry(key_name, TRUE) == FAIL)
5206 errmsg = (char_u *)N_("E522: Not found in termcap");
5207 }
5208 else
5209 {
5210 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005211 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005212 if (*p == '\\' && p[1] != NUL)
5213 ++p;
5214 nextchar = *p;
5215 *p = NUL;
5216 add_termcode(key_name, arg, FALSE);
5217 *p = nextchar;
5218 }
5219 if (full_screen)
5220 ttest(FALSE);
5221 redraw_all_later(CLEAR);
5222 }
5223 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005224
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005226 did_set_option(opt_idx, opt_flags,
5227 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 }
5229
5230skip:
5231 /*
5232 * Advance to next argument.
5233 * - skip until a blank found, taking care of backslashes
5234 * - skip blanks
5235 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5236 */
5237 for (i = 0; i < 2 ; ++i)
5238 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005239 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005240 if (*arg++ == '\\' && *arg != NUL)
5241 ++arg;
5242 arg = skipwhite(arg);
5243 if (*arg != '=')
5244 break;
5245 }
5246 }
5247
5248 if (errmsg != NULL)
5249 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005250 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005251 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005252 if (i + (arg - startarg) < IOSIZE)
5253 {
5254 /* append the argument with the error */
5255 STRCAT(IObuff, ": ");
5256 mch_memmove(IObuff + i, startarg, (arg - startarg));
5257 IObuff[i + (arg - startarg)] = NUL;
5258 }
5259 /* make sure all characters are printable */
5260 trans_characters(IObuff, IOSIZE);
5261
5262 ++no_wait_return; /* wait_return done later */
5263 emsg(IObuff); /* show error highlighted */
5264 --no_wait_return;
5265
5266 return FAIL;
5267 }
5268
5269 arg = skipwhite(arg);
5270 }
5271
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005272theend:
5273 if (silent_mode && did_show)
5274 {
5275 /* After displaying option values in silent mode. */
5276 silent_mode = FALSE;
5277 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5278 msg_putchar('\n');
5279 cursor_on(); /* msg_start() switches it off */
5280 out_flush();
5281 silent_mode = TRUE;
5282 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5283 }
5284
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285 return OK;
5286}
5287
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005288/*
5289 * Call this when an option has been given a new value through a user command.
5290 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5291 */
5292 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005293did_set_option(
5294 int opt_idx,
5295 int opt_flags, /* possibly with OPT_MODELINE */
5296 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005297{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005298 long_u *p;
5299
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005300 options[opt_idx].flags |= P_WAS_SET;
5301
5302 /* When an option is set in the sandbox, from a modeline or in secure mode
5303 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005304 * flag. */
5305 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005306 if (secure
5307#ifdef HAVE_SANDBOX
5308 || sandbox != 0
5309#endif
5310 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005311 *p = *p | P_INSECURE;
5312 else if (new_value)
5313 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005314}
5315
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005317illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005318{
5319 if (errbuf == NULL)
5320 return (char_u *)"";
5321 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005322 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323 return errbuf;
5324}
5325
5326/*
5327 * Convert a key name or string into a key value.
5328 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005329 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005331 int
5332string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333{
5334 if (*arg == '<')
5335 return find_key_option(arg + 1);
5336 if (*arg == '^')
5337 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005338 if (multi_byte)
5339 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340 return *arg;
5341}
5342
5343#ifdef FEAT_CMDWIN
5344/*
5345 * Check value of 'cedit' and set cedit_key.
5346 * Returns NULL if value is OK, error message otherwise.
5347 */
5348 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005349check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350{
5351 int n;
5352
5353 if (*p_cedit == NUL)
5354 cedit_key = -1;
5355 else
5356 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005357 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358 if (vim_isprintc(n))
5359 return e_invarg;
5360 cedit_key = n;
5361 }
5362 return NULL;
5363}
5364#endif
5365
5366#ifdef FEAT_TITLE
5367/*
5368 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5369 * maketitle() to create and display it.
5370 * When switching the title or icon off, call mch_restore_title() to get
5371 * the old value back.
5372 */
5373 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005374did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375{
5376 if (starting != NO_SCREEN
5377#ifdef FEAT_GUI
5378 && !gui.starting
5379#endif
5380 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005382}
5383#endif
5384
5385/*
5386 * set_options_bin - called when 'bin' changes value.
5387 */
5388 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005389set_options_bin(
5390 int oldval,
5391 int newval,
5392 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005393{
5394 /*
5395 * The option values that are changed when 'bin' changes are
5396 * copied when 'bin is set and restored when 'bin' is reset.
5397 */
5398 if (newval)
5399 {
5400 if (!oldval) /* switched on */
5401 {
5402 if (!(opt_flags & OPT_GLOBAL))
5403 {
5404 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5405 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5406 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5407 curbuf->b_p_et_nobin = curbuf->b_p_et;
5408 }
5409 if (!(opt_flags & OPT_LOCAL))
5410 {
5411 p_tw_nobin = p_tw;
5412 p_wm_nobin = p_wm;
5413 p_ml_nobin = p_ml;
5414 p_et_nobin = p_et;
5415 }
5416 }
5417
5418 if (!(opt_flags & OPT_GLOBAL))
5419 {
5420 curbuf->b_p_tw = 0; /* no automatic line wrap */
5421 curbuf->b_p_wm = 0; /* no automatic line wrap */
5422 curbuf->b_p_ml = 0; /* no modelines */
5423 curbuf->b_p_et = 0; /* no expandtab */
5424 }
5425 if (!(opt_flags & OPT_LOCAL))
5426 {
5427 p_tw = 0;
5428 p_wm = 0;
5429 p_ml = FALSE;
5430 p_et = FALSE;
5431 p_bin = TRUE; /* needed when called for the "-b" argument */
5432 }
5433 }
5434 else if (oldval) /* switched off */
5435 {
5436 if (!(opt_flags & OPT_GLOBAL))
5437 {
5438 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5439 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5440 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5441 curbuf->b_p_et = curbuf->b_p_et_nobin;
5442 }
5443 if (!(opt_flags & OPT_LOCAL))
5444 {
5445 p_tw = p_tw_nobin;
5446 p_wm = p_wm_nobin;
5447 p_ml = p_ml_nobin;
5448 p_et = p_et_nobin;
5449 }
5450 }
5451}
5452
5453#ifdef FEAT_VIMINFO
5454/*
5455 * Find the parameter represented by the given character (eg ', :, ", or /),
5456 * and return its associated value in the 'viminfo' string.
5457 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005458 * If the parameter is not specified in the string or there is no following
5459 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460 */
5461 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005462get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463{
5464 char_u *p;
5465
5466 p = find_viminfo_parameter(type);
5467 if (p != NULL && VIM_ISDIGIT(*p))
5468 return atoi((char *)p);
5469 return -1;
5470}
5471
5472/*
5473 * Find the parameter represented by the given character (eg ''', ':', '"', or
5474 * '/') in the 'viminfo' option and return a pointer to the string after it.
5475 * Return NULL if the parameter is not specified in the string.
5476 */
5477 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005478find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005479{
5480 char_u *p;
5481
5482 for (p = p_viminfo; *p; ++p)
5483 {
5484 if (*p == type)
5485 return p + 1;
5486 if (*p == 'n') /* 'n' is always the last one */
5487 break;
5488 p = vim_strchr(p, ','); /* skip until next ',' */
5489 if (p == NULL) /* hit the end without finding parameter */
5490 break;
5491 }
5492 return NULL;
5493}
5494#endif
5495
5496/*
5497 * Expand environment variables for some string options.
5498 * These string options cannot be indirect!
5499 * If "val" is NULL expand the current value of the option.
5500 * Return pointer to NameBuff, or NULL when not expanded.
5501 */
5502 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005503option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504{
5505 /* if option doesn't need expansion nothing to do */
5506 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5507 return NULL;
5508
5509 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5510 * expand_env() would truncate the string. */
5511 if (val != NULL && STRLEN(val) > MAXPATHL)
5512 return NULL;
5513
5514 if (val == NULL)
5515 val = *(char_u **)options[opt_idx].var;
5516
5517 /*
5518 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5519 * Escape spaces when expanding 'tags', they are used to separate file
5520 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005521 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522 */
5523 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005524 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005525#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005526 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5527#endif
5528 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5530 return NULL;
5531
5532 return NameBuff;
5533}
5534
5535/*
5536 * After setting various option values: recompute variables that depend on
5537 * option values.
5538 */
5539 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005540didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541{
5542 /* initialize the table for 'iskeyword' et.al. */
5543 (void)init_chartab();
5544
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005545#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005547#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005548 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005549 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550#ifdef FEAT_SESSION
5551 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5552 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5553#endif
5554#ifdef FEAT_FOLDING
5555 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5556#endif
5557 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005558 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559#ifdef FEAT_VIRTUALEDIT
5560 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5561#endif
5562#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5563 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5564#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005565#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005566 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005567 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005568 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005569 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005570#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5572 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5573#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005574#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5576#endif
5577#ifdef FEAT_CMDWIN
5578 /* set cedit_key */
5579 (void)check_cedit();
5580#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005581#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005582 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005583#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005584#ifdef FEAT_LINEBREAK
5585 /* initialize the table for 'breakat'. */
5586 fill_breakat_flags();
5587#endif
5588
5589}
5590
5591/*
5592 * More side effects of setting options.
5593 */
5594 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005595didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005596{
5597 /* Initialize the highlight_attr[] table. */
5598 (void)highlight_changed();
5599
5600 /* Parse default for 'wildmode' */
5601 check_opt_wim();
5602
5603 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005604 /* Parse default for 'fillchars'. */
5605 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005606
5607#ifdef FEAT_CLIPBOARD
5608 /* Parse default for 'clipboard' */
5609 (void)check_clipboard_option();
5610#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611}
5612
5613/*
5614 * Check for string options that are NULL (normally only termcap options).
5615 */
5616 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005617check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005618{
5619 int opt_idx;
5620
5621 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5622 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5623 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5624}
5625
5626/*
5627 * Check string options in a buffer for NULL value.
5628 */
5629 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005630check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005632 check_string_option(&buf->b_p_bh);
5633 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005634#ifdef FEAT_MBYTE
5635 check_string_option(&buf->b_p_fenc);
5636#endif
5637 check_string_option(&buf->b_p_ff);
5638#ifdef FEAT_FIND_ID
5639 check_string_option(&buf->b_p_def);
5640 check_string_option(&buf->b_p_inc);
5641# ifdef FEAT_EVAL
5642 check_string_option(&buf->b_p_inex);
5643# endif
5644#endif
5645#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5646 check_string_option(&buf->b_p_inde);
5647 check_string_option(&buf->b_p_indk);
5648#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005649#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5650 check_string_option(&buf->b_p_bexpr);
5651#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005652#if defined(FEAT_CRYPT)
5653 check_string_option(&buf->b_p_cm);
5654#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005655 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005656#if defined(FEAT_EVAL)
5657 check_string_option(&buf->b_p_fex);
5658#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005659#ifdef FEAT_CRYPT
5660 check_string_option(&buf->b_p_key);
5661#endif
5662 check_string_option(&buf->b_p_kp);
5663 check_string_option(&buf->b_p_mps);
5664 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005665 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666 check_string_option(&buf->b_p_isk);
5667#ifdef FEAT_COMMENTS
5668 check_string_option(&buf->b_p_com);
5669#endif
5670#ifdef FEAT_FOLDING
5671 check_string_option(&buf->b_p_cms);
5672#endif
5673 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005674#ifdef FEAT_TEXTOBJ
5675 check_string_option(&buf->b_p_qe);
5676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677#ifdef FEAT_SYN_HL
5678 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005679 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005680#endif
5681#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005682 check_string_option(&buf->b_s.b_p_spc);
5683 check_string_option(&buf->b_s.b_p_spf);
5684 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685#endif
5686#ifdef FEAT_SEARCHPATH
5687 check_string_option(&buf->b_p_sua);
5688#endif
5689#ifdef FEAT_CINDENT
5690 check_string_option(&buf->b_p_cink);
5691 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005692 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5696 check_string_option(&buf->b_p_cinw);
5697#endif
5698#ifdef FEAT_INS_EXPAND
5699 check_string_option(&buf->b_p_cpt);
5700#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005701#ifdef FEAT_COMPL_FUNC
5702 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005703 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705#ifdef FEAT_KEYMAP
5706 check_string_option(&buf->b_p_keymap);
5707#endif
5708#ifdef FEAT_QUICKFIX
5709 check_string_option(&buf->b_p_gp);
5710 check_string_option(&buf->b_p_mp);
5711 check_string_option(&buf->b_p_efm);
5712#endif
5713 check_string_option(&buf->b_p_ep);
5714 check_string_option(&buf->b_p_path);
5715 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005716 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717#ifdef FEAT_INS_EXPAND
5718 check_string_option(&buf->b_p_dict);
5719 check_string_option(&buf->b_p_tsr);
5720#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005721#ifdef FEAT_LISP
5722 check_string_option(&buf->b_p_lw);
5723#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005724 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005725#ifdef FEAT_MBYTE
5726 check_string_option(&buf->b_p_menc);
5727#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728}
5729
5730/*
5731 * Free the string allocated for an option.
5732 * Checks for the string being empty_option. This may happen if we're out of
5733 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5734 * check_options().
5735 * Does NOT check for P_ALLOCED flag!
5736 */
5737 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005738free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739{
5740 if (p != empty_option)
5741 vim_free(p);
5742}
5743
5744 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005745clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746{
5747 if (*pp != empty_option)
5748 vim_free(*pp);
5749 *pp = empty_option;
5750}
5751
5752 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005753check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754{
5755 if (*pp == NULL)
5756 *pp = empty_option;
5757}
5758
5759/*
5760 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5761 */
5762 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005763set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764{
5765 int opt_idx;
5766
5767 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5768 if (options[opt_idx].var == (char_u *)p)
5769 {
5770 options[opt_idx].flags |= P_ALLOCED;
5771 return;
5772 }
5773 return; /* cannot happen: didn't find it! */
5774}
5775
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005776#if defined(FEAT_EVAL) || defined(PROTO)
5777/*
5778 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5779 * Return FALSE when it wasn't.
5780 * Return -1 for an unknown option.
5781 */
5782 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005783was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005784{
5785 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005786 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005787
5788 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005789 {
5790 flagp = insecure_flag(idx, opt_flags);
5791 return (*flagp & P_INSECURE) != 0;
5792 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005793 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005794 return -1;
5795}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005796
5797/*
5798 * Get a pointer to the flags used for the P_INSECURE flag of option
5799 * "opt_idx". For some local options a local flags field is used.
5800 */
5801 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005802insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005803{
5804 if (opt_flags & OPT_LOCAL)
5805 switch ((int)options[opt_idx].indir)
5806 {
5807#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005808 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005809#endif
5810#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005811# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005812 case PV_FDE: return &curwin->w_p_fde_flags;
5813 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005814# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005815# ifdef FEAT_BEVAL
5816 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5817# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005818# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005819 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005820# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005821 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005822# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005823 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005824# endif
5825#endif
5826 }
5827
5828 /* Nothing special, return global flags field. */
5829 return &options[opt_idx].flags;
5830}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005831#endif
5832
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005833#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005834static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005835
5836/*
5837 * Redraw the window title and/or tab page text later.
5838 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005839static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005840{
5841 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005842 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005843}
5844#endif
5845
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846/*
5847 * Set a string option to a new value (without checking the effect).
5848 * The string is copied into allocated memory.
5849 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005850 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005851 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 */
5853 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005854set_string_option_direct(
5855 char_u *name,
5856 int opt_idx,
5857 char_u *val,
5858 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5859 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860{
5861 char_u *s;
5862 char_u **varp;
5863 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005864 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865
Bram Moolenaar89d40322006-08-29 15:30:07 +00005866 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005868 idx = findoption(name);
5869 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005870 {
5871 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005872 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875 }
5876
Bram Moolenaar89d40322006-08-29 15:30:07 +00005877 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878 return;
5879
5880 s = vim_strsave(val);
5881 if (s != NULL)
5882 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005883 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005884 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005885 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 free_string_option(*varp);
5887 *varp = s;
5888
5889 /* For buffer/window local option may also set the global value. */
5890 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005891 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892
Bram Moolenaar89d40322006-08-29 15:30:07 +00005893 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894
5895 /* When setting both values of a global option with a local value,
5896 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005897 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 {
5899 free_string_option(*varp);
5900 *varp = empty_option;
5901 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005902# ifdef FEAT_EVAL
5903 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005904 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005905 set_sid == 0 ? current_SID : set_sid);
5906# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 }
5908}
5909
5910/*
5911 * Set global value for string option when it's a local option.
5912 */
5913 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005914set_string_option_global(
5915 int opt_idx, /* option index */
5916 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917{
5918 char_u **p, *s;
5919
5920 /* the global value is always allocated */
5921 if (options[opt_idx].var == VAR_WIN)
5922 p = (char_u **)GLOBAL_WO(varp);
5923 else
5924 p = (char_u **)options[opt_idx].var;
5925 if (options[opt_idx].indir != PV_NONE
5926 && p != varp
5927 && (s = vim_strsave(*varp)) != NULL)
5928 {
5929 free_string_option(*p);
5930 *p = s;
5931 }
5932}
5933
5934/*
5935 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005936 *
5937 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005939 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005940set_string_option(
5941 int opt_idx,
5942 char_u *value,
5943 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944{
5945 char_u *s;
5946 char_u **varp;
5947 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005948#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005949 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005950 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005951#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005952 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953
5954 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005955 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956
5957 s = vim_strsave(value);
5958 if (s != NULL)
5959 {
5960 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5961 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005962 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 ? OPT_GLOBAL : OPT_LOCAL)
5964 : opt_flags);
5965 oldval = *varp;
5966 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005967
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005968#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005969 if (!starting
5970# ifdef FEAT_CRYPT
5971 && options[opt_idx].indir != PV_KEY
5972# endif
5973 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005974 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005975 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005976 saved_newval = vim_strsave(s);
5977 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005978#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005979 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5980 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005981 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005982
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005983#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005984 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005985 if (r == NULL)
5986 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005988 vim_free(saved_oldval);
5989 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005990#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005992 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993}
5994
5995/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005996 * Return TRUE if "val" is a valid 'filetype' name.
5997 * Also used for 'syntax' and 'keymap'.
5998 */
5999 static int
6000valid_filetype(char_u *val)
6001{
6002 char_u *s;
6003
6004 for (s = val; *s != NUL; ++s)
6005 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6006 return FALSE;
6007 return TRUE;
6008}
6009
6010/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011 * Handle string options that need some action to perform when changed.
6012 * Returns NULL for success, or an error message for an error.
6013 */
6014 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006015did_set_string_option(
6016 int opt_idx, /* index in options[] table */
6017 char_u **varp, /* pointer to the option variable */
6018 int new_value_alloced, /* new value was allocated */
6019 char_u *oldval, /* previous value of the option */
6020 char_u *errbuf, /* buffer for errors, or NULL */
6021 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006022{
6023 char_u *errmsg = NULL;
6024 char_u *s, *p;
6025 int did_chartab = FALSE;
6026 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006027 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006028#ifdef FEAT_GUI
6029 /* set when changing an option that only requires a redraw in the GUI */
6030 int redraw_gui_only = FALSE;
6031#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006032 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006033#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6034 int did_swaptcap = FALSE;
6035#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006036
6037 /* Get the global option to compare with, otherwise we would have to check
6038 * two values for all local options. */
6039 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6040
6041 /* Disallow changing some options from secure mode */
6042 if ((secure
6043#ifdef HAVE_SANDBOX
6044 || sandbox != 0
6045#endif
6046 ) && (options[opt_idx].flags & P_SECURE))
6047 {
6048 errmsg = e_secure;
6049 }
6050
Bram Moolenaar7554da42016-11-25 22:04:13 +01006051 /* Check for a "normal" directory or file name in some options. Disallow a
6052 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006053 * are often illegal in a file name. Be more permissive if "secure" is off.
6054 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006055 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006056 && vim_strpbrk(*varp, (char_u *)(secure
6057 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006058 || ((options[opt_idx].flags & P_NDNAME)
6059 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006060 {
6061 errmsg = e_invarg;
6062 }
6063
Bram Moolenaar071d4272004-06-13 20:20:40 +00006064 /* 'term' */
6065 else if (varp == &T_NAME)
6066 {
6067 if (T_NAME[0] == NUL)
6068 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6069#ifdef FEAT_GUI
6070 if (gui.in_use)
6071 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6072 else if (term_is_gui(T_NAME))
6073 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6074#endif
6075 else if (set_termname(T_NAME) == FAIL)
6076 errmsg = (char_u *)N_("E522: Not found in termcap");
6077 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006078 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 /* Screen colors may have changed. */
6080 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006081
6082 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6083 * P_ALLOCED flag on 'term'. */
6084 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006085 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006086 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087 }
6088
6089 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006090 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006092 char_u *bkc = p_bkc;
6093 unsigned int *flags = &bkc_flags;
6094
6095 if (opt_flags & OPT_LOCAL)
6096 {
6097 bkc = curbuf->b_p_bkc;
6098 flags = &curbuf->b_bkc_flags;
6099 }
6100
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006101 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6102 /* make the local value empty: use the global value */
6103 *flags = 0;
6104 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006106 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6107 errmsg = e_invarg;
6108 if ((((int)*flags & BKC_AUTO) != 0)
6109 + (((int)*flags & BKC_YES) != 0)
6110 + (((int)*flags & BKC_NO) != 0) != 1)
6111 {
6112 /* Must have exactly one of "auto", "yes" and "no". */
6113 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6114 errmsg = e_invarg;
6115 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 }
6117 }
6118
6119 /* 'backupext' and 'patchmode' */
6120 else if (varp == &p_bex || varp == &p_pm)
6121 {
6122 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6123 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6124 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6125 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006126#ifdef FEAT_LINEBREAK
6127 /* 'breakindentopt' */
6128 else if (varp == &curwin->w_p_briopt)
6129 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006130 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006131 errmsg = e_invarg;
6132 }
6133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134
6135 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006136 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006138 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139 */
6140 else if ( varp == &p_isi
6141 || varp == &(curbuf->b_p_isk)
6142 || varp == &p_isp
6143 || varp == &p_isf)
6144 {
6145 if (init_chartab() == FAIL)
6146 {
6147 did_chartab = TRUE; /* need to restore it below */
6148 errmsg = e_invarg; /* error in value */
6149 }
6150 }
6151
6152 /* 'helpfile' */
6153 else if (varp == &p_hf)
6154 {
6155 /* May compute new values for $VIM and $VIMRUNTIME */
6156 if (didset_vim)
6157 {
6158 vim_setenv((char_u *)"VIM", (char_u *)"");
6159 didset_vim = FALSE;
6160 }
6161 if (didset_vimruntime)
6162 {
6163 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6164 didset_vimruntime = FALSE;
6165 }
6166 }
6167
Bram Moolenaar1a384422010-07-14 19:53:30 +02006168#ifdef FEAT_SYN_HL
6169 /* 'colorcolumn' */
6170 else if (varp == &curwin->w_p_cc)
6171 errmsg = check_colorcolumn(curwin);
6172#endif
6173
Bram Moolenaar071d4272004-06-13 20:20:40 +00006174#ifdef FEAT_MULTI_LANG
6175 /* 'helplang' */
6176 else if (varp == &p_hlg)
6177 {
6178 /* Check for "", "ab", "ab,cd", etc. */
6179 for (s = p_hlg; *s != NUL; s += 3)
6180 {
6181 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6182 {
6183 errmsg = e_invarg;
6184 break;
6185 }
6186 if (s[2] == NUL)
6187 break;
6188 }
6189 }
6190#endif
6191
6192 /* 'highlight' */
6193 else if (varp == &p_hl)
6194 {
6195 if (highlight_changed() == FAIL)
6196 errmsg = e_invarg; /* invalid flags */
6197 }
6198
6199 /* 'nrformats' */
6200 else if (gvarp == &p_nf)
6201 {
6202 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6203 errmsg = e_invarg;
6204 }
6205
6206#ifdef FEAT_SESSION
6207 /* 'sessionoptions' */
6208 else if (varp == &p_ssop)
6209 {
6210 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6211 errmsg = e_invarg;
6212 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6213 {
6214 /* Don't allow both "sesdir" and "curdir". */
6215 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6216 errmsg = e_invarg;
6217 }
6218 }
6219 /* 'viewoptions' */
6220 else if (varp == &p_vop)
6221 {
6222 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6223 errmsg = e_invarg;
6224 }
6225#endif
6226
6227 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006228 else if (varp == &p_sbo)
6229 {
6230 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6231 errmsg = e_invarg;
6232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006233
6234 /* 'ambiwidth' */
6235#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006236 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237 {
6238 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6239 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006240 else if (set_chars_option(&p_lcs) != NULL)
6241 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006242 else if (set_chars_option(&p_fcs) != NULL)
6243 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244 }
6245#endif
6246
6247 /* 'background' */
6248 else if (varp == &p_bg)
6249 {
6250 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6251 {
6252#ifdef FEAT_EVAL
6253 int dark = (*p_bg == 'd');
6254#endif
6255
6256 init_highlight(FALSE, FALSE);
6257
6258#ifdef FEAT_EVAL
6259 if (dark != (*p_bg == 'd')
6260 && get_var_value((char_u *)"g:colors_name") != NULL)
6261 {
6262 /* The color scheme must have set 'background' back to another
6263 * value, that's not what we want here. Disable the color
6264 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006265 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266 free_string_option(p_bg);
6267 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6268 check_string_option(&p_bg);
6269 init_highlight(FALSE, FALSE);
6270 }
6271#endif
6272 }
6273 else
6274 errmsg = e_invarg;
6275 }
6276
6277 /* 'wildmode' */
6278 else if (varp == &p_wim)
6279 {
6280 if (check_opt_wim() == FAIL)
6281 errmsg = e_invarg;
6282 }
6283
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006284#ifdef FEAT_CMDL_COMPL
6285 /* 'wildoptions' */
6286 else if (varp == &p_wop)
6287 {
6288 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6289 errmsg = e_invarg;
6290 }
6291#endif
6292
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293#ifdef FEAT_WAK
6294 /* 'winaltkeys' */
6295 else if (varp == &p_wak)
6296 {
6297 if (*p_wak == NUL
6298 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6299 errmsg = e_invarg;
6300# ifdef FEAT_MENU
6301# ifdef FEAT_GUI_MOTIF
6302 else if (gui.in_use)
6303 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6304# else
6305# ifdef FEAT_GUI_GTK
6306 else if (gui.in_use)
6307 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6308# endif
6309# endif
6310# endif
6311 }
6312#endif
6313
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314 /* 'eventignore' */
6315 else if (varp == &p_ei)
6316 {
6317 if (check_ei() == FAIL)
6318 errmsg = e_invarg;
6319 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006320
6321#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006322 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6323 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6324 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 {
6326 if (gvarp == &p_fenc)
6327 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006328 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329 errmsg = e_modifiable;
6330 else if (vim_strchr(*varp, ',') != NULL)
6331 /* No comma allowed in 'fileencoding'; catches confusing it
6332 * with 'fileencodings'. */
6333 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006335 {
6336# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006338 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006340 /* Add 'fileencoding' to the swap file. */
6341 ml_setflags(curbuf);
6342 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 }
6344 if (errmsg == NULL)
6345 {
6346 /* canonize the value, so that STRCMP() can be used on it */
6347 p = enc_canonize(*varp);
6348 if (p != NULL)
6349 {
6350 vim_free(*varp);
6351 *varp = p;
6352 }
6353 if (varp == &p_enc)
6354 {
6355 errmsg = mb_init();
6356# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006357 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006358# endif
6359 }
6360 }
6361
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006362# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6364 {
6365 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6366 if (STRCMP(p_tenc, "utf-8") != 0)
6367 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6368 }
6369# endif
6370
6371 if (errmsg == NULL)
6372 {
6373# ifdef FEAT_KEYMAP
6374 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6375 * (with another encoding). */
6376 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6377 (void)keymap_init();
6378# endif
6379
6380 /* When 'termencoding' is not empty and 'encoding' changes or when
6381 * 'termencoding' changes, need to setup for keyboard input and
6382 * display output conversion. */
6383 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6384 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006385 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6386 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6387 {
6388 EMSG3(_("E950: Cannot convert between %s and %s"),
6389 p_tenc, p_enc);
6390 errmsg = e_invarg;
6391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006393
6394# if defined(WIN3264) && defined(FEAT_MBYTE)
6395 /* $HOME may have characters in active code page. */
6396 if (varp == &p_enc)
6397 init_homedir();
6398# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006399 }
6400 }
6401#endif
6402
6403#if defined(FEAT_POSTSCRIPT)
6404 else if (varp == &p_penc)
6405 {
6406 /* Canonize printencoding if VIM standard one */
6407 p = enc_canonize(p_penc);
6408 if (p != NULL)
6409 {
6410 vim_free(p_penc);
6411 p_penc = p;
6412 }
6413 else
6414 {
6415 /* Ensure lower case and '-' for '_' */
6416 for (s = p_penc; *s != NUL; s++)
6417 {
6418 if (*s == '_')
6419 *s = '-';
6420 else
6421 *s = TOLOWER_ASC(*s);
6422 }
6423 }
6424 }
6425#endif
6426
Bram Moolenaar9372a112005-12-06 19:59:18 +00006427#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428 else if (varp == &p_imak)
6429 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006430 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006431 errmsg = e_invarg;
6432 }
6433#endif
6434
6435#ifdef FEAT_KEYMAP
6436 else if (varp == &curbuf->b_p_keymap)
6437 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006438 if (!valid_filetype(*varp))
6439 errmsg = e_invarg;
6440 else
6441 /* load or unload key mapping tables */
6442 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443
Bram Moolenaarfab06232009-03-04 03:13:35 +00006444 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006446 if (*curbuf->b_p_keymap != NUL)
6447 {
6448 /* Installed a new keymap, switch on using it. */
6449 curbuf->b_p_iminsert = B_IMODE_LMAP;
6450 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6451 curbuf->b_p_imsearch = B_IMODE_LMAP;
6452 }
6453 else
6454 {
6455 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6456 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6457 curbuf->b_p_iminsert = B_IMODE_NONE;
6458 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6459 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6460 }
6461 if ((opt_flags & OPT_LOCAL) == 0)
6462 {
6463 set_iminsert_global();
6464 set_imsearch_global();
6465 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 }
6468 }
6469#endif
6470
6471 /* 'fileformat' */
6472 else if (gvarp == &p_ff)
6473 {
6474 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6475 errmsg = e_modifiable;
6476 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6477 errmsg = e_invarg;
6478 else
6479 {
6480 /* may also change 'textmode' */
6481 if (get_fileformat(curbuf) == EOL_DOS)
6482 curbuf->b_p_tx = TRUE;
6483 else
6484 curbuf->b_p_tx = FALSE;
6485#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006486 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006488 /* update flag in swap file */
6489 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006490 /* Redraw needed when switching to/from "mac": a CR in the text
6491 * will be displayed differently. */
6492 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6493 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006494 }
6495 }
6496
6497 /* 'fileformats' */
6498 else if (varp == &p_ffs)
6499 {
6500 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6501 errmsg = e_invarg;
6502 else
6503 {
6504 /* also change 'textauto' */
6505 if (*p_ffs == NUL)
6506 p_ta = FALSE;
6507 else
6508 p_ta = TRUE;
6509 }
6510 }
6511
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006512#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006513 /* 'cryptkey' */
6514 else if (gvarp == &p_key)
6515 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006516# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006517 /* Make sure the ":set" command doesn't show the new value in the
6518 * history. */
6519 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006520# endif
6521 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6522 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006523 ml_set_crypt_key(curbuf, oldval,
6524 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006525 }
6526
6527 else if (gvarp == &p_cm)
6528 {
6529 if (opt_flags & OPT_LOCAL)
6530 p = curbuf->b_p_cm;
6531 else
6532 p = p_cm;
6533 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6534 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006535 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006536 errmsg = e_invarg;
6537 else
6538 {
6539 /* When setting the global value to empty, make it "zip". */
6540 if (*p_cm == NUL)
6541 {
6542 if (new_value_alloced)
6543 free_string_option(p_cm);
6544 p_cm = vim_strsave((char_u *)"zip");
6545 new_value_alloced = TRUE;
6546 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006547 /* When using ":set cm=name" the local value is going to be empty.
6548 * Do that here, otherwise the crypt functions will still use the
6549 * local value. */
6550 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6551 {
6552 free_string_option(curbuf->b_p_cm);
6553 curbuf->b_p_cm = empty_option;
6554 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006555
6556 /* Need to update the swapfile when the effective method changed.
6557 * Set "s" to the effective old value, "p" to the effective new
6558 * method and compare. */
6559 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6560 s = p_cm; /* was previously using the global value */
6561 else
6562 s = oldval;
6563 if (*curbuf->b_p_cm == NUL)
6564 p = p_cm; /* is now using the global value */
6565 else
6566 p = curbuf->b_p_cm;
6567 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006568 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006569
6570 /* If the global value changes need to update the swapfile for all
6571 * buffers using that value. */
6572 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6573 {
6574 buf_T *buf;
6575
Bram Moolenaar29323592016-07-24 22:04:11 +02006576 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006577 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006578 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006579 }
6580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 }
6582#endif
6583
6584 /* 'matchpairs' */
6585 else if (gvarp == &p_mps)
6586 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006587#ifdef FEAT_MBYTE
6588 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006590 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006591 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006592 int x2 = -1;
6593 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006594
6595 if (*p != NUL)
6596 p += mb_ptr2len(p);
6597 if (*p != NUL)
6598 x2 = *p++;
6599 if (*p != NUL)
6600 {
6601 x3 = mb_ptr2char(p);
6602 p += mb_ptr2len(p);
6603 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006604 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006605 {
6606 errmsg = e_invarg;
6607 break;
6608 }
6609 if (*p == NUL)
6610 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006611 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006612 }
6613 else
6614#endif
6615 {
6616 /* Check for "x:y,x:y" */
6617 for (p = *varp; *p != NUL; p += 4)
6618 {
6619 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6620 {
6621 errmsg = e_invarg;
6622 break;
6623 }
6624 if (p[3] == NUL)
6625 break;
6626 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006627 }
6628 }
6629
6630#ifdef FEAT_COMMENTS
6631 /* 'comments' */
6632 else if (gvarp == &p_com)
6633 {
6634 for (s = *varp; *s; )
6635 {
6636 while (*s && *s != ':')
6637 {
6638 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6639 && !VIM_ISDIGIT(*s) && *s != '-')
6640 {
6641 errmsg = illegal_char(errbuf, *s);
6642 break;
6643 }
6644 ++s;
6645 }
6646 if (*s++ == NUL)
6647 errmsg = (char_u *)N_("E524: Missing colon");
6648 else if (*s == ',' || *s == NUL)
6649 errmsg = (char_u *)N_("E525: Zero length string");
6650 if (errmsg != NULL)
6651 break;
6652 while (*s && *s != ',')
6653 {
6654 if (*s == '\\' && s[1] != NUL)
6655 ++s;
6656 ++s;
6657 }
6658 s = skip_to_option_part(s);
6659 }
6660 }
6661#endif
6662
6663 /* 'listchars' */
6664 else if (varp == &p_lcs)
6665 {
6666 errmsg = set_chars_option(varp);
6667 }
6668
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669 /* 'fillchars' */
6670 else if (varp == &p_fcs)
6671 {
6672 errmsg = set_chars_option(varp);
6673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674
6675#ifdef FEAT_CMDWIN
6676 /* 'cedit' */
6677 else if (varp == &p_cedit)
6678 {
6679 errmsg = check_cedit();
6680 }
6681#endif
6682
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006683 /* 'verbosefile' */
6684 else if (varp == &p_vfile)
6685 {
6686 verbose_stop();
6687 if (*p_vfile != NUL && verbose_open() == FAIL)
6688 errmsg = e_invarg;
6689 }
6690
Bram Moolenaar071d4272004-06-13 20:20:40 +00006691#ifdef FEAT_VIMINFO
6692 /* 'viminfo' */
6693 else if (varp == &p_viminfo)
6694 {
6695 for (s = p_viminfo; *s;)
6696 {
6697 /* Check it's a valid character */
6698 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6699 {
6700 errmsg = illegal_char(errbuf, *s);
6701 break;
6702 }
6703 if (*s == 'n') /* name is always last one */
6704 {
6705 break;
6706 }
6707 else if (*s == 'r') /* skip until next ',' */
6708 {
6709 while (*++s && *s != ',')
6710 ;
6711 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006712 else if (*s == '%')
6713 {
6714 /* optional number */
6715 while (vim_isdigit(*++s))
6716 ;
6717 }
6718 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719 ++s; /* no extra chars */
6720 else /* must have a number */
6721 {
6722 while (vim_isdigit(*++s))
6723 ;
6724
6725 if (!VIM_ISDIGIT(*(s - 1)))
6726 {
6727 if (errbuf != NULL)
6728 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006729 sprintf((char *)errbuf,
6730 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006731 transchar_byte(*(s - 1)));
6732 errmsg = errbuf;
6733 }
6734 else
6735 errmsg = (char_u *)"";
6736 break;
6737 }
6738 }
6739 if (*s == ',')
6740 ++s;
6741 else if (*s)
6742 {
6743 if (errbuf != NULL)
6744 errmsg = (char_u *)N_("E527: Missing comma");
6745 else
6746 errmsg = (char_u *)"";
6747 break;
6748 }
6749 }
6750 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6751 errmsg = (char_u *)N_("E528: Must specify a ' value");
6752 }
6753#endif /* FEAT_VIMINFO */
6754
6755 /* terminal options */
6756 else if (istermoption(&options[opt_idx]) && full_screen)
6757 {
6758 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6759 if (varp == &T_CCO)
6760 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006761 int colors = atoi((char *)T_CCO);
6762
6763 /* Only reinitialize colors if t_Co value has really changed to
6764 * avoid expensive reload of colorscheme if t_Co is set to the
6765 * same value multiple times. */
6766 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006768 t_colors = colors;
6769 if (t_colors <= 1)
6770 {
6771 if (new_value_alloced)
6772 vim_free(T_CCO);
6773 T_CCO = empty_option;
6774 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006775#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6776 if (is_term_win32())
6777 {
6778 swap_tcap();
6779 did_swaptcap = TRUE;
6780 }
6781#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006782 /* We now have a different color setup, initialize it again. */
6783 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006784 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 }
6786 ttest(FALSE);
6787 if (varp == &T_ME)
6788 {
6789 out_str(T_ME);
6790 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006791#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 /* Since t_me has been set, this probably means that the user
6793 * wants to use this as default colors. Need to reset default
6794 * background/foreground colors. */
6795 mch_set_normal_colors();
6796#endif
6797 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006798 if (varp == &T_BE && termcap_active)
6799 {
6800 if (*T_BE == NUL)
6801 /* When clearing t_BE we assume the user no longer wants
6802 * bracketed paste, thus disable it by writing t_BD. */
6803 out_str(T_BD);
6804 else
6805 out_str(T_BE);
6806 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807 }
6808
6809#ifdef FEAT_LINEBREAK
6810 /* 'showbreak' */
6811 else if (varp == &p_sbr)
6812 {
6813 for (s = p_sbr; *s; )
6814 {
6815 if (ptr2cells(s) != 1)
6816 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006817 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006818 }
6819 }
6820#endif
6821
6822#ifdef FEAT_GUI
6823 /* 'guifont' */
6824 else if (varp == &p_guifont)
6825 {
6826 if (gui.in_use)
6827 {
6828 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006829# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006830 /*
6831 * Put up a font dialog and let the user select a new value.
6832 * If this is cancelled go back to the old value but don't
6833 * give an error message.
6834 */
6835 if (STRCMP(p, "*") == 0)
6836 {
6837 p = gui_mch_font_dialog(oldval);
6838
6839 if (new_value_alloced)
6840 free_string_option(p_guifont);
6841
6842 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6843 new_value_alloced = TRUE;
6844 }
6845# endif
6846 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6847 {
6848# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6849 if (STRCMP(p_guifont, "*") == 0)
6850 {
6851 /* Dialog was cancelled: Keep the old value without giving
6852 * an error message. */
6853 if (new_value_alloced)
6854 free_string_option(p_guifont);
6855 p_guifont = vim_strsave(oldval);
6856 new_value_alloced = TRUE;
6857 }
6858 else
6859# endif
6860 errmsg = (char_u *)N_("E596: Invalid font(s)");
6861 }
6862 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006863 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006864 }
6865# ifdef FEAT_XFONTSET
6866 else if (varp == &p_guifontset)
6867 {
6868 if (STRCMP(p_guifontset, "*") == 0)
6869 errmsg = (char_u *)N_("E597: can't select fontset");
6870 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6871 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006872 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 }
6874# endif
6875# ifdef FEAT_MBYTE
6876 else if (varp == &p_guifontwide)
6877 {
6878 if (STRCMP(p_guifontwide, "*") == 0)
6879 errmsg = (char_u *)N_("E533: can't select wide font");
6880 else if (gui_get_wide_font() == FAIL)
6881 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006882 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883 }
6884# endif
6885#endif
6886
6887#ifdef CURSOR_SHAPE
6888 /* 'guicursor' */
6889 else if (varp == &p_guicursor)
6890 errmsg = parse_shape_opt(SHAPE_CURSOR);
6891#endif
6892
6893#ifdef FEAT_MOUSESHAPE
6894 /* 'mouseshape' */
6895 else if (varp == &p_mouseshape)
6896 {
6897 errmsg = parse_shape_opt(SHAPE_MOUSE);
6898 update_mouseshape(-1);
6899 }
6900#endif
6901
6902#ifdef FEAT_PRINTER
6903 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006904 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006905# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006906 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006907 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006908# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909#endif
6910
6911#ifdef FEAT_LANGMAP
6912 /* 'langmap' */
6913 else if (varp == &p_langmap)
6914 langmap_set();
6915#endif
6916
6917#ifdef FEAT_LINEBREAK
6918 /* 'breakat' */
6919 else if (varp == &p_breakat)
6920 fill_breakat_flags();
6921#endif
6922
6923#ifdef FEAT_TITLE
6924 /* 'titlestring' and 'iconstring' */
6925 else if (varp == &p_titlestring || varp == &p_iconstring)
6926 {
6927# ifdef FEAT_STL_OPT
6928 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6929
6930 /* NULL => statusline syntax */
6931 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6932 stl_syntax |= flagval;
6933 else
6934 stl_syntax &= ~flagval;
6935# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006936 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937 }
6938#endif
6939
6940#ifdef FEAT_GUI
6941 /* 'guioptions' */
6942 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006943 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006945 redraw_gui_only = TRUE;
6946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947#endif
6948
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006949#if defined(FEAT_GUI_TABLINE)
6950 /* 'guitablabel' */
6951 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006952 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006953 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006954 redraw_gui_only = TRUE;
6955 }
6956 /* 'guitabtooltip' */
6957 else if (varp == &p_gtt)
6958 {
6959 redraw_gui_only = TRUE;
6960 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006961#endif
6962
Bram Moolenaar071d4272004-06-13 20:20:40 +00006963#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6964 /* 'ttymouse' */
6965 else if (varp == &p_ttym)
6966 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006967 /* Switch the mouse off before changing the escape sequences used for
6968 * that. */
6969 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6971 errmsg = e_invarg;
6972 else
6973 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006974 if (termcap_active)
6975 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006976 }
6977#endif
6978
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 /* 'selection' */
6980 else if (varp == &p_sel)
6981 {
6982 if (*p_sel == NUL
6983 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6984 errmsg = e_invarg;
6985 }
6986
6987 /* 'selectmode' */
6988 else if (varp == &p_slm)
6989 {
6990 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6991 errmsg = e_invarg;
6992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993
6994#ifdef FEAT_BROWSE
6995 /* 'browsedir' */
6996 else if (varp == &p_bsdir)
6997 {
6998 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6999 && !mch_isdir(p_bsdir))
7000 errmsg = e_invarg;
7001 }
7002#endif
7003
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004 /* 'keymodel' */
7005 else if (varp == &p_km)
7006 {
7007 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7008 errmsg = e_invarg;
7009 else
7010 {
7011 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7012 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7013 }
7014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015
7016 /* 'mousemodel' */
7017 else if (varp == &p_mousem)
7018 {
7019 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7020 errmsg = e_invarg;
7021#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7022 else if (*p_mousem != *oldval)
7023 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7024 * to create or delete the popup menus. */
7025 gui_motif_update_mousemodel(root_menu);
7026#endif
7027 }
7028
7029 /* 'switchbuf' */
7030 else if (varp == &p_swb)
7031 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007032 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007033 errmsg = e_invarg;
7034 }
7035
7036 /* 'debug' */
7037 else if (varp == &p_debug)
7038 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007039 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007040 errmsg = e_invarg;
7041 }
7042
7043 /* 'display' */
7044 else if (varp == &p_dy)
7045 {
7046 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7047 errmsg = e_invarg;
7048 else
7049 (void)init_chartab();
7050
7051 }
7052
Bram Moolenaar071d4272004-06-13 20:20:40 +00007053 /* 'eadirection' */
7054 else if (varp == &p_ead)
7055 {
7056 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7057 errmsg = e_invarg;
7058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059
7060#ifdef FEAT_CLIPBOARD
7061 /* 'clipboard' */
7062 else if (varp == &p_cb)
7063 errmsg = check_clipboard_option();
7064#endif
7065
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007066#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007067 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7068 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007069 else if (varp == &(curwin->w_s->b_p_spl)
7070 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007071 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007072 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007073 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007074 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007075 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007076 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007077 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007078 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007079 /* 'spellsuggest' */
7080 else if (varp == &p_sps)
7081 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007082 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007083 errmsg = e_invarg;
7084 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007085 /* 'mkspellmem' */
7086 else if (varp == &p_msm)
7087 {
7088 if (spell_check_msm() != OK)
7089 errmsg = e_invarg;
7090 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007091#endif
7092
Bram Moolenaar071d4272004-06-13 20:20:40 +00007093 /* When 'bufhidden' is set, check for valid value. */
7094 else if (gvarp == &p_bh)
7095 {
7096 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7097 errmsg = e_invarg;
7098 }
7099
7100 /* When 'buftype' is set, check for valid value. */
7101 else if (gvarp == &p_bt)
7102 {
7103 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7104 errmsg = e_invarg;
7105 else
7106 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007107 if (curwin->w_status_height)
7108 {
7109 curwin->w_redr_status = TRUE;
7110 redraw_later(VALID);
7111 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007113#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007114 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007115#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007116 }
7117 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007118
7119#ifdef FEAT_STL_OPT
7120 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007121 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 {
7123 int wid;
7124
7125 if (varp == &p_ruf) /* reset ru_wid first */
7126 ru_wid = 0;
7127 s = *varp;
7128 if (varp == &p_ruf && *s == '%')
7129 {
7130 /* set ru_wid if 'ruf' starts with "%99(" */
7131 if (*++s == '-') /* ignore a '-' */
7132 s++;
7133 wid = getdigits(&s);
7134 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7135 ru_wid = wid;
7136 else
7137 errmsg = check_stl_option(p_ruf);
7138 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007139 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007140 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007141 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007142 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143 comp_col();
7144 }
7145#endif
7146
7147#ifdef FEAT_INS_EXPAND
7148 /* check if it is a valid value for 'complete' -- Acevedo */
7149 else if (gvarp == &p_cpt)
7150 {
7151 for (s = *varp; *s;)
7152 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007153 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 s++;
7155 if (!*s)
7156 break;
7157 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7158 {
7159 errmsg = illegal_char(errbuf, *s);
7160 break;
7161 }
7162 if (*++s != NUL && *s != ',' && *s != ' ')
7163 {
7164 if (s[-1] == 'k' || s[-1] == 's')
7165 {
7166 /* skip optional filename after 'k' and 's' */
7167 while (*s && *s != ',' && *s != ' ')
7168 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007169 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007170 ++s;
7171 ++s;
7172 }
7173 }
7174 else
7175 {
7176 if (errbuf != NULL)
7177 {
7178 sprintf((char *)errbuf,
7179 _("E535: Illegal character after <%c>"),
7180 *--s);
7181 errmsg = errbuf;
7182 }
7183 else
7184 errmsg = (char_u *)"";
7185 break;
7186 }
7187 }
7188 }
7189 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007190
7191 /* 'completeopt' */
7192 else if (varp == &p_cot)
7193 {
7194 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7195 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007196 else
7197 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007198 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007199#endif /* FEAT_INS_EXPAND */
7200
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007201#ifdef FEAT_SIGNS
7202 /* 'signcolumn' */
7203 else if (varp == &curwin->w_p_scl)
7204 {
7205 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7206 errmsg = e_invarg;
7207 }
7208#endif
7209
Bram Moolenaar071d4272004-06-13 20:20:40 +00007210
7211#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007212 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213 else if (varp == &p_toolbar)
7214 {
7215 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7216 &toolbar_flags, TRUE) != OK)
7217 errmsg = e_invarg;
7218 else
7219 {
7220 out_flush();
7221 gui_mch_show_toolbar((toolbar_flags &
7222 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7223 }
7224 }
7225#endif
7226
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007227#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007228 /* 'toolbariconsize': GTK+ 2 only */
7229 else if (varp == &p_tbis)
7230 {
7231 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7232 errmsg = e_invarg;
7233 else
7234 {
7235 out_flush();
7236 gui_mch_show_toolbar((toolbar_flags &
7237 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7238 }
7239 }
7240#endif
7241
7242 /* 'pastetoggle': translate key codes like in a mapping */
7243 else if (varp == &p_pt)
7244 {
7245 if (*p_pt)
7246 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007247 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007248 if (p != NULL)
7249 {
7250 if (new_value_alloced)
7251 free_string_option(p_pt);
7252 p_pt = p;
7253 new_value_alloced = TRUE;
7254 }
7255 }
7256 }
7257
7258 /* 'backspace' */
7259 else if (varp == &p_bs)
7260 {
7261 if (VIM_ISDIGIT(*p_bs))
7262 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007263 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007264 errmsg = e_invarg;
7265 }
7266 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7267 errmsg = e_invarg;
7268 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007269 else if (varp == &p_bo)
7270 {
7271 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7272 errmsg = e_invarg;
7273 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007275 /* 'tagcase' */
7276 else if (gvarp == &p_tc)
7277 {
7278 unsigned int *flags;
7279
7280 if (opt_flags & OPT_LOCAL)
7281 {
7282 p = curbuf->b_p_tc;
7283 flags = &curbuf->b_tc_flags;
7284 }
7285 else
7286 {
7287 p = p_tc;
7288 flags = &tc_flags;
7289 }
7290
7291 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7292 /* make the local value empty: use the global value */
7293 *flags = 0;
7294 else if (*p == NUL
7295 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7296 errmsg = e_invarg;
7297 }
7298
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007299#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300 /* 'casemap' */
7301 else if (varp == &p_cmp)
7302 {
7303 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7304 errmsg = e_invarg;
7305 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007307
7308#ifdef FEAT_DIFF
7309 /* 'diffopt' */
7310 else if (varp == &p_dip)
7311 {
7312 if (diffopt_changed() == FAIL)
7313 errmsg = e_invarg;
7314 }
7315#endif
7316
7317#ifdef FEAT_FOLDING
7318 /* 'foldmethod' */
7319 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7320 {
7321 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7322 || *curwin->w_p_fdm == NUL)
7323 errmsg = e_invarg;
7324 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007325 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007326 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007327 if (foldmethodIsDiff(curwin))
7328 newFoldLevel();
7329 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007330 }
7331# ifdef FEAT_EVAL
7332 /* 'foldexpr' */
7333 else if (varp == &curwin->w_p_fde)
7334 {
7335 if (foldmethodIsExpr(curwin))
7336 foldUpdateAll(curwin);
7337 }
7338# endif
7339 /* 'foldmarker' */
7340 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7341 {
7342 p = vim_strchr(*varp, ',');
7343 if (p == NULL)
7344 errmsg = (char_u *)N_("E536: comma required");
7345 else if (p == *varp || p[1] == NUL)
7346 errmsg = e_invarg;
7347 else if (foldmethodIsMarker(curwin))
7348 foldUpdateAll(curwin);
7349 }
7350 /* 'commentstring' */
7351 else if (gvarp == &p_cms)
7352 {
7353 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7354 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7355 }
7356 /* 'foldopen' */
7357 else if (varp == &p_fdo)
7358 {
7359 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7360 errmsg = e_invarg;
7361 }
7362 /* 'foldclose' */
7363 else if (varp == &p_fcl)
7364 {
7365 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7366 errmsg = e_invarg;
7367 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007368 /* 'foldignore' */
7369 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7370 {
7371 if (foldmethodIsIndent(curwin))
7372 foldUpdateAll(curwin);
7373 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007374#endif
7375
7376#ifdef FEAT_VIRTUALEDIT
7377 /* 'virtualedit' */
7378 else if (varp == &p_ve)
7379 {
7380 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7381 errmsg = e_invarg;
7382 else if (STRCMP(p_ve, oldval) != 0)
7383 {
7384 /* Recompute cursor position in case the new 've' setting
7385 * changes something. */
7386 validate_virtcol();
7387 coladvance(curwin->w_virtcol);
7388 }
7389 }
7390#endif
7391
7392#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7393 else if (varp == &p_csqf)
7394 {
7395 if (p_csqf != NULL)
7396 {
7397 p = p_csqf;
7398 while (*p != NUL)
7399 {
7400 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7401 || p[1] == NUL
7402 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7403 || (p[2] != NUL && p[2] != ','))
7404 {
7405 errmsg = e_invarg;
7406 break;
7407 }
7408 else if (p[2] == NUL)
7409 break;
7410 else
7411 p += 3;
7412 }
7413 }
7414 }
7415#endif
7416
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007417#ifdef FEAT_CINDENT
7418 /* 'cinoptions' */
7419 else if (gvarp == &p_cino)
7420 {
7421 /* TODO: recognize errors */
7422 parse_cino(curbuf);
7423 }
7424#endif
7425
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007426#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007427 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007428 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007429 {
7430 if (!gui_mch_set_rendering_options(p_rop))
7431 errmsg = e_invarg;
7432 }
7433#endif
7434
Bram Moolenaard0b51382016-11-04 15:23:45 +01007435 else if (gvarp == &p_ft)
7436 {
7437 if (!valid_filetype(*varp))
7438 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007439 else
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007440 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007441 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007442
7443#ifdef FEAT_SYN_HL
7444 else if (gvarp == &p_syn)
7445 {
7446 if (!valid_filetype(*varp))
7447 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007448 else
7449 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007450 }
7451#endif
7452
Bram Moolenaar825680f2017-07-22 17:04:02 +02007453#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007454 /* 'termwinkey' */
7455 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007456 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007457 if (*curwin->w_p_twk != NUL
7458 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007459 errmsg = e_invarg;
7460 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007461 /* 'termwinsize' */
7462 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007463 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007464 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007465 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007466 p = skipdigits(curwin->w_p_tws);
7467 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007468 || (*p != 'x' && *p != '*')
7469 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007470 errmsg = e_invarg;
7471 }
7472 }
7473#endif
7474
Bram Moolenaar071d4272004-06-13 20:20:40 +00007475 /* Options that are a list of flags. */
7476 else
7477 {
7478 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007479 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007481 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007483 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007484 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007485 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007487#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007488 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007489 p = (char_u *)COCU_ALL;
7490#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007491 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 {
7493#ifdef FEAT_MOUSE
7494 p = (char_u *)MOUSE_ALL;
7495#else
7496 if (*p_mouse != NUL)
7497 errmsg = (char_u *)N_("E538: No mouse support");
7498#endif
7499 }
7500#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007501 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502 p = (char_u *)GO_ALL;
7503#endif
7504 if (p != NULL)
7505 {
7506 for (s = *varp; *s; ++s)
7507 if (vim_strchr(p, *s) == NULL)
7508 {
7509 errmsg = illegal_char(errbuf, *s);
7510 break;
7511 }
7512 }
7513 }
7514
7515 /*
7516 * If error detected, restore the previous value.
7517 */
7518 if (errmsg != NULL)
7519 {
7520 if (new_value_alloced)
7521 free_string_option(*varp);
7522 *varp = oldval;
7523 /*
7524 * When resetting some values, need to act on it.
7525 */
7526 if (did_chartab)
7527 (void)init_chartab();
7528 if (varp == &p_hl)
7529 (void)highlight_changed();
7530 }
7531 else
7532 {
7533#ifdef FEAT_EVAL
7534 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007535 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007536#endif
7537 /*
7538 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007539 * Use "free_oldval", because recursiveness may change the flags under
7540 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007542 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543 free_string_option(oldval);
7544 if (new_value_alloced)
7545 options[opt_idx].flags |= P_ALLOCED;
7546 else
7547 options[opt_idx].flags &= ~P_ALLOCED;
7548
7549 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007550 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 {
7552 /* global option with local value set to use global value; free
7553 * the local value and make it empty */
7554 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7555 free_string_option(*(char_u **)p);
7556 *(char_u **)p = empty_option;
7557 }
7558
7559 /* May set global value for local option. */
7560 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7561 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007562
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007563 /*
7564 * Trigger the autocommand only after setting the flags.
7565 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007566#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007567 /* When 'syntax' is set, load the syntax of that name */
7568 if (varp == &(curbuf->b_p_syn))
7569 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007570 // Only pass TRUE for "force" when the value changed, to avoid
7571 // endless recurrence. */
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007572 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007573 curbuf->b_fname, value_changed, curbuf);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007574 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007575#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007576 else if (varp == &(curbuf->b_p_ft))
7577 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007578 /* 'filetype' is set, trigger the FileType autocommand.
7579 * Skip this when called from a modeline and the filetype was
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007580 * already set to this value.
7581 * Only pass TRUE for "force" when the value changed, to avoid
7582 * endless recurrence. */
7583 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007584 {
7585 did_filetype = TRUE;
7586 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007587 curbuf->b_fname, value_changed, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007588 /* Just in case the old "curbuf" is now invalid. */
7589 if (varp != &(curbuf->b_p_ft))
7590 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007591 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007592 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007593#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007594 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007595 {
7596 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007597 char_u *q = curwin->w_s->b_p_spl;
7598
7599 /* Skip the first name if it is "cjk". */
7600 if (STRNCMP(q, "cjk,", 4) == 0)
7601 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007602
7603 /*
7604 * Source the spell/LANG.vim in 'runtimepath'.
7605 * They could set 'spellcapcheck' depending on the language.
7606 * Use the first name in 'spelllang' up to '_region' or
7607 * '.encoding'.
7608 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007609 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007610 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7611 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007612 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007613 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007614 }
7615#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007616 }
7617
7618#ifdef FEAT_MOUSE
7619 if (varp == &p_mouse)
7620 {
7621# ifdef FEAT_MOUSE_TTY
7622 if (*p_mouse == NUL)
7623 mch_setmouse(FALSE); /* switch mouse off */
7624 else
7625# endif
7626 setmouse(); /* in case 'mouse' changed */
7627 }
7628#endif
7629
Bram Moolenaar913077c2012-03-28 19:59:04 +02007630 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007631 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007632 curwin->w_set_curswant = TRUE;
7633
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007634#ifdef FEAT_GUI
7635 /* check redraw when it's not a GUI option or the GUI is active. */
7636 if (!redraw_gui_only || gui.in_use)
7637#endif
7638 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007639
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007640#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7641 if (did_swaptcap)
7642 {
7643 if (t_colors < 256)
7644 p_tgc = 0;
7645 set_termname((char_u *)"win32");
7646 init_highlight(TRUE, FALSE);
7647 }
7648#endif
7649
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650 return errmsg;
7651}
7652
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007653#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007654/*
7655 * Simple int comparison function for use with qsort()
7656 */
7657 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007658int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007659{
7660 return *(const int *)a - *(const int *)b;
7661}
7662
7663/*
7664 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7665 * Returns error message, NULL if it's OK.
7666 */
7667 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007668check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007669{
7670 char_u *s;
7671 int col;
7672 int count = 0;
7673 int color_cols[256];
7674 int i;
7675 int j = 0;
7676
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007677 if (wp->w_buffer == NULL)
7678 return NULL; /* buffer was closed */
7679
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007680 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007681 {
7682 if (*s == '-' || *s == '+')
7683 {
7684 /* -N and +N: add to 'textwidth' */
7685 col = (*s == '-') ? -1 : 1;
7686 ++s;
7687 if (!VIM_ISDIGIT(*s))
7688 return e_invarg;
7689 col = col * getdigits(&s);
7690 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007691 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007692 col += wp->w_buffer->b_p_tw;
7693 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007694 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007695 }
7696 else if (VIM_ISDIGIT(*s))
7697 col = getdigits(&s);
7698 else
7699 return e_invarg;
7700 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007701skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007702 if (*s == NUL)
7703 break;
7704 if (*s != ',')
7705 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007706 if (*++s == NUL)
7707 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007708 }
7709
7710 vim_free(wp->w_p_cc_cols);
7711 if (count == 0)
7712 wp->w_p_cc_cols = NULL;
7713 else
7714 {
7715 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7716 if (wp->w_p_cc_cols != NULL)
7717 {
7718 /* sort the columns for faster usage on screen redraw inside
7719 * win_line() */
7720 qsort(color_cols, count, sizeof(int), int_cmp);
7721
7722 for (i = 0; i < count; ++i)
7723 /* skip duplicates */
7724 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7725 wp->w_p_cc_cols[j++] = color_cols[i];
7726 wp->w_p_cc_cols[j] = -1; /* end marker */
7727 }
7728 }
7729
7730 return NULL; /* no error */
7731}
7732#endif
7733
Bram Moolenaar071d4272004-06-13 20:20:40 +00007734/*
7735 * Handle setting 'listchars' or 'fillchars'.
7736 * Returns error message, NULL if it's OK.
7737 */
7738 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007739set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007740{
7741 int round, i, len, entries;
7742 char_u *p, *s;
7743 int c1, c2 = 0;
7744 struct charstab
7745 {
7746 int *cp;
7747 char *name;
7748 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749 static struct charstab filltab[] =
7750 {
7751 {&fill_stl, "stl"},
7752 {&fill_stlnc, "stlnc"},
7753 {&fill_vert, "vert"},
7754 {&fill_fold, "fold"},
7755 {&fill_diff, "diff"},
7756 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007757 static struct charstab lcstab[] =
7758 {
7759 {&lcs_eol, "eol"},
7760 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007761 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007762 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007763 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 {&lcs_tab2, "tab"},
7765 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007766#ifdef FEAT_CONCEAL
7767 {&lcs_conceal, "conceal"},
7768#else
7769 {NULL, "conceal"},
7770#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007771 };
7772 struct charstab *tab;
7773
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007775 {
7776 tab = lcstab;
7777 entries = sizeof(lcstab) / sizeof(struct charstab);
7778 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 else
7780 {
7781 tab = filltab;
7782 entries = sizeof(filltab) / sizeof(struct charstab);
7783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784
7785 /* first round: check for valid value, second round: assign values */
7786 for (round = 0; round <= 1; ++round)
7787 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007788 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007789 {
7790 /* After checking that the value is valid: set defaults: space for
7791 * 'fillchars', NUL for 'listchars' */
7792 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007793 if (tab[i].cp != NULL)
7794 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795 if (varp == &p_lcs)
7796 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007797 else
7798 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 }
7800 p = *varp;
7801 while (*p)
7802 {
7803 for (i = 0; i < entries; ++i)
7804 {
7805 len = (int)STRLEN(tab[i].name);
7806 if (STRNCMP(p, tab[i].name, len) == 0
7807 && p[len] == ':'
7808 && p[len + 1] != NUL)
7809 {
7810 s = p + len + 1;
7811#ifdef FEAT_MBYTE
7812 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007813 if (mb_char2cells(c1) > 1)
7814 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007815#else
7816 c1 = *s++;
7817#endif
7818 if (tab[i].cp == &lcs_tab2)
7819 {
7820 if (*s == NUL)
7821 continue;
7822#ifdef FEAT_MBYTE
7823 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007824 if (mb_char2cells(c2) > 1)
7825 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007826#else
7827 c2 = *s++;
7828#endif
7829 }
7830 if (*s == ',' || *s == NUL)
7831 {
7832 if (round)
7833 {
7834 if (tab[i].cp == &lcs_tab2)
7835 {
7836 lcs_tab1 = c1;
7837 lcs_tab2 = c2;
7838 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007839 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007840 *(tab[i].cp) = c1;
7841
7842 }
7843 p = s;
7844 break;
7845 }
7846 }
7847 }
7848
7849 if (i == entries)
7850 return e_invarg;
7851 if (*p == ',')
7852 ++p;
7853 }
7854 }
7855
7856 return NULL; /* no error */
7857}
7858
7859#ifdef FEAT_STL_OPT
7860/*
7861 * Check validity of options with the 'statusline' format.
7862 * Return error message or NULL.
7863 */
7864 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007865check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007866{
7867 int itemcnt = 0;
7868 int groupdepth = 0;
7869 static char_u errbuf[80];
7870
7871 while (*s && itemcnt < STL_MAX_ITEM)
7872 {
7873 /* Check for valid keys after % sequences */
7874 while (*s && *s != '%')
7875 s++;
7876 if (!*s)
7877 break;
7878 s++;
7879 if (*s != '%' && *s != ')')
7880 ++itemcnt;
7881 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7882 {
7883 s++;
7884 continue;
7885 }
7886 if (*s == ')')
7887 {
7888 s++;
7889 if (--groupdepth < 0)
7890 break;
7891 continue;
7892 }
7893 if (*s == '-')
7894 s++;
7895 while (VIM_ISDIGIT(*s))
7896 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007897 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 continue;
7899 if (*s == '.')
7900 {
7901 s++;
7902 while (*s && VIM_ISDIGIT(*s))
7903 s++;
7904 }
7905 if (*s == '(')
7906 {
7907 groupdepth++;
7908 continue;
7909 }
7910 if (vim_strchr(STL_ALL, *s) == NULL)
7911 {
7912 return illegal_char(errbuf, *s);
7913 }
7914 if (*s == '{')
7915 {
7916 s++;
7917 while (*s != '}' && *s)
7918 s++;
7919 if (*s != '}')
7920 return (char_u *)N_("E540: Unclosed expression sequence");
7921 }
7922 }
7923 if (itemcnt >= STL_MAX_ITEM)
7924 return (char_u *)N_("E541: too many items");
7925 if (groupdepth != 0)
7926 return (char_u *)N_("E542: unbalanced groups");
7927 return NULL;
7928}
7929#endif
7930
7931#ifdef FEAT_CLIPBOARD
7932/*
7933 * Extract the items in the 'clipboard' option and set global values.
7934 */
7935 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007936check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007938 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007939 int new_autoselect_star = FALSE;
7940 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007941 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007942 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943 regprog_T *new_exclude_prog = NULL;
7944 char_u *errmsg = NULL;
7945 char_u *p;
7946
7947 for (p = p_cb; *p != NUL; )
7948 {
7949 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7950 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007951 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952 p += 7;
7953 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007954 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007955 && (p[11] == ',' || p[11] == NUL))
7956 {
7957 new_unnamed |= CLIP_UNNAMED_PLUS;
7958 p += 11;
7959 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007961 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007963 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 p += 10;
7965 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007966 else if (STRNCMP(p, "autoselectplus", 14) == 0
7967 && (p[14] == ',' || p[14] == NUL))
7968 {
7969 new_autoselect_plus = TRUE;
7970 p += 14;
7971 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007973 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007974 {
7975 new_autoselectml = TRUE;
7976 p += 12;
7977 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007978 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7979 {
7980 new_html = TRUE;
7981 p += 4;
7982 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7984 {
7985 p += 8;
7986 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7987 if (new_exclude_prog == NULL)
7988 errmsg = e_invarg;
7989 break;
7990 }
7991 else
7992 {
7993 errmsg = e_invarg;
7994 break;
7995 }
7996 if (*p == ',')
7997 ++p;
7998 }
7999 if (errmsg == NULL)
8000 {
8001 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008002 clip_autoselect_star = new_autoselect_star;
8003 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008005 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008006 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008008#ifdef FEAT_GUI_GTK
8009 if (gui.in_use)
8010 {
8011 gui_gtk_set_selection_targets();
8012 gui_gtk_set_dnd_targets();
8013 }
8014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015 }
8016 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008017 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018
8019 return errmsg;
8020}
8021#endif
8022
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008023#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008024 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008025did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008026{
8027 char_u *errmsg = NULL;
8028 win_T *wp;
8029 int l;
8030
8031 if (is_spellfile)
8032 {
8033 l = (int)STRLEN(curwin->w_s->b_p_spf);
8034 if (l > 0 && (l < 4
8035 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8036 errmsg = e_invarg;
8037 }
8038
8039 if (errmsg == NULL)
8040 {
8041 FOR_ALL_WINDOWS(wp)
8042 if (wp->w_buffer == curbuf && wp->w_p_spell)
8043 {
8044 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008045 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008046 }
8047 }
8048 return errmsg;
8049}
8050
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008051/*
8052 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8053 * Return error message when failed, NULL when OK.
8054 */
8055 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008056compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008057{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008058 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008059 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008060
Bram Moolenaar860cae12010-06-05 23:22:07 +02008061 if (*synblock->b_p_spc == NUL)
8062 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008063 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008064 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008065 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008066 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008067 if (re != NULL)
8068 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008069 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008070 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008071 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008072 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008073 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008074 return e_invarg;
8075 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008076 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008077 }
8078
Bram Moolenaar473de612013-06-08 18:19:48 +02008079 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008080 return NULL;
8081}
8082#endif
8083
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008084#if defined(FEAT_EVAL) || defined(PROTO)
8085/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008086 * Set the scriptID for an option, taking care of setting the buffer- or
8087 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008088 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008089 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008090set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008091{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008092 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8093 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008094
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008095 /* Remember where the option was set. For local options need to do that
8096 * in the buffer or window structure. */
8097 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008098 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008099 if (both || (opt_flags & OPT_LOCAL))
8100 {
8101 if (indir & PV_BUF)
8102 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8103 else if (indir & PV_WIN)
8104 curwin->w_p_scriptID[indir & PV_MASK] = id;
8105 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008106}
8107#endif
8108
Bram Moolenaar071d4272004-06-13 20:20:40 +00008109/*
8110 * Set the value of a boolean option, and take care of side effects.
8111 * Returns NULL for success, or an error message for an error.
8112 */
8113 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008114set_bool_option(
8115 int opt_idx, /* index in options[] table */
8116 char_u *varp, /* pointer to the option variable */
8117 int value, /* new value */
8118 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119{
8120 int old_value = *(int *)varp;
8121
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122 /* Disallow changing some options from secure mode */
8123 if ((secure
8124#ifdef HAVE_SANDBOX
8125 || sandbox != 0
8126#endif
8127 ) && (options[opt_idx].flags & P_SECURE))
8128 return e_secure;
8129
8130 *(int *)varp = value; /* set the new value */
8131#ifdef FEAT_EVAL
8132 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008133 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134#endif
8135
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008136#ifdef FEAT_GUI
8137 need_mouse_correct = TRUE;
8138#endif
8139
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140 /* May set global value for local option. */
8141 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8142 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8143
8144 /*
8145 * Handle side effects of changing a bool option.
8146 */
8147
8148 /* 'compatible' */
8149 if ((int *)varp == &p_cp)
8150 {
8151 compatible_set();
8152 }
8153
Bram Moolenaar920694c2016-08-21 17:45:02 +02008154#ifdef FEAT_LANGMAP
8155 if ((int *)varp == &p_lrm)
8156 /* 'langremap' -> !'langnoremap' */
8157 p_lnr = !p_lrm;
8158 else if ((int *)varp == &p_lnr)
8159 /* 'langnoremap' -> !'langremap' */
8160 p_lrm = !p_lnr;
8161#endif
8162
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008163#ifdef FEAT_PERSISTENT_UNDO
8164 /* 'undofile' */
8165 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8166 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008167 /* Only take action when the option was set. When reset we do not
8168 * delete the undo file, the option may be set again without making
8169 * any changes in between. */
8170 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008171 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008172 char_u hash[UNDO_HASH_SIZE];
8173 buf_T *save_curbuf = curbuf;
8174
Bram Moolenaar29323592016-07-24 22:04:11 +02008175 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008176 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008177 /* When 'undofile' is set globally: for every buffer, otherwise
8178 * only for the current buffer: Try to read in the undofile,
8179 * if one exists, the buffer wasn't changed and the buffer was
8180 * loaded */
8181 if ((curbuf == save_curbuf
8182 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8183 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8184 {
8185 u_compute_hash(hash);
8186 u_read_undo(NULL, hash, curbuf->b_fname);
8187 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008188 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008189 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008190 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008191 }
8192#endif
8193
Bram Moolenaar071d4272004-06-13 20:20:40 +00008194 else if ((int *)varp == &curbuf->b_p_ro)
8195 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008196 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8198 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008199
8200 /* when 'readonly' is set may give W10 again */
8201 if (curbuf->b_p_ro)
8202 curbuf->b_did_warn = FALSE;
8203
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008205 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206#endif
8207 }
8208
Bram Moolenaar9c449722010-07-20 18:44:27 +02008209#ifdef FEAT_GUI
8210 else if ((int *)varp == &p_mh)
8211 {
8212 if (!p_mh)
8213 gui_mch_mousehide(FALSE);
8214 }
8215#endif
8216
Bram Moolenaara539df02010-08-01 14:35:05 +02008217 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008219 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008220# ifdef FEAT_TERMINAL
8221 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008222 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8223 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008224 {
8225 curbuf->b_p_ma = FALSE;
8226 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8227 }
8228# endif
8229# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008230 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008231# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008232 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008233#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234 /* when 'endofline' is changed, redraw the window title */
8235 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008236 {
8237 redraw_titles();
8238 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008239 /* when 'fixeol' is changed, redraw the window title */
8240 else if ((int *)varp == &curbuf->b_p_fixeol)
8241 {
8242 redraw_titles();
8243 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008244# ifdef FEAT_MBYTE
8245 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008246 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008247 {
8248 redraw_titles();
8249 }
8250# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251#endif
8252
8253 /* when 'bin' is set also set some other options */
8254 else if ((int *)varp == &curbuf->b_p_bin)
8255 {
8256 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8257#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008258 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008259#endif
8260 }
8261
Bram Moolenaar071d4272004-06-13 20:20:40 +00008262 /* when 'buflisted' changes, trigger autocommands */
8263 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8264 {
8265 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8266 NULL, NULL, TRUE, curbuf);
8267 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268
8269 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8270 else if ((int *)varp == &curbuf->b_p_swf)
8271 {
8272 if (curbuf->b_p_swf && p_uc)
8273 ml_open_file(curbuf); /* create the swap file */
8274 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008275 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8276 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008277 mf_close_file(curbuf, TRUE); /* remove the swap file */
8278 }
8279
8280 /* when 'terse' is set change 'shortmess' */
8281 else if ((int *)varp == &p_terse)
8282 {
8283 char_u *p;
8284
8285 p = vim_strchr(p_shm, SHM_SEARCH);
8286
8287 /* insert 's' in p_shm */
8288 if (p_terse && p == NULL)
8289 {
8290 STRCPY(IObuff, p_shm);
8291 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008292 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008293 }
8294 /* remove 's' from p_shm */
8295 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008296 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 }
8298
8299 /* when 'paste' is set or reset also change other options */
8300 else if ((int *)varp == &p_paste)
8301 {
8302 paste_option_changed();
8303 }
8304
8305 /* when 'insertmode' is set from an autocommand need to do work here */
8306 else if ((int *)varp == &p_im)
8307 {
8308 if (p_im)
8309 {
8310 if ((State & INSERT) == 0)
8311 need_start_insertmode = TRUE;
8312 stop_insert_mode = FALSE;
8313 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008314 /* only reset if it was set previously */
8315 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 {
8317 need_start_insertmode = FALSE;
8318 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008319 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 clear_cmdline = TRUE; /* remove "(insert)" */
8321 restart_edit = 0;
8322 }
8323 }
8324
8325 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8326 else if ((int *)varp == &p_ic && p_hls)
8327 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008328 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008329 }
8330
8331#ifdef FEAT_SEARCH_EXTRA
8332 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8333 else if ((int *)varp == &p_hls)
8334 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008335 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008336 }
8337#endif
8338
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8340 * at the end of normal_cmd() */
8341 else if ((int *)varp == &curwin->w_p_scb)
8342 {
8343 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008344 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008346 curwin->w_scbind_pos = curwin->w_topline;
8347 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008349
Bram Moolenaar4033c552017-09-16 20:54:51 +02008350#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351 /* There can be only one window with 'previewwindow' set. */
8352 else if ((int *)varp == &curwin->w_p_pvw)
8353 {
8354 if (curwin->w_p_pvw)
8355 {
8356 win_T *win;
8357
Bram Moolenaar29323592016-07-24 22:04:11 +02008358 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359 if (win->w_p_pvw && win != curwin)
8360 {
8361 curwin->w_p_pvw = FALSE;
8362 return (char_u *)N_("E590: A preview window already exists");
8363 }
8364 }
8365 }
8366#endif
8367
8368 /* when 'textmode' is set or reset also change 'fileformat' */
8369 else if ((int *)varp == &curbuf->b_p_tx)
8370 {
8371 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8372 }
8373
8374 /* when 'textauto' is set or reset also change 'fileformats' */
8375 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376 set_string_option_direct((char_u *)"ffs", -1,
8377 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008378 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008379
8380 /*
8381 * When 'lisp' option changes include/exclude '-' in
8382 * keyword characters.
8383 */
8384#ifdef FEAT_LISP
8385 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8386 {
8387 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8388 }
8389#endif
8390
8391#ifdef FEAT_TITLE
8392 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008393 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008395 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 }
8397#endif
8398
8399 else if ((int *)varp == &curbuf->b_changed)
8400 {
8401 if (!value)
8402 save_file_ff(curbuf); /* Buffer is unchanged */
8403#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008404 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 }
8408
8409#ifdef BACKSLASH_IN_FILENAME
8410 else if ((int *)varp == &p_ssl)
8411 {
8412 if (p_ssl)
8413 {
8414 psepc = '/';
8415 psepcN = '\\';
8416 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417 }
8418 else
8419 {
8420 psepc = '\\';
8421 psepcN = '/';
8422 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 }
8424
8425 /* need to adjust the file name arguments and buffer names. */
8426 buflist_slash_adjust();
8427 alist_slash_adjust();
8428# ifdef FEAT_EVAL
8429 scriptnames_slash_adjust();
8430# endif
8431 }
8432#endif
8433
8434 /* If 'wrap' is set, set w_leftcol to zero. */
8435 else if ((int *)varp == &curwin->w_p_wrap)
8436 {
8437 if (curwin->w_p_wrap)
8438 curwin->w_leftcol = 0;
8439 }
8440
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 else if ((int *)varp == &p_ea)
8442 {
8443 if (p_ea && !old_value)
8444 win_equal(curwin, FALSE, 0);
8445 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008446
8447 else if ((int *)varp == &p_wiv)
8448 {
8449 /*
8450 * When 'weirdinvert' changed, set/reset 't_xs'.
8451 * Then set 'weirdinvert' according to value of 't_xs'.
8452 */
8453 if (p_wiv && !old_value)
8454 T_XS = (char_u *)"y";
8455 else if (!p_wiv && old_value)
8456 T_XS = empty_option;
8457 p_wiv = (*T_XS != NUL);
8458 }
8459
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008460#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008461 else if ((int *)varp == &p_beval)
8462 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008463 if (!balloonEvalForTerm)
8464 {
8465 if (p_beval && !old_value)
8466 gui_mch_enable_beval_area(balloonEval);
8467 else if (!p_beval && old_value)
8468 gui_mch_disable_beval_area(balloonEval);
8469 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008470 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008471#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008472#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008473 else if ((int *)varp == &p_bevalterm)
8474 {
8475 mch_bevalterm_changed();
8476 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008477#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008479#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008480 else if ((int *)varp == &p_acd)
8481 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008482 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008483 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008484 }
8485#endif
8486
8487#ifdef FEAT_DIFF
8488 /* 'diff' */
8489 else if ((int *)varp == &curwin->w_p_diff)
8490 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008491 /* May add or remove the buffer from the list of diff buffers. */
8492 diff_buf_adjust(curwin);
8493# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008494 if (foldmethodIsDiff(curwin))
8495 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008496# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008497 }
8498#endif
8499
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008500#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008501 /* 'imdisable' */
8502 else if ((int *)varp == &p_imdisable)
8503 {
8504 /* Only de-activate it here, it will be enabled when changing mode. */
8505 if (p_imdisable)
8506 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008507 else if (State & INSERT)
8508 /* When the option is set from an autocommand, it may need to take
8509 * effect right away. */
8510 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511 }
8512#endif
8513
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008514#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008515 /* 'spell' */
8516 else if ((int *)varp == &curwin->w_p_spell)
8517 {
8518 if (curwin->w_p_spell)
8519 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008520 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008521 if (errmsg != NULL)
8522 EMSG(_(errmsg));
8523 }
8524 }
8525#endif
8526
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527#ifdef FEAT_FKMAP
8528 else if ((int *)varp == &p_altkeymap)
8529 {
8530 if (old_value != p_altkeymap)
8531 {
8532 if (!p_altkeymap)
8533 {
8534 p_hkmap = p_fkmap;
8535 p_fkmap = 0;
8536 }
8537 else
8538 {
8539 p_fkmap = p_hkmap;
8540 p_hkmap = 0;
8541 }
8542 (void)init_chartab();
8543 }
8544 }
8545
8546 /*
8547 * In case some second language keymapping options have changed, check
8548 * and correct the setting in a consistent way.
8549 */
8550
8551 /*
8552 * If hkmap or fkmap are set, reset Arabic keymapping.
8553 */
8554 if ((p_hkmap || p_fkmap) && p_altkeymap)
8555 {
8556 p_altkeymap = p_fkmap;
8557# ifdef FEAT_ARABIC
8558 curwin->w_p_arab = FALSE;
8559# endif
8560 (void)init_chartab();
8561 }
8562
8563 /*
8564 * If hkmap set, reset Farsi keymapping.
8565 */
8566 if (p_hkmap && p_altkeymap)
8567 {
8568 p_altkeymap = 0;
8569 p_fkmap = 0;
8570# ifdef FEAT_ARABIC
8571 curwin->w_p_arab = FALSE;
8572# endif
8573 (void)init_chartab();
8574 }
8575
8576 /*
8577 * If fkmap set, reset Hebrew keymapping.
8578 */
8579 if (p_fkmap && !p_altkeymap)
8580 {
8581 p_altkeymap = 1;
8582 p_hkmap = 0;
8583# ifdef FEAT_ARABIC
8584 curwin->w_p_arab = FALSE;
8585# endif
8586 (void)init_chartab();
8587 }
8588#endif
8589
8590#ifdef FEAT_ARABIC
8591 if ((int *)varp == &curwin->w_p_arab)
8592 {
8593 if (curwin->w_p_arab)
8594 {
8595 /*
8596 * 'arabic' is set, handle various sub-settings.
8597 */
8598 if (!p_tbidi)
8599 {
8600 /* set rightleft mode */
8601 if (!curwin->w_p_rl)
8602 {
8603 curwin->w_p_rl = TRUE;
8604 changed_window_setting();
8605 }
8606
8607 /* Enable Arabic shaping (major part of what Arabic requires) */
8608 if (!p_arshape)
8609 {
8610 p_arshape = TRUE;
8611 redraw_later_clear();
8612 }
8613 }
8614
8615 /* Arabic requires a utf-8 encoding, inform the user if its not
8616 * set. */
8617 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008618 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008619 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8620
Bram Moolenaar8820b482017-03-16 17:23:31 +01008621 msg_source(HL_ATTR(HLF_W));
8622 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008623#ifdef FEAT_EVAL
8624 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8625#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008626 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627
8628# ifdef FEAT_MBYTE
8629 /* set 'delcombine' */
8630 p_deco = TRUE;
8631# endif
8632
8633# ifdef FEAT_KEYMAP
8634 /* Force-set the necessary keymap for arabic */
8635 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8636 OPT_LOCAL);
8637# endif
8638# ifdef FEAT_FKMAP
8639 p_altkeymap = 0;
8640 p_hkmap = 0;
8641 p_fkmap = 0;
8642 (void)init_chartab();
8643# endif
8644 }
8645 else
8646 {
8647 /*
8648 * 'arabic' is reset, handle various sub-settings.
8649 */
8650 if (!p_tbidi)
8651 {
8652 /* reset rightleft mode */
8653 if (curwin->w_p_rl)
8654 {
8655 curwin->w_p_rl = FALSE;
8656 changed_window_setting();
8657 }
8658
8659 /* 'arabicshape' isn't reset, it is a global option and
8660 * another window may still need it "on". */
8661 }
8662
8663 /* 'delcombine' isn't reset, it is a global option and another
8664 * window may still want it "on". */
8665
8666# ifdef FEAT_KEYMAP
8667 /* Revert to the default keymap */
8668 curbuf->b_p_iminsert = B_IMODE_NONE;
8669 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8670# endif
8671 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008672 }
8673
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008674#endif
8675
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008676#ifdef FEAT_TERMGUICOLORS
8677 /* 'termguicolors' */
8678 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008679 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008680# ifdef FEAT_VTP
8681 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8682 if (!has_vtp_working())
8683 {
8684 p_tgc = 0;
8685 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8686 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008687 if (is_term_win32())
8688 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008689# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008690# ifdef FEAT_GUI
8691 if (!gui.in_use && !gui.starting)
8692# endif
8693 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008694# ifdef FEAT_VTP
8695 control_console_color_rgb();
8696 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008697 if (is_term_win32())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008698 set_termname(T_NAME);
8699# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008700 }
8701#endif
8702
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 /*
8704 * End of handling side effects for bool options.
8705 */
8706
Bram Moolenaar53744302015-07-17 17:38:22 +02008707 /* after handling side effects, call autocommand */
8708
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709 options[opt_idx].flags |= P_WAS_SET;
8710
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008711#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008712 if (!starting)
8713 {
8714 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008715 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8716 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8717 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008718 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8719 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8720 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8721 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8722 reset_v_option_vars();
8723 }
8724#endif
8725
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008727 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008728 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008729 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008730 check_redraw(options[opt_idx].flags);
8731
8732 return NULL;
8733}
8734
8735/*
8736 * Set the value of a number option, and take care of side effects.
8737 * Returns NULL for success, or an error message for an error.
8738 */
8739 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008740set_num_option(
8741 int opt_idx, /* index in options[] table */
8742 char_u *varp, /* pointer to the option variable */
8743 long value, /* new value */
8744 char_u *errbuf, /* buffer for error messages */
8745 size_t errbuflen, /* length of "errbuf" */
8746 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747 OPT_MODELINE */
8748{
8749 char_u *errmsg = NULL;
8750 long old_value = *(long *)varp;
8751 long old_Rows = Rows; /* remember old Rows */
8752 long old_Columns = Columns; /* remember old Columns */
8753 long *pp = (long *)varp;
8754
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008755 /* Disallow changing some options from secure mode. */
8756 if ((secure
8757#ifdef HAVE_SANDBOX
8758 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008759#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008760 ) && (options[opt_idx].flags & P_SECURE))
8761 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762
8763 *pp = value;
8764#ifdef FEAT_EVAL
8765 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008766 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008767#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008768#ifdef FEAT_GUI
8769 need_mouse_correct = TRUE;
8770#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771
Bram Moolenaar14f24742012-08-08 18:01:05 +02008772 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773 {
8774 errmsg = e_positive;
8775 curbuf->b_p_sw = curbuf->b_p_ts;
8776 }
8777
8778 /*
8779 * Number options that need some action when changed
8780 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781 if (pp == &p_wh || pp == &p_hh)
8782 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008783 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784 if (p_wh < 1)
8785 {
8786 errmsg = e_positive;
8787 p_wh = 1;
8788 }
8789 if (p_wmh > p_wh)
8790 {
8791 errmsg = e_winheight;
8792 p_wh = p_wmh;
8793 }
8794 if (p_hh < 0)
8795 {
8796 errmsg = e_positive;
8797 p_hh = 0;
8798 }
8799
8800 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008801 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802 {
8803 if (pp == &p_wh && curwin->w_height < p_wh)
8804 win_setheight((int)p_wh);
8805 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8806 win_setheight((int)p_hh);
8807 }
8808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 else if (pp == &p_wmh)
8810 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008811 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008812 if (p_wmh < 0)
8813 {
8814 errmsg = e_positive;
8815 p_wmh = 0;
8816 }
8817 if (p_wmh > p_wh)
8818 {
8819 errmsg = e_winheight;
8820 p_wmh = p_wh;
8821 }
8822 win_setminheight();
8823 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008824 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008826 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 if (p_wiw < 1)
8828 {
8829 errmsg = e_positive;
8830 p_wiw = 1;
8831 }
8832 if (p_wmw > p_wiw)
8833 {
8834 errmsg = e_winwidth;
8835 p_wiw = p_wmw;
8836 }
8837
8838 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008839 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 win_setwidth((int)p_wiw);
8841 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008842 else if (pp == &p_wmw)
8843 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008844 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845 if (p_wmw < 0)
8846 {
8847 errmsg = e_positive;
8848 p_wmw = 0;
8849 }
8850 if (p_wmw > p_wiw)
8851 {
8852 errmsg = e_winwidth;
8853 p_wmw = p_wiw;
8854 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008855 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 /* (re)set last window status line */
8859 else if (pp == &p_ls)
8860 {
8861 last_status(FALSE);
8862 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008863
8864 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008865 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008866 {
8867 shell_new_rows(); /* recompute window positions and heights */
8868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869
8870#ifdef FEAT_GUI
8871 else if (pp == &p_linespace)
8872 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008873 /* Recompute gui.char_height and resize the Vim window to keep the
8874 * same number of lines. */
8875 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008876 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008877 }
8878#endif
8879
8880#ifdef FEAT_FOLDING
8881 /* 'foldlevel' */
8882 else if (pp == &curwin->w_p_fdl)
8883 {
8884 if (curwin->w_p_fdl < 0)
8885 curwin->w_p_fdl = 0;
8886 newFoldLevel();
8887 }
8888
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008889 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008890 else if (pp == &curwin->w_p_fml)
8891 {
8892 foldUpdateAll(curwin);
8893 }
8894
8895 /* 'foldnestmax' */
8896 else if (pp == &curwin->w_p_fdn)
8897 {
8898 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8899 foldUpdateAll(curwin);
8900 }
8901
8902 /* 'foldcolumn' */
8903 else if (pp == &curwin->w_p_fdc)
8904 {
8905 if (curwin->w_p_fdc < 0)
8906 {
8907 errmsg = e_positive;
8908 curwin->w_p_fdc = 0;
8909 }
8910 else if (curwin->w_p_fdc > 12)
8911 {
8912 errmsg = e_invarg;
8913 curwin->w_p_fdc = 12;
8914 }
8915 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008916#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008917
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008918#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919 /* 'shiftwidth' or 'tabstop' */
8920 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8921 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008922# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 if (foldmethodIsIndent(curwin))
8924 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008925# endif
8926# ifdef FEAT_CINDENT
8927 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8928 * parse 'cinoptions'. */
8929 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8930 parse_cino(curbuf);
8931# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008934
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008935#ifdef FEAT_MBYTE
8936 /* 'maxcombine' */
8937 else if (pp == &p_mco)
8938 {
8939 if (p_mco > MAX_MCO)
8940 p_mco = MAX_MCO;
8941 else if (p_mco < 0)
8942 p_mco = 0;
8943 screenclear(); /* will re-allocate the screen */
8944 }
8945#endif
8946
Bram Moolenaar071d4272004-06-13 20:20:40 +00008947 else if (pp == &curbuf->b_p_iminsert)
8948 {
8949 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8950 {
8951 errmsg = e_invarg;
8952 curbuf->b_p_iminsert = B_IMODE_NONE;
8953 }
8954 p_iminsert = curbuf->b_p_iminsert;
8955 if (termcap_active) /* don't do this in the alternate screen */
8956 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008957#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008958 /* Show/unshow value of 'keymap' in status lines. */
8959 status_redraw_curbuf();
8960#endif
8961 }
8962
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008963#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8964 /* 'imstyle' */
8965 else if (pp == &p_imst)
8966 {
8967 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8968 errmsg = e_invarg;
8969 }
8970#endif
8971
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008972 else if (pp == &p_window)
8973 {
8974 if (p_window < 1)
8975 p_window = 1;
8976 else if (p_window >= Rows)
8977 p_window = Rows - 1;
8978 }
8979
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 else if (pp == &curbuf->b_p_imsearch)
8981 {
8982 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8983 {
8984 errmsg = e_invarg;
8985 curbuf->b_p_imsearch = B_IMODE_NONE;
8986 }
8987 p_imsearch = curbuf->b_p_imsearch;
8988 }
8989
8990#ifdef FEAT_TITLE
8991 /* if 'titlelen' has changed, redraw the title */
8992 else if (pp == &p_titlelen)
8993 {
8994 if (p_titlelen < 0)
8995 {
8996 errmsg = e_positive;
8997 p_titlelen = 85;
8998 }
8999 if (starting != NO_SCREEN && old_value != p_titlelen)
9000 need_maketitle = TRUE;
9001 }
9002#endif
9003
9004 /* if p_ch changed value, change the command line height */
9005 else if (pp == &p_ch)
9006 {
9007 if (p_ch < 1)
9008 {
9009 errmsg = e_positive;
9010 p_ch = 1;
9011 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009012 if (p_ch > Rows - min_rows() + 1)
9013 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014
9015 /* Only compute the new window layout when startup has been
9016 * completed. Otherwise the frame sizes may be wrong. */
9017 if (p_ch != old_value && full_screen
9018#ifdef FEAT_GUI
9019 && !gui.starting
9020#endif
9021 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009022 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009023 }
9024
9025 /* when 'updatecount' changes from zero to non-zero, open swap files */
9026 else if (pp == &p_uc)
9027 {
9028 if (p_uc < 0)
9029 {
9030 errmsg = e_positive;
9031 p_uc = 100;
9032 }
9033 if (p_uc && !old_value)
9034 ml_open_files();
9035 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009036#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009037 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009038 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009039 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009040 {
9041 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009042 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009043 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009044 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009045 {
9046 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009047 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009048 }
9049 }
9050#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009051#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009052 else if (pp == &p_mzq)
9053 mzvim_reset_timer();
9054#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009055
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009056#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9057 /* 'pyxversion' */
9058 else if (pp == &p_pyx)
9059 {
9060 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9061 errmsg = e_invarg;
9062 }
9063#endif
9064
Bram Moolenaar071d4272004-06-13 20:20:40 +00009065 /* sync undo before 'undolevels' changes */
9066 else if (pp == &p_ul)
9067 {
9068 /* use the old value, otherwise u_sync() may not work properly */
9069 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009070 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009071 p_ul = value;
9072 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009073 else if (pp == &curbuf->b_p_ul)
9074 {
9075 /* use the old value, otherwise u_sync() may not work properly */
9076 curbuf->b_p_ul = old_value;
9077 u_sync(TRUE);
9078 curbuf->b_p_ul = value;
9079 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009081#ifdef FEAT_LINEBREAK
9082 /* 'numberwidth' must be positive */
9083 else if (pp == &curwin->w_p_nuw)
9084 {
9085 if (curwin->w_p_nuw < 1)
9086 {
9087 errmsg = e_positive;
9088 curwin->w_p_nuw = 1;
9089 }
9090 if (curwin->w_p_nuw > 10)
9091 {
9092 errmsg = e_invarg;
9093 curwin->w_p_nuw = 10;
9094 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009095 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009096 }
9097#endif
9098
Bram Moolenaar1a384422010-07-14 19:53:30 +02009099 else if (pp == &curbuf->b_p_tw)
9100 {
9101 if (curbuf->b_p_tw < 0)
9102 {
9103 errmsg = e_positive;
9104 curbuf->b_p_tw = 0;
9105 }
9106#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009107 {
9108 win_T *wp;
9109 tabpage_T *tp;
9110
9111 FOR_ALL_TAB_WINDOWS(tp, wp)
9112 check_colorcolumn(wp);
9113 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009114#endif
9115 }
9116
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 /*
9118 * Check the bounds for numeric options here
9119 */
9120 if (Rows < min_rows() && full_screen)
9121 {
9122 if (errbuf != NULL)
9123 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009124 vim_snprintf((char *)errbuf, errbuflen,
9125 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009126 errmsg = errbuf;
9127 }
9128 Rows = min_rows();
9129 }
9130 if (Columns < MIN_COLUMNS && full_screen)
9131 {
9132 if (errbuf != NULL)
9133 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009134 vim_snprintf((char *)errbuf, errbuflen,
9135 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136 errmsg = errbuf;
9137 }
9138 Columns = MIN_COLUMNS;
9139 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009140 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 /*
9143 * If the screen (shell) height has been changed, assume it is the
9144 * physical screenheight.
9145 */
9146 if (old_Rows != Rows || old_Columns != Columns)
9147 {
9148 /* Changing the screen size is not allowed while updating the screen. */
9149 if (updating_screen)
9150 *pp = old_value;
9151 else if (full_screen
9152#ifdef FEAT_GUI
9153 && !gui.starting
9154#endif
9155 )
9156 set_shellsize((int)Columns, (int)Rows, TRUE);
9157 else
9158 {
9159 /* Postpone the resizing; check the size and cmdline position for
9160 * messages. */
9161 check_shellsize();
9162 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9163 cmdline_row = Rows - p_ch;
9164 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009165 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009166 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 }
9168
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169 if (curbuf->b_p_ts <= 0)
9170 {
9171 errmsg = e_positive;
9172 curbuf->b_p_ts = 8;
9173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009174 if (p_tm < 0)
9175 {
9176 errmsg = e_positive;
9177 p_tm = 0;
9178 }
9179 if ((curwin->w_p_scr <= 0
9180 || (curwin->w_p_scr > curwin->w_height
9181 && curwin->w_height > 0))
9182 && full_screen)
9183 {
9184 if (pp == &(curwin->w_p_scr))
9185 {
9186 if (curwin->w_p_scr != 0)
9187 errmsg = e_scroll;
9188 win_comp_scroll(curwin);
9189 }
9190 /* If 'scroll' became invalid because of a side effect silently adjust
9191 * it. */
9192 else if (curwin->w_p_scr <= 0)
9193 curwin->w_p_scr = 1;
9194 else /* curwin->w_p_scr > curwin->w_height */
9195 curwin->w_p_scr = curwin->w_height;
9196 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009197 if (p_hi < 0)
9198 {
9199 errmsg = e_positive;
9200 p_hi = 0;
9201 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009202 else if (p_hi > 10000)
9203 {
9204 errmsg = e_invarg;
9205 p_hi = 10000;
9206 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009207 if (p_re < 0 || p_re > 2)
9208 {
9209 errmsg = e_invarg;
9210 p_re = 0;
9211 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009212 if (p_report < 0)
9213 {
9214 errmsg = e_positive;
9215 p_report = 1;
9216 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009217 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009218 {
9219 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9220 p_sj = Rows / 2;
9221 else
9222 {
9223 errmsg = e_scroll;
9224 p_sj = 1;
9225 }
9226 }
9227 if (p_so < 0 && full_screen)
9228 {
9229 errmsg = e_scroll;
9230 p_so = 0;
9231 }
9232 if (p_siso < 0 && full_screen)
9233 {
9234 errmsg = e_positive;
9235 p_siso = 0;
9236 }
9237#ifdef FEAT_CMDWIN
9238 if (p_cwh < 1)
9239 {
9240 errmsg = e_positive;
9241 p_cwh = 1;
9242 }
9243#endif
9244 if (p_ut < 0)
9245 {
9246 errmsg = e_positive;
9247 p_ut = 2000;
9248 }
9249 if (p_ss < 0)
9250 {
9251 errmsg = e_positive;
9252 p_ss = 0;
9253 }
9254
9255 /* May set global value for local option. */
9256 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9257 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9258
9259 options[opt_idx].flags |= P_WAS_SET;
9260
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009261#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009262 if (!starting && errmsg == NULL)
9263 {
9264 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009265 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9266 vim_snprintf((char *)buf_new, 10, "%ld", value);
9267 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009268 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9269 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9270 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9271 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9272 reset_v_option_vars();
9273 }
9274#endif
9275
Bram Moolenaar071d4272004-06-13 20:20:40 +00009276 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009277 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009278 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009279 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280 check_redraw(options[opt_idx].flags);
9281
9282 return errmsg;
9283}
9284
9285/*
9286 * Called after an option changed: check if something needs to be redrawn.
9287 */
9288 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009289check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009290{
9291 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009292 int doclear = (flags & P_RCLR) == P_RCLR;
9293 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009294
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9296 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009297
9298 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9299 changed_window_setting();
9300 if (flags & P_RBUF)
9301 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009302 if (flags & P_RWINONLY)
9303 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009304 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305 redraw_all_later(CLEAR);
9306 else if (all)
9307 redraw_all_later(NOT_VALID);
9308}
9309
9310/*
9311 * Find index for option 'arg'.
9312 * Return -1 if not found.
9313 */
9314 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009315findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316{
9317 int opt_idx;
9318 char *s, *p;
9319 static short quick_tab[27] = {0, 0}; /* quick access table */
9320 int is_term_opt;
9321
9322 /*
9323 * For first call: Initialize the quick-access table.
9324 * It contains the index for the first option that starts with a certain
9325 * letter. There are 26 letters, plus the first "t_" option.
9326 */
9327 if (quick_tab[1] == 0)
9328 {
9329 p = options[0].fullname;
9330 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9331 {
9332 if (s[0] != p[0])
9333 {
9334 if (s[0] == 't' && s[1] == '_')
9335 quick_tab[26] = opt_idx;
9336 else
9337 quick_tab[CharOrdLow(s[0])] = opt_idx;
9338 }
9339 p = s;
9340 }
9341 }
9342
9343 /*
9344 * Check for name starting with an illegal character.
9345 */
9346#ifdef EBCDIC
9347 if (!islower(arg[0]))
9348#else
9349 if (arg[0] < 'a' || arg[0] > 'z')
9350#endif
9351 return -1;
9352
9353 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9354 if (is_term_opt)
9355 opt_idx = quick_tab[26];
9356 else
9357 opt_idx = quick_tab[CharOrdLow(arg[0])];
9358 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9359 {
9360 if (STRCMP(arg, s) == 0) /* match full name */
9361 break;
9362 }
9363 if (s == NULL && !is_term_opt)
9364 {
9365 opt_idx = quick_tab[CharOrdLow(arg[0])];
9366 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9367 {
9368 s = options[opt_idx].shortname;
9369 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9370 break;
9371 s = NULL;
9372 }
9373 }
9374 if (s == NULL)
9375 opt_idx = -1;
9376 return opt_idx;
9377}
9378
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009379#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009380/*
9381 * Get the value for an option.
9382 *
9383 * Returns:
9384 * Number or Toggle option: 1, *numval gets value.
9385 * String option: 0, *stringval gets allocated string.
9386 * Hidden Number or Toggle option: -1.
9387 * hidden String option: -2.
9388 * unknown option: -3.
9389 */
9390 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009391get_option_value(
9392 char_u *name,
9393 long *numval,
9394 char_u **stringval, /* NULL when only checking existence */
9395 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396{
9397 int opt_idx;
9398 char_u *varp;
9399
9400 opt_idx = findoption(name);
9401 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009402 {
9403 int key;
9404
9405 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9406 && (key = find_key_option(name)) != 0)
9407 {
9408 char_u key_name[2];
9409 char_u *p;
9410
9411 if (key < 0)
9412 {
9413 key_name[0] = KEY2TERMCAP0(key);
9414 key_name[1] = KEY2TERMCAP1(key);
9415 }
9416 else
9417 {
9418 key_name[0] = KS_KEY;
9419 key_name[1] = (key & 0xff);
9420 }
9421 p = find_termcode(key_name);
9422 if (p != NULL)
9423 {
9424 if (stringval != NULL)
9425 *stringval = vim_strsave(p);
9426 return 0;
9427 }
9428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009429 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009430 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009431
9432 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9433
9434 if (options[opt_idx].flags & P_STRING)
9435 {
9436 if (varp == NULL) /* hidden option */
9437 return -2;
9438 if (stringval != NULL)
9439 {
9440#ifdef FEAT_CRYPT
9441 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009442 if ((char_u **)varp == &curbuf->b_p_key
9443 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009444 *stringval = vim_strsave((char_u *)"*****");
9445 else
9446#endif
9447 *stringval = vim_strsave(*(char_u **)(varp));
9448 }
9449 return 0;
9450 }
9451
9452 if (varp == NULL) /* hidden option */
9453 return -1;
9454 if (options[opt_idx].flags & P_NUM)
9455 *numval = *(long *)varp;
9456 else
9457 {
9458 /* Special case: 'modified' is b_changed, but we also want to consider
9459 * it set when 'ff' or 'fenc' changed. */
9460 if ((int *)varp == &curbuf->b_changed)
9461 *numval = curbufIsChanged();
9462 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009463 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009464 }
9465 return 1;
9466}
9467#endif
9468
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009469#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009470/*
9471 * Returns the option attributes and its value. Unlike the above function it
9472 * will return either global value or local value of the option depending on
9473 * what was requested, but it will never return global value if it was
9474 * requested to return local one and vice versa. Neither it will return
9475 * buffer-local value if it was requested to return window-local one.
9476 *
9477 * Pretends that option is absent if it is not present in the requested scope
9478 * (i.e. has no global, window-local or buffer-local value depending on
9479 * opt_type). Uses
9480 *
9481 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009482 * 0 hidden or unknown option, also option that does not have requested
9483 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009484 * see SOPT_* in vim.h for other flags
9485 *
9486 * Possible opt_type values: see SREQ_* in vim.h
9487 */
9488 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009489get_option_value_strict(
9490 char_u *name,
9491 long *numval,
9492 char_u **stringval, /* NULL when only obtaining attributes */
9493 int opt_type,
9494 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009495{
9496 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009497 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009498 struct vimoption *p;
9499 int r = 0;
9500
9501 opt_idx = findoption(name);
9502 if (opt_idx < 0)
9503 return 0;
9504
9505 p = &(options[opt_idx]);
9506
9507 /* Hidden option */
9508 if (p->var == NULL)
9509 return 0;
9510
9511 if (p->flags & P_BOOL)
9512 r |= SOPT_BOOL;
9513 else if (p->flags & P_NUM)
9514 r |= SOPT_NUM;
9515 else if (p->flags & P_STRING)
9516 r |= SOPT_STRING;
9517
9518 if (p->indir == PV_NONE)
9519 {
9520 if (opt_type == SREQ_GLOBAL)
9521 r |= SOPT_GLOBAL;
9522 else
9523 return 0; /* Did not request global-only option */
9524 }
9525 else
9526 {
9527 if (p->indir & PV_BOTH)
9528 r |= SOPT_GLOBAL;
9529 else if (opt_type == SREQ_GLOBAL)
9530 return 0; /* Requested global option */
9531
9532 if (p->indir & PV_WIN)
9533 {
9534 if (opt_type == SREQ_BUF)
9535 return 0; /* Did not request window-local option */
9536 else
9537 r |= SOPT_WIN;
9538 }
9539 else if (p->indir & PV_BUF)
9540 {
9541 if (opt_type == SREQ_WIN)
9542 return 0; /* Did not request buffer-local option */
9543 else
9544 r |= SOPT_BUF;
9545 }
9546 }
9547
9548 if (stringval == NULL)
9549 return r;
9550
9551 if (opt_type == SREQ_GLOBAL)
9552 varp = p->var;
9553 else
9554 {
9555 if (opt_type == SREQ_BUF)
9556 {
9557 /* Special case: 'modified' is b_changed, but we also want to
9558 * consider it set when 'ff' or 'fenc' changed. */
9559 if (p->indir == PV_MOD)
9560 {
9561 *numval = bufIsChanged((buf_T *) from);
9562 varp = NULL;
9563 }
9564#ifdef FEAT_CRYPT
9565 else if (p->indir == PV_KEY)
9566 {
9567 /* never return the value of the crypt key */
9568 *stringval = NULL;
9569 varp = NULL;
9570 }
9571#endif
9572 else
9573 {
9574 aco_save_T aco;
9575 aucmd_prepbuf(&aco, (buf_T *) from);
9576 varp = get_varp(p);
9577 aucmd_restbuf(&aco);
9578 }
9579 }
9580 else if (opt_type == SREQ_WIN)
9581 {
9582 win_T *save_curwin;
9583 save_curwin = curwin;
9584 curwin = (win_T *) from;
9585 curbuf = curwin->w_buffer;
9586 varp = get_varp(p);
9587 curwin = save_curwin;
9588 curbuf = curwin->w_buffer;
9589 }
9590 if (varp == p->var)
9591 return (r | SOPT_UNSET);
9592 }
9593
9594 if (varp != NULL)
9595 {
9596 if (p->flags & P_STRING)
9597 *stringval = vim_strsave(*(char_u **)(varp));
9598 else if (p->flags & P_NUM)
9599 *numval = *(long *) varp;
9600 else
9601 *numval = *(int *)varp;
9602 }
9603
9604 return r;
9605}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009606
9607/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009608 * Iterate over options. First argument is a pointer to a pointer to a
9609 * structure inside options[] array, second is option type like in the above
9610 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009611 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009612 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009613 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009614 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009615 * first argument to NULL.
9616 *
9617 * Returns full option name for current option on each call.
9618 */
9619 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009620option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009621{
9622 struct vimoption *ret = NULL;
9623 do
9624 {
9625 if (*option == NULL)
9626 *option = (void *) options;
9627 else if (((struct vimoption *) (*option))->fullname == NULL)
9628 {
9629 *option = NULL;
9630 return NULL;
9631 }
9632 else
9633 *option = (void *) (((struct vimoption *) (*option)) + 1);
9634
9635 ret = ((struct vimoption *) (*option));
9636
9637 /* Hidden option */
9638 if (ret->var == NULL)
9639 {
9640 ret = NULL;
9641 continue;
9642 }
9643
9644 switch (opt_type)
9645 {
9646 case SREQ_GLOBAL:
9647 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9648 ret = NULL;
9649 break;
9650 case SREQ_BUF:
9651 if (!(ret->indir & PV_BUF))
9652 ret = NULL;
9653 break;
9654 case SREQ_WIN:
9655 if (!(ret->indir & PV_WIN))
9656 ret = NULL;
9657 break;
9658 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009659 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009660 return NULL;
9661 }
9662 }
9663 while (ret == NULL);
9664
9665 return (char_u *)ret->fullname;
9666}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009667#endif
9668
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669/*
9670 * Set the value of option "name".
9671 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009672 *
9673 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009674 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009675 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009676set_option_value(
9677 char_u *name,
9678 long number,
9679 char_u *string,
9680 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681{
9682 int opt_idx;
9683 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009684 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009685
9686 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009687 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009688 {
9689 int key;
9690
9691 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9692 && (key = find_key_option(name)) != 0)
9693 {
9694 char_u key_name[2];
9695
9696 if (key < 0)
9697 {
9698 key_name[0] = KEY2TERMCAP0(key);
9699 key_name[1] = KEY2TERMCAP1(key);
9700 }
9701 else
9702 {
9703 key_name[0] = KS_KEY;
9704 key_name[1] = (key & 0xff);
9705 }
9706 add_termcode(key_name, string, FALSE);
9707 if (full_screen)
9708 ttest(FALSE);
9709 redraw_all_later(CLEAR);
9710 return NULL;
9711 }
9712
Bram Moolenaar071d4272004-06-13 20:20:40 +00009713 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009714 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715 else
9716 {
9717 flags = options[opt_idx].flags;
9718#ifdef HAVE_SANDBOX
9719 /* Disallow changing some options in the sandbox */
9720 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009721 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009722 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009723 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009726 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009727 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728 else
9729 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009730 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 if (varp != NULL) /* hidden option is not changed */
9732 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009733 if (number == 0 && string != NULL)
9734 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009735 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009736
9737 /* Either we are given a string or we are setting option
9738 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009739 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009740 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009741 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009742 {
9743 /* There's another character after zeros or the string
9744 * is empty. In both cases, we are trying to set a
9745 * num option using a string. */
9746 EMSG3(_("E521: Number required: &%s = '%s'"),
9747 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009748 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009749
9750 }
9751 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009753 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009754 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009756 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009757 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758 }
9759 }
9760 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009761 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762}
9763
9764/*
9765 * Get the terminal code for a terminal option.
9766 * Returns NULL when not found.
9767 */
9768 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009769get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770{
9771 int opt_idx;
9772 char_u *varp;
9773
9774 if (tname[0] != 't' || tname[1] != '_' ||
9775 tname[2] == NUL || tname[3] == NUL)
9776 return NULL;
9777 if ((opt_idx = findoption(tname)) >= 0)
9778 {
9779 varp = get_varp(&(options[opt_idx]));
9780 if (varp != NULL)
9781 varp = *(char_u **)(varp);
9782 return varp;
9783 }
9784 return find_termcode(tname + 2);
9785}
9786
9787 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009788get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009789{
9790 int i;
9791
9792 i = findoption((char_u *)"hl");
9793 if (i >= 0)
9794 return options[i].def_val[VI_DEFAULT];
9795 return (char_u *)NULL;
9796}
9797
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009798#if defined(FEAT_MBYTE) || defined(PROTO)
9799 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009800get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009801{
9802 int i;
9803
9804 i = findoption((char_u *)"enc");
9805 if (i >= 0)
9806 return options[i].def_val[VI_DEFAULT];
9807 return (char_u *)NULL;
9808}
9809#endif
9810
Bram Moolenaar071d4272004-06-13 20:20:40 +00009811/*
9812 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9813 */
9814 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009815find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816{
9817 int key;
9818 int modifiers;
9819
9820 /*
9821 * Don't use get_special_key_code() for t_xx, we don't want it to call
9822 * add_termcap_entry().
9823 */
9824 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9825 key = TERMCAP2KEY(arg[2], arg[3]);
9826 else
9827 {
9828 --arg; /* put arg at the '<' */
9829 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009830 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009831 if (modifiers) /* can't handle modifiers here */
9832 key = 0;
9833 }
9834 return key;
9835}
9836
9837/*
9838 * if 'all' == 0: show changed options
9839 * if 'all' == 1: show all normal options
9840 * if 'all' == 2: show all terminal options
9841 */
9842 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009843showoptions(
9844 int all,
9845 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009846{
9847 struct vimoption *p;
9848 int col;
9849 int isterm;
9850 char_u *varp;
9851 struct vimoption **items;
9852 int item_count;
9853 int run;
9854 int row, rows;
9855 int cols;
9856 int i;
9857 int len;
9858
9859#define INC 20
9860#define GAP 3
9861
9862 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9863 PARAM_COUNT));
9864 if (items == NULL)
9865 return;
9866
9867 /* Highlight title */
9868 if (all == 2)
9869 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9870 else if (opt_flags & OPT_GLOBAL)
9871 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9872 else if (opt_flags & OPT_LOCAL)
9873 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9874 else
9875 MSG_PUTS_TITLE(_("\n--- Options ---"));
9876
9877 /*
9878 * do the loop two times:
9879 * 1. display the short items
9880 * 2. display the long items (only strings and numbers)
9881 */
9882 for (run = 1; run <= 2 && !got_int; ++run)
9883 {
9884 /*
9885 * collect the items in items[]
9886 */
9887 item_count = 0;
9888 for (p = &options[0]; p->fullname != NULL; p++)
9889 {
9890 varp = NULL;
9891 isterm = istermoption(p);
9892 if (opt_flags != 0)
9893 {
9894 if (p->indir != PV_NONE && !isterm)
9895 varp = get_varp_scope(p, opt_flags);
9896 }
9897 else
9898 varp = get_varp(p);
9899 if (varp != NULL
9900 && ((all == 2 && isterm)
9901 || (all == 1 && !isterm)
9902 || (all == 0 && !optval_default(p, varp))))
9903 {
9904 if (p->flags & P_BOOL)
9905 len = 1; /* a toggle option fits always */
9906 else
9907 {
9908 option_value2string(p, opt_flags);
9909 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9910 }
9911 if ((len <= INC - GAP && run == 1) ||
9912 (len > INC - GAP && run == 2))
9913 items[item_count++] = p;
9914 }
9915 }
9916
9917 /*
9918 * display the items
9919 */
9920 if (run == 1)
9921 {
9922 cols = (Columns + GAP - 3) / INC;
9923 if (cols == 0)
9924 cols = 1;
9925 rows = (item_count + cols - 1) / cols;
9926 }
9927 else /* run == 2 */
9928 rows = item_count;
9929 for (row = 0; row < rows && !got_int; ++row)
9930 {
9931 msg_putchar('\n'); /* go to next line */
9932 if (got_int) /* 'q' typed in more */
9933 break;
9934 col = 0;
9935 for (i = row; i < item_count; i += rows)
9936 {
9937 msg_col = col; /* make columns */
9938 showoneopt(items[i], opt_flags);
9939 col += INC;
9940 }
9941 out_flush();
9942 ui_breakcheck();
9943 }
9944 }
9945 vim_free(items);
9946}
9947
9948/*
9949 * Return TRUE if option "p" has its default value.
9950 */
9951 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009952optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953{
9954 int dvi;
9955
9956 if (varp == NULL)
9957 return TRUE; /* hidden option is always at default */
9958 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9959 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009960 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009962 /* the cast to long is required for Manx C, long_i is
9963 * needed for MSVC */
9964 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965 /* P_STRING */
9966 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9967}
9968
9969/*
9970 * showoneopt: show the value of one option
9971 * must not be called with a hidden option!
9972 */
9973 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009974showoneopt(
9975 struct vimoption *p,
9976 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009978 char_u *varp;
9979 int save_silent = silent_mode;
9980
9981 silent_mode = FALSE;
9982 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983
9984 varp = get_varp_scope(p, opt_flags);
9985
9986 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9987 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9988 ? !curbufIsChanged() : !*(int *)varp))
9989 MSG_PUTS("no");
9990 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9991 MSG_PUTS("--");
9992 else
9993 MSG_PUTS(" ");
9994 MSG_PUTS(p->fullname);
9995 if (!(p->flags & P_BOOL))
9996 {
9997 msg_putchar('=');
9998 /* put value string in NameBuff */
9999 option_value2string(p, opt_flags);
10000 msg_outtrans(NameBuff);
10001 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010002
10003 silent_mode = save_silent;
10004 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010005}
10006
10007/*
10008 * Write modified options as ":set" commands to a file.
10009 *
10010 * There are three values for "opt_flags":
10011 * OPT_GLOBAL: Write global option values and fresh values of
10012 * buffer-local options (used for start of a session
10013 * file).
10014 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10015 * curwin (used for a vimrc file).
10016 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10017 * and local values for window-local options of
10018 * curwin. Local values are also written when at the
10019 * default value, because a modeline or autocommand
10020 * may have set them when doing ":edit file" and the
10021 * user has set them back at the default or fresh
10022 * value.
10023 * When "local_only" is TRUE, don't write fresh
10024 * values, only local values (for ":mkview").
10025 * (fresh value = value used for a new buffer or window for a local option).
10026 *
10027 * Return FAIL on error, OK otherwise.
10028 */
10029 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010030makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031{
10032 struct vimoption *p;
10033 char_u *varp; /* currently used value */
10034 char_u *varp_fresh; /* local value */
10035 char_u *varp_local = NULL; /* fresh value */
10036 char *cmd;
10037 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010038 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010039
10040 /*
10041 * The options that don't have a default (terminal name, columns, lines)
10042 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010043 * Do the loop over "options[]" twice: once for options with the
10044 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010045 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010046 for (pri = 1; pri >= 0; --pri)
10047 {
10048 for (p = &options[0]; !istermoption(p); p++)
10049 if (!(p->flags & P_NO_MKRC)
10050 && !istermoption(p)
10051 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052 {
10053 /* skip global option when only doing locals */
10054 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10055 continue;
10056
10057 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10058 * file, they are always buffer-specific. */
10059 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10060 continue;
10061
10062 /* Global values are only written when not at the default value. */
10063 varp = get_varp_scope(p, opt_flags);
10064 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10065 continue;
10066
10067 round = 2;
10068 if (p->indir != PV_NONE)
10069 {
10070 if (p->var == VAR_WIN)
10071 {
10072 /* skip window-local option when only doing globals */
10073 if (!(opt_flags & OPT_LOCAL))
10074 continue;
10075 /* When fresh value of window-local option is not at the
10076 * default, need to write it too. */
10077 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10078 {
10079 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10080 if (!optval_default(p, varp_fresh))
10081 {
10082 round = 1;
10083 varp_local = varp;
10084 varp = varp_fresh;
10085 }
10086 }
10087 }
10088 }
10089
10090 /* Round 1: fresh value for window-local options.
10091 * Round 2: other values */
10092 for ( ; round <= 2; varp = varp_local, ++round)
10093 {
10094 if (round == 1 || (opt_flags & OPT_GLOBAL))
10095 cmd = "set";
10096 else
10097 cmd = "setlocal";
10098
10099 if (p->flags & P_BOOL)
10100 {
10101 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10102 return FAIL;
10103 }
10104 else if (p->flags & P_NUM)
10105 {
10106 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10107 return FAIL;
10108 }
10109 else /* P_STRING */
10110 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010111 int do_endif = FALSE;
10112
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113 /* Don't set 'syntax' and 'filetype' again if the value is
10114 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010115 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010116#if defined(FEAT_SYN_HL)
10117 p->indir == PV_SYN ||
10118#endif
10119 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120 {
10121 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10122 *(char_u **)(varp)) < 0
10123 || put_eol(fd) < 0)
10124 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010125 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126 }
10127 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10128 (p->flags & P_EXPAND) != 0) == FAIL)
10129 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010130 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131 {
10132 if (put_line(fd, "endif") == FAIL)
10133 return FAIL;
10134 }
10135 }
10136 }
10137 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139 return OK;
10140}
10141
10142#if defined(FEAT_FOLDING) || defined(PROTO)
10143/*
10144 * Generate set commands for the local fold options only. Used when
10145 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10146 */
10147 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010148makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149{
10150 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10151# ifdef FEAT_EVAL
10152 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10153 == FAIL
10154# endif
10155 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10156 == FAIL
10157 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10158 == FAIL
10159 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10160 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10161 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10162 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10163 )
10164 return FAIL;
10165
10166 return OK;
10167}
10168#endif
10169
10170 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010171put_setstring(
10172 FILE *fd,
10173 char *cmd,
10174 char *name,
10175 char_u **valuep,
10176 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177{
10178 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010179 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180
10181 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10182 return FAIL;
10183 if (*valuep != NULL)
10184 {
10185 /* Output 'pastetoggle' as key names. For other
10186 * options some characters have to be escaped with
10187 * CTRL-V or backslash */
10188 if (valuep == &p_pt)
10189 {
10190 s = *valuep;
10191 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010192 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 return FAIL;
10194 }
10195 else if (expand)
10196 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010197 buf = alloc(MAXPATHL);
10198 if (buf == NULL)
10199 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10201 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010202 {
10203 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010205 }
10206 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207 }
10208 else if (put_escstr(fd, *valuep, 2) == FAIL)
10209 return FAIL;
10210 }
10211 if (put_eol(fd) < 0)
10212 return FAIL;
10213 return OK;
10214}
10215
10216 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010217put_setnum(
10218 FILE *fd,
10219 char *cmd,
10220 char *name,
10221 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222{
10223 long wc;
10224
10225 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10226 return FAIL;
10227 if (wc_use_keyname((char_u *)valuep, &wc))
10228 {
10229 /* print 'wildchar' and 'wildcharm' as a key name */
10230 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10231 return FAIL;
10232 }
10233 else if (fprintf(fd, "%ld", *valuep) < 0)
10234 return FAIL;
10235 if (put_eol(fd) < 0)
10236 return FAIL;
10237 return OK;
10238}
10239
10240 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010241put_setbool(
10242 FILE *fd,
10243 char *cmd,
10244 char *name,
10245 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246{
Bram Moolenaar893de922007-10-02 18:40:57 +000010247 if (value < 0) /* global/local option using global value */
10248 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010249 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10250 || put_eol(fd) < 0)
10251 return FAIL;
10252 return OK;
10253}
10254
10255/*
10256 * Clear all the terminal options.
10257 * If the option has been allocated, free the memory.
10258 * Terminal options are never hidden or indirect.
10259 */
10260 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010261clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010263 /*
10264 * Reset a few things before clearing the old options. This may cause
10265 * outputting a few things that the terminal doesn't understand, but the
10266 * screen will be cleared later, so this is OK.
10267 */
10268#ifdef FEAT_MOUSE_TTY
10269 mch_setmouse(FALSE); /* switch mouse off */
10270#endif
10271#ifdef FEAT_TITLE
10272 mch_restore_title(3); /* restore window titles */
10273#endif
10274#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10275 /* When starting the GUI close the display opened for the clipboard.
10276 * After restoring the title, because that will need the display. */
10277 if (gui.starting)
10278 clear_xterm_clip();
10279#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010280 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010282 free_termoptions();
10283}
10284
10285 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010286free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010287{
10288 struct vimoption *p;
10289
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290 for (p = &options[0]; p->fullname != NULL; p++)
10291 if (istermoption(p))
10292 {
10293 if (p->flags & P_ALLOCED)
10294 free_string_option(*(char_u **)(p->var));
10295 if (p->flags & P_DEF_ALLOCED)
10296 free_string_option(p->def_val[VI_DEFAULT]);
10297 *(char_u **)(p->var) = empty_option;
10298 p->def_val[VI_DEFAULT] = empty_option;
10299 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10300 }
10301 clear_termcodes();
10302}
10303
10304/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010305 * Free the string for one term option, if it was allocated.
10306 * Set the string to empty_option and clear allocated flag.
10307 * "var" points to the option value.
10308 */
10309 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010310free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010311{
10312 struct vimoption *p;
10313
10314 for (p = &options[0]; p->fullname != NULL; p++)
10315 if (p->var == var)
10316 {
10317 if (p->flags & P_ALLOCED)
10318 free_string_option(*(char_u **)(p->var));
10319 *(char_u **)(p->var) = empty_option;
10320 p->flags &= ~P_ALLOCED;
10321 break;
10322 }
10323}
10324
10325/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 * Set the terminal option defaults to the current value.
10327 * Used after setting the terminal name.
10328 */
10329 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010330set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331{
10332 struct vimoption *p;
10333
10334 for (p = &options[0]; p->fullname != NULL; p++)
10335 {
10336 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10337 {
10338 if (p->flags & P_DEF_ALLOCED)
10339 {
10340 free_string_option(p->def_val[VI_DEFAULT]);
10341 p->flags &= ~P_DEF_ALLOCED;
10342 }
10343 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10344 if (p->flags & P_ALLOCED)
10345 {
10346 p->flags |= P_DEF_ALLOCED;
10347 p->flags &= ~P_ALLOCED; /* don't free the value now */
10348 }
10349 }
10350 }
10351}
10352
10353/*
10354 * return TRUE if 'p' starts with 't_'
10355 */
10356 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010357istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358{
10359 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10360}
10361
10362/*
10363 * Compute columns for ruler and shown command. 'sc_col' is also used to
10364 * decide what the maximum length of a message on the status line can be.
10365 * If there is a status line for the last window, 'sc_col' is independent
10366 * of 'ru_col'.
10367 */
10368
10369#define COL_RULER 17 /* columns needed by standard ruler */
10370
10371 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010372comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010374#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010375 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376
10377 sc_col = 0;
10378 ru_col = 0;
10379 if (p_ru)
10380 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010381# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010382 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010383# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010385# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386 /* no last status line, adjust sc_col */
10387 if (!last_has_status)
10388 sc_col = ru_col;
10389 }
10390 if (p_sc)
10391 {
10392 sc_col += SHOWCMD_COLS;
10393 if (!p_ru || last_has_status) /* no need for separating space */
10394 ++sc_col;
10395 }
10396 sc_col = Columns - sc_col;
10397 ru_col = Columns - ru_col;
10398 if (sc_col <= 0) /* screen too narrow, will become a mess */
10399 sc_col = 1;
10400 if (ru_col <= 0)
10401 ru_col = 1;
10402#else
10403 sc_col = Columns;
10404 ru_col = Columns;
10405#endif
10406}
10407
10408/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010409 * Unset local option value, similar to ":set opt<".
10410 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010411 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010412unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413{
10414 struct vimoption *p;
10415 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010416 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010417
10418 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010419 if (opt_idx < 0)
10420 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010421 p = &(options[opt_idx]);
10422
10423 switch ((int)p->indir)
10424 {
10425 /* global option with local value: use local value if it's been set */
10426 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010427 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010428 break;
10429 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010430 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 break;
10432 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010433 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434 break;
10435 case PV_AR:
10436 buf->b_p_ar = -1;
10437 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010438 case PV_BKC:
10439 clear_string_option(&buf->b_p_bkc);
10440 buf->b_bkc_flags = 0;
10441 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010442 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010443 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010444 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010445 case PV_TC:
10446 clear_string_option(&buf->b_p_tc);
10447 buf->b_tc_flags = 0;
10448 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010449#ifdef FEAT_FIND_ID
10450 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010451 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 break;
10453 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010454 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010455 break;
10456#endif
10457#ifdef FEAT_INS_EXPAND
10458 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010459 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010460 break;
10461 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010462 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010463 break;
10464#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010465 case PV_FP:
10466 clear_string_option(&buf->b_p_fp);
10467 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010468#ifdef FEAT_QUICKFIX
10469 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010470 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010471 break;
10472 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010473 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010474 break;
10475 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010476 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010477 break;
10478#endif
10479#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10480 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010481 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010482 break;
10483#endif
10484#if defined(FEAT_CRYPT)
10485 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010486 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010487 break;
10488#endif
10489#ifdef FEAT_STL_OPT
10490 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010491 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010492 break;
10493#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010494 case PV_UL:
10495 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10496 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010497#ifdef FEAT_LISP
10498 case PV_LW:
10499 clear_string_option(&buf->b_p_lw);
10500 break;
10501#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010502#ifdef FEAT_MBYTE
10503 case PV_MENC:
10504 clear_string_option(&buf->b_p_menc);
10505 break;
10506#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010507 }
10508}
10509
10510/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511 * Get pointer to option variable, depending on local or global scope.
10512 */
10513 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010514get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515{
10516 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10517 {
10518 if (p->var == VAR_WIN)
10519 return (char_u *)GLOBAL_WO(get_varp(p));
10520 return p->var;
10521 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010522 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523 {
10524 switch ((int)p->indir)
10525 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010526 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010528 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10529 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10530 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010531#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010532 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10533 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10534 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010535 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010536 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010537 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010539 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10540 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541#endif
10542#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010543 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10544 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010546#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10547 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10548#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010549#if defined(FEAT_CRYPT)
10550 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10551#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010552#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010553 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010554#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010555 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010556#ifdef FEAT_LISP
10557 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10558#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010559 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010560#ifdef FEAT_MBYTE
10561 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563 }
10564 return NULL; /* "cannot happen" */
10565 }
10566 return get_varp(p);
10567}
10568
10569/*
10570 * Get pointer to option variable.
10571 */
10572 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010573get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574{
10575 /* hidden option, always return NULL */
10576 if (p->var == NULL)
10577 return NULL;
10578
10579 switch ((int)p->indir)
10580 {
10581 case PV_NONE: return p->var;
10582
10583 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010586 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010588 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010590 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010592 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010594 case PV_TC: return *curbuf->b_p_tc != NUL
10595 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010596 case PV_BKC: return *curbuf->b_p_bkc != NUL
10597 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010599 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010601 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10603#endif
10604#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010605 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010607 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10609#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010610 case PV_FP: return *curbuf->b_p_fp != NUL
10611 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010613 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010615 case PV_GP: return *curbuf->b_p_gp != NUL
10616 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10617 case PV_MP: return *curbuf->b_p_mp != NUL
10618 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010620#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10621 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10622 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10623#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010624#if defined(FEAT_CRYPT)
10625 case PV_CM: return *curbuf->b_p_cm != NUL
10626 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10627#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010628#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010629 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010630 ? (char_u *)&(curwin->w_p_stl) : p->var;
10631#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010632 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10633 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010634#ifdef FEAT_LISP
10635 case PV_LW: return *curbuf->b_p_lw != NUL
10636 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10637#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010638#ifdef FEAT_MBYTE
10639 case PV_MENC: return *curbuf->b_p_menc != NUL
10640 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642
10643#ifdef FEAT_ARABIC
10644 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10645#endif
10646 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010647#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010648 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10649#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010650#ifdef FEAT_SYN_HL
10651 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10652 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010653 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010654#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655#ifdef FEAT_DIFF
10656 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10657#endif
10658#ifdef FEAT_FOLDING
10659 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10660 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10661 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10662 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10663 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10664 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10665 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10666# ifdef FEAT_EVAL
10667 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10668 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10669# endif
10670 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10671#endif
10672 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010673 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010674#ifdef FEAT_LINEBREAK
10675 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010677 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010678 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010679#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10681#endif
10682#ifdef FEAT_RIGHTLEFT
10683 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10684 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10685#endif
10686 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10687 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10688#ifdef FEAT_LINEBREAK
10689 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010690 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10691 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010693 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010694 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010695#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010696 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10697 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10698#endif
10699#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010700 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10701 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10702 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704
10705 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10706 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10707#ifdef FEAT_MBYTE
10708 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010710 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10711 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010712 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10713 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10714#ifdef FEAT_CINDENT
10715 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10716 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10717 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10718#endif
10719#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10720 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10721#endif
10722#ifdef FEAT_COMMENTS
10723 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10724#endif
10725#ifdef FEAT_FOLDING
10726 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10727#endif
10728#ifdef FEAT_INS_EXPAND
10729 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10730#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010731#ifdef FEAT_COMPL_FUNC
10732 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010733 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010734#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010736 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10738#ifdef FEAT_MBYTE
10739 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10740#endif
10741 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010742 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010744 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10746 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10747 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10748 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10749#ifdef FEAT_FIND_ID
10750# ifdef FEAT_EVAL
10751 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10752# endif
10753#endif
10754#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10755 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10756 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10757#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010758#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010759 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761#ifdef FEAT_CRYPT
10762 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10763#endif
10764#ifdef FEAT_LISP
10765 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10766#endif
10767 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10768 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10769 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10770 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10771 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010773#ifdef FEAT_TEXTOBJ
10774 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10775#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010776 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10777#ifdef FEAT_SMARTINDENT
10778 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10779#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10782#ifdef FEAT_SEARCHPATH
10783 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10784#endif
10785 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10786#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010787 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010788 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10789#endif
10790#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010791 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10792 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10793 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010794#endif
10795 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10796 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10797 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10798 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010799#ifdef FEAT_PERSISTENT_UNDO
10800 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010802 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10803#ifdef FEAT_KEYMAP
10804 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10805#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010806#ifdef FEAT_SIGNS
10807 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10808#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010809 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810 }
10811 /* always return a valid pointer to avoid a crash! */
10812 return (char_u *)&(curbuf->b_p_wm);
10813}
10814
10815/*
10816 * Get the value of 'equalprg', either the buffer-local one or the global one.
10817 */
10818 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010819get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820{
10821 if (*curbuf->b_p_ep == NUL)
10822 return p_ep;
10823 return curbuf->b_p_ep;
10824}
10825
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826/*
10827 * Copy options from one window to another.
10828 * Used when splitting a window.
10829 */
10830 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010831win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832{
10833 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10834 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10835# ifdef FEAT_RIGHTLEFT
10836# ifdef FEAT_FKMAP
10837 /* Is this right? */
10838 wp_to->w_farsi = wp_from->w_farsi;
10839# endif
10840# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010841#if defined(FEAT_LINEBREAK)
10842 briopt_check(wp_to);
10843#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010844}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845
10846/*
10847 * Copy the options from one winopt_T to another.
10848 * Doesn't free the old option values in "to", use clear_winopt() for that.
10849 * The 'scroll' option is not copied, because it depends on the window height.
10850 * The 'previewwindow' option is reset, there can be only one preview window.
10851 */
10852 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010853copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854{
10855#ifdef FEAT_ARABIC
10856 to->wo_arab = from->wo_arab;
10857#endif
10858 to->wo_list = from->wo_list;
10859 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010860 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010861#ifdef FEAT_LINEBREAK
10862 to->wo_nuw = from->wo_nuw;
10863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864#ifdef FEAT_RIGHTLEFT
10865 to->wo_rl = from->wo_rl;
10866 to->wo_rlc = vim_strsave(from->wo_rlc);
10867#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010868#ifdef FEAT_STL_OPT
10869 to->wo_stl = vim_strsave(from->wo_stl);
10870#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010872#ifdef FEAT_DIFF
10873 to->wo_wrap_save = from->wo_wrap_save;
10874#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010875#ifdef FEAT_LINEBREAK
10876 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010877 to->wo_bri = from->wo_bri;
10878 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010881 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010882 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010883 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010884#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010885 to->wo_spell = from->wo_spell;
10886#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010887#ifdef FEAT_SYN_HL
10888 to->wo_cuc = from->wo_cuc;
10889 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010890 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010891#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892#ifdef FEAT_DIFF
10893 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010894 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010896#ifdef FEAT_CONCEAL
10897 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010898 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010899#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010900#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010901 to->wo_twk = vim_strsave(from->wo_twk);
10902 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010903#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904#ifdef FEAT_FOLDING
10905 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010906 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010908 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909 to->wo_fdi = vim_strsave(from->wo_fdi);
10910 to->wo_fml = from->wo_fml;
10911 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010912 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010914 to->wo_fdm_save = from->wo_diff_saved
10915 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916 to->wo_fdn = from->wo_fdn;
10917# ifdef FEAT_EVAL
10918 to->wo_fde = vim_strsave(from->wo_fde);
10919 to->wo_fdt = vim_strsave(from->wo_fdt);
10920# endif
10921 to->wo_fmr = vim_strsave(from->wo_fmr);
10922#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010923#ifdef FEAT_SIGNS
10924 to->wo_scl = vim_strsave(from->wo_scl);
10925#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010926 check_winopt(to); /* don't want NULL pointers */
10927}
10928
10929/*
10930 * Check string options in a window for a NULL value.
10931 */
10932 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010933check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010934{
10935 check_winopt(&win->w_onebuf_opt);
10936 check_winopt(&win->w_allbuf_opt);
10937}
10938
10939/*
10940 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10941 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010942 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010943check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944{
10945#ifdef FEAT_FOLDING
10946 check_string_option(&wop->wo_fdi);
10947 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010948 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949# ifdef FEAT_EVAL
10950 check_string_option(&wop->wo_fde);
10951 check_string_option(&wop->wo_fdt);
10952# endif
10953 check_string_option(&wop->wo_fmr);
10954#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010955#ifdef FEAT_SIGNS
10956 check_string_option(&wop->wo_scl);
10957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010958#ifdef FEAT_RIGHTLEFT
10959 check_string_option(&wop->wo_rlc);
10960#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010961#ifdef FEAT_STL_OPT
10962 check_string_option(&wop->wo_stl);
10963#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010964#ifdef FEAT_SYN_HL
10965 check_string_option(&wop->wo_cc);
10966#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010967#ifdef FEAT_CONCEAL
10968 check_string_option(&wop->wo_cocu);
10969#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010970#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010971 check_string_option(&wop->wo_twk);
10972 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010973#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010974#ifdef FEAT_LINEBREAK
10975 check_string_option(&wop->wo_briopt);
10976#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010977}
10978
10979/*
10980 * Free the allocated memory inside a winopt_T.
10981 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010983clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010984{
10985#ifdef FEAT_FOLDING
10986 clear_string_option(&wop->wo_fdi);
10987 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010988 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989# ifdef FEAT_EVAL
10990 clear_string_option(&wop->wo_fde);
10991 clear_string_option(&wop->wo_fdt);
10992# endif
10993 clear_string_option(&wop->wo_fmr);
10994#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010995#ifdef FEAT_SIGNS
10996 clear_string_option(&wop->wo_scl);
10997#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010998#ifdef FEAT_LINEBREAK
10999 clear_string_option(&wop->wo_briopt);
11000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011001#ifdef FEAT_RIGHTLEFT
11002 clear_string_option(&wop->wo_rlc);
11003#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011004#ifdef FEAT_STL_OPT
11005 clear_string_option(&wop->wo_stl);
11006#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011007#ifdef FEAT_SYN_HL
11008 clear_string_option(&wop->wo_cc);
11009#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011010#ifdef FEAT_CONCEAL
11011 clear_string_option(&wop->wo_cocu);
11012#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011013#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011014 clear_string_option(&wop->wo_twk);
11015 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011016#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011017}
11018
11019/*
11020 * Copy global option values to local options for one buffer.
11021 * Used when creating a new buffer and sometimes when entering a buffer.
11022 * flags:
11023 * BCO_ENTER We will enter the buf buffer.
11024 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11025 * appropriate.
11026 * BCO_NOHELP Don't copy the values to a help buffer.
11027 */
11028 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011029buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011030{
11031 int should_copy = TRUE;
11032 char_u *save_p_isk = NULL; /* init for GCC */
11033 int dont_do_help;
11034 int did_isk = FALSE;
11035
11036 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011037 * Skip this when the option defaults have not been set yet. Happens when
11038 * main() allocates the first buffer.
11039 */
11040 if (p_cpo != NULL)
11041 {
11042 /*
11043 * Always copy when entering and 'cpo' contains 'S'.
11044 * Don't copy when already initialized.
11045 * Don't copy when 'cpo' contains 's' and not entering.
11046 * 'S' BCO_ENTER initialized 's' should_copy
11047 * yes yes X X TRUE
11048 * yes no yes X FALSE
11049 * no X yes X FALSE
11050 * X no no yes FALSE
11051 * X no no no TRUE
11052 * no yes no X TRUE
11053 */
11054 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11055 && (buf->b_p_initialized
11056 || (!(flags & BCO_ENTER)
11057 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11058 should_copy = FALSE;
11059
11060 if (should_copy || (flags & BCO_ALWAYS))
11061 {
11062 /* Don't copy the options specific to a help buffer when
11063 * BCO_NOHELP is given or the options were initialized already
11064 * (jumping back to a help file with CTRL-T or CTRL-O) */
11065 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11066 || buf->b_p_initialized;
11067 if (dont_do_help) /* don't free b_p_isk */
11068 {
11069 save_p_isk = buf->b_p_isk;
11070 buf->b_p_isk = NULL;
11071 }
11072 /*
11073 * Always free the allocated strings.
11074 * If not already initialized, set 'readonly' and copy 'fileformat'.
11075 */
11076 if (!buf->b_p_initialized)
11077 {
11078 free_buf_options(buf, TRUE);
11079 buf->b_p_ro = FALSE; /* don't copy readonly */
11080 buf->b_p_tx = p_tx;
11081#ifdef FEAT_MBYTE
11082 buf->b_p_fenc = vim_strsave(p_fenc);
11083#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011084 switch (*p_ffs)
11085 {
11086 case 'm':
11087 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11088 case 'd':
11089 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11090 case 'u':
11091 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11092 default:
11093 buf->b_p_ff = vim_strsave(p_ff);
11094 }
11095 if (buf->b_p_ff != NULL)
11096 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 buf->b_p_bh = empty_option;
11098 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099 }
11100 else
11101 free_buf_options(buf, FALSE);
11102
11103 buf->b_p_ai = p_ai;
11104 buf->b_p_ai_nopaste = p_ai_nopaste;
11105 buf->b_p_sw = p_sw;
11106 buf->b_p_tw = p_tw;
11107 buf->b_p_tw_nopaste = p_tw_nopaste;
11108 buf->b_p_tw_nobin = p_tw_nobin;
11109 buf->b_p_wm = p_wm;
11110 buf->b_p_wm_nopaste = p_wm_nopaste;
11111 buf->b_p_wm_nobin = p_wm_nobin;
11112 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011113#ifdef FEAT_MBYTE
11114 buf->b_p_bomb = p_bomb;
11115#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011116 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011117 buf->b_p_et = p_et;
11118 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011119 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120 buf->b_p_ml = p_ml;
11121 buf->b_p_ml_nobin = p_ml_nobin;
11122 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011123 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124#ifdef FEAT_INS_EXPAND
11125 buf->b_p_cpt = vim_strsave(p_cpt);
11126#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011127#ifdef FEAT_COMPL_FUNC
11128 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011129 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011130#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011131 buf->b_p_sts = p_sts;
11132 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011134#ifdef FEAT_COMMENTS
11135 buf->b_p_com = vim_strsave(p_com);
11136#endif
11137#ifdef FEAT_FOLDING
11138 buf->b_p_cms = vim_strsave(p_cms);
11139#endif
11140 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011141 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142 buf->b_p_nf = vim_strsave(p_nf);
11143 buf->b_p_mps = vim_strsave(p_mps);
11144#ifdef FEAT_SMARTINDENT
11145 buf->b_p_si = p_si;
11146#endif
11147 buf->b_p_ci = p_ci;
11148#ifdef FEAT_CINDENT
11149 buf->b_p_cin = p_cin;
11150 buf->b_p_cink = vim_strsave(p_cink);
11151 buf->b_p_cino = vim_strsave(p_cino);
11152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011153 /* Don't copy 'filetype', it must be detected */
11154 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155 buf->b_p_pi = p_pi;
11156#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11157 buf->b_p_cinw = vim_strsave(p_cinw);
11158#endif
11159#ifdef FEAT_LISP
11160 buf->b_p_lisp = p_lisp;
11161#endif
11162#ifdef FEAT_SYN_HL
11163 /* Don't copy 'syntax', it must be set */
11164 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011165 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011166 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011167#endif
11168#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011169 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011170 (void)compile_cap_prog(&buf->b_s);
11171 buf->b_s.b_p_spf = vim_strsave(p_spf);
11172 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173#endif
11174#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11175 buf->b_p_inde = vim_strsave(p_inde);
11176 buf->b_p_indk = vim_strsave(p_indk);
11177#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011178 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011179#if defined(FEAT_EVAL)
11180 buf->b_p_fex = vim_strsave(p_fex);
11181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011182#ifdef FEAT_CRYPT
11183 buf->b_p_key = vim_strsave(p_key);
11184#endif
11185#ifdef FEAT_SEARCHPATH
11186 buf->b_p_sua = vim_strsave(p_sua);
11187#endif
11188#ifdef FEAT_KEYMAP
11189 buf->b_p_keymap = vim_strsave(p_keymap);
11190 buf->b_kmap_state |= KEYMAP_INIT;
11191#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011192#ifdef FEAT_TERMINAL
11193 buf->b_p_twsl = p_twsl;
11194#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195 /* This isn't really an option, but copying the langmap and IME
11196 * state from the current buffer is better than resetting it. */
11197 buf->b_p_iminsert = p_iminsert;
11198 buf->b_p_imsearch = p_imsearch;
11199
11200 /* options that are normally global but also have a local value
11201 * are not copied, start using the global value */
11202 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011203 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011204 buf->b_p_bkc = empty_option;
11205 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206#ifdef FEAT_QUICKFIX
11207 buf->b_p_gp = empty_option;
11208 buf->b_p_mp = empty_option;
11209 buf->b_p_efm = empty_option;
11210#endif
11211 buf->b_p_ep = empty_option;
11212 buf->b_p_kp = empty_option;
11213 buf->b_p_path = empty_option;
11214 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011215 buf->b_p_tc = empty_option;
11216 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217#ifdef FEAT_FIND_ID
11218 buf->b_p_def = empty_option;
11219 buf->b_p_inc = empty_option;
11220# ifdef FEAT_EVAL
11221 buf->b_p_inex = vim_strsave(p_inex);
11222# endif
11223#endif
11224#ifdef FEAT_INS_EXPAND
11225 buf->b_p_dict = empty_option;
11226 buf->b_p_tsr = empty_option;
11227#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011228#ifdef FEAT_TEXTOBJ
11229 buf->b_p_qe = vim_strsave(p_qe);
11230#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011231#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11232 buf->b_p_bexpr = empty_option;
11233#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011234#if defined(FEAT_CRYPT)
11235 buf->b_p_cm = empty_option;
11236#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011237#ifdef FEAT_PERSISTENT_UNDO
11238 buf->b_p_udf = p_udf;
11239#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011240#ifdef FEAT_LISP
11241 buf->b_p_lw = empty_option;
11242#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011243#ifdef FEAT_MBYTE
11244 buf->b_p_menc = empty_option;
11245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011246
11247 /*
11248 * Don't copy the options set by ex_help(), use the saved values,
11249 * when going from a help buffer to a non-help buffer.
11250 * Don't touch these at all when BCO_NOHELP is used and going from
11251 * or to a help buffer.
11252 */
11253 if (dont_do_help)
11254 buf->b_p_isk = save_p_isk;
11255 else
11256 {
11257 buf->b_p_isk = vim_strsave(p_isk);
11258 did_isk = TRUE;
11259 buf->b_p_ts = p_ts;
11260 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011261 if (buf->b_p_bt[0] == 'h')
11262 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011263 buf->b_p_ma = p_ma;
11264 }
11265 }
11266
11267 /*
11268 * When the options should be copied (ignoring BCO_ALWAYS), set the
11269 * flag that indicates that the options have been initialized.
11270 */
11271 if (should_copy)
11272 buf->b_p_initialized = TRUE;
11273 }
11274
11275 check_buf_options(buf); /* make sure we don't have NULLs */
11276 if (did_isk)
11277 (void)buf_init_chartab(buf, FALSE);
11278}
11279
11280/*
11281 * Reset the 'modifiable' option and its default value.
11282 */
11283 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011284reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011285{
11286 int opt_idx;
11287
11288 curbuf->b_p_ma = FALSE;
11289 p_ma = FALSE;
11290 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011291 if (opt_idx >= 0)
11292 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011293}
11294
11295/*
11296 * Set the global value for 'iminsert' to the local value.
11297 */
11298 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011299set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011300{
11301 p_iminsert = curbuf->b_p_iminsert;
11302}
11303
11304/*
11305 * Set the global value for 'imsearch' to the local value.
11306 */
11307 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011308set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011309{
11310 p_imsearch = curbuf->b_p_imsearch;
11311}
11312
11313#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11314static int expand_option_idx = -1;
11315static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11316static int expand_option_flags = 0;
11317
11318 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011319set_context_in_set_cmd(
11320 expand_T *xp,
11321 char_u *arg,
11322 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323{
11324 int nextchar;
11325 long_u flags = 0; /* init for GCC */
11326 int opt_idx = 0; /* init for GCC */
11327 char_u *p;
11328 char_u *s;
11329 int is_term_option = FALSE;
11330 int key;
11331
11332 expand_option_flags = opt_flags;
11333
11334 xp->xp_context = EXPAND_SETTINGS;
11335 if (*arg == NUL)
11336 {
11337 xp->xp_pattern = arg;
11338 return;
11339 }
11340 p = arg + STRLEN(arg) - 1;
11341 if (*p == ' ' && *(p - 1) != '\\')
11342 {
11343 xp->xp_pattern = p + 1;
11344 return;
11345 }
11346 while (p > arg)
11347 {
11348 s = p;
11349 /* count number of backslashes before ' ' or ',' */
11350 if (*p == ' ' || *p == ',')
11351 {
11352 while (s > arg && *(s - 1) == '\\')
11353 --s;
11354 }
11355 /* break at a space with an even number of backslashes */
11356 if (*p == ' ' && ((p - s) & 1) == 0)
11357 {
11358 ++p;
11359 break;
11360 }
11361 --p;
11362 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011363 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364 {
11365 xp->xp_context = EXPAND_BOOL_SETTINGS;
11366 p += 2;
11367 }
11368 if (STRNCMP(p, "inv", 3) == 0)
11369 {
11370 xp->xp_context = EXPAND_BOOL_SETTINGS;
11371 p += 3;
11372 }
11373 xp->xp_pattern = arg = p;
11374 if (*arg == '<')
11375 {
11376 while (*p != '>')
11377 if (*p++ == NUL) /* expand terminal option name */
11378 return;
11379 key = get_special_key_code(arg + 1);
11380 if (key == 0) /* unknown name */
11381 {
11382 xp->xp_context = EXPAND_NOTHING;
11383 return;
11384 }
11385 nextchar = *++p;
11386 is_term_option = TRUE;
11387 expand_option_name[2] = KEY2TERMCAP0(key);
11388 expand_option_name[3] = KEY2TERMCAP1(key);
11389 }
11390 else
11391 {
11392 if (p[0] == 't' && p[1] == '_')
11393 {
11394 p += 2;
11395 if (*p != NUL)
11396 ++p;
11397 if (*p == NUL)
11398 return; /* expand option name */
11399 nextchar = *++p;
11400 is_term_option = TRUE;
11401 expand_option_name[2] = p[-2];
11402 expand_option_name[3] = p[-1];
11403 }
11404 else
11405 {
11406 /* Allow * wildcard */
11407 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11408 p++;
11409 if (*p == NUL)
11410 return;
11411 nextchar = *p;
11412 *p = NUL;
11413 opt_idx = findoption(arg);
11414 *p = nextchar;
11415 if (opt_idx == -1 || options[opt_idx].var == NULL)
11416 {
11417 xp->xp_context = EXPAND_NOTHING;
11418 return;
11419 }
11420 flags = options[opt_idx].flags;
11421 if (flags & P_BOOL)
11422 {
11423 xp->xp_context = EXPAND_NOTHING;
11424 return;
11425 }
11426 }
11427 }
11428 /* handle "-=" and "+=" */
11429 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11430 {
11431 ++p;
11432 nextchar = '=';
11433 }
11434 if ((nextchar != '=' && nextchar != ':')
11435 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11436 {
11437 xp->xp_context = EXPAND_UNSUCCESSFUL;
11438 return;
11439 }
11440 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11441 {
11442 xp->xp_context = EXPAND_OLD_SETTING;
11443 if (is_term_option)
11444 expand_option_idx = -1;
11445 else
11446 expand_option_idx = opt_idx;
11447 xp->xp_pattern = p + 1;
11448 return;
11449 }
11450 xp->xp_context = EXPAND_NOTHING;
11451 if (is_term_option || (flags & P_NUM))
11452 return;
11453
11454 xp->xp_pattern = p + 1;
11455
11456 if (flags & P_EXPAND)
11457 {
11458 p = options[opt_idx].var;
11459 if (p == (char_u *)&p_bdir
11460 || p == (char_u *)&p_dir
11461 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011462 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011463 || p == (char_u *)&p_rtp
11464#ifdef FEAT_SEARCHPATH
11465 || p == (char_u *)&p_cdpath
11466#endif
11467#ifdef FEAT_SESSION
11468 || p == (char_u *)&p_vdir
11469#endif
11470 )
11471 {
11472 xp->xp_context = EXPAND_DIRECTORIES;
11473 if (p == (char_u *)&p_path
11474#ifdef FEAT_SEARCHPATH
11475 || p == (char_u *)&p_cdpath
11476#endif
11477 )
11478 xp->xp_backslash = XP_BS_THREE;
11479 else
11480 xp->xp_backslash = XP_BS_ONE;
11481 }
11482 else
11483 {
11484 xp->xp_context = EXPAND_FILES;
11485 /* for 'tags' need three backslashes for a space */
11486 if (p == (char_u *)&p_tags)
11487 xp->xp_backslash = XP_BS_THREE;
11488 else
11489 xp->xp_backslash = XP_BS_ONE;
11490 }
11491 }
11492
11493 /* For an option that is a list of file names, find the start of the
11494 * last file name. */
11495 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11496 {
11497 /* count number of backslashes before ' ' or ',' */
11498 if (*p == ' ' || *p == ',')
11499 {
11500 s = p;
11501 while (s > xp->xp_pattern && *(s - 1) == '\\')
11502 --s;
11503 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11504 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11505 {
11506 xp->xp_pattern = p + 1;
11507 break;
11508 }
11509 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011510
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011511#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011512 /* for 'spellsuggest' start at "file:" */
11513 if (options[opt_idx].var == (char_u *)&p_sps
11514 && STRNCMP(p, "file:", 5) == 0)
11515 {
11516 xp->xp_pattern = p + 5;
11517 break;
11518 }
11519#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011520 }
11521
11522 return;
11523}
11524
11525 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011526ExpandSettings(
11527 expand_T *xp,
11528 regmatch_T *regmatch,
11529 int *num_file,
11530 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531{
11532 int num_normal = 0; /* Nr of matching non-term-code settings */
11533 int num_term = 0; /* Nr of matching terminal code settings */
11534 int opt_idx;
11535 int match;
11536 int count = 0;
11537 char_u *str;
11538 int loop;
11539 int is_term_opt;
11540 char_u name_buf[MAX_KEY_NAME_LEN];
11541 static char *(names[]) = {"all", "termcap"};
11542 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11543
11544 /* do this loop twice:
11545 * loop == 0: count the number of matching options
11546 * loop == 1: copy the matching options into allocated memory
11547 */
11548 for (loop = 0; loop <= 1; ++loop)
11549 {
11550 regmatch->rm_ic = ic;
11551 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11552 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011553 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11554 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11556 {
11557 if (loop == 0)
11558 num_normal++;
11559 else
11560 (*file)[count++] = vim_strsave((char_u *)names[match]);
11561 }
11562 }
11563 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11564 opt_idx++)
11565 {
11566 if (options[opt_idx].var == NULL)
11567 continue;
11568 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11569 && !(options[opt_idx].flags & P_BOOL))
11570 continue;
11571 is_term_opt = istermoption(&options[opt_idx]);
11572 if (is_term_opt && num_normal > 0)
11573 continue;
11574 match = FALSE;
11575 if (vim_regexec(regmatch, str, (colnr_T)0)
11576 || (options[opt_idx].shortname != NULL
11577 && vim_regexec(regmatch,
11578 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11579 match = TRUE;
11580 else if (is_term_opt)
11581 {
11582 name_buf[0] = '<';
11583 name_buf[1] = 't';
11584 name_buf[2] = '_';
11585 name_buf[3] = str[2];
11586 name_buf[4] = str[3];
11587 name_buf[5] = '>';
11588 name_buf[6] = NUL;
11589 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11590 {
11591 match = TRUE;
11592 str = name_buf;
11593 }
11594 }
11595 if (match)
11596 {
11597 if (loop == 0)
11598 {
11599 if (is_term_opt)
11600 num_term++;
11601 else
11602 num_normal++;
11603 }
11604 else
11605 (*file)[count++] = vim_strsave(str);
11606 }
11607 }
11608 /*
11609 * Check terminal key codes, these are not in the option table
11610 */
11611 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11612 {
11613 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11614 {
11615 if (!isprint(str[0]) || !isprint(str[1]))
11616 continue;
11617
11618 name_buf[0] = 't';
11619 name_buf[1] = '_';
11620 name_buf[2] = str[0];
11621 name_buf[3] = str[1];
11622 name_buf[4] = NUL;
11623
11624 match = FALSE;
11625 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11626 match = TRUE;
11627 else
11628 {
11629 name_buf[0] = '<';
11630 name_buf[1] = 't';
11631 name_buf[2] = '_';
11632 name_buf[3] = str[0];
11633 name_buf[4] = str[1];
11634 name_buf[5] = '>';
11635 name_buf[6] = NUL;
11636
11637 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11638 match = TRUE;
11639 }
11640 if (match)
11641 {
11642 if (loop == 0)
11643 num_term++;
11644 else
11645 (*file)[count++] = vim_strsave(name_buf);
11646 }
11647 }
11648
11649 /*
11650 * Check special key names.
11651 */
11652 regmatch->rm_ic = TRUE; /* ignore case here */
11653 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11654 {
11655 name_buf[0] = '<';
11656 STRCPY(name_buf + 1, str);
11657 STRCAT(name_buf, ">");
11658
11659 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11660 {
11661 if (loop == 0)
11662 num_term++;
11663 else
11664 (*file)[count++] = vim_strsave(name_buf);
11665 }
11666 }
11667 }
11668 if (loop == 0)
11669 {
11670 if (num_normal > 0)
11671 *num_file = num_normal;
11672 else if (num_term > 0)
11673 *num_file = num_term;
11674 else
11675 return OK;
11676 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11677 if (*file == NULL)
11678 {
11679 *file = (char_u **)"";
11680 return FAIL;
11681 }
11682 }
11683 }
11684 return OK;
11685}
11686
11687 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011688ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689{
11690 char_u *var = NULL; /* init for GCC */
11691 char_u *buf;
11692
11693 *num_file = 0;
11694 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11695 if (*file == NULL)
11696 return FAIL;
11697
11698 /*
11699 * For a terminal key code expand_option_idx is < 0.
11700 */
11701 if (expand_option_idx < 0)
11702 {
11703 var = find_termcode(expand_option_name + 2);
11704 if (var == NULL)
11705 expand_option_idx = findoption(expand_option_name);
11706 }
11707
11708 if (expand_option_idx >= 0)
11709 {
11710 /* put string of option value in NameBuff */
11711 option_value2string(&options[expand_option_idx], expand_option_flags);
11712 var = NameBuff;
11713 }
11714 else if (var == NULL)
11715 var = (char_u *)"";
11716
11717 /* A backslash is required before some characters. This is the reverse of
11718 * what happens in do_set(). */
11719 buf = vim_strsave_escaped(var, escape_chars);
11720
11721 if (buf == NULL)
11722 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011723 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011724 return FAIL;
11725 }
11726
11727#ifdef BACKSLASH_IN_FILENAME
11728 /* For MS-Windows et al. we don't double backslashes at the start and
11729 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011730 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731 if (var[0] == '\\' && var[1] == '\\'
11732 && expand_option_idx >= 0
11733 && (options[expand_option_idx].flags & P_EXPAND)
11734 && vim_isfilec(var[2])
11735 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011736 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011737#endif
11738
11739 *file[0] = buf;
11740 *num_file = 1;
11741 return OK;
11742}
11743#endif
11744
11745/*
11746 * Get the value for the numeric or string option *opp in a nice format into
11747 * NameBuff[]. Must not be called with a hidden option!
11748 */
11749 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011750option_value2string(
11751 struct vimoption *opp,
11752 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011753{
11754 char_u *varp;
11755
11756 varp = get_varp_scope(opp, opt_flags);
11757
11758 if (opp->flags & P_NUM)
11759 {
11760 long wc = 0;
11761
11762 if (wc_use_keyname(varp, &wc))
11763 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11764 else if (wc != 0)
11765 STRCPY(NameBuff, transchar((int)wc));
11766 else
11767 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11768 }
11769 else /* P_STRING */
11770 {
11771 varp = *(char_u **)(varp);
11772 if (varp == NULL) /* just in case */
11773 NameBuff[0] = NUL;
11774#ifdef FEAT_CRYPT
11775 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011776 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777 STRCPY(NameBuff, "*****");
11778#endif
11779 else if (opp->flags & P_EXPAND)
11780 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11781 /* Translate 'pastetoggle' into special key names */
11782 else if ((char_u **)opp->var == &p_pt)
11783 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11784 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011785 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011786 }
11787}
11788
11789/*
11790 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11791 * printed as a keyname.
11792 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11793 */
11794 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011795wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011796{
11797 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11798 {
11799 *wcp = *(long *)varp;
11800 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11801 return TRUE;
11802 }
11803 return FALSE;
11804}
11805
Bram Moolenaar01615492015-02-03 13:00:38 +010011806#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011808 * Any character has an equivalent 'langmap' character. This is used for
11809 * keyboards that have a special language mode that sends characters above
11810 * 128 (although other characters can be translated too). The "to" field is a
11811 * Vim command character. This avoids having to switch the keyboard back to
11812 * ASCII mode when leaving Insert mode.
11813 *
11814 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11815 * commands.
11816 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11817 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11818 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011820# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011821/*
11822 * With multi-byte support use growarray for 'langmap' chars >= 256
11823 */
11824typedef struct
11825{
11826 int from;
11827 int to;
11828} langmap_entry_T;
11829
11830static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011831static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011832
11833/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011834 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11835 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011836 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011837 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011838langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011839{
11840 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011841 int a = 0;
11842 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011843
11844 /* Do a binary search for an existing entry. */
11845 while (a != b)
11846 {
11847 int i = (a + b) / 2;
11848 int d = entries[i].from - from;
11849
11850 if (d == 0)
11851 {
11852 entries[i].to = to;
11853 return;
11854 }
11855 if (d < 0)
11856 a = i + 1;
11857 else
11858 b = i;
11859 }
11860
11861 if (ga_grow(&langmap_mapga, 1) != OK)
11862 return; /* out of memory */
11863
11864 /* insert new entry at position "a" */
11865 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11866 mch_memmove(entries + 1, entries,
11867 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11868 ++langmap_mapga.ga_len;
11869 entries[0].from = from;
11870 entries[0].to = to;
11871}
11872
11873/*
11874 * Apply 'langmap' to multi-byte character "c" and return the result.
11875 */
11876 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011877langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011878{
11879 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11880 int a = 0;
11881 int b = langmap_mapga.ga_len;
11882
11883 while (a != b)
11884 {
11885 int i = (a + b) / 2;
11886 int d = entries[i].from - c;
11887
11888 if (d == 0)
11889 return entries[i].to; /* found matching entry */
11890 if (d < 0)
11891 a = i + 1;
11892 else
11893 b = i;
11894 }
11895 return c; /* no entry found, return "c" unmodified */
11896}
11897# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011898
11899 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011900langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901{
11902 int i;
11903
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011904 for (i = 0; i < 256; i++)
11905 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11906# ifdef FEAT_MBYTE
11907 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11908# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909}
11910
11911/*
11912 * Called when langmap option is set; the language map can be
11913 * changed at any time!
11914 */
11915 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011916langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011917{
11918 char_u *p;
11919 char_u *p2;
11920 int from, to;
11921
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011922#ifdef FEAT_MBYTE
11923 ga_clear(&langmap_mapga); /* clear the previous map first */
11924#endif
11925 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926
11927 for (p = p_langmap; p[0] != NUL; )
11928 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011929 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011930 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931 {
11932 if (p2[0] == '\\' && p2[1] != NUL)
11933 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934 }
11935 if (p2[0] == ';')
11936 ++p2; /* abcd;ABCD form, p2 points to A */
11937 else
11938 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11939 while (p[0])
11940 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011941 if (p[0] == ',')
11942 {
11943 ++p;
11944 break;
11945 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011946 if (p[0] == '\\' && p[1] != NUL)
11947 ++p;
11948#ifdef FEAT_MBYTE
11949 from = (*mb_ptr2char)(p);
11950#else
11951 from = p[0];
11952#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011953 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011954 if (p2 == NULL)
11955 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011956 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011957 if (p[0] != ',')
11958 {
11959 if (p[0] == '\\')
11960 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011961#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011962 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011964 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011967 }
11968 else
11969 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011970 if (p2[0] != ',')
11971 {
11972 if (p2[0] == '\\')
11973 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011974#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011975 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011977 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011979 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980 }
11981 if (to == NUL)
11982 {
11983 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11984 transchar(from));
11985 return;
11986 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011987
11988#ifdef FEAT_MBYTE
11989 if (from >= 256)
11990 langmap_set_entry(from, to);
11991 else
11992#endif
11993 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011994
11995 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011996 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011997 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011999 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012000 if (*p == ';')
12001 {
12002 p = p2;
12003 if (p[0] != NUL)
12004 {
12005 if (p[0] != ',')
12006 {
12007 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12008 return;
12009 }
12010 ++p;
12011 }
12012 break;
12013 }
12014 }
12015 }
12016 }
12017}
12018#endif
12019
12020/*
12021 * Return TRUE if format option 'x' is in effect.
12022 * Take care of no formatting when 'paste' is set.
12023 */
12024 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012025has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012026{
12027 if (p_paste)
12028 return FALSE;
12029 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12030}
12031
12032/*
12033 * Return TRUE if "x" is present in 'shortmess' option, or
12034 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12035 */
12036 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012037shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012038{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012039 return p_shm != NULL &&
12040 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012041 || (vim_strchr(p_shm, 'a') != NULL
12042 && vim_strchr((char_u *)SHM_A, x) != NULL));
12043}
12044
12045/*
12046 * paste_option_changed() - Called after p_paste was set or reset.
12047 */
12048 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012049paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050{
12051 static int old_p_paste = FALSE;
12052 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012053 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054#ifdef FEAT_CMDL_INFO
12055 static int save_ru = 0;
12056#endif
12057#ifdef FEAT_RIGHTLEFT
12058 static int save_ri = 0;
12059 static int save_hkmap = 0;
12060#endif
12061 buf_T *buf;
12062
12063 if (p_paste)
12064 {
12065 /*
12066 * Paste switched from off to on.
12067 * Save the current values, so they can be restored later.
12068 */
12069 if (!old_p_paste)
12070 {
12071 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012072 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012073 {
12074 buf->b_p_tw_nopaste = buf->b_p_tw;
12075 buf->b_p_wm_nopaste = buf->b_p_wm;
12076 buf->b_p_sts_nopaste = buf->b_p_sts;
12077 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012078 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012079 }
12080
12081 /* save global options */
12082 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012083 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012084#ifdef FEAT_CMDL_INFO
12085 save_ru = p_ru;
12086#endif
12087#ifdef FEAT_RIGHTLEFT
12088 save_ri = p_ri;
12089 save_hkmap = p_hkmap;
12090#endif
12091 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012092 p_ai_nopaste = p_ai;
12093 p_et_nopaste = p_et;
12094 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 p_tw_nopaste = p_tw;
12096 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097 }
12098
12099 /*
12100 * Always set the option values, also when 'paste' is set when it is
12101 * already on.
12102 */
12103 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012104 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012105 {
12106 buf->b_p_tw = 0; /* textwidth is 0 */
12107 buf->b_p_wm = 0; /* wrapmargin is 0 */
12108 buf->b_p_sts = 0; /* softtabstop is 0 */
12109 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012110 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111 }
12112
12113 /* set global options */
12114 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012115 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012116#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012117 if (p_ru)
12118 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119 p_ru = 0; /* no ruler */
12120#endif
12121#ifdef FEAT_RIGHTLEFT
12122 p_ri = 0; /* no reverse insert */
12123 p_hkmap = 0; /* no Hebrew keyboard */
12124#endif
12125 /* set global values for local buffer options */
12126 p_tw = 0;
12127 p_wm = 0;
12128 p_sts = 0;
12129 p_ai = 0;
12130 }
12131
12132 /*
12133 * Paste switched from on to off: Restore saved values.
12134 */
12135 else if (old_p_paste)
12136 {
12137 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012138 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139 {
12140 buf->b_p_tw = buf->b_p_tw_nopaste;
12141 buf->b_p_wm = buf->b_p_wm_nopaste;
12142 buf->b_p_sts = buf->b_p_sts_nopaste;
12143 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012144 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012145 }
12146
12147 /* restore global options */
12148 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012149 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012150#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012151 if (p_ru != save_ru)
12152 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012153 p_ru = save_ru;
12154#endif
12155#ifdef FEAT_RIGHTLEFT
12156 p_ri = save_ri;
12157 p_hkmap = save_hkmap;
12158#endif
12159 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012160 p_ai = p_ai_nopaste;
12161 p_et = p_et_nopaste;
12162 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163 p_tw = p_tw_nopaste;
12164 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 }
12166
12167 old_p_paste = p_paste;
12168}
12169
12170/*
12171 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12172 *
12173 * Reset 'compatible' and set the values for options that didn't get set yet
12174 * to the Vim defaults.
12175 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012176 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012177 */
12178 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012179vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012180{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012181 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012182 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012183 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012184
12185 if (!option_was_set((char_u *)"cp"))
12186 {
12187 p_cp = FALSE;
12188 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12189 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12190 set_option_default(opt_idx, OPT_FREE, FALSE);
12191 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012192 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012194
12195 if (fname != NULL)
12196 {
12197 p = vim_getenv(envname, &dofree);
12198 if (p == NULL)
12199 {
12200 /* Set $MYVIMRC to the first vimrc file found. */
12201 p = FullName_save(fname, FALSE);
12202 if (p != NULL)
12203 {
12204 vim_setenv(envname, p);
12205 vim_free(p);
12206 }
12207 }
12208 else if (dofree)
12209 vim_free(p);
12210 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211}
12212
12213/*
12214 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12215 */
12216 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012217change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012218{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012219 int opt_idx;
12220
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221 if (p_cp != on)
12222 {
12223 p_cp = on;
12224 compatible_set();
12225 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012226 opt_idx = findoption((char_u *)"cp");
12227 if (opt_idx >= 0)
12228 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012229}
12230
12231/*
12232 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012233 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012234 */
12235 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012236option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012237{
12238 int idx;
12239
12240 idx = findoption(name);
12241 if (idx < 0) /* unknown option */
12242 return FALSE;
12243 if (options[idx].flags & P_WAS_SET)
12244 return TRUE;
12245 return FALSE;
12246}
12247
12248/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012249 * Reset the flag indicating option "name" was set.
12250 */
12251 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012252reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012253{
12254 int idx = findoption(name);
12255
12256 if (idx >= 0)
12257 options[idx].flags &= ~P_WAS_SET;
12258}
12259
12260/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261 * compatible_set() - Called when 'compatible' has been set or unset.
12262 *
12263 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12264 * flag) to a Vi compatible value.
12265 * When 'compatible' is unset: Set all options that have a different default
12266 * for Vim (without the P_VI_DEF flag) to that default.
12267 */
12268 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012269compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270{
12271 int opt_idx;
12272
12273 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12274 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12275 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12276 set_option_default(opt_idx, OPT_FREE, p_cp);
12277 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012278 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012279}
12280
12281#ifdef FEAT_LINEBREAK
12282
12283# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12284 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012285 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012286# endif
12287
12288/*
12289 * fill_breakat_flags() -- called when 'breakat' changes value.
12290 */
12291 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012292fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012293{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012294 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295 int i;
12296
12297 for (i = 0; i < 256; i++)
12298 breakat_flags[i] = FALSE;
12299
12300 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012301 for (p = p_breakat; *p; p++)
12302 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012303}
12304
12305# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012306 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012307# endif
12308
12309#endif
12310
12311/*
12312 * Check an option that can be a range of string values.
12313 *
12314 * Return OK for correct value, FAIL otherwise.
12315 * Empty is always OK.
12316 */
12317 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012318check_opt_strings(
12319 char_u *val,
12320 char **values,
12321 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012322{
12323 return opt_strings_flags(val, values, NULL, list);
12324}
12325
12326/*
12327 * Handle an option that can be a range of string values.
12328 * Set a flag in "*flagp" for each string present.
12329 *
12330 * Return OK for correct value, FAIL otherwise.
12331 * Empty is always OK.
12332 */
12333 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012334opt_strings_flags(
12335 char_u *val, /* new value */
12336 char **values, /* array of valid string values */
12337 unsigned *flagp,
12338 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012339{
12340 int i;
12341 int len;
12342 unsigned new_flags = 0;
12343
12344 while (*val)
12345 {
12346 for (i = 0; ; ++i)
12347 {
12348 if (values[i] == NULL) /* val not found in values[] */
12349 return FAIL;
12350
12351 len = (int)STRLEN(values[i]);
12352 if (STRNCMP(values[i], val, len) == 0
12353 && ((list && val[len] == ',') || val[len] == NUL))
12354 {
12355 val += len + (val[len] == ',');
12356 new_flags |= (1 << i);
12357 break; /* check next item in val list */
12358 }
12359 }
12360 }
12361 if (flagp != NULL)
12362 *flagp = new_flags;
12363
12364 return OK;
12365}
12366
12367/*
12368 * Read the 'wildmode' option, fill wim_flags[].
12369 */
12370 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012371check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012372{
12373 char_u new_wim_flags[4];
12374 char_u *p;
12375 int i;
12376 int idx = 0;
12377
12378 for (i = 0; i < 4; ++i)
12379 new_wim_flags[i] = 0;
12380
12381 for (p = p_wim; *p; ++p)
12382 {
12383 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12384 ;
12385 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12386 return FAIL;
12387 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12388 new_wim_flags[idx] |= WIM_LONGEST;
12389 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12390 new_wim_flags[idx] |= WIM_FULL;
12391 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12392 new_wim_flags[idx] |= WIM_LIST;
12393 else
12394 return FAIL;
12395 p += i;
12396 if (*p == NUL)
12397 break;
12398 if (*p == ',')
12399 {
12400 if (idx == 3)
12401 return FAIL;
12402 ++idx;
12403 }
12404 }
12405
12406 /* fill remaining entries with last flag */
12407 while (idx < 3)
12408 {
12409 new_wim_flags[idx + 1] = new_wim_flags[idx];
12410 ++idx;
12411 }
12412
12413 /* only when there are no errors, wim_flags[] is changed */
12414 for (i = 0; i < 4; ++i)
12415 wim_flags[i] = new_wim_flags[i];
12416 return OK;
12417}
12418
12419/*
12420 * Check if backspacing over something is allowed.
12421 */
12422 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012423can_bs(
12424 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012425{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012426#ifdef FEAT_JOB_CHANNEL
12427 if (what == BS_START && bt_prompt(curbuf))
12428 return FALSE;
12429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012430 switch (*p_bs)
12431 {
12432 case '2': return TRUE;
12433 case '1': return (what != BS_START);
12434 case '0': return FALSE;
12435 }
12436 return vim_strchr(p_bs, what) != NULL;
12437}
12438
12439/*
12440 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12441 * the file must be considered changed when the value is different.
12442 */
12443 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012444save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445{
12446 buf->b_start_ffc = *buf->b_p_ff;
12447 buf->b_start_eol = buf->b_p_eol;
12448#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012449 buf->b_start_bomb = buf->b_p_bomb;
12450
Bram Moolenaar071d4272004-06-13 20:20:40 +000012451 /* Only use free/alloc when necessary, they take time. */
12452 if (buf->b_start_fenc == NULL
12453 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12454 {
12455 vim_free(buf->b_start_fenc);
12456 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12457 }
12458#endif
12459}
12460
12461/*
12462 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12463 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012464 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12465 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012466 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012467 * When "ignore_empty" is true don't consider a new, empty buffer to be
12468 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012469 */
12470 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012471file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012473 /* In a buffer that was never loaded the options are not valid. */
12474 if (buf->b_flags & BF_NEVERLOADED)
12475 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012476 if (ignore_empty
12477 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012478 && buf->b_ml.ml_line_count == 1
12479 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12480 return FALSE;
12481 if (buf->b_start_ffc != *buf->b_p_ff)
12482 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012483 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012484 return TRUE;
12485#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012486 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12487 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012488 if (buf->b_start_fenc == NULL)
12489 return (*buf->b_p_fenc != NUL);
12490 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12491#else
12492 return FALSE;
12493#endif
12494}
12495
12496/*
12497 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12498 */
12499 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012500check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012501{
12502 return check_opt_strings(p, p_ff_values, FALSE);
12503}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012504
12505/*
12506 * Return the effective shiftwidth value for current buffer, using the
12507 * 'tabstop' value when 'shiftwidth' is zero.
12508 */
12509 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012510get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012511{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012512 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012513}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012514
12515/*
12516 * Return the effective softtabstop value for the current buffer, using the
12517 * 'tabstop' value when 'softtabstop' is negative.
12518 */
12519 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012520get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012521{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012522 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012523}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012524
12525/*
12526 * Check matchpairs option for "*initc".
12527 * If there is a match set "*initc" to the matching character and "*findc" to
12528 * the opposite character. Set "*backwards" to the direction.
12529 * When "switchit" is TRUE swap the direction.
12530 */
12531 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012532find_mps_values(
12533 int *initc,
12534 int *findc,
12535 int *backwards,
12536 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012537{
12538 char_u *ptr;
12539
12540 ptr = curbuf->b_p_mps;
12541 while (*ptr != NUL)
12542 {
12543#ifdef FEAT_MBYTE
12544 if (has_mbyte)
12545 {
12546 char_u *prev;
12547
12548 if (mb_ptr2char(ptr) == *initc)
12549 {
12550 if (switchit)
12551 {
12552 *findc = *initc;
12553 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12554 *backwards = TRUE;
12555 }
12556 else
12557 {
12558 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12559 *backwards = FALSE;
12560 }
12561 return;
12562 }
12563 prev = ptr;
12564 ptr += mb_ptr2len(ptr) + 1;
12565 if (mb_ptr2char(ptr) == *initc)
12566 {
12567 if (switchit)
12568 {
12569 *findc = *initc;
12570 *initc = mb_ptr2char(prev);
12571 *backwards = FALSE;
12572 }
12573 else
12574 {
12575 *findc = mb_ptr2char(prev);
12576 *backwards = TRUE;
12577 }
12578 return;
12579 }
12580 ptr += mb_ptr2len(ptr);
12581 }
12582 else
12583#endif
12584 {
12585 if (*ptr == *initc)
12586 {
12587 if (switchit)
12588 {
12589 *backwards = TRUE;
12590 *findc = *initc;
12591 *initc = ptr[2];
12592 }
12593 else
12594 {
12595 *backwards = FALSE;
12596 *findc = ptr[2];
12597 }
12598 return;
12599 }
12600 ptr += 2;
12601 if (*ptr == *initc)
12602 {
12603 if (switchit)
12604 {
12605 *backwards = FALSE;
12606 *findc = *initc;
12607 *initc = ptr[-2];
12608 }
12609 else
12610 {
12611 *backwards = TRUE;
12612 *findc = ptr[-2];
12613 }
12614 return;
12615 }
12616 ++ptr;
12617 }
12618 if (*ptr == ',')
12619 ++ptr;
12620 }
12621}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012622
12623#if defined(FEAT_LINEBREAK) || defined(PROTO)
12624/*
12625 * This is called when 'breakindentopt' is changed and when a window is
12626 * initialized.
12627 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012628 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012629briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012630{
12631 char_u *p;
12632 int bri_shift = 0;
12633 long bri_min = 20;
12634 int bri_sbr = FALSE;
12635
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012636 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012637 while (*p != NUL)
12638 {
12639 if (STRNCMP(p, "shift:", 6) == 0
12640 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12641 {
12642 p += 6;
12643 bri_shift = getdigits(&p);
12644 }
12645 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12646 {
12647 p += 4;
12648 bri_min = getdigits(&p);
12649 }
12650 else if (STRNCMP(p, "sbr", 3) == 0)
12651 {
12652 p += 3;
12653 bri_sbr = TRUE;
12654 }
12655 if (*p != ',' && *p != NUL)
12656 return FAIL;
12657 if (*p == ',')
12658 ++p;
12659 }
12660
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012661 wp->w_p_brishift = bri_shift;
12662 wp->w_p_brimin = bri_min;
12663 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012664
12665 return OK;
12666}
12667#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012668
12669/*
12670 * Get the local or global value of 'backupcopy'.
12671 */
12672 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012673get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012674{
12675 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12676}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012677
12678#if defined(FEAT_SIGNS) || defined(PROTO)
12679/*
12680 * Return TRUE when window "wp" has a column to draw signs in.
12681 */
12682 int
12683signcolumn_on(win_T *wp)
12684{
12685 if (*wp->w_p_scl == 'n')
12686 return FALSE;
12687 if (*wp->w_p_scl == 'y')
12688 return TRUE;
12689 return (wp->w_buffer->b_signlist != NULL
12690# ifdef FEAT_NETBEANS_INTG
12691 || wp->w_buffer->b_has_sign_column
12692# endif
12693 );
12694}
12695#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012696
12697#if defined(FEAT_EVAL) || defined(PROTO)
12698/*
12699 * Get window or buffer local options.
12700 */
12701 dict_T *
12702get_winbuf_options(int bufopt)
12703{
12704 dict_T *d;
12705 int opt_idx;
12706
12707 d = dict_alloc();
12708 if (d == NULL)
12709 return NULL;
12710
12711 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12712 {
12713 struct vimoption *opt = &options[opt_idx];
12714
12715 if ((bufopt && (opt->indir & PV_BUF))
12716 || (!bufopt && (opt->indir & PV_WIN)))
12717 {
12718 char_u *varp = get_varp(opt);
12719
12720 if (varp != NULL)
12721 {
12722 if (opt->flags & P_STRING)
12723 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012724 else if (opt->flags & P_NUM)
12725 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012726 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012727 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012728 }
12729 }
12730 }
12731
12732 return d;
12733}
12734#endif