blob: aea5066470da934bf465b115a448f2378198e5e8 [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
378static long p_twsl;
379#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 /* TODO: remove this deprecated entry */
Bram Moolenaar8c041b62018-04-14 18:14:06 +02002758 {"terminalscroll", "tlsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2759#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002760 (char_u *)&p_twsl, PV_TWSL,
Bram Moolenaar8c041b62018-04-14 18:14:06 +02002761 {(char_u *)10000L, (char_u *)10000L}
2762#else
2763 (char_u *)NULL, PV_NONE,
2764 {(char_u *)NULL, (char_u *)0L}
2765#endif
2766 SCRIPTID_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002767 /* TODO: remove this deprecated entry */
2768 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002769#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002770 (char_u *)VAR_WIN, PV_TWK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002771 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002772#else
2773 (char_u *)NULL, PV_NONE,
2774 {(char_u *)NULL, (char_u *)0L}
2775#endif
2776 SCRIPTID_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002777 /* TODO: remove this deprecated entry */
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002778 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2779#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002780 (char_u *)VAR_WIN, PV_TWS,
2781 {(char_u *)"", (char_u *)NULL}
2782#else
2783 (char_u *)NULL, PV_NONE,
2784 {(char_u *)NULL, (char_u *)0L}
2785#endif
2786 SCRIPTID_INIT},
2787 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2788#ifdef FEAT_TERMINAL
2789 (char_u *)VAR_WIN, PV_TWK,
2790 {(char_u *)"", (char_u *)NULL}
2791#else
2792 (char_u *)NULL, PV_NONE,
2793 {(char_u *)NULL, (char_u *)0L}
2794#endif
2795 SCRIPTID_INIT},
2796 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2797#ifdef FEAT_TERMINAL
2798 (char_u *)&p_twsl, PV_TWSL,
2799 {(char_u *)10000L, (char_u *)10000L}
2800#else
2801 (char_u *)NULL, PV_NONE,
2802 {(char_u *)NULL, (char_u *)0L}
2803#endif
2804 SCRIPTID_INIT},
2805 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2806#ifdef FEAT_TERMINAL
2807 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002808 {(char_u *)"", (char_u *)NULL}
2809#else
2810 (char_u *)NULL, PV_NONE,
2811 {(char_u *)NULL, (char_u *)0L}
2812#endif
2813 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"terse", NULL, P_BOOL|P_VI_DEF,
2815 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"textauto", "ta", P_BOOL|P_VIM,
2818 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2820 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2822 (char_u *)&p_tx, PV_TX,
2823 {
2824#ifdef USE_CRNL
2825 (char_u *)TRUE,
2826#else
2827 (char_u *)FALSE,
2828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002830 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002833 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002835 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836#else
2837 (char_u *)NULL, PV_NONE,
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2841 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"timeout", "to", P_BOOL|P_VI_DEF,
2844 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2847 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 {"title", NULL, P_BOOL|P_VI_DEF,
2850#ifdef FEAT_TITLE
2851 (char_u *)&p_title, PV_NONE,
2852#else
2853 (char_u *)NULL, PV_NONE,
2854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"titlelen", NULL, P_NUM|P_VI_DEF,
2857#ifdef FEAT_TITLE
2858 (char_u *)&p_titlelen, PV_NONE,
2859#else
2860 (char_u *)NULL, PV_NONE,
2861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002863 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864#ifdef FEAT_TITLE
2865 (char_u *)&p_titleold, PV_NONE,
2866 {(char_u *)N_("Thanks for flying Vim"),
2867 (char_u *)0L}
2868#else
2869 (char_u *)NULL, PV_NONE,
2870 {(char_u *)0L, (char_u *)0L}
2871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"titlestring", NULL, P_STRING|P_VI_DEF,
2874#ifdef FEAT_TITLE
2875 (char_u *)&p_titlestring, PV_NONE,
2876#else
2877 (char_u *)NULL, PV_NONE,
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002880 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002881#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002884#else
2885 (char_u *)NULL, PV_NONE,
2886 {(char_u *)0L, (char_u *)0L}
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002890#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002892 {(char_u *)"small", (char_u *)0L}
2893#else
2894 (char_u *)NULL, PV_NONE,
2895 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002897 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2899 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2902 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002903 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2905 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002906 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2908 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2911#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2912 (char_u *)&p_ttym, PV_NONE,
2913#else
2914 (char_u *)NULL, PV_NONE,
2915#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2918 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2921 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002923 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2924 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002925#ifdef FEAT_PERSISTENT_UNDO
2926 (char_u *)&p_udir, PV_NONE,
2927 {(char_u *)".", (char_u *)0L}
2928#else
2929 (char_u *)NULL, PV_NONE,
2930 {(char_u *)0L, (char_u *)0L}
2931#endif
2932 SCRIPTID_INIT},
2933 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2934#ifdef FEAT_PERSISTENT_UNDO
2935 (char_u *)&p_udf, PV_UDF,
2936#else
2937 (char_u *)NULL, PV_NONE,
2938#endif
2939 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002941 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002943#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 (char_u *)1000L,
2945#else
2946 (char_u *)100L,
2947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002949 {"undoreload", "ur", P_NUM|P_VI_DEF,
2950 (char_u *)&p_ur, PV_NONE,
2951 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 {"updatecount", "uc", P_NUM|P_VI_DEF,
2953 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002954 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 {"updatetime", "ut", P_NUM|P_VI_DEF,
2956 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"verbose", "vbs", P_NUM|P_VI_DEF,
2959 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002961 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2962 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002963 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2965#ifdef FEAT_SESSION
2966 (char_u *)&p_vdir, PV_NONE,
2967 {(char_u *)DFLT_VDIR, (char_u *)0L}
2968#else
2969 (char_u *)NULL, PV_NONE,
2970 {(char_u *)0L, (char_u *)0L}
2971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002972 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002973 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974#ifdef FEAT_SESSION
2975 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002976 {(char_u *)"folds,options,cursor,curdir",
2977 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978#else
2979 (char_u *)NULL, PV_NONE,
2980 {(char_u *)0L, (char_u *)0L}
2981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002982 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002983 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984#ifdef FEAT_VIMINFO
2985 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002986#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002987 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988#else
2989# ifdef AMIGA
2990 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002991 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002993 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994# endif
2995#endif
2996#else
2997 (char_u *)NULL, PV_NONE,
2998 {(char_u *)0L, (char_u *)0L}
2999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003000 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02003001 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
3002#ifdef FEAT_VIMINFO
3003 (char_u *)&p_viminfofile, PV_NONE,
3004 {(char_u *)"", (char_u *)0L}
3005#else
3006 (char_u *)NULL, PV_NONE,
3007 {(char_u *)0L, (char_u *)0L}
3008#endif
3009 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003010 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
3011 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012#ifdef FEAT_VIRTUALEDIT
3013 (char_u *)&p_ve, PV_NONE,
3014 {(char_u *)"", (char_u *)""}
3015#else
3016 (char_u *)NULL, PV_NONE,
3017 {(char_u *)0L, (char_u *)0L}
3018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003019 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3021 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"w300", NULL, P_NUM|P_VI_DEF,
3024 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003025 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 {"w1200", NULL, P_NUM|P_VI_DEF,
3027 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"w9600", NULL, P_NUM|P_VI_DEF,
3030 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003031 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 {"warn", NULL, P_BOOL|P_VI_DEF,
3033 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003034 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3036 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003038 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003040 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 {"wildchar", "wc", P_NUM|P_VIM,
3042 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003043 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3044 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003045 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003047 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003048 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049#ifdef FEAT_WILDIGN
3050 (char_u *)&p_wig, PV_NONE,
3051#else
3052 (char_u *)NULL, PV_NONE,
3053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003054 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003055 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3056 (char_u *)&p_wic, PV_NONE,
3057 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3059#ifdef FEAT_WILDMENU
3060 (char_u *)&p_wmnu, PV_NONE,
3061#else
3062 (char_u *)NULL, PV_NONE,
3063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003065 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003067 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003068 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3069#ifdef FEAT_CMDL_COMPL
3070 (char_u *)&p_wop, PV_NONE,
3071 {(char_u *)"", (char_u *)0L}
3072#else
3073 (char_u *)NULL, PV_NONE,
3074 {(char_u *)NULL, (char_u *)0L}
3075#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003076 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3078#ifdef FEAT_WAK
3079 (char_u *)&p_wak, PV_NONE,
3080 {(char_u *)"menu", (char_u *)0L}
3081#else
3082 (char_u *)NULL, PV_NONE,
3083 {(char_u *)NULL, (char_u *)0L}
3084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003087 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003088 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003091 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003094 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003095 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003096 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003100 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003103 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003104 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003105#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003106 (char_u *)&p_winptydll, PV_NONE, {
3107# ifdef _WIN64
3108 (char_u *)"winpty64.dll",
3109# else
3110 (char_u *)"winpty32.dll",
3111# endif
3112 (char_u *)0L}
3113#else
3114 (char_u *)NULL, PV_NONE,
3115 {(char_u *)0L, (char_u *)0L}
3116#endif
3117 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003120 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3122 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003123 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3125 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003126 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3128 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003129 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 {"write", NULL, P_BOOL|P_VI_DEF,
3131 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003132 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 {"writeany", "wa", P_BOOL|P_VI_DEF,
3134 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003135 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3137 (char_u *)&p_wb, PV_NONE,
3138 {
3139#ifdef FEAT_WRITEBACKUP
3140 (char_u *)TRUE,
3141#else
3142 (char_u *)FALSE,
3143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003144 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 {"writedelay", "wd", P_NUM|P_VI_DEF,
3146 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003147 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148
3149/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003150#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003152 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153
3154 p_term("t_AB", T_CAB)
3155 p_term("t_AF", T_CAF)
3156 p_term("t_AL", T_CAL)
3157 p_term("t_al", T_AL)
3158 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003159 p_term("t_BE", T_BE)
3160 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 p_term("t_cd", T_CD)
3162 p_term("t_ce", T_CE)
3163 p_term("t_cl", T_CL)
3164 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003165 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_Co", T_CCO)
3167 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003168 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_da", T_DA)
3172 p_term("t_db", T_DB)
3173 p_term("t_DL", T_CDL)
3174 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003175 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003178 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_IE", T_CIE)
3180 p_term("t_IS", T_CIS)
3181 p_term("t_ke", T_KE)
3182 p_term("t_ks", T_KS)
3183 p_term("t_le", T_LE)
3184 p_term("t_mb", T_MB)
3185 p_term("t_md", T_MD)
3186 p_term("t_me", T_ME)
3187 p_term("t_mr", T_MR)
3188 p_term("t_ms", T_MS)
3189 p_term("t_nd", T_ND)
3190 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003191 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003192 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003193 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003195 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 p_term("t_RV", T_CRV)
3197 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003198 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003200 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003201 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003202 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003204 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003206 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207 p_term("t_te", T_TE)
3208 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003209 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003210 p_term("t_ts", T_TS)
3211 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 p_term("t_ue", T_UE)
3213 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003214 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215 p_term("t_vb", T_VB)
3216 p_term("t_ve", T_VE)
3217 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003218 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 p_term("t_vs", T_VS)
3220 p_term("t_WP", T_CWP)
3221 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003222 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 p_term("t_xs", T_XS)
3224 p_term("t_ZH", T_CZH)
3225 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003226 p_term("t_8f", T_8F)
3227 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228
3229/* terminal key codes are not in here */
3230
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003231 /* end marker */
3232 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233};
3234
3235#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3236
3237#ifdef FEAT_MBYTE
3238static char *(p_ambw_values[]) = {"single", "double", NULL};
3239#endif
3240static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003241static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003243#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003244static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003245#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003246#ifdef FEAT_CMDL_COMPL
3247static char *(p_wop_values[]) = {"tagfile", NULL};
3248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249#ifdef FEAT_WAK
3250static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3251#endif
3252static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3254static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#ifdef FEAT_BROWSE
3257static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003260static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003262static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003263static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3265#ifdef FEAT_FOLDING
3266static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003267# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003269# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270 NULL};
3271static char *(p_fcl_values[]) = {"all", NULL};
3272#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003273#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003274static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003275#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003276#ifdef FEAT_SIGNS
3277static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3278#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static void set_option_default(int, int opt_flags, int compatible);
3281static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003282static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static char_u *term_bg_default(void);
3284static void did_set_option(int opt_idx, int opt_flags, int new_value);
3285static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288#endif
3289#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003290static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static char_u *option_expand(int opt_idx, char_u *val);
3293static void didset_options(void);
3294static void didset_options2(void);
3295static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003296#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003297static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003298#else
3299# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3300#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static void set_string_option_global(int opt_idx, char_u **varp);
3302static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3303static 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);
3304static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003305#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003311#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static char_u *did_set_spell_option(int is_spellfile);
3313static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003314#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003315#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003316static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003317#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003318static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3319static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3320static void check_redraw(long_u flags);
3321static int findoption(char_u *);
3322static int find_key_option(char_u *);
3323static void showoptions(int all, int opt_flags);
3324static int optval_default(struct vimoption *, char_u *varp);
3325static void showoneopt(struct vimoption *, int opt_flags);
3326static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3327static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3328static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3329static int istermoption(struct vimoption *);
3330static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3331static char_u *get_varp(struct vimoption *);
3332static void option_value2string(struct vimoption *, int opt_flags);
3333static void check_winopt(winopt_T *wop);
3334static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003336static void langmap_init(void);
3337static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003339static void paste_option_changed(void);
3340static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003342static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003344static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3345static int check_opt_strings(char_u *val, char **values, int);
3346static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003347#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003348static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350
3351/*
3352 * Initialize the options, first part.
3353 *
3354 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003355 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356 */
3357 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003358set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359{
3360 char_u *p;
3361 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003362 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363
3364#ifdef FEAT_LANGMAP
3365 langmap_init();
3366#endif
3367
3368 /* Be Vi compatible by default */
3369 p_cp = TRUE;
3370
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003371 /* Use POSIX compatibility when $VIM_POSIX is set. */
3372 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003373 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003374 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003375 set_string_default("shm", (char_u *)"A");
3376 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003377
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 /*
3379 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003380 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003382 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003383#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003384 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003386 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387# endif
3388#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003389 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003390 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391
3392#ifdef FEAT_WILDIGN
3393 /*
3394 * Set the default for 'backupskip' to include environment variables for
3395 * temp files.
3396 */
3397 {
3398# ifdef UNIX
3399 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3400# else
3401 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3402# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003403 int len;
3404 garray_T ga;
3405 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406
3407 ga_init2(&ga, 1, 100);
3408 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3409 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003410 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411# ifdef UNIX
3412 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003413# ifdef MACOS_X
3414 p = (char_u *)"/private/tmp";
3415# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003417# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 else
3419# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003420 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421 if (p != NULL && *p != NUL)
3422 {
3423 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003424 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425 if (ga_grow(&ga, len) == OK)
3426 {
3427 if (ga.ga_len > 0)
3428 STRCAT(ga.ga_data, ",");
3429 STRCAT(ga.ga_data, p);
3430 add_pathsep(ga.ga_data);
3431 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 ga.ga_len += len;
3433 }
3434 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003435 if (mustfree)
3436 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 }
3438 if (ga.ga_data != NULL)
3439 {
3440 set_string_default("bsk", ga.ga_data);
3441 vim_free(ga.ga_data);
3442 }
3443 }
3444#endif
3445
3446 /*
3447 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3448 */
3449 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003450 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003452#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3453 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3454#endif
3455 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003456#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003457 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003458 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459#else
3460# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003461 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003462 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003464 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003465# endif
3466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003468 opt_idx = findoption((char_u *)"maxmem");
3469 if (opt_idx >= 0)
3470 {
3471#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003472 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3473 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003474#endif
3475 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3476 }
3477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478 }
3479
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480#ifdef FEAT_SEARCHPATH
3481 {
3482 char_u *cdpath;
3483 char_u *buf;
3484 int i;
3485 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003486 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487
3488 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003489 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490 if (cdpath != NULL)
3491 {
3492 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3493 if (buf != NULL)
3494 {
3495 buf[0] = ','; /* start with ",", current dir first */
3496 j = 1;
3497 for (i = 0; cdpath[i] != NUL; ++i)
3498 {
3499 if (vim_ispathlistsep(cdpath[i]))
3500 buf[j++] = ',';
3501 else
3502 {
3503 if (cdpath[i] == ' ' || cdpath[i] == ',')
3504 buf[j++] = '\\';
3505 buf[j++] = cdpath[i];
3506 }
3507 }
3508 buf[j] = NUL;
3509 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003510 if (opt_idx >= 0)
3511 {
3512 options[opt_idx].def_val[VI_DEFAULT] = buf;
3513 options[opt_idx].flags |= P_DEF_ALLOCED;
3514 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003515 else
3516 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003517 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003518 if (mustfree)
3519 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003520 }
3521 }
3522#endif
3523
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003524#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003525 /* Set print encoding on platforms that don't default to latin1 */
3526 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003527# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 (char_u *)"cp1252"
3529# else
3530# ifdef VMS
3531 (char_u *)"dec-mcs"
3532# else
3533# ifdef EBCDIC
3534 (char_u *)"ebcdic-uk"
3535# else
3536# ifdef MAC
3537 (char_u *)"mac-roman"
3538# else /* HPUX */
3539 (char_u *)"hp-roman8"
3540# endif
3541# endif
3542# endif
3543# endif
3544 );
3545#endif
3546
3547#ifdef FEAT_POSTSCRIPT
3548 /* 'printexpr' must be allocated to be able to evaluate it. */
3549 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003550# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003551 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003552# else
3553# ifdef VMS
3554 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3555
3556# else
3557 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3558# endif
3559# endif
3560 );
3561#endif
3562
3563 /*
3564 * Set all the options (except the terminal options) to their default
3565 * value. Also set the global value for local options.
3566 */
3567 set_options_default(0);
3568
Bram Moolenaar07268702018-03-01 21:57:32 +01003569#ifdef CLEAN_RUNTIMEPATH
3570 if (clean_arg)
3571 {
3572 opt_idx = findoption((char_u *)"runtimepath");
3573 if (opt_idx >= 0)
3574 {
3575 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3576 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3577 }
3578 opt_idx = findoption((char_u *)"packpath");
3579 if (opt_idx >= 0)
3580 {
3581 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3582 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3583 }
3584 }
3585#endif
3586
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587#ifdef FEAT_GUI
3588 if (found_reverse_arg)
3589 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3590#endif
3591
3592 curbuf->b_p_initialized = TRUE;
3593 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003594 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003595 check_buf_options(curbuf);
3596 check_win_options(curwin);
3597 check_options();
3598
3599 /* Must be before option_expand(), because that one needs vim_isIDc() */
3600 didset_options();
3601
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003602#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003603 /* Use the current chartab for the generic chartab. This is not in
3604 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003605 init_spell_chartab();
3606#endif
3607
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608 /*
3609 * Expand environment variables and things like "~" for the defaults.
3610 * If option_expand() returns non-NULL the variable is expanded. This can
3611 * only happen for non-indirect options.
3612 * Also set the default to the expanded value, so ":set" does not list
3613 * them.
3614 * Don't set the P_ALLOCED flag, because we don't want to free the
3615 * default.
3616 */
3617 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3618 {
3619 if ((options[opt_idx].flags & P_GETTEXT)
3620 && options[opt_idx].var != NULL)
3621 p = (char_u *)_(*(char **)options[opt_idx].var);
3622 else
3623 p = option_expand(opt_idx, NULL);
3624 if (p != NULL && (p = vim_strsave(p)) != NULL)
3625 {
3626 *(char_u **)options[opt_idx].var = p;
3627 /* VIMEXP
3628 * Defaults for all expanded options are currently the same for Vi
3629 * and Vim. When this changes, add some code here! Also need to
3630 * split P_DEF_ALLOCED in two.
3631 */
3632 if (options[opt_idx].flags & P_DEF_ALLOCED)
3633 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3634 options[opt_idx].def_val[VI_DEFAULT] = p;
3635 options[opt_idx].flags |= P_DEF_ALLOCED;
3636 }
3637 }
3638
Bram Moolenaar071d4272004-06-13 20:20:40 +00003639 save_file_ff(curbuf); /* Buffer is unchanged */
3640
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641#if defined(FEAT_ARABIC)
3642 /* Detect use of mlterm.
3643 * Mlterm is a terminal emulator akin to xterm that has some special
3644 * abilities (bidi namely).
3645 * NOTE: mlterm's author is being asked to 'set' a variable
3646 * instead of an environment variable due to inheritance.
3647 */
3648 if (mch_getenv((char_u *)"MLTERM") != NULL)
3649 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3650#endif
3651
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003652 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653
3654#ifdef FEAT_MBYTE
3655# if defined(WIN3264) && defined(FEAT_GETTEXT)
3656 /*
3657 * If $LANG isn't set, try to get a good value for it. This makes the
3658 * right language be used automatically. Don't do this for English.
3659 */
3660 if (mch_getenv((char_u *)"LANG") == NULL)
3661 {
3662 char buf[20];
3663
3664 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3665 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3666 * only the first two. */
3667 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3668 (LPTSTR)buf, 20);
3669 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3670 {
3671 /* There are a few exceptions (probably more) */
3672 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3673 STRCPY(buf, "zh_TW");
3674 else if (STRNICMP(buf, "chs", 3) == 0
3675 || STRNICMP(buf, "zhc", 3) == 0)
3676 STRCPY(buf, "zh_CN");
3677 else if (STRNICMP(buf, "jp", 2) == 0)
3678 STRCPY(buf, "ja");
3679 else
3680 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003681 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682 }
3683 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003684# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003685# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003686 /* Moved to os_mac_conv.c to avoid dependency problems. */
3687 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003688# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689# endif
3690
3691 /* enc_locale() will try to find the encoding of the current locale. */
3692 p = enc_locale();
3693 if (p != NULL)
3694 {
3695 char_u *save_enc;
3696
3697 /* Try setting 'encoding' and check if the value is valid.
3698 * If not, go back to the default "latin1". */
3699 save_enc = p_enc;
3700 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003701 if (STRCMP(p_enc, "gb18030") == 0)
3702 {
3703 /* We don't support "gb18030", but "cp936" is a good substitute
3704 * for practical purposes, thus use that. It's not an alias to
3705 * still support conversion between gb18030 and utf-8. */
3706 p_enc = vim_strsave((char_u *)"cp936");
3707 vim_free(p);
3708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 if (mb_init() == NULL)
3710 {
3711 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003712 if (opt_idx >= 0)
3713 {
3714 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3715 options[opt_idx].flags |= P_DEF_ALLOCED;
3716 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717
Bram Moolenaard0573012017-10-28 21:11:06 +02003718#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003719 if (STRCMP(p_enc, "latin1") == 0
3720# ifdef FEAT_MBYTE
3721 || enc_utf8
3722# endif
3723 )
3724 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003725 /* Adjust the default for 'isprint' and 'iskeyword' to match
3726 * latin1. Also set the defaults for when 'nocompatible' is
3727 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003728 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003729 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003730 set_string_option_direct((char_u *)"isk", -1,
3731 ISK_LATIN1, OPT_FREE, SID_NONE);
3732 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003733 if (opt_idx >= 0)
3734 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003735 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003736 if (opt_idx >= 0)
3737 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003738 (void)init_chartab();
3739 }
3740#endif
3741
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742# if defined(WIN3264) && !defined(FEAT_GUI)
3743 /* Win32 console: When GetACP() returns a different value from
3744 * GetConsoleCP() set 'termencoding'. */
3745 if (GetACP() != GetConsoleCP())
3746 {
3747 char buf[50];
3748
3749 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3750 p_tenc = vim_strsave((char_u *)buf);
3751 if (p_tenc != NULL)
3752 {
3753 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003754 if (opt_idx >= 0)
3755 {
3756 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3757 options[opt_idx].flags |= P_DEF_ALLOCED;
3758 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 convert_setup(&input_conv, p_tenc, p_enc);
3760 convert_setup(&output_conv, p_enc, p_tenc);
3761 }
3762 else
3763 p_tenc = empty_option;
3764 }
3765# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003766# if defined(WIN3264) && defined(FEAT_MBYTE)
3767 /* $HOME may have characters in active code page. */
3768 init_homedir();
3769# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 }
3771 else
3772 {
3773 vim_free(p_enc);
3774 p_enc = save_enc;
3775 }
3776 }
3777#endif
3778
3779#ifdef FEAT_MULTI_LANG
3780 /* Set the default for 'helplang'. */
3781 set_helplang_default(get_mess_lang());
3782#endif
3783}
3784
3785/*
3786 * Set an option to its default value.
3787 * This does not take care of side effects!
3788 */
3789 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003790set_option_default(
3791 int opt_idx,
3792 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3793 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794{
3795 char_u *varp; /* pointer to variable for current option */
3796 int dvi; /* index in def_val[] */
3797 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003798 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3800
3801 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3802 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003803 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003804 {
3805 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3806 if (flags & P_STRING)
3807 {
3808 /* Use set_string_option_direct() for local options to handle
3809 * freeing and allocating the value. */
3810 if (options[opt_idx].indir != PV_NONE)
3811 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003812 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 else
3814 {
3815 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3816 free_string_option(*(char_u **)(varp));
3817 *(char_u **)varp = options[opt_idx].def_val[dvi];
3818 options[opt_idx].flags &= ~P_ALLOCED;
3819 }
3820 }
3821 else if (flags & P_NUM)
3822 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003823 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824 win_comp_scroll(curwin);
3825 else
3826 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003827 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828 /* May also set global value for local option. */
3829 if (both)
3830 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3831 *(long *)varp;
3832 }
3833 }
3834 else /* P_BOOL */
3835 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003836 /* the cast to long is required for Manx C, long_i is needed for
3837 * MSVC */
3838 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003839#ifdef UNIX
3840 /* 'modeline' defaults to off for root */
3841 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3842 *(int *)varp = FALSE;
3843#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844 /* May also set global value for local option. */
3845 if (both)
3846 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3847 *(int *)varp;
3848 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003849
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003850 /* The default value is not insecure. */
3851 flagsp = insecure_flag(opt_idx, opt_flags);
3852 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853 }
3854
3855#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003856 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857#endif
3858}
3859
3860/*
3861 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003862 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863 */
3864 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003865set_options_default(
3866 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867{
3868 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003870 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871
3872 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003873 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003874#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003875 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003876 || (TRUE
3877# if defined(FEAT_MBYTE)
3878 && options[i].var != (char_u *)&p_enc
3879# endif
3880# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003881 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003882 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003883# endif
3884 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003885#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003886 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 set_option_default(i, opt_flags, p_cp);
3888
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003890 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003892#ifdef FEAT_CINDENT
3893 parse_cino(curbuf);
3894#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895}
3896
3897/*
3898 * Set the Vi-default value of a string option.
3899 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003900 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003902 static void
3903set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904{
3905 char_u *p;
3906 int opt_idx;
3907
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003908 if (escape && vim_strchr(val, ' ') != NULL)
3909 p = vim_strsave_escaped(val, (char_u *)" ");
3910 else
3911 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 if (p != NULL) /* we don't want a NULL */
3913 {
3914 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003915 if (opt_idx >= 0)
3916 {
3917 if (options[opt_idx].flags & P_DEF_ALLOCED)
3918 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3919 options[opt_idx].def_val[VI_DEFAULT] = p;
3920 options[opt_idx].flags |= P_DEF_ALLOCED;
3921 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 }
3923}
3924
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003925 void
3926set_string_default(char *name, char_u *val)
3927{
3928 set_string_default_esc(name, val, FALSE);
3929}
3930
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931/*
3932 * Set the Vi-default value of a number option.
3933 * Used for 'lines' and 'columns'.
3934 */
3935 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003936set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003938 int opt_idx;
3939
3940 opt_idx = findoption((char_u *)name);
3941 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003942 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943}
3944
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003945#if defined(EXITFREE) || defined(PROTO)
3946/*
3947 * Free all options.
3948 */
3949 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003950free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003951{
3952 int i;
3953
3954 for (i = 0; !istermoption(&options[i]); i++)
3955 {
3956 if (options[i].indir == PV_NONE)
3957 {
3958 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003959 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003960 free_string_option(*(char_u **)options[i].var);
3961 if (options[i].flags & P_DEF_ALLOCED)
3962 free_string_option(options[i].def_val[VI_DEFAULT]);
3963 }
3964 else if (options[i].var != VAR_WIN
3965 && (options[i].flags & P_STRING))
3966 /* buffer-local option: free global value */
3967 free_string_option(*(char_u **)options[i].var);
3968 }
3969}
3970#endif
3971
3972
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973/*
3974 * Initialize the options, part two: After getting Rows and Columns and
3975 * setting 'term'.
3976 */
3977 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003978set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003980 int idx;
3981
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003983 * 'scroll' defaults to half the window height. The stored default is zero,
3984 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003986 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003987 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003988 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989 comp_col();
3990
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003991 /*
3992 * 'window' is only for backwards compatibility with Vi.
3993 * Default is Rows - 1.
3994 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003995 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003996 p_window = Rows - 1;
3997 set_number_default("window", Rows - 1);
3998
Bram Moolenaarf740b292006-02-16 22:11:02 +00003999 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004000#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00004001 /*
4002 * If 'background' wasn't set by the user, try guessing the value,
4003 * depending on the terminal name. Only need to check for terminals
4004 * with a dark background, that can handle color.
4005 */
4006 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004007 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4008 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004010 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004011 /* don't mark it as set, when starting the GUI it may be
4012 * changed again */
4013 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 }
4015#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004016
4017#ifdef CURSOR_SHAPE
4018 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4019#endif
4020#ifdef FEAT_MOUSESHAPE
4021 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4022#endif
4023#ifdef FEAT_PRINTER
4024 (void)parse_printoptions(); /* parse 'printoptions' default value */
4025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026}
4027
4028/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004029 * Return "dark" or "light" depending on the kind of terminal.
4030 * This is just guessing! Recognized are:
4031 * "linux" Linux console
4032 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004033 * "cygwin.*" Cygwin shell
4034 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004035 * We also check the COLORFGBG environment variable, which is set by
4036 * rxvt and derivatives. This variable contains either two or three
4037 * values separated by semicolons; we want the last value in either
4038 * case. If this value is 0-6 or 8, our background is dark.
4039 */
4040 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004041term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004042{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004043#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004044 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004045 return (char_u *)"dark";
4046#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004047 char_u *p;
4048
Bram Moolenaarf740b292006-02-16 22:11:02 +00004049 if (STRCMP(T_NAME, "linux") == 0
4050 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004051 || STRNCMP(T_NAME, "cygwin", 6) == 0
4052 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004053 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4054 && (p = vim_strrchr(p, ';')) != NULL
4055 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4056 && p[2] == NUL))
4057 return (char_u *)"dark";
4058 return (char_u *)"light";
4059#endif
4060}
4061
4062/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 * Initialize the options, part three: After reading the .vimrc
4064 */
4065 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004066set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004068#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069/*
4070 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4071 * This is done after other initializations, where 'shell' might have been
4072 * set, but only if they have not been set before.
4073 */
4074 char_u *p;
4075 int idx_srr;
4076 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004077# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 int idx_sp;
4079 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081
4082 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004083 if (idx_srr < 0)
4084 do_srr = FALSE;
4085 else
4086 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004087# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004089 if (idx_sp < 0)
4090 do_sp = FALSE;
4091 else
4092 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004094 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 if (p != NULL)
4096 {
4097 /*
4098 * Default for p_sp is "| tee", for p_srr is ">".
4099 * For known shells it is changed here to include stderr.
4100 */
4101 if ( fnamecmp(p, "csh") == 0
4102 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004103# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 || fnamecmp(p, "csh.exe") == 0
4105 || fnamecmp(p, "tcsh.exe") == 0
4106# endif
4107 )
4108 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004109# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 if (do_sp)
4111 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004112# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004114# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004116# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4118 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 if (do_srr)
4121 {
4122 p_srr = (char_u *)">&";
4123 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4124 }
4125 }
4126 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004127 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 if ( fnamecmp(p, "sh") == 0
4129 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004130 || fnamecmp(p, "mksh") == 0
4131 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004133 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004135 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004136# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 || fnamecmp(p, "cmd") == 0
4138 || fnamecmp(p, "sh.exe") == 0
4139 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004140 || fnamecmp(p, "mksh.exe") == 0
4141 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004143 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 || fnamecmp(p, "bash.exe") == 0
4145 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004147 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004149# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 if (do_sp)
4151 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004152# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004154# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004156# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4158 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004159# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 if (do_srr)
4161 {
4162 p_srr = (char_u *)">%s 2>&1";
4163 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4164 }
4165 }
4166 vim_free(p);
4167 }
4168#endif
4169
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004170#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004172 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4173 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 * This is done after other initializations, where 'shell' might have been
4175 * set, but only if they have not been set before. Default for p_shcf is
4176 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004177 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004179 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180 {
4181 int idx3;
4182
4183 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004184 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004185 {
4186 p_shcf = (char_u *)"-c";
4187 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4188 }
4189
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 /* Somehow Win32 requires the quotes around the redirection too */
4191 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004192 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 {
4194 p_sxq = (char_u *)"\"";
4195 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4196 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004198 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4199 {
4200 int idx3;
4201
4202 /*
4203 * cmd.exe on Windows will strip the first and last double quote given
4204 * on the command line, e.g. most of the time things like:
4205 * cmd /c "my path/to/echo" "my args to echo"
4206 * become:
4207 * my path/to/echo" "my args to echo
4208 * when executed.
4209 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004210 * To avoid this, set shellxquote to surround the command in
4211 * parenthesis. This appears to make most commands work, without
4212 * breaking commands that worked previously, such as
4213 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004214 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004215 idx3 = findoption((char_u *)"sxq");
4216 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4217 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004218 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004219 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4220 }
4221
Bram Moolenaara64ba222012-02-12 23:23:31 +01004222 idx3 = findoption((char_u *)"shcf");
4223 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4224 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004225 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004226 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4227 }
4228 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229#endif
4230
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004231 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004232 {
4233 int idx_ffs = findoption((char_u *)"ffs");
4234
4235 /* Apply the first entry of 'fileformats' to the initial buffer. */
4236 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4237 set_fileformat(default_fileformat(), OPT_LOCAL);
4238 }
4239
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240#ifdef FEAT_TITLE
4241 set_title_defaults();
4242#endif
4243}
4244
4245#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4246/*
4247 * When 'helplang' is still at its default value, set it to "lang".
4248 * Only the first two characters of "lang" are used.
4249 */
4250 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004251set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004252{
4253 int idx;
4254
4255 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4256 return;
4257 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004258 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259 {
4260 if (options[idx].flags & P_ALLOCED)
4261 free_string_option(p_hlg);
4262 p_hlg = vim_strsave(lang);
4263 if (p_hlg == NULL)
4264 p_hlg = empty_option;
4265 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004266 {
4267 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4268 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4269 {
4270 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4271 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004273 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004274 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004275 options[idx].flags |= P_ALLOCED;
4276 }
4277}
4278#endif
4279
4280#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004281static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282
4283 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004284gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004285{
4286 if (gui_get_lightness(gui.back_pixel) < 127)
4287 return (char_u *)"dark";
4288 return (char_u *)"light";
4289}
4290
4291/*
4292 * Option initializations that can only be done after opening the GUI window.
4293 */
4294 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004295init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004296{
4297 /* Set the 'background' option according to the lightness of the
4298 * background color, unless the user has set it already. */
4299 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4300 {
4301 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4302 highlight_changed();
4303 }
4304}
4305#endif
4306
4307#ifdef FEAT_TITLE
4308/*
4309 * 'title' and 'icon' only default to true if they have not been set or reset
4310 * in .vimrc and we can read the old value.
4311 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4312 * they can be reset. This reduces startup time when using X on a remote
4313 * machine.
4314 */
4315 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004316set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004317{
4318 int idx1;
4319 long val;
4320
4321 /*
4322 * If GUI is (going to be) used, we can always set the window title and
4323 * icon name. Saves a bit of time, because the X11 display server does
4324 * not need to be contacted.
4325 */
4326 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004327 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004328 {
4329#ifdef FEAT_GUI
4330 if (gui.starting || gui.in_use)
4331 val = TRUE;
4332 else
4333#endif
4334 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004335 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004336 p_title = val;
4337 }
4338 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004339 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340 {
4341#ifdef FEAT_GUI
4342 if (gui.starting || gui.in_use)
4343 val = TRUE;
4344 else
4345#endif
4346 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004347 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004348 p_icon = val;
4349 }
4350}
4351#endif
4352
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004353#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004354 static void
4355trigger_optionsset_string(
4356 int opt_idx,
4357 int opt_flags,
4358 char_u *oldval,
4359 char_u *newval)
4360{
4361 if (oldval != NULL && newval != NULL)
4362 {
4363 char_u buf_type[7];
4364
4365 sprintf((char *)buf_type, "%s",
4366 (opt_flags & OPT_LOCAL) ? "local" : "global");
4367 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4368 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4369 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4370 apply_autocmds(EVENT_OPTIONSET,
4371 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4372 reset_v_option_vars();
4373 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004374}
4375#endif
4376
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377/*
4378 * Parse 'arg' for option settings.
4379 *
4380 * 'arg' may be IObuff, but only when no errors can be present and option
4381 * does not need to be expanded with option_expand().
4382 * "opt_flags":
4383 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004384 * OPT_GLOBAL for ":setglobal"
4385 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004386 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004387 * OPT_WINONLY to only set window-local options
4388 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 *
4390 * returns FAIL if an error is detected, OK otherwise
4391 */
4392 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004393do_set(
4394 char_u *arg, /* option string (may be written to!) */
4395 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396{
4397 int opt_idx;
4398 char_u *errmsg;
4399 char_u errbuf[80];
4400 char_u *startarg;
4401 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4402 int nextchar; /* next non-white char after option name */
4403 int afterchar; /* character just after option name */
4404 int len;
4405 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004406 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004407 int key;
4408 long_u flags; /* flags for current option */
4409 char_u *varp = NULL; /* pointer to variable for current option */
4410 int did_show = FALSE; /* already showed one value */
4411 int adding; /* "opt+=arg" */
4412 int prepending; /* "opt^=arg" */
4413 int removing; /* "opt-=arg" */
4414 int cp_val = 0;
4415 char_u key_name[2];
4416
4417 if (*arg == NUL)
4418 {
4419 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004420 did_show = TRUE;
4421 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004422 }
4423
4424 while (*arg != NUL) /* loop to process all options */
4425 {
4426 errmsg = NULL;
4427 startarg = arg; /* remember for error message */
4428
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004429 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4430 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004431 {
4432 /*
4433 * ":set all" show all options.
4434 * ":set all&" set all options to their default value.
4435 */
4436 arg += 3;
4437 if (*arg == '&')
4438 {
4439 ++arg;
4440 /* Only for :set command set global value of local options. */
4441 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004442 didset_options();
4443 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004444 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445 }
4446 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004447 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004448 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004449 did_show = TRUE;
4450 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004451 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004452 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004453 {
4454 showoptions(2, opt_flags);
4455 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004456 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004457 arg += 7;
4458 }
4459 else
4460 {
4461 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004462 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004463 {
4464 prefix = 0;
4465 arg += 2;
4466 }
4467 else if (STRNCMP(arg, "inv", 3) == 0)
4468 {
4469 prefix = 2;
4470 arg += 3;
4471 }
4472
4473 /* find end of name */
4474 key = 0;
4475 if (*arg == '<')
4476 {
4477 nextchar = 0;
4478 opt_idx = -1;
4479 /* look out for <t_>;> */
4480 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4481 len = 5;
4482 else
4483 {
4484 len = 1;
4485 while (arg[len] != NUL && arg[len] != '>')
4486 ++len;
4487 }
4488 if (arg[len] != '>')
4489 {
4490 errmsg = e_invarg;
4491 goto skip;
4492 }
4493 arg[len] = NUL; /* put NUL after name */
4494 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4495 opt_idx = findoption(arg + 1);
4496 arg[len++] = '>'; /* restore '>' */
4497 if (opt_idx == -1)
4498 key = find_key_option(arg + 1);
4499 }
4500 else
4501 {
4502 len = 0;
4503 /*
4504 * The two characters after "t_" may not be alphanumeric.
4505 */
4506 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4507 len = 4;
4508 else
4509 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4510 ++len;
4511 nextchar = arg[len];
4512 arg[len] = NUL; /* put NUL after name */
4513 opt_idx = findoption(arg);
4514 arg[len] = nextchar; /* restore nextchar */
4515 if (opt_idx == -1)
4516 key = find_key_option(arg);
4517 }
4518
4519 /* remember character after option name */
4520 afterchar = arg[len];
4521
4522 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004523 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004524 ++len;
4525
4526 adding = FALSE;
4527 prepending = FALSE;
4528 removing = FALSE;
4529 if (arg[len] != NUL && arg[len + 1] == '=')
4530 {
4531 if (arg[len] == '+')
4532 {
4533 adding = TRUE; /* "+=" */
4534 ++len;
4535 }
4536 else if (arg[len] == '^')
4537 {
4538 prepending = TRUE; /* "^=" */
4539 ++len;
4540 }
4541 else if (arg[len] == '-')
4542 {
4543 removing = TRUE; /* "-=" */
4544 ++len;
4545 }
4546 }
4547 nextchar = arg[len];
4548
4549 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4550 {
4551 errmsg = (char_u *)N_("E518: Unknown option");
4552 goto skip;
4553 }
4554
4555 if (opt_idx >= 0)
4556 {
4557 if (options[opt_idx].var == NULL) /* hidden option: skip */
4558 {
4559 /* Only give an error message when requesting the value of
4560 * a hidden option, ignore setting it. */
4561 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4562 && (!(options[opt_idx].flags & P_BOOL)
4563 || nextchar == '?'))
4564 errmsg = (char_u *)N_("E519: Option not supported");
4565 goto skip;
4566 }
4567
4568 flags = options[opt_idx].flags;
4569 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4570 }
4571 else
4572 {
4573 flags = P_STRING;
4574 if (key < 0)
4575 {
4576 key_name[0] = KEY2TERMCAP0(key);
4577 key_name[1] = KEY2TERMCAP1(key);
4578 }
4579 else
4580 {
4581 key_name[0] = KS_KEY;
4582 key_name[1] = (key & 0xff);
4583 }
4584 }
4585
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004586 /* Skip all options that are not window-local (used when showing
4587 * an already loaded buffer in a window). */
4588 if ((opt_flags & OPT_WINONLY)
4589 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4590 goto skip;
4591
Bram Moolenaara3227e22006-03-08 21:32:40 +00004592 /* Skip all options that are window-local (used for :vimgrep). */
4593 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4594 && options[opt_idx].var == VAR_WIN)
4595 goto skip;
4596
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004597 /* Disallow changing some options from modelines. */
4598 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004599 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004600 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004601 {
4602 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4603 goto skip;
4604 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004605#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004606 /* In diff mode some options are overruled. This avoids that
4607 * 'foldmethod' becomes "marker" instead of "diff" and that
4608 * "wrap" gets set. */
4609 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004610 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004611 && (
4612#ifdef FEAT_FOLDING
4613 options[opt_idx].indir == PV_FDM ||
4614#endif
4615 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004616 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004618 }
4619
4620#ifdef HAVE_SANDBOX
4621 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004622 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 {
4624 errmsg = (char_u *)_(e_sandbox);
4625 goto skip;
4626 }
4627#endif
4628
4629 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4630 {
4631 arg += len;
4632 cp_val = p_cp;
4633 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4634 {
4635 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4636 {
4637 cp_val = FALSE;
4638 arg += 3;
4639 }
4640 else /* "opt&vi": set to Vi default */
4641 {
4642 cp_val = TRUE;
4643 arg += 2;
4644 }
4645 }
4646 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004647 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004648 {
4649 errmsg = e_trailing;
4650 goto skip;
4651 }
4652 }
4653
4654 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004655 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4656 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004657 */
4658 if (nextchar == '?'
4659 || (prefix == 1
4660 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4661 && !(flags & P_BOOL)))
4662 {
4663 /*
4664 * print value
4665 */
4666 if (did_show)
4667 msg_putchar('\n'); /* cursor below last one */
4668 else
4669 {
4670 gotocmdline(TRUE); /* cursor at status line */
4671 did_show = TRUE; /* remember that we did a line */
4672 }
4673 if (opt_idx >= 0)
4674 {
4675 showoneopt(&options[opt_idx], opt_flags);
4676#ifdef FEAT_EVAL
4677 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004678 {
4679 /* Mention where the option was last set. */
4680 if (varp == options[opt_idx].var)
4681 last_set_msg(options[opt_idx].scriptID);
4682 else if ((int)options[opt_idx].indir & PV_WIN)
4683 last_set_msg(curwin->w_p_scriptID[
4684 (int)options[opt_idx].indir & PV_MASK]);
4685 else if ((int)options[opt_idx].indir & PV_BUF)
4686 last_set_msg(curbuf->b_p_scriptID[
4687 (int)options[opt_idx].indir & PV_MASK]);
4688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004689#endif
4690 }
4691 else
4692 {
4693 char_u *p;
4694
4695 p = find_termcode(key_name);
4696 if (p == NULL)
4697 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004698 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004699 goto skip;
4700 }
4701 else
4702 (void)show_one_termcode(key_name, p, TRUE);
4703 }
4704 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004705 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004706 errmsg = e_trailing;
4707 }
4708 else
4709 {
4710 if (flags & P_BOOL) /* boolean */
4711 {
4712 if (nextchar == '=' || nextchar == ':')
4713 {
4714 errmsg = e_invarg;
4715 goto skip;
4716 }
4717
4718 /*
4719 * ":set opt!": invert
4720 * ":set opt&": reset to default value
4721 * ":set opt<": reset to global value
4722 */
4723 if (nextchar == '!')
4724 value = *(int *)(varp) ^ 1;
4725 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004726 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727 ((flags & P_VI_DEF) || cp_val)
4728 ? VI_DEFAULT : VIM_DEFAULT];
4729 else if (nextchar == '<')
4730 {
4731 /* For 'autoread' -1 means to use global value. */
4732 if ((int *)varp == &curbuf->b_p_ar
4733 && opt_flags == OPT_LOCAL)
4734 value = -1;
4735 else
4736 value = *(int *)get_varp_scope(&(options[opt_idx]),
4737 OPT_GLOBAL);
4738 }
4739 else
4740 {
4741 /*
4742 * ":set invopt": invert
4743 * ":set opt" or ":set noopt": set or reset
4744 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004745 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004746 {
4747 errmsg = e_trailing;
4748 goto skip;
4749 }
4750 if (prefix == 2) /* inv */
4751 value = *(int *)(varp) ^ 1;
4752 else
4753 value = prefix;
4754 }
4755
4756 errmsg = set_bool_option(opt_idx, varp, (int)value,
4757 opt_flags);
4758 }
4759 else /* numeric or string */
4760 {
4761 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4762 || prefix != 1)
4763 {
4764 errmsg = e_invarg;
4765 goto skip;
4766 }
4767
4768 if (flags & P_NUM) /* numeric */
4769 {
4770 /*
4771 * Different ways to set a number option:
4772 * & set to default value
4773 * < set to global value
4774 * <xx> accept special key codes for 'wildchar'
4775 * c accept any non-digit for 'wildchar'
4776 * [-]0-9 set number
4777 * other error
4778 */
4779 ++arg;
4780 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004781 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004782 ((flags & P_VI_DEF) || cp_val)
4783 ? VI_DEFAULT : VIM_DEFAULT];
4784 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004785 {
4786 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4787 * use the global value. */
4788 if ((long *)varp == &curbuf->b_p_ul
4789 && opt_flags == OPT_LOCAL)
4790 value = NO_LOCAL_UNDOLEVEL;
4791 else
4792 value = *(long *)get_varp_scope(
4793 &(options[opt_idx]), OPT_GLOBAL);
4794 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 else if (((long *)varp == &p_wc
4796 || (long *)varp == &p_wcm)
4797 && (*arg == '<'
4798 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004799 || (*arg != NUL
4800 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004801 && !VIM_ISDIGIT(*arg))))
4802 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004803 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 if (value == 0 && (long *)varp != &p_wcm)
4805 {
4806 errmsg = e_invarg;
4807 goto skip;
4808 }
4809 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004810 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4811 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004812 /* Allow negative (for 'undolevels'), octal and
4813 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004814 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4815 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004816 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004817 {
4818 errmsg = e_invarg;
4819 goto skip;
4820 }
4821 }
4822 else
4823 {
4824 errmsg = (char_u *)N_("E521: Number required after =");
4825 goto skip;
4826 }
4827
4828 if (adding)
4829 value = *(long *)varp + value;
4830 if (prepending)
4831 value = *(long *)varp * value;
4832 if (removing)
4833 value = *(long *)varp - value;
4834 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004835 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004836 }
4837 else if (opt_idx >= 0) /* string */
4838 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004839 char_u *save_arg = NULL;
4840 char_u *s = NULL;
4841 char_u *oldval = NULL; /* previous value if *varp */
4842 char_u *newval;
4843 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004844#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004845 char_u *saved_origval = NULL;
4846 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004847#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004848 unsigned newlen;
4849 int comma;
4850 int bs;
4851 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004852 was allocated */
4853
4854 /* When using ":set opt=val" for a global option
4855 * with a local value the local value will be
4856 * reset, use the global value here. */
4857 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004858 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004859 varp = options[opt_idx].var;
4860
4861 /* The old value is kept until we are sure that the
4862 * new value is valid. */
4863 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004864
4865 /* When setting the local value of a global
4866 * option, the old value may be the global value. */
4867 if (((int)options[opt_idx].indir & PV_BOTH)
4868 && (opt_flags & OPT_LOCAL))
4869 origval = *(char_u **)get_varp(
4870 &options[opt_idx]);
4871 else
4872 origval = oldval;
4873
Bram Moolenaar071d4272004-06-13 20:20:40 +00004874 if (nextchar == '&') /* set to default val */
4875 {
4876 newval = options[opt_idx].def_val[
4877 ((flags & P_VI_DEF) || cp_val)
4878 ? VI_DEFAULT : VIM_DEFAULT];
4879 if ((char_u **)varp == &p_bg)
4880 {
4881 /* guess the value of 'background' */
4882#ifdef FEAT_GUI
4883 if (gui.in_use)
4884 newval = gui_bg_default();
4885 else
4886#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004887 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004888 }
4889
4890 /* expand environment variables and ~ (since the
4891 * default value was already expanded, only
4892 * required when an environment variable was set
4893 * later */
4894 if (newval == NULL)
4895 newval = empty_option;
4896 else
4897 {
4898 s = option_expand(opt_idx, newval);
4899 if (s == NULL)
4900 s = newval;
4901 newval = vim_strsave(s);
4902 }
4903 new_value_alloced = TRUE;
4904 }
4905 else if (nextchar == '<') /* set to global val */
4906 {
4907 newval = vim_strsave(*(char_u **)get_varp_scope(
4908 &(options[opt_idx]), OPT_GLOBAL));
4909 new_value_alloced = TRUE;
4910 }
4911 else
4912 {
4913 ++arg; /* jump to after the '=' or ':' */
4914
4915 /*
4916 * Set 'keywordprg' to ":help" if an empty
4917 * value was passed to :set by the user.
4918 * Misuse errbuf[] for the resulting string.
4919 */
4920 if (varp == (char_u *)&p_kp
4921 && (*arg == NUL || *arg == ' '))
4922 {
4923 STRCPY(errbuf, ":help");
4924 save_arg = arg;
4925 arg = errbuf;
4926 }
4927 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004928 * Convert 'backspace' number to string, for
4929 * adding, prepending and removing string.
4930 */
4931 else if (varp == (char_u *)&p_bs
4932 && VIM_ISDIGIT(**(char_u **)varp))
4933 {
4934 i = getdigits((char_u **)varp);
4935 switch (i)
4936 {
4937 case 0:
4938 *(char_u **)varp = empty_option;
4939 break;
4940 case 1:
4941 *(char_u **)varp = vim_strsave(
4942 (char_u *)"indent,eol");
4943 break;
4944 case 2:
4945 *(char_u **)varp = vim_strsave(
4946 (char_u *)"indent,eol,start");
4947 break;
4948 }
4949 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004950 if (origval == oldval)
4951 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004952 oldval = *(char_u **)varp;
4953 }
4954 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004955 * Convert 'whichwrap' number to string, for
4956 * backwards compatibility with Vim 3.0.
4957 * Misuse errbuf[] for the resulting string.
4958 */
4959 else if (varp == (char_u *)&p_ww
4960 && VIM_ISDIGIT(*arg))
4961 {
4962 *errbuf = NUL;
4963 i = getdigits(&arg);
4964 if (i & 1)
4965 STRCAT(errbuf, "b,");
4966 if (i & 2)
4967 STRCAT(errbuf, "s,");
4968 if (i & 4)
4969 STRCAT(errbuf, "h,l,");
4970 if (i & 8)
4971 STRCAT(errbuf, "<,>,");
4972 if (i & 16)
4973 STRCAT(errbuf, "[,],");
4974 if (*errbuf != NUL) /* remove trailing , */
4975 errbuf[STRLEN(errbuf) - 1] = NUL;
4976 save_arg = arg;
4977 arg = errbuf;
4978 }
4979 /*
4980 * Remove '>' before 'dir' and 'bdir', for
4981 * backwards compatibility with version 3.0
4982 */
4983 else if ( *arg == '>'
4984 && (varp == (char_u *)&p_dir
4985 || varp == (char_u *)&p_bdir))
4986 {
4987 ++arg;
4988 }
4989
Bram Moolenaar071d4272004-06-13 20:20:40 +00004990 /*
4991 * Copy the new string into allocated memory.
4992 * Can't use set_string_option_direct(), because
4993 * we need to remove the backslashes.
4994 */
4995 /* get a bit too much */
4996 newlen = (unsigned)STRLEN(arg) + 1;
4997 if (adding || prepending || removing)
4998 newlen += (unsigned)STRLEN(origval) + 1;
4999 newval = alloc(newlen);
5000 if (newval == NULL) /* out of mem, don't change */
5001 break;
5002 s = newval;
5003
5004 /*
5005 * Copy the string, skip over escaped chars.
5006 * For MS-DOS and WIN32 backslashes before normal
5007 * file name characters are not removed, and keep
5008 * backslash at start, for "\\machine\path", but
5009 * do remove it for "\\\\machine\\path".
5010 * The reverse is found in ExpandOldSetting().
5011 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005012 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005013 {
5014 if (*arg == '\\' && arg[1] != NUL
5015#ifdef BACKSLASH_IN_FILENAME
5016 && !((flags & P_EXPAND)
5017 && vim_isfilec(arg[1])
5018 && (arg[1] != '\\'
5019 || (s == newval
5020 && arg[2] != '\\')))
5021#endif
5022 )
5023 ++arg; /* remove backslash */
5024#ifdef FEAT_MBYTE
5025 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005026 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005027 {
5028 /* copy multibyte char */
5029 mch_memmove(s, arg, (size_t)i);
5030 arg += i;
5031 s += i;
5032 }
5033 else
5034#endif
5035 *s++ = *arg++;
5036 }
5037 *s = NUL;
5038
5039 /*
5040 * Expand environment variables and ~.
5041 * Don't do it when adding without inserting a
5042 * comma.
5043 */
5044 if (!(adding || prepending || removing)
5045 || (flags & P_COMMA))
5046 {
5047 s = option_expand(opt_idx, newval);
5048 if (s != NULL)
5049 {
5050 vim_free(newval);
5051 newlen = (unsigned)STRLEN(s) + 1;
5052 if (adding || prepending || removing)
5053 newlen += (unsigned)STRLEN(origval) + 1;
5054 newval = alloc(newlen);
5055 if (newval == NULL)
5056 break;
5057 STRCPY(newval, s);
5058 }
5059 }
5060
5061 /* locate newval[] in origval[] when removing it
5062 * and when adding to avoid duplicates */
5063 i = 0; /* init for GCC */
5064 if (removing || (flags & P_NODUP))
5065 {
5066 i = (int)STRLEN(newval);
5067 bs = 0;
5068 for (s = origval; *s; ++s)
5069 {
5070 if ((!(flags & P_COMMA)
5071 || s == origval
5072 || (s[-1] == ',' && !(bs & 1)))
5073 && STRNCMP(s, newval, i) == 0
5074 && (!(flags & P_COMMA)
5075 || s[i] == ','
5076 || s[i] == NUL))
5077 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005078 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005079 * even number of backslashes or a single
5080 * backslash preceded by a comma before it
5081 * is recognized as a separator */
5082 if ((s > origval + 1
5083 && s[-1] == '\\'
5084 && s[-2] != ',')
5085 || (s == origval + 1
5086 && s[-1] == '\\'))
5087
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088 ++bs;
5089 else
5090 bs = 0;
5091 }
5092
5093 /* do not add if already there */
5094 if ((adding || prepending) && *s)
5095 {
5096 prepending = FALSE;
5097 adding = FALSE;
5098 STRCPY(newval, origval);
5099 }
5100 }
5101
5102 /* concatenate the two strings; add a ',' if
5103 * needed */
5104 if (adding || prepending)
5105 {
5106 comma = ((flags & P_COMMA) && *origval != NUL
5107 && *newval != NUL);
5108 if (adding)
5109 {
5110 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005111 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005112 if (comma && i > 1
5113 && (flags & P_ONECOMMA) == P_ONECOMMA
5114 && origval[i - 1] == ','
5115 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005116 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005117 mch_memmove(newval + i + comma, newval,
5118 STRLEN(newval) + 1);
5119 mch_memmove(newval, origval, (size_t)i);
5120 }
5121 else
5122 {
5123 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005124 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 }
5126 if (comma)
5127 newval[i] = ',';
5128 }
5129
5130 /* Remove newval[] from origval[]. (Note: "i" has
5131 * been set above and is used here). */
5132 if (removing)
5133 {
5134 STRCPY(newval, origval);
5135 if (*s)
5136 {
5137 /* may need to remove a comma */
5138 if (flags & P_COMMA)
5139 {
5140 if (s == origval)
5141 {
5142 /* include comma after string */
5143 if (s[i] == ',')
5144 ++i;
5145 }
5146 else
5147 {
5148 /* include comma before string */
5149 --s;
5150 ++i;
5151 }
5152 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005153 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005154 }
5155 }
5156
5157 if (flags & P_FLAGLIST)
5158 {
5159 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005160 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005161 {
5162 /* if options have P_FLAGLIST and
5163 * P_ONECOMMA such as 'whichwrap' */
5164 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005165 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005166 if (*s != ',' && *(s + 1) == ','
5167 && vim_strchr(s + 2, *s) != NULL)
5168 {
5169 /* Remove the duplicated value and
5170 * the next comma. */
5171 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005172 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005174 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005175 else
5176 {
5177 if ((!(flags & P_COMMA) || *s != ',')
5178 && vim_strchr(s + 1, *s) != NULL)
5179 {
5180 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005181 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005182 }
5183 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005184 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005185 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186 }
5187
5188 if (save_arg != NULL) /* number for 'whichwrap' */
5189 arg = save_arg;
5190 new_value_alloced = TRUE;
5191 }
5192
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005193 /*
5194 * Set the new value.
5195 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005196 *(char_u **)(varp) = newval;
5197
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005198#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005199 if (!starting
5200# ifdef FEAT_CRYPT
5201 && options[opt_idx].indir != PV_KEY
5202# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005203 && origval != NULL && newval != NULL)
5204 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005205 /* origval may be freed by
5206 * did_set_string_option(), make a copy. */
5207 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005208 /* newval (and varp) may become invalid if the
5209 * buffer is closed by autocommands. */
5210 saved_newval = vim_strsave(newval);
5211 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005212#endif
5213
Bram Moolenaar071d4272004-06-13 20:20:40 +00005214 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005215 * ":set" on local options. Note: when setting 'syntax'
5216 * or 'filetype' autocommands may be triggered that can
5217 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005218 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5219 new_value_alloced, oldval, errbuf, opt_flags);
5220
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005221#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005222 if (errmsg == NULL)
5223 trigger_optionsset_string(opt_idx, opt_flags,
5224 saved_origval, saved_newval);
5225 vim_free(saved_origval);
5226 vim_free(saved_newval);
5227#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 /* If error detected, print the error message. */
5229 if (errmsg != NULL)
5230 goto skip;
5231 }
5232 else /* key code option */
5233 {
5234 char_u *p;
5235
5236 if (nextchar == '&')
5237 {
5238 if (add_termcap_entry(key_name, TRUE) == FAIL)
5239 errmsg = (char_u *)N_("E522: Not found in termcap");
5240 }
5241 else
5242 {
5243 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005244 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245 if (*p == '\\' && p[1] != NUL)
5246 ++p;
5247 nextchar = *p;
5248 *p = NUL;
5249 add_termcode(key_name, arg, FALSE);
5250 *p = nextchar;
5251 }
5252 if (full_screen)
5253 ttest(FALSE);
5254 redraw_all_later(CLEAR);
5255 }
5256 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005257
Bram Moolenaar071d4272004-06-13 20:20:40 +00005258 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005259 did_set_option(opt_idx, opt_flags,
5260 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005261 }
5262
5263skip:
5264 /*
5265 * Advance to next argument.
5266 * - skip until a blank found, taking care of backslashes
5267 * - skip blanks
5268 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5269 */
5270 for (i = 0; i < 2 ; ++i)
5271 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005272 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273 if (*arg++ == '\\' && *arg != NUL)
5274 ++arg;
5275 arg = skipwhite(arg);
5276 if (*arg != '=')
5277 break;
5278 }
5279 }
5280
5281 if (errmsg != NULL)
5282 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005283 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005284 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285 if (i + (arg - startarg) < IOSIZE)
5286 {
5287 /* append the argument with the error */
5288 STRCAT(IObuff, ": ");
5289 mch_memmove(IObuff + i, startarg, (arg - startarg));
5290 IObuff[i + (arg - startarg)] = NUL;
5291 }
5292 /* make sure all characters are printable */
5293 trans_characters(IObuff, IOSIZE);
5294
5295 ++no_wait_return; /* wait_return done later */
5296 emsg(IObuff); /* show error highlighted */
5297 --no_wait_return;
5298
5299 return FAIL;
5300 }
5301
5302 arg = skipwhite(arg);
5303 }
5304
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005305theend:
5306 if (silent_mode && did_show)
5307 {
5308 /* After displaying option values in silent mode. */
5309 silent_mode = FALSE;
5310 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5311 msg_putchar('\n');
5312 cursor_on(); /* msg_start() switches it off */
5313 out_flush();
5314 silent_mode = TRUE;
5315 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5316 }
5317
Bram Moolenaar071d4272004-06-13 20:20:40 +00005318 return OK;
5319}
5320
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005321/*
5322 * Call this when an option has been given a new value through a user command.
5323 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5324 */
5325 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005326did_set_option(
5327 int opt_idx,
5328 int opt_flags, /* possibly with OPT_MODELINE */
5329 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005330{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005331 long_u *p;
5332
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005333 options[opt_idx].flags |= P_WAS_SET;
5334
5335 /* When an option is set in the sandbox, from a modeline or in secure mode
5336 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005337 * flag. */
5338 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005339 if (secure
5340#ifdef HAVE_SANDBOX
5341 || sandbox != 0
5342#endif
5343 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005344 *p = *p | P_INSECURE;
5345 else if (new_value)
5346 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005347}
5348
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005350illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351{
5352 if (errbuf == NULL)
5353 return (char_u *)"";
5354 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005355 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356 return errbuf;
5357}
5358
5359/*
5360 * Convert a key name or string into a key value.
5361 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005362 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005364 int
5365string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005366{
5367 if (*arg == '<')
5368 return find_key_option(arg + 1);
5369 if (*arg == '^')
5370 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005371 if (multi_byte)
5372 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373 return *arg;
5374}
5375
5376#ifdef FEAT_CMDWIN
5377/*
5378 * Check value of 'cedit' and set cedit_key.
5379 * Returns NULL if value is OK, error message otherwise.
5380 */
5381 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005382check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005383{
5384 int n;
5385
5386 if (*p_cedit == NUL)
5387 cedit_key = -1;
5388 else
5389 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005390 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005391 if (vim_isprintc(n))
5392 return e_invarg;
5393 cedit_key = n;
5394 }
5395 return NULL;
5396}
5397#endif
5398
5399#ifdef FEAT_TITLE
5400/*
5401 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5402 * maketitle() to create and display it.
5403 * When switching the title or icon off, call mch_restore_title() to get
5404 * the old value back.
5405 */
5406 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005407did_set_title(
5408 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005409{
5410 if (starting != NO_SCREEN
5411#ifdef FEAT_GUI
5412 && !gui.starting
5413#endif
5414 )
5415 {
5416 maketitle();
5417 if (icon)
5418 {
5419 if (!p_icon)
5420 mch_restore_title(2);
5421 }
5422 else
5423 {
5424 if (!p_title)
5425 mch_restore_title(1);
5426 }
5427 }
5428}
5429#endif
5430
5431/*
5432 * set_options_bin - called when 'bin' changes value.
5433 */
5434 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005435set_options_bin(
5436 int oldval,
5437 int newval,
5438 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005439{
5440 /*
5441 * The option values that are changed when 'bin' changes are
5442 * copied when 'bin is set and restored when 'bin' is reset.
5443 */
5444 if (newval)
5445 {
5446 if (!oldval) /* switched on */
5447 {
5448 if (!(opt_flags & OPT_GLOBAL))
5449 {
5450 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5451 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5452 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5453 curbuf->b_p_et_nobin = curbuf->b_p_et;
5454 }
5455 if (!(opt_flags & OPT_LOCAL))
5456 {
5457 p_tw_nobin = p_tw;
5458 p_wm_nobin = p_wm;
5459 p_ml_nobin = p_ml;
5460 p_et_nobin = p_et;
5461 }
5462 }
5463
5464 if (!(opt_flags & OPT_GLOBAL))
5465 {
5466 curbuf->b_p_tw = 0; /* no automatic line wrap */
5467 curbuf->b_p_wm = 0; /* no automatic line wrap */
5468 curbuf->b_p_ml = 0; /* no modelines */
5469 curbuf->b_p_et = 0; /* no expandtab */
5470 }
5471 if (!(opt_flags & OPT_LOCAL))
5472 {
5473 p_tw = 0;
5474 p_wm = 0;
5475 p_ml = FALSE;
5476 p_et = FALSE;
5477 p_bin = TRUE; /* needed when called for the "-b" argument */
5478 }
5479 }
5480 else if (oldval) /* switched off */
5481 {
5482 if (!(opt_flags & OPT_GLOBAL))
5483 {
5484 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5485 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5486 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5487 curbuf->b_p_et = curbuf->b_p_et_nobin;
5488 }
5489 if (!(opt_flags & OPT_LOCAL))
5490 {
5491 p_tw = p_tw_nobin;
5492 p_wm = p_wm_nobin;
5493 p_ml = p_ml_nobin;
5494 p_et = p_et_nobin;
5495 }
5496 }
5497}
5498
5499#ifdef FEAT_VIMINFO
5500/*
5501 * Find the parameter represented by the given character (eg ', :, ", or /),
5502 * and return its associated value in the 'viminfo' string.
5503 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005504 * If the parameter is not specified in the string or there is no following
5505 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005506 */
5507 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005508get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509{
5510 char_u *p;
5511
5512 p = find_viminfo_parameter(type);
5513 if (p != NULL && VIM_ISDIGIT(*p))
5514 return atoi((char *)p);
5515 return -1;
5516}
5517
5518/*
5519 * Find the parameter represented by the given character (eg ''', ':', '"', or
5520 * '/') in the 'viminfo' option and return a pointer to the string after it.
5521 * Return NULL if the parameter is not specified in the string.
5522 */
5523 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005524find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525{
5526 char_u *p;
5527
5528 for (p = p_viminfo; *p; ++p)
5529 {
5530 if (*p == type)
5531 return p + 1;
5532 if (*p == 'n') /* 'n' is always the last one */
5533 break;
5534 p = vim_strchr(p, ','); /* skip until next ',' */
5535 if (p == NULL) /* hit the end without finding parameter */
5536 break;
5537 }
5538 return NULL;
5539}
5540#endif
5541
5542/*
5543 * Expand environment variables for some string options.
5544 * These string options cannot be indirect!
5545 * If "val" is NULL expand the current value of the option.
5546 * Return pointer to NameBuff, or NULL when not expanded.
5547 */
5548 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005549option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550{
5551 /* if option doesn't need expansion nothing to do */
5552 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5553 return NULL;
5554
5555 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5556 * expand_env() would truncate the string. */
5557 if (val != NULL && STRLEN(val) > MAXPATHL)
5558 return NULL;
5559
5560 if (val == NULL)
5561 val = *(char_u **)options[opt_idx].var;
5562
5563 /*
5564 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5565 * Escape spaces when expanding 'tags', they are used to separate file
5566 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005567 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568 */
5569 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005570 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005571#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005572 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5573#endif
5574 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5576 return NULL;
5577
5578 return NameBuff;
5579}
5580
5581/*
5582 * After setting various option values: recompute variables that depend on
5583 * option values.
5584 */
5585 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005586didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005587{
5588 /* initialize the table for 'iskeyword' et.al. */
5589 (void)init_chartab();
5590
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005591#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005592 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005593#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005594 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005595 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005596#ifdef FEAT_SESSION
5597 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5598 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5599#endif
5600#ifdef FEAT_FOLDING
5601 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5602#endif
5603 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005604 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605#ifdef FEAT_VIRTUALEDIT
5606 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5607#endif
5608#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5609 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5610#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005611#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005612 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005613 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005614 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005615 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5618 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5619#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005620#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5622#endif
5623#ifdef FEAT_CMDWIN
5624 /* set cedit_key */
5625 (void)check_cedit();
5626#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005627#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005628 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005629#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005630#ifdef FEAT_LINEBREAK
5631 /* initialize the table for 'breakat'. */
5632 fill_breakat_flags();
5633#endif
5634
5635}
5636
5637/*
5638 * More side effects of setting options.
5639 */
5640 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005641didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005642{
5643 /* Initialize the highlight_attr[] table. */
5644 (void)highlight_changed();
5645
5646 /* Parse default for 'wildmode' */
5647 check_opt_wim();
5648
5649 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005650 /* Parse default for 'fillchars'. */
5651 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005652
5653#ifdef FEAT_CLIPBOARD
5654 /* Parse default for 'clipboard' */
5655 (void)check_clipboard_option();
5656#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657}
5658
5659/*
5660 * Check for string options that are NULL (normally only termcap options).
5661 */
5662 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005663check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664{
5665 int opt_idx;
5666
5667 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5668 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5669 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5670}
5671
5672/*
5673 * Check string options in a buffer for NULL value.
5674 */
5675 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005676check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678 check_string_option(&buf->b_p_bh);
5679 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680#ifdef FEAT_MBYTE
5681 check_string_option(&buf->b_p_fenc);
5682#endif
5683 check_string_option(&buf->b_p_ff);
5684#ifdef FEAT_FIND_ID
5685 check_string_option(&buf->b_p_def);
5686 check_string_option(&buf->b_p_inc);
5687# ifdef FEAT_EVAL
5688 check_string_option(&buf->b_p_inex);
5689# endif
5690#endif
5691#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5692 check_string_option(&buf->b_p_inde);
5693 check_string_option(&buf->b_p_indk);
5694#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005695#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5696 check_string_option(&buf->b_p_bexpr);
5697#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005698#if defined(FEAT_CRYPT)
5699 check_string_option(&buf->b_p_cm);
5700#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005701 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005702#if defined(FEAT_EVAL)
5703 check_string_option(&buf->b_p_fex);
5704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705#ifdef FEAT_CRYPT
5706 check_string_option(&buf->b_p_key);
5707#endif
5708 check_string_option(&buf->b_p_kp);
5709 check_string_option(&buf->b_p_mps);
5710 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005711 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712 check_string_option(&buf->b_p_isk);
5713#ifdef FEAT_COMMENTS
5714 check_string_option(&buf->b_p_com);
5715#endif
5716#ifdef FEAT_FOLDING
5717 check_string_option(&buf->b_p_cms);
5718#endif
5719 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005720#ifdef FEAT_TEXTOBJ
5721 check_string_option(&buf->b_p_qe);
5722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005723#ifdef FEAT_SYN_HL
5724 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005725 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005726#endif
5727#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005728 check_string_option(&buf->b_s.b_p_spc);
5729 check_string_option(&buf->b_s.b_p_spf);
5730 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731#endif
5732#ifdef FEAT_SEARCHPATH
5733 check_string_option(&buf->b_p_sua);
5734#endif
5735#ifdef FEAT_CINDENT
5736 check_string_option(&buf->b_p_cink);
5737 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005738 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005741#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5742 check_string_option(&buf->b_p_cinw);
5743#endif
5744#ifdef FEAT_INS_EXPAND
5745 check_string_option(&buf->b_p_cpt);
5746#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005747#ifdef FEAT_COMPL_FUNC
5748 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005749 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751#ifdef FEAT_KEYMAP
5752 check_string_option(&buf->b_p_keymap);
5753#endif
5754#ifdef FEAT_QUICKFIX
5755 check_string_option(&buf->b_p_gp);
5756 check_string_option(&buf->b_p_mp);
5757 check_string_option(&buf->b_p_efm);
5758#endif
5759 check_string_option(&buf->b_p_ep);
5760 check_string_option(&buf->b_p_path);
5761 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005762 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005763#ifdef FEAT_INS_EXPAND
5764 check_string_option(&buf->b_p_dict);
5765 check_string_option(&buf->b_p_tsr);
5766#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005767#ifdef FEAT_LISP
5768 check_string_option(&buf->b_p_lw);
5769#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005770 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005771#ifdef FEAT_MBYTE
5772 check_string_option(&buf->b_p_menc);
5773#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005774}
5775
5776/*
5777 * Free the string allocated for an option.
5778 * Checks for the string being empty_option. This may happen if we're out of
5779 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5780 * check_options().
5781 * Does NOT check for P_ALLOCED flag!
5782 */
5783 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005784free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785{
5786 if (p != empty_option)
5787 vim_free(p);
5788}
5789
5790 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005791clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005792{
5793 if (*pp != empty_option)
5794 vim_free(*pp);
5795 *pp = empty_option;
5796}
5797
5798 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005799check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005800{
5801 if (*pp == NULL)
5802 *pp = empty_option;
5803}
5804
5805/*
5806 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5807 */
5808 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005809set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005810{
5811 int opt_idx;
5812
5813 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5814 if (options[opt_idx].var == (char_u *)p)
5815 {
5816 options[opt_idx].flags |= P_ALLOCED;
5817 return;
5818 }
5819 return; /* cannot happen: didn't find it! */
5820}
5821
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005822#if defined(FEAT_EVAL) || defined(PROTO)
5823/*
5824 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5825 * Return FALSE when it wasn't.
5826 * Return -1 for an unknown option.
5827 */
5828 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005829was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005830{
5831 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005832 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005833
5834 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005835 {
5836 flagp = insecure_flag(idx, opt_flags);
5837 return (*flagp & P_INSECURE) != 0;
5838 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005839 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005840 return -1;
5841}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005842
5843/*
5844 * Get a pointer to the flags used for the P_INSECURE flag of option
5845 * "opt_idx". For some local options a local flags field is used.
5846 */
5847 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005848insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005849{
5850 if (opt_flags & OPT_LOCAL)
5851 switch ((int)options[opt_idx].indir)
5852 {
5853#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005854 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005855#endif
5856#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005857# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005858 case PV_FDE: return &curwin->w_p_fde_flags;
5859 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005860# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005861# ifdef FEAT_BEVAL
5862 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5863# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005864# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005865 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005866# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005867 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005868# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005869 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005870# endif
5871#endif
5872 }
5873
5874 /* Nothing special, return global flags field. */
5875 return &options[opt_idx].flags;
5876}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005877#endif
5878
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005879#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005880static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005881
5882/*
5883 * Redraw the window title and/or tab page text later.
5884 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005885static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005886{
5887 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005888 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005889}
5890#endif
5891
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892/*
5893 * Set a string option to a new value (without checking the effect).
5894 * The string is copied into allocated memory.
5895 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005896 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005897 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 */
5899 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005900set_string_option_direct(
5901 char_u *name,
5902 int opt_idx,
5903 char_u *val,
5904 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5905 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906{
5907 char_u *s;
5908 char_u **varp;
5909 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005910 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911
Bram Moolenaar89d40322006-08-29 15:30:07 +00005912 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005914 idx = findoption(name);
5915 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005916 {
5917 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005918 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921 }
5922
Bram Moolenaar89d40322006-08-29 15:30:07 +00005923 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924 return;
5925
5926 s = vim_strsave(val);
5927 if (s != NULL)
5928 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005929 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005931 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932 free_string_option(*varp);
5933 *varp = s;
5934
5935 /* For buffer/window local option may also set the global value. */
5936 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005937 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938
Bram Moolenaar89d40322006-08-29 15:30:07 +00005939 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940
5941 /* When setting both values of a global option with a local value,
5942 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005943 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944 {
5945 free_string_option(*varp);
5946 *varp = empty_option;
5947 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005948# ifdef FEAT_EVAL
5949 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005950 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005951 set_sid == 0 ? current_SID : set_sid);
5952# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953 }
5954}
5955
5956/*
5957 * Set global value for string option when it's a local option.
5958 */
5959 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005960set_string_option_global(
5961 int opt_idx, /* option index */
5962 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963{
5964 char_u **p, *s;
5965
5966 /* the global value is always allocated */
5967 if (options[opt_idx].var == VAR_WIN)
5968 p = (char_u **)GLOBAL_WO(varp);
5969 else
5970 p = (char_u **)options[opt_idx].var;
5971 if (options[opt_idx].indir != PV_NONE
5972 && p != varp
5973 && (s = vim_strsave(*varp)) != NULL)
5974 {
5975 free_string_option(*p);
5976 *p = s;
5977 }
5978}
5979
5980/*
5981 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005982 *
5983 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005985 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005986set_string_option(
5987 int opt_idx,
5988 char_u *value,
5989 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990{
5991 char_u *s;
5992 char_u **varp;
5993 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005994#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005995 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005996 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005997#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005998 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999
6000 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006001 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002
6003 s = vim_strsave(value);
6004 if (s != NULL)
6005 {
6006 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6007 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006008 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009 ? OPT_GLOBAL : OPT_LOCAL)
6010 : opt_flags);
6011 oldval = *varp;
6012 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006013
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006014#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006015 if (!starting
6016# ifdef FEAT_CRYPT
6017 && options[opt_idx].indir != PV_KEY
6018# endif
6019 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006020 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006021 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006022 saved_newval = vim_strsave(s);
6023 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006024#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006025 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6026 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006027 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006028
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006029#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006030 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006031 if (r == NULL)
6032 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006033 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006034 vim_free(saved_oldval);
6035 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006036#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006038 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006039}
6040
6041/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006042 * Return TRUE if "val" is a valid 'filetype' name.
6043 * Also used for 'syntax' and 'keymap'.
6044 */
6045 static int
6046valid_filetype(char_u *val)
6047{
6048 char_u *s;
6049
6050 for (s = val; *s != NUL; ++s)
6051 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6052 return FALSE;
6053 return TRUE;
6054}
6055
6056/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006057 * Handle string options that need some action to perform when changed.
6058 * Returns NULL for success, or an error message for an error.
6059 */
6060 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006061did_set_string_option(
6062 int opt_idx, /* index in options[] table */
6063 char_u **varp, /* pointer to the option variable */
6064 int new_value_alloced, /* new value was allocated */
6065 char_u *oldval, /* previous value of the option */
6066 char_u *errbuf, /* buffer for errors, or NULL */
6067 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006068{
6069 char_u *errmsg = NULL;
6070 char_u *s, *p;
6071 int did_chartab = FALSE;
6072 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006073 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006074#ifdef FEAT_GUI
6075 /* set when changing an option that only requires a redraw in the GUI */
6076 int redraw_gui_only = FALSE;
6077#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006078 int ft_changed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079
6080 /* Get the global option to compare with, otherwise we would have to check
6081 * two values for all local options. */
6082 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6083
6084 /* Disallow changing some options from secure mode */
6085 if ((secure
6086#ifdef HAVE_SANDBOX
6087 || sandbox != 0
6088#endif
6089 ) && (options[opt_idx].flags & P_SECURE))
6090 {
6091 errmsg = e_secure;
6092 }
6093
Bram Moolenaar7554da42016-11-25 22:04:13 +01006094 /* Check for a "normal" directory or file name in some options. Disallow a
6095 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006096 * are often illegal in a file name. Be more permissive if "secure" is off.
6097 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006098 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006099 && vim_strpbrk(*varp, (char_u *)(secure
6100 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006101 || ((options[opt_idx].flags & P_NDNAME)
6102 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006103 {
6104 errmsg = e_invarg;
6105 }
6106
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107 /* 'term' */
6108 else if (varp == &T_NAME)
6109 {
6110 if (T_NAME[0] == NUL)
6111 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6112#ifdef FEAT_GUI
6113 if (gui.in_use)
6114 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6115 else if (term_is_gui(T_NAME))
6116 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6117#endif
6118 else if (set_termname(T_NAME) == FAIL)
6119 errmsg = (char_u *)N_("E522: Not found in termcap");
6120 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006121 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006122 /* Screen colors may have changed. */
6123 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006124
6125 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6126 * P_ALLOCED flag on 'term'. */
6127 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006128 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006129 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130 }
6131
6132 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006133 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006135 char_u *bkc = p_bkc;
6136 unsigned int *flags = &bkc_flags;
6137
6138 if (opt_flags & OPT_LOCAL)
6139 {
6140 bkc = curbuf->b_p_bkc;
6141 flags = &curbuf->b_bkc_flags;
6142 }
6143
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006144 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6145 /* make the local value empty: use the global value */
6146 *flags = 0;
6147 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006149 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6150 errmsg = e_invarg;
6151 if ((((int)*flags & BKC_AUTO) != 0)
6152 + (((int)*flags & BKC_YES) != 0)
6153 + (((int)*flags & BKC_NO) != 0) != 1)
6154 {
6155 /* Must have exactly one of "auto", "yes" and "no". */
6156 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6157 errmsg = e_invarg;
6158 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159 }
6160 }
6161
6162 /* 'backupext' and 'patchmode' */
6163 else if (varp == &p_bex || varp == &p_pm)
6164 {
6165 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6166 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6167 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6168 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006169#ifdef FEAT_LINEBREAK
6170 /* 'breakindentopt' */
6171 else if (varp == &curwin->w_p_briopt)
6172 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006173 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006174 errmsg = e_invarg;
6175 }
6176#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006177
6178 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006179 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006180 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006181 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006182 */
6183 else if ( varp == &p_isi
6184 || varp == &(curbuf->b_p_isk)
6185 || varp == &p_isp
6186 || varp == &p_isf)
6187 {
6188 if (init_chartab() == FAIL)
6189 {
6190 did_chartab = TRUE; /* need to restore it below */
6191 errmsg = e_invarg; /* error in value */
6192 }
6193 }
6194
6195 /* 'helpfile' */
6196 else if (varp == &p_hf)
6197 {
6198 /* May compute new values for $VIM and $VIMRUNTIME */
6199 if (didset_vim)
6200 {
6201 vim_setenv((char_u *)"VIM", (char_u *)"");
6202 didset_vim = FALSE;
6203 }
6204 if (didset_vimruntime)
6205 {
6206 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6207 didset_vimruntime = FALSE;
6208 }
6209 }
6210
Bram Moolenaar1a384422010-07-14 19:53:30 +02006211#ifdef FEAT_SYN_HL
6212 /* 'colorcolumn' */
6213 else if (varp == &curwin->w_p_cc)
6214 errmsg = check_colorcolumn(curwin);
6215#endif
6216
Bram Moolenaar071d4272004-06-13 20:20:40 +00006217#ifdef FEAT_MULTI_LANG
6218 /* 'helplang' */
6219 else if (varp == &p_hlg)
6220 {
6221 /* Check for "", "ab", "ab,cd", etc. */
6222 for (s = p_hlg; *s != NUL; s += 3)
6223 {
6224 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6225 {
6226 errmsg = e_invarg;
6227 break;
6228 }
6229 if (s[2] == NUL)
6230 break;
6231 }
6232 }
6233#endif
6234
6235 /* 'highlight' */
6236 else if (varp == &p_hl)
6237 {
6238 if (highlight_changed() == FAIL)
6239 errmsg = e_invarg; /* invalid flags */
6240 }
6241
6242 /* 'nrformats' */
6243 else if (gvarp == &p_nf)
6244 {
6245 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6246 errmsg = e_invarg;
6247 }
6248
6249#ifdef FEAT_SESSION
6250 /* 'sessionoptions' */
6251 else if (varp == &p_ssop)
6252 {
6253 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6254 errmsg = e_invarg;
6255 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6256 {
6257 /* Don't allow both "sesdir" and "curdir". */
6258 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6259 errmsg = e_invarg;
6260 }
6261 }
6262 /* 'viewoptions' */
6263 else if (varp == &p_vop)
6264 {
6265 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6266 errmsg = e_invarg;
6267 }
6268#endif
6269
6270 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006271 else if (varp == &p_sbo)
6272 {
6273 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6274 errmsg = e_invarg;
6275 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276
6277 /* 'ambiwidth' */
6278#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006279 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006280 {
6281 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6282 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006283 else if (set_chars_option(&p_lcs) != NULL)
6284 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006285 else if (set_chars_option(&p_fcs) != NULL)
6286 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006287 }
6288#endif
6289
6290 /* 'background' */
6291 else if (varp == &p_bg)
6292 {
6293 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6294 {
6295#ifdef FEAT_EVAL
6296 int dark = (*p_bg == 'd');
6297#endif
6298
6299 init_highlight(FALSE, FALSE);
6300
6301#ifdef FEAT_EVAL
6302 if (dark != (*p_bg == 'd')
6303 && get_var_value((char_u *)"g:colors_name") != NULL)
6304 {
6305 /* The color scheme must have set 'background' back to another
6306 * value, that's not what we want here. Disable the color
6307 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006308 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006309 free_string_option(p_bg);
6310 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6311 check_string_option(&p_bg);
6312 init_highlight(FALSE, FALSE);
6313 }
6314#endif
6315 }
6316 else
6317 errmsg = e_invarg;
6318 }
6319
6320 /* 'wildmode' */
6321 else if (varp == &p_wim)
6322 {
6323 if (check_opt_wim() == FAIL)
6324 errmsg = e_invarg;
6325 }
6326
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006327#ifdef FEAT_CMDL_COMPL
6328 /* 'wildoptions' */
6329 else if (varp == &p_wop)
6330 {
6331 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6332 errmsg = e_invarg;
6333 }
6334#endif
6335
Bram Moolenaar071d4272004-06-13 20:20:40 +00006336#ifdef FEAT_WAK
6337 /* 'winaltkeys' */
6338 else if (varp == &p_wak)
6339 {
6340 if (*p_wak == NUL
6341 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6342 errmsg = e_invarg;
6343# ifdef FEAT_MENU
6344# ifdef FEAT_GUI_MOTIF
6345 else if (gui.in_use)
6346 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6347# else
6348# ifdef FEAT_GUI_GTK
6349 else if (gui.in_use)
6350 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6351# endif
6352# endif
6353# endif
6354 }
6355#endif
6356
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357 /* 'eventignore' */
6358 else if (varp == &p_ei)
6359 {
6360 if (check_ei() == FAIL)
6361 errmsg = e_invarg;
6362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363
6364#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006365 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6366 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6367 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006368 {
6369 if (gvarp == &p_fenc)
6370 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006371 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 errmsg = e_modifiable;
6373 else if (vim_strchr(*varp, ',') != NULL)
6374 /* No comma allowed in 'fileencoding'; catches confusing it
6375 * with 'fileencodings'. */
6376 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006378 {
6379# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006381 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006383 /* Add 'fileencoding' to the swap file. */
6384 ml_setflags(curbuf);
6385 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 }
6387 if (errmsg == NULL)
6388 {
6389 /* canonize the value, so that STRCMP() can be used on it */
6390 p = enc_canonize(*varp);
6391 if (p != NULL)
6392 {
6393 vim_free(*varp);
6394 *varp = p;
6395 }
6396 if (varp == &p_enc)
6397 {
6398 errmsg = mb_init();
6399# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006400 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401# endif
6402 }
6403 }
6404
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006405# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006406 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6407 {
6408 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6409 if (STRCMP(p_tenc, "utf-8") != 0)
6410 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6411 }
6412# endif
6413
6414 if (errmsg == NULL)
6415 {
6416# ifdef FEAT_KEYMAP
6417 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6418 * (with another encoding). */
6419 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6420 (void)keymap_init();
6421# endif
6422
6423 /* When 'termencoding' is not empty and 'encoding' changes or when
6424 * 'termencoding' changes, need to setup for keyboard input and
6425 * display output conversion. */
6426 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6427 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006428 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6429 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6430 {
6431 EMSG3(_("E950: Cannot convert between %s and %s"),
6432 p_tenc, p_enc);
6433 errmsg = e_invarg;
6434 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006435 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006436
6437# if defined(WIN3264) && defined(FEAT_MBYTE)
6438 /* $HOME may have characters in active code page. */
6439 if (varp == &p_enc)
6440 init_homedir();
6441# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006442 }
6443 }
6444#endif
6445
6446#if defined(FEAT_POSTSCRIPT)
6447 else if (varp == &p_penc)
6448 {
6449 /* Canonize printencoding if VIM standard one */
6450 p = enc_canonize(p_penc);
6451 if (p != NULL)
6452 {
6453 vim_free(p_penc);
6454 p_penc = p;
6455 }
6456 else
6457 {
6458 /* Ensure lower case and '-' for '_' */
6459 for (s = p_penc; *s != NUL; s++)
6460 {
6461 if (*s == '_')
6462 *s = '-';
6463 else
6464 *s = TOLOWER_ASC(*s);
6465 }
6466 }
6467 }
6468#endif
6469
Bram Moolenaar9372a112005-12-06 19:59:18 +00006470#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006471 else if (varp == &p_imak)
6472 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006473 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006474 errmsg = e_invarg;
6475 }
6476#endif
6477
6478#ifdef FEAT_KEYMAP
6479 else if (varp == &curbuf->b_p_keymap)
6480 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006481 if (!valid_filetype(*varp))
6482 errmsg = e_invarg;
6483 else
6484 /* load or unload key mapping tables */
6485 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006486
Bram Moolenaarfab06232009-03-04 03:13:35 +00006487 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006488 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006489 if (*curbuf->b_p_keymap != NUL)
6490 {
6491 /* Installed a new keymap, switch on using it. */
6492 curbuf->b_p_iminsert = B_IMODE_LMAP;
6493 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6494 curbuf->b_p_imsearch = B_IMODE_LMAP;
6495 }
6496 else
6497 {
6498 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6499 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6500 curbuf->b_p_iminsert = B_IMODE_NONE;
6501 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6502 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6503 }
6504 if ((opt_flags & OPT_LOCAL) == 0)
6505 {
6506 set_iminsert_global();
6507 set_imsearch_global();
6508 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006509 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006510 }
6511 }
6512#endif
6513
6514 /* 'fileformat' */
6515 else if (gvarp == &p_ff)
6516 {
6517 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6518 errmsg = e_modifiable;
6519 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6520 errmsg = e_invarg;
6521 else
6522 {
6523 /* may also change 'textmode' */
6524 if (get_fileformat(curbuf) == EOL_DOS)
6525 curbuf->b_p_tx = TRUE;
6526 else
6527 curbuf->b_p_tx = FALSE;
6528#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006529 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006531 /* update flag in swap file */
6532 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006533 /* Redraw needed when switching to/from "mac": a CR in the text
6534 * will be displayed differently. */
6535 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6536 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006537 }
6538 }
6539
6540 /* 'fileformats' */
6541 else if (varp == &p_ffs)
6542 {
6543 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6544 errmsg = e_invarg;
6545 else
6546 {
6547 /* also change 'textauto' */
6548 if (*p_ffs == NUL)
6549 p_ta = FALSE;
6550 else
6551 p_ta = TRUE;
6552 }
6553 }
6554
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006555#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556 /* 'cryptkey' */
6557 else if (gvarp == &p_key)
6558 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006559# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006560 /* Make sure the ":set" command doesn't show the new value in the
6561 * history. */
6562 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006563# endif
6564 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6565 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006566 ml_set_crypt_key(curbuf, oldval,
6567 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006568 }
6569
6570 else if (gvarp == &p_cm)
6571 {
6572 if (opt_flags & OPT_LOCAL)
6573 p = curbuf->b_p_cm;
6574 else
6575 p = p_cm;
6576 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6577 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006578 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006579 errmsg = e_invarg;
6580 else
6581 {
6582 /* When setting the global value to empty, make it "zip". */
6583 if (*p_cm == NUL)
6584 {
6585 if (new_value_alloced)
6586 free_string_option(p_cm);
6587 p_cm = vim_strsave((char_u *)"zip");
6588 new_value_alloced = TRUE;
6589 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006590 /* When using ":set cm=name" the local value is going to be empty.
6591 * Do that here, otherwise the crypt functions will still use the
6592 * local value. */
6593 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6594 {
6595 free_string_option(curbuf->b_p_cm);
6596 curbuf->b_p_cm = empty_option;
6597 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006598
6599 /* Need to update the swapfile when the effective method changed.
6600 * Set "s" to the effective old value, "p" to the effective new
6601 * method and compare. */
6602 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6603 s = p_cm; /* was previously using the global value */
6604 else
6605 s = oldval;
6606 if (*curbuf->b_p_cm == NUL)
6607 p = p_cm; /* is now using the global value */
6608 else
6609 p = curbuf->b_p_cm;
6610 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006611 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006612
6613 /* If the global value changes need to update the swapfile for all
6614 * buffers using that value. */
6615 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6616 {
6617 buf_T *buf;
6618
Bram Moolenaar29323592016-07-24 22:04:11 +02006619 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006620 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006621 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006622 }
6623 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 }
6625#endif
6626
6627 /* 'matchpairs' */
6628 else if (gvarp == &p_mps)
6629 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006630#ifdef FEAT_MBYTE
6631 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006632 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006633 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006635 int x2 = -1;
6636 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006637
6638 if (*p != NUL)
6639 p += mb_ptr2len(p);
6640 if (*p != NUL)
6641 x2 = *p++;
6642 if (*p != NUL)
6643 {
6644 x3 = mb_ptr2char(p);
6645 p += mb_ptr2len(p);
6646 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006647 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006648 {
6649 errmsg = e_invarg;
6650 break;
6651 }
6652 if (*p == NUL)
6653 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006655 }
6656 else
6657#endif
6658 {
6659 /* Check for "x:y,x:y" */
6660 for (p = *varp; *p != NUL; p += 4)
6661 {
6662 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6663 {
6664 errmsg = e_invarg;
6665 break;
6666 }
6667 if (p[3] == NUL)
6668 break;
6669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670 }
6671 }
6672
6673#ifdef FEAT_COMMENTS
6674 /* 'comments' */
6675 else if (gvarp == &p_com)
6676 {
6677 for (s = *varp; *s; )
6678 {
6679 while (*s && *s != ':')
6680 {
6681 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6682 && !VIM_ISDIGIT(*s) && *s != '-')
6683 {
6684 errmsg = illegal_char(errbuf, *s);
6685 break;
6686 }
6687 ++s;
6688 }
6689 if (*s++ == NUL)
6690 errmsg = (char_u *)N_("E524: Missing colon");
6691 else if (*s == ',' || *s == NUL)
6692 errmsg = (char_u *)N_("E525: Zero length string");
6693 if (errmsg != NULL)
6694 break;
6695 while (*s && *s != ',')
6696 {
6697 if (*s == '\\' && s[1] != NUL)
6698 ++s;
6699 ++s;
6700 }
6701 s = skip_to_option_part(s);
6702 }
6703 }
6704#endif
6705
6706 /* 'listchars' */
6707 else if (varp == &p_lcs)
6708 {
6709 errmsg = set_chars_option(varp);
6710 }
6711
Bram Moolenaar071d4272004-06-13 20:20:40 +00006712 /* 'fillchars' */
6713 else if (varp == &p_fcs)
6714 {
6715 errmsg = set_chars_option(varp);
6716 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006717
6718#ifdef FEAT_CMDWIN
6719 /* 'cedit' */
6720 else if (varp == &p_cedit)
6721 {
6722 errmsg = check_cedit();
6723 }
6724#endif
6725
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006726 /* 'verbosefile' */
6727 else if (varp == &p_vfile)
6728 {
6729 verbose_stop();
6730 if (*p_vfile != NUL && verbose_open() == FAIL)
6731 errmsg = e_invarg;
6732 }
6733
Bram Moolenaar071d4272004-06-13 20:20:40 +00006734#ifdef FEAT_VIMINFO
6735 /* 'viminfo' */
6736 else if (varp == &p_viminfo)
6737 {
6738 for (s = p_viminfo; *s;)
6739 {
6740 /* Check it's a valid character */
6741 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6742 {
6743 errmsg = illegal_char(errbuf, *s);
6744 break;
6745 }
6746 if (*s == 'n') /* name is always last one */
6747 {
6748 break;
6749 }
6750 else if (*s == 'r') /* skip until next ',' */
6751 {
6752 while (*++s && *s != ',')
6753 ;
6754 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006755 else if (*s == '%')
6756 {
6757 /* optional number */
6758 while (vim_isdigit(*++s))
6759 ;
6760 }
6761 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762 ++s; /* no extra chars */
6763 else /* must have a number */
6764 {
6765 while (vim_isdigit(*++s))
6766 ;
6767
6768 if (!VIM_ISDIGIT(*(s - 1)))
6769 {
6770 if (errbuf != NULL)
6771 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006772 sprintf((char *)errbuf,
6773 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006774 transchar_byte(*(s - 1)));
6775 errmsg = errbuf;
6776 }
6777 else
6778 errmsg = (char_u *)"";
6779 break;
6780 }
6781 }
6782 if (*s == ',')
6783 ++s;
6784 else if (*s)
6785 {
6786 if (errbuf != NULL)
6787 errmsg = (char_u *)N_("E527: Missing comma");
6788 else
6789 errmsg = (char_u *)"";
6790 break;
6791 }
6792 }
6793 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6794 errmsg = (char_u *)N_("E528: Must specify a ' value");
6795 }
6796#endif /* FEAT_VIMINFO */
6797
6798 /* terminal options */
6799 else if (istermoption(&options[opt_idx]) && full_screen)
6800 {
6801 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6802 if (varp == &T_CCO)
6803 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006804 int colors = atoi((char *)T_CCO);
6805
6806 /* Only reinitialize colors if t_Co value has really changed to
6807 * avoid expensive reload of colorscheme if t_Co is set to the
6808 * same value multiple times. */
6809 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006810 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006811 t_colors = colors;
6812 if (t_colors <= 1)
6813 {
6814 if (new_value_alloced)
6815 vim_free(T_CCO);
6816 T_CCO = empty_option;
6817 }
6818 /* We now have a different color setup, initialize it again. */
6819 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 }
6822 ttest(FALSE);
6823 if (varp == &T_ME)
6824 {
6825 out_str(T_ME);
6826 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006827#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 /* Since t_me has been set, this probably means that the user
6829 * wants to use this as default colors. Need to reset default
6830 * background/foreground colors. */
6831 mch_set_normal_colors();
6832#endif
6833 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006834 if (varp == &T_BE && termcap_active)
6835 {
6836 if (*T_BE == NUL)
6837 /* When clearing t_BE we assume the user no longer wants
6838 * bracketed paste, thus disable it by writing t_BD. */
6839 out_str(T_BD);
6840 else
6841 out_str(T_BE);
6842 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006843 }
6844
6845#ifdef FEAT_LINEBREAK
6846 /* 'showbreak' */
6847 else if (varp == &p_sbr)
6848 {
6849 for (s = p_sbr; *s; )
6850 {
6851 if (ptr2cells(s) != 1)
6852 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006853 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006854 }
6855 }
6856#endif
6857
6858#ifdef FEAT_GUI
6859 /* 'guifont' */
6860 else if (varp == &p_guifont)
6861 {
6862 if (gui.in_use)
6863 {
6864 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006865# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006866 /*
6867 * Put up a font dialog and let the user select a new value.
6868 * If this is cancelled go back to the old value but don't
6869 * give an error message.
6870 */
6871 if (STRCMP(p, "*") == 0)
6872 {
6873 p = gui_mch_font_dialog(oldval);
6874
6875 if (new_value_alloced)
6876 free_string_option(p_guifont);
6877
6878 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6879 new_value_alloced = TRUE;
6880 }
6881# endif
6882 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6883 {
6884# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6885 if (STRCMP(p_guifont, "*") == 0)
6886 {
6887 /* Dialog was cancelled: Keep the old value without giving
6888 * an error message. */
6889 if (new_value_alloced)
6890 free_string_option(p_guifont);
6891 p_guifont = vim_strsave(oldval);
6892 new_value_alloced = TRUE;
6893 }
6894 else
6895# endif
6896 errmsg = (char_u *)N_("E596: Invalid font(s)");
6897 }
6898 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006899 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006900 }
6901# ifdef FEAT_XFONTSET
6902 else if (varp == &p_guifontset)
6903 {
6904 if (STRCMP(p_guifontset, "*") == 0)
6905 errmsg = (char_u *)N_("E597: can't select fontset");
6906 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6907 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006908 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909 }
6910# endif
6911# ifdef FEAT_MBYTE
6912 else if (varp == &p_guifontwide)
6913 {
6914 if (STRCMP(p_guifontwide, "*") == 0)
6915 errmsg = (char_u *)N_("E533: can't select wide font");
6916 else if (gui_get_wide_font() == FAIL)
6917 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006918 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006919 }
6920# endif
6921#endif
6922
6923#ifdef CURSOR_SHAPE
6924 /* 'guicursor' */
6925 else if (varp == &p_guicursor)
6926 errmsg = parse_shape_opt(SHAPE_CURSOR);
6927#endif
6928
6929#ifdef FEAT_MOUSESHAPE
6930 /* 'mouseshape' */
6931 else if (varp == &p_mouseshape)
6932 {
6933 errmsg = parse_shape_opt(SHAPE_MOUSE);
6934 update_mouseshape(-1);
6935 }
6936#endif
6937
6938#ifdef FEAT_PRINTER
6939 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006940 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006941# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006942 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006943 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006944# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006945#endif
6946
6947#ifdef FEAT_LANGMAP
6948 /* 'langmap' */
6949 else if (varp == &p_langmap)
6950 langmap_set();
6951#endif
6952
6953#ifdef FEAT_LINEBREAK
6954 /* 'breakat' */
6955 else if (varp == &p_breakat)
6956 fill_breakat_flags();
6957#endif
6958
6959#ifdef FEAT_TITLE
6960 /* 'titlestring' and 'iconstring' */
6961 else if (varp == &p_titlestring || varp == &p_iconstring)
6962 {
6963# ifdef FEAT_STL_OPT
6964 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6965
6966 /* NULL => statusline syntax */
6967 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6968 stl_syntax |= flagval;
6969 else
6970 stl_syntax &= ~flagval;
6971# endif
6972 did_set_title(varp == &p_iconstring);
6973
6974 }
6975#endif
6976
6977#ifdef FEAT_GUI
6978 /* 'guioptions' */
6979 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006980 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006981 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006982 redraw_gui_only = TRUE;
6983 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006984#endif
6985
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006986#if defined(FEAT_GUI_TABLINE)
6987 /* 'guitablabel' */
6988 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006989 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006990 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006991 redraw_gui_only = TRUE;
6992 }
6993 /* 'guitabtooltip' */
6994 else if (varp == &p_gtt)
6995 {
6996 redraw_gui_only = TRUE;
6997 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006998#endif
6999
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7001 /* 'ttymouse' */
7002 else if (varp == &p_ttym)
7003 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007004 /* Switch the mouse off before changing the escape sequences used for
7005 * that. */
7006 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7008 errmsg = e_invarg;
7009 else
7010 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007011 if (termcap_active)
7012 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013 }
7014#endif
7015
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016 /* 'selection' */
7017 else if (varp == &p_sel)
7018 {
7019 if (*p_sel == NUL
7020 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7021 errmsg = e_invarg;
7022 }
7023
7024 /* 'selectmode' */
7025 else if (varp == &p_slm)
7026 {
7027 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7028 errmsg = e_invarg;
7029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030
7031#ifdef FEAT_BROWSE
7032 /* 'browsedir' */
7033 else if (varp == &p_bsdir)
7034 {
7035 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7036 && !mch_isdir(p_bsdir))
7037 errmsg = e_invarg;
7038 }
7039#endif
7040
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 /* 'keymodel' */
7042 else if (varp == &p_km)
7043 {
7044 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7045 errmsg = e_invarg;
7046 else
7047 {
7048 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7049 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7050 }
7051 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052
7053 /* 'mousemodel' */
7054 else if (varp == &p_mousem)
7055 {
7056 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7057 errmsg = e_invarg;
7058#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7059 else if (*p_mousem != *oldval)
7060 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7061 * to create or delete the popup menus. */
7062 gui_motif_update_mousemodel(root_menu);
7063#endif
7064 }
7065
7066 /* 'switchbuf' */
7067 else if (varp == &p_swb)
7068 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007069 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 errmsg = e_invarg;
7071 }
7072
7073 /* 'debug' */
7074 else if (varp == &p_debug)
7075 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007076 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 errmsg = e_invarg;
7078 }
7079
7080 /* 'display' */
7081 else if (varp == &p_dy)
7082 {
7083 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7084 errmsg = e_invarg;
7085 else
7086 (void)init_chartab();
7087
7088 }
7089
Bram Moolenaar071d4272004-06-13 20:20:40 +00007090 /* 'eadirection' */
7091 else if (varp == &p_ead)
7092 {
7093 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7094 errmsg = e_invarg;
7095 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096
7097#ifdef FEAT_CLIPBOARD
7098 /* 'clipboard' */
7099 else if (varp == &p_cb)
7100 errmsg = check_clipboard_option();
7101#endif
7102
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007103#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007104 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7105 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007106 else if (varp == &(curwin->w_s->b_p_spl)
7107 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007108 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007109 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007110 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007111 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007112 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007113 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007114 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007115 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007116 /* 'spellsuggest' */
7117 else if (varp == &p_sps)
7118 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007119 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007120 errmsg = e_invarg;
7121 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007122 /* 'mkspellmem' */
7123 else if (varp == &p_msm)
7124 {
7125 if (spell_check_msm() != OK)
7126 errmsg = e_invarg;
7127 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007128#endif
7129
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130 /* When 'bufhidden' is set, check for valid value. */
7131 else if (gvarp == &p_bh)
7132 {
7133 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7134 errmsg = e_invarg;
7135 }
7136
7137 /* When 'buftype' is set, check for valid value. */
7138 else if (gvarp == &p_bt)
7139 {
7140 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7141 errmsg = e_invarg;
7142 else
7143 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144 if (curwin->w_status_height)
7145 {
7146 curwin->w_redr_status = TRUE;
7147 redraw_later(VALID);
7148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007149 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007150#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007151 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153 }
7154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007155
7156#ifdef FEAT_STL_OPT
7157 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007158 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007159 {
7160 int wid;
7161
7162 if (varp == &p_ruf) /* reset ru_wid first */
7163 ru_wid = 0;
7164 s = *varp;
7165 if (varp == &p_ruf && *s == '%')
7166 {
7167 /* set ru_wid if 'ruf' starts with "%99(" */
7168 if (*++s == '-') /* ignore a '-' */
7169 s++;
7170 wid = getdigits(&s);
7171 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7172 ru_wid = wid;
7173 else
7174 errmsg = check_stl_option(p_ruf);
7175 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007176 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007177 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007178 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007179 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180 comp_col();
7181 }
7182#endif
7183
7184#ifdef FEAT_INS_EXPAND
7185 /* check if it is a valid value for 'complete' -- Acevedo */
7186 else if (gvarp == &p_cpt)
7187 {
7188 for (s = *varp; *s;)
7189 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007190 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191 s++;
7192 if (!*s)
7193 break;
7194 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7195 {
7196 errmsg = illegal_char(errbuf, *s);
7197 break;
7198 }
7199 if (*++s != NUL && *s != ',' && *s != ' ')
7200 {
7201 if (s[-1] == 'k' || s[-1] == 's')
7202 {
7203 /* skip optional filename after 'k' and 's' */
7204 while (*s && *s != ',' && *s != ' ')
7205 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007206 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007207 ++s;
7208 ++s;
7209 }
7210 }
7211 else
7212 {
7213 if (errbuf != NULL)
7214 {
7215 sprintf((char *)errbuf,
7216 _("E535: Illegal character after <%c>"),
7217 *--s);
7218 errmsg = errbuf;
7219 }
7220 else
7221 errmsg = (char_u *)"";
7222 break;
7223 }
7224 }
7225 }
7226 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007227
7228 /* 'completeopt' */
7229 else if (varp == &p_cot)
7230 {
7231 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7232 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007233 else
7234 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007236#endif /* FEAT_INS_EXPAND */
7237
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007238#ifdef FEAT_SIGNS
7239 /* 'signcolumn' */
7240 else if (varp == &curwin->w_p_scl)
7241 {
7242 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7243 errmsg = e_invarg;
7244 }
7245#endif
7246
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247
7248#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007249 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007250 else if (varp == &p_toolbar)
7251 {
7252 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7253 &toolbar_flags, TRUE) != OK)
7254 errmsg = e_invarg;
7255 else
7256 {
7257 out_flush();
7258 gui_mch_show_toolbar((toolbar_flags &
7259 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7260 }
7261 }
7262#endif
7263
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007264#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265 /* 'toolbariconsize': GTK+ 2 only */
7266 else if (varp == &p_tbis)
7267 {
7268 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7269 errmsg = e_invarg;
7270 else
7271 {
7272 out_flush();
7273 gui_mch_show_toolbar((toolbar_flags &
7274 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7275 }
7276 }
7277#endif
7278
7279 /* 'pastetoggle': translate key codes like in a mapping */
7280 else if (varp == &p_pt)
7281 {
7282 if (*p_pt)
7283 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007284 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285 if (p != NULL)
7286 {
7287 if (new_value_alloced)
7288 free_string_option(p_pt);
7289 p_pt = p;
7290 new_value_alloced = TRUE;
7291 }
7292 }
7293 }
7294
7295 /* 'backspace' */
7296 else if (varp == &p_bs)
7297 {
7298 if (VIM_ISDIGIT(*p_bs))
7299 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007300 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301 errmsg = e_invarg;
7302 }
7303 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7304 errmsg = e_invarg;
7305 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007306 else if (varp == &p_bo)
7307 {
7308 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7309 errmsg = e_invarg;
7310 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007312 /* 'tagcase' */
7313 else if (gvarp == &p_tc)
7314 {
7315 unsigned int *flags;
7316
7317 if (opt_flags & OPT_LOCAL)
7318 {
7319 p = curbuf->b_p_tc;
7320 flags = &curbuf->b_tc_flags;
7321 }
7322 else
7323 {
7324 p = p_tc;
7325 flags = &tc_flags;
7326 }
7327
7328 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7329 /* make the local value empty: use the global value */
7330 *flags = 0;
7331 else if (*p == NUL
7332 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7333 errmsg = e_invarg;
7334 }
7335
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007336#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007337 /* 'casemap' */
7338 else if (varp == &p_cmp)
7339 {
7340 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7341 errmsg = e_invarg;
7342 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344
7345#ifdef FEAT_DIFF
7346 /* 'diffopt' */
7347 else if (varp == &p_dip)
7348 {
7349 if (diffopt_changed() == FAIL)
7350 errmsg = e_invarg;
7351 }
7352#endif
7353
7354#ifdef FEAT_FOLDING
7355 /* 'foldmethod' */
7356 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7357 {
7358 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7359 || *curwin->w_p_fdm == NUL)
7360 errmsg = e_invarg;
7361 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007362 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007363 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007364 if (foldmethodIsDiff(curwin))
7365 newFoldLevel();
7366 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007367 }
7368# ifdef FEAT_EVAL
7369 /* 'foldexpr' */
7370 else if (varp == &curwin->w_p_fde)
7371 {
7372 if (foldmethodIsExpr(curwin))
7373 foldUpdateAll(curwin);
7374 }
7375# endif
7376 /* 'foldmarker' */
7377 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7378 {
7379 p = vim_strchr(*varp, ',');
7380 if (p == NULL)
7381 errmsg = (char_u *)N_("E536: comma required");
7382 else if (p == *varp || p[1] == NUL)
7383 errmsg = e_invarg;
7384 else if (foldmethodIsMarker(curwin))
7385 foldUpdateAll(curwin);
7386 }
7387 /* 'commentstring' */
7388 else if (gvarp == &p_cms)
7389 {
7390 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7391 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7392 }
7393 /* 'foldopen' */
7394 else if (varp == &p_fdo)
7395 {
7396 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7397 errmsg = e_invarg;
7398 }
7399 /* 'foldclose' */
7400 else if (varp == &p_fcl)
7401 {
7402 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7403 errmsg = e_invarg;
7404 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007405 /* 'foldignore' */
7406 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7407 {
7408 if (foldmethodIsIndent(curwin))
7409 foldUpdateAll(curwin);
7410 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007411#endif
7412
7413#ifdef FEAT_VIRTUALEDIT
7414 /* 'virtualedit' */
7415 else if (varp == &p_ve)
7416 {
7417 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7418 errmsg = e_invarg;
7419 else if (STRCMP(p_ve, oldval) != 0)
7420 {
7421 /* Recompute cursor position in case the new 've' setting
7422 * changes something. */
7423 validate_virtcol();
7424 coladvance(curwin->w_virtcol);
7425 }
7426 }
7427#endif
7428
7429#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7430 else if (varp == &p_csqf)
7431 {
7432 if (p_csqf != NULL)
7433 {
7434 p = p_csqf;
7435 while (*p != NUL)
7436 {
7437 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7438 || p[1] == NUL
7439 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7440 || (p[2] != NUL && p[2] != ','))
7441 {
7442 errmsg = e_invarg;
7443 break;
7444 }
7445 else if (p[2] == NUL)
7446 break;
7447 else
7448 p += 3;
7449 }
7450 }
7451 }
7452#endif
7453
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007454#ifdef FEAT_CINDENT
7455 /* 'cinoptions' */
7456 else if (gvarp == &p_cino)
7457 {
7458 /* TODO: recognize errors */
7459 parse_cino(curbuf);
7460 }
7461#endif
7462
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007463#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007464 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007465 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007466 {
7467 if (!gui_mch_set_rendering_options(p_rop))
7468 errmsg = e_invarg;
7469 }
7470#endif
7471
Bram Moolenaard0b51382016-11-04 15:23:45 +01007472 else if (gvarp == &p_ft)
7473 {
7474 if (!valid_filetype(*varp))
7475 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007476 else
7477 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007478 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007479
7480#ifdef FEAT_SYN_HL
7481 else if (gvarp == &p_syn)
7482 {
7483 if (!valid_filetype(*varp))
7484 errmsg = e_invarg;
7485 }
7486#endif
7487
Bram Moolenaar825680f2017-07-22 17:04:02 +02007488#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007489 /* 'termwinkey' */
7490 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007491 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007492 if (*curwin->w_p_twk != NUL
7493 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007494 errmsg = e_invarg;
7495 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007496 /* 'termwinsize' */
7497 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007498 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007499 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007500 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007501 p = skipdigits(curwin->w_p_tws);
7502 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007503 || (*p != 'x' && *p != '*')
7504 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007505 errmsg = e_invarg;
7506 }
7507 }
7508#endif
7509
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510 /* Options that are a list of flags. */
7511 else
7512 {
7513 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007514 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007515 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007516 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007517 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007518 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007520 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007522#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007523 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007524 p = (char_u *)COCU_ALL;
7525#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007526 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 {
7528#ifdef FEAT_MOUSE
7529 p = (char_u *)MOUSE_ALL;
7530#else
7531 if (*p_mouse != NUL)
7532 errmsg = (char_u *)N_("E538: No mouse support");
7533#endif
7534 }
7535#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007536 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007537 p = (char_u *)GO_ALL;
7538#endif
7539 if (p != NULL)
7540 {
7541 for (s = *varp; *s; ++s)
7542 if (vim_strchr(p, *s) == NULL)
7543 {
7544 errmsg = illegal_char(errbuf, *s);
7545 break;
7546 }
7547 }
7548 }
7549
7550 /*
7551 * If error detected, restore the previous value.
7552 */
7553 if (errmsg != NULL)
7554 {
7555 if (new_value_alloced)
7556 free_string_option(*varp);
7557 *varp = oldval;
7558 /*
7559 * When resetting some values, need to act on it.
7560 */
7561 if (did_chartab)
7562 (void)init_chartab();
7563 if (varp == &p_hl)
7564 (void)highlight_changed();
7565 }
7566 else
7567 {
7568#ifdef FEAT_EVAL
7569 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007570 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571#endif
7572 /*
7573 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007574 * Use "free_oldval", because recursiveness may change the flags under
7575 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007576 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007577 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007578 free_string_option(oldval);
7579 if (new_value_alloced)
7580 options[opt_idx].flags |= P_ALLOCED;
7581 else
7582 options[opt_idx].flags &= ~P_ALLOCED;
7583
7584 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007585 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007586 {
7587 /* global option with local value set to use global value; free
7588 * the local value and make it empty */
7589 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7590 free_string_option(*(char_u **)p);
7591 *(char_u **)p = empty_option;
7592 }
7593
7594 /* May set global value for local option. */
7595 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7596 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007597
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007598 /*
7599 * Trigger the autocommand only after setting the flags.
7600 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007601#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007602 /* When 'syntax' is set, load the syntax of that name */
7603 if (varp == &(curbuf->b_p_syn))
7604 {
7605 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7606 curbuf->b_fname, TRUE, curbuf);
7607 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007608#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007609 else if (varp == &(curbuf->b_p_ft))
7610 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007611 /* 'filetype' is set, trigger the FileType autocommand.
7612 * Skip this when called from a modeline and the filetype was
7613 * already set to this value. */
7614 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7615 {
7616 did_filetype = TRUE;
7617 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007618 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007619 /* Just in case the old "curbuf" is now invalid. */
7620 if (varp != &(curbuf->b_p_ft))
7621 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007622 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007623 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007624#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007625 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007626 {
7627 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007628 char_u *q = curwin->w_s->b_p_spl;
7629
7630 /* Skip the first name if it is "cjk". */
7631 if (STRNCMP(q, "cjk,", 4) == 0)
7632 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007633
7634 /*
7635 * Source the spell/LANG.vim in 'runtimepath'.
7636 * They could set 'spellcapcheck' depending on the language.
7637 * Use the first name in 'spelllang' up to '_region' or
7638 * '.encoding'.
7639 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007640 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007641 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7642 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007643 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007644 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007645 }
7646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647 }
7648
7649#ifdef FEAT_MOUSE
7650 if (varp == &p_mouse)
7651 {
7652# ifdef FEAT_MOUSE_TTY
7653 if (*p_mouse == NUL)
7654 mch_setmouse(FALSE); /* switch mouse off */
7655 else
7656# endif
7657 setmouse(); /* in case 'mouse' changed */
7658 }
7659#endif
7660
Bram Moolenaar913077c2012-03-28 19:59:04 +02007661 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007662 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007663 curwin->w_set_curswant = TRUE;
7664
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007665#ifdef FEAT_GUI
7666 /* check redraw when it's not a GUI option or the GUI is active. */
7667 if (!redraw_gui_only || gui.in_use)
7668#endif
7669 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670
7671 return errmsg;
7672}
7673
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007674#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007675/*
7676 * Simple int comparison function for use with qsort()
7677 */
7678 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007679int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007680{
7681 return *(const int *)a - *(const int *)b;
7682}
7683
7684/*
7685 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7686 * Returns error message, NULL if it's OK.
7687 */
7688 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007689check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007690{
7691 char_u *s;
7692 int col;
7693 int count = 0;
7694 int color_cols[256];
7695 int i;
7696 int j = 0;
7697
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007698 if (wp->w_buffer == NULL)
7699 return NULL; /* buffer was closed */
7700
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007701 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007702 {
7703 if (*s == '-' || *s == '+')
7704 {
7705 /* -N and +N: add to 'textwidth' */
7706 col = (*s == '-') ? -1 : 1;
7707 ++s;
7708 if (!VIM_ISDIGIT(*s))
7709 return e_invarg;
7710 col = col * getdigits(&s);
7711 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007712 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007713 col += wp->w_buffer->b_p_tw;
7714 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007715 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007716 }
7717 else if (VIM_ISDIGIT(*s))
7718 col = getdigits(&s);
7719 else
7720 return e_invarg;
7721 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007722skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007723 if (*s == NUL)
7724 break;
7725 if (*s != ',')
7726 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007727 if (*++s == NUL)
7728 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007729 }
7730
7731 vim_free(wp->w_p_cc_cols);
7732 if (count == 0)
7733 wp->w_p_cc_cols = NULL;
7734 else
7735 {
7736 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7737 if (wp->w_p_cc_cols != NULL)
7738 {
7739 /* sort the columns for faster usage on screen redraw inside
7740 * win_line() */
7741 qsort(color_cols, count, sizeof(int), int_cmp);
7742
7743 for (i = 0; i < count; ++i)
7744 /* skip duplicates */
7745 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7746 wp->w_p_cc_cols[j++] = color_cols[i];
7747 wp->w_p_cc_cols[j] = -1; /* end marker */
7748 }
7749 }
7750
7751 return NULL; /* no error */
7752}
7753#endif
7754
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755/*
7756 * Handle setting 'listchars' or 'fillchars'.
7757 * Returns error message, NULL if it's OK.
7758 */
7759 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007760set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761{
7762 int round, i, len, entries;
7763 char_u *p, *s;
7764 int c1, c2 = 0;
7765 struct charstab
7766 {
7767 int *cp;
7768 char *name;
7769 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770 static struct charstab filltab[] =
7771 {
7772 {&fill_stl, "stl"},
7773 {&fill_stlnc, "stlnc"},
7774 {&fill_vert, "vert"},
7775 {&fill_fold, "fold"},
7776 {&fill_diff, "diff"},
7777 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 static struct charstab lcstab[] =
7779 {
7780 {&lcs_eol, "eol"},
7781 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007782 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007784 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785 {&lcs_tab2, "tab"},
7786 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007787#ifdef FEAT_CONCEAL
7788 {&lcs_conceal, "conceal"},
7789#else
7790 {NULL, "conceal"},
7791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792 };
7793 struct charstab *tab;
7794
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007796 {
7797 tab = lcstab;
7798 entries = sizeof(lcstab) / sizeof(struct charstab);
7799 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 else
7801 {
7802 tab = filltab;
7803 entries = sizeof(filltab) / sizeof(struct charstab);
7804 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007805
7806 /* first round: check for valid value, second round: assign values */
7807 for (round = 0; round <= 1; ++round)
7808 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007809 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810 {
7811 /* After checking that the value is valid: set defaults: space for
7812 * 'fillchars', NUL for 'listchars' */
7813 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007814 if (tab[i].cp != NULL)
7815 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816 if (varp == &p_lcs)
7817 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 else
7819 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820 }
7821 p = *varp;
7822 while (*p)
7823 {
7824 for (i = 0; i < entries; ++i)
7825 {
7826 len = (int)STRLEN(tab[i].name);
7827 if (STRNCMP(p, tab[i].name, len) == 0
7828 && p[len] == ':'
7829 && p[len + 1] != NUL)
7830 {
7831 s = p + len + 1;
7832#ifdef FEAT_MBYTE
7833 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007834 if (mb_char2cells(c1) > 1)
7835 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836#else
7837 c1 = *s++;
7838#endif
7839 if (tab[i].cp == &lcs_tab2)
7840 {
7841 if (*s == NUL)
7842 continue;
7843#ifdef FEAT_MBYTE
7844 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007845 if (mb_char2cells(c2) > 1)
7846 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007847#else
7848 c2 = *s++;
7849#endif
7850 }
7851 if (*s == ',' || *s == NUL)
7852 {
7853 if (round)
7854 {
7855 if (tab[i].cp == &lcs_tab2)
7856 {
7857 lcs_tab1 = c1;
7858 lcs_tab2 = c2;
7859 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007860 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861 *(tab[i].cp) = c1;
7862
7863 }
7864 p = s;
7865 break;
7866 }
7867 }
7868 }
7869
7870 if (i == entries)
7871 return e_invarg;
7872 if (*p == ',')
7873 ++p;
7874 }
7875 }
7876
7877 return NULL; /* no error */
7878}
7879
7880#ifdef FEAT_STL_OPT
7881/*
7882 * Check validity of options with the 'statusline' format.
7883 * Return error message or NULL.
7884 */
7885 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007886check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007887{
7888 int itemcnt = 0;
7889 int groupdepth = 0;
7890 static char_u errbuf[80];
7891
7892 while (*s && itemcnt < STL_MAX_ITEM)
7893 {
7894 /* Check for valid keys after % sequences */
7895 while (*s && *s != '%')
7896 s++;
7897 if (!*s)
7898 break;
7899 s++;
7900 if (*s != '%' && *s != ')')
7901 ++itemcnt;
7902 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7903 {
7904 s++;
7905 continue;
7906 }
7907 if (*s == ')')
7908 {
7909 s++;
7910 if (--groupdepth < 0)
7911 break;
7912 continue;
7913 }
7914 if (*s == '-')
7915 s++;
7916 while (VIM_ISDIGIT(*s))
7917 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007918 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 continue;
7920 if (*s == '.')
7921 {
7922 s++;
7923 while (*s && VIM_ISDIGIT(*s))
7924 s++;
7925 }
7926 if (*s == '(')
7927 {
7928 groupdepth++;
7929 continue;
7930 }
7931 if (vim_strchr(STL_ALL, *s) == NULL)
7932 {
7933 return illegal_char(errbuf, *s);
7934 }
7935 if (*s == '{')
7936 {
7937 s++;
7938 while (*s != '}' && *s)
7939 s++;
7940 if (*s != '}')
7941 return (char_u *)N_("E540: Unclosed expression sequence");
7942 }
7943 }
7944 if (itemcnt >= STL_MAX_ITEM)
7945 return (char_u *)N_("E541: too many items");
7946 if (groupdepth != 0)
7947 return (char_u *)N_("E542: unbalanced groups");
7948 return NULL;
7949}
7950#endif
7951
7952#ifdef FEAT_CLIPBOARD
7953/*
7954 * Extract the items in the 'clipboard' option and set global values.
7955 */
7956 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007957check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007959 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007960 int new_autoselect_star = FALSE;
7961 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007963 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 regprog_T *new_exclude_prog = NULL;
7965 char_u *errmsg = NULL;
7966 char_u *p;
7967
7968 for (p = p_cb; *p != NUL; )
7969 {
7970 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7971 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007972 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973 p += 7;
7974 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007975 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007976 && (p[11] == ',' || p[11] == NUL))
7977 {
7978 new_unnamed |= CLIP_UNNAMED_PLUS;
7979 p += 11;
7980 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007982 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007984 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 p += 10;
7986 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007987 else if (STRNCMP(p, "autoselectplus", 14) == 0
7988 && (p[14] == ',' || p[14] == NUL))
7989 {
7990 new_autoselect_plus = TRUE;
7991 p += 14;
7992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007994 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995 {
7996 new_autoselectml = TRUE;
7997 p += 12;
7998 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007999 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8000 {
8001 new_html = TRUE;
8002 p += 4;
8003 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8005 {
8006 p += 8;
8007 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8008 if (new_exclude_prog == NULL)
8009 errmsg = e_invarg;
8010 break;
8011 }
8012 else
8013 {
8014 errmsg = e_invarg;
8015 break;
8016 }
8017 if (*p == ',')
8018 ++p;
8019 }
8020 if (errmsg == NULL)
8021 {
8022 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008023 clip_autoselect_star = new_autoselect_star;
8024 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008026 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008027 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008028 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008029#ifdef FEAT_GUI_GTK
8030 if (gui.in_use)
8031 {
8032 gui_gtk_set_selection_targets();
8033 gui_gtk_set_dnd_targets();
8034 }
8035#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008036 }
8037 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008038 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008039
8040 return errmsg;
8041}
8042#endif
8043
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008044#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008045 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008046did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008047{
8048 char_u *errmsg = NULL;
8049 win_T *wp;
8050 int l;
8051
8052 if (is_spellfile)
8053 {
8054 l = (int)STRLEN(curwin->w_s->b_p_spf);
8055 if (l > 0 && (l < 4
8056 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8057 errmsg = e_invarg;
8058 }
8059
8060 if (errmsg == NULL)
8061 {
8062 FOR_ALL_WINDOWS(wp)
8063 if (wp->w_buffer == curbuf && wp->w_p_spell)
8064 {
8065 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008066 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008067 }
8068 }
8069 return errmsg;
8070}
8071
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008072/*
8073 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8074 * Return error message when failed, NULL when OK.
8075 */
8076 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008077compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008078{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008079 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008080 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008081
Bram Moolenaar860cae12010-06-05 23:22:07 +02008082 if (*synblock->b_p_spc == NUL)
8083 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008084 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008085 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008086 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008087 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008088 if (re != NULL)
8089 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008090 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008091 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008092 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008093 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008094 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008095 return e_invarg;
8096 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008097 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008098 }
8099
Bram Moolenaar473de612013-06-08 18:19:48 +02008100 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008101 return NULL;
8102}
8103#endif
8104
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008105#if defined(FEAT_EVAL) || defined(PROTO)
8106/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008107 * Set the scriptID for an option, taking care of setting the buffer- or
8108 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008109 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008110 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008111set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008112{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008113 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8114 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008115
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008116 /* Remember where the option was set. For local options need to do that
8117 * in the buffer or window structure. */
8118 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008119 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008120 if (both || (opt_flags & OPT_LOCAL))
8121 {
8122 if (indir & PV_BUF)
8123 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8124 else if (indir & PV_WIN)
8125 curwin->w_p_scriptID[indir & PV_MASK] = id;
8126 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008127}
8128#endif
8129
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130/*
8131 * Set the value of a boolean option, and take care of side effects.
8132 * Returns NULL for success, or an error message for an error.
8133 */
8134 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008135set_bool_option(
8136 int opt_idx, /* index in options[] table */
8137 char_u *varp, /* pointer to the option variable */
8138 int value, /* new value */
8139 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140{
8141 int old_value = *(int *)varp;
8142
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 /* Disallow changing some options from secure mode */
8144 if ((secure
8145#ifdef HAVE_SANDBOX
8146 || sandbox != 0
8147#endif
8148 ) && (options[opt_idx].flags & P_SECURE))
8149 return e_secure;
8150
8151 *(int *)varp = value; /* set the new value */
8152#ifdef FEAT_EVAL
8153 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008154 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155#endif
8156
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008157#ifdef FEAT_GUI
8158 need_mouse_correct = TRUE;
8159#endif
8160
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161 /* May set global value for local option. */
8162 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8163 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8164
8165 /*
8166 * Handle side effects of changing a bool option.
8167 */
8168
8169 /* 'compatible' */
8170 if ((int *)varp == &p_cp)
8171 {
8172 compatible_set();
8173 }
8174
Bram Moolenaar920694c2016-08-21 17:45:02 +02008175#ifdef FEAT_LANGMAP
8176 if ((int *)varp == &p_lrm)
8177 /* 'langremap' -> !'langnoremap' */
8178 p_lnr = !p_lrm;
8179 else if ((int *)varp == &p_lnr)
8180 /* 'langnoremap' -> !'langremap' */
8181 p_lrm = !p_lnr;
8182#endif
8183
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008184#ifdef FEAT_PERSISTENT_UNDO
8185 /* 'undofile' */
8186 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8187 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008188 /* Only take action when the option was set. When reset we do not
8189 * delete the undo file, the option may be set again without making
8190 * any changes in between. */
8191 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008192 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008193 char_u hash[UNDO_HASH_SIZE];
8194 buf_T *save_curbuf = curbuf;
8195
Bram Moolenaar29323592016-07-24 22:04:11 +02008196 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008197 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008198 /* When 'undofile' is set globally: for every buffer, otherwise
8199 * only for the current buffer: Try to read in the undofile,
8200 * if one exists, the buffer wasn't changed and the buffer was
8201 * loaded */
8202 if ((curbuf == save_curbuf
8203 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8204 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8205 {
8206 u_compute_hash(hash);
8207 u_read_undo(NULL, hash, curbuf->b_fname);
8208 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008209 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008210 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008211 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008212 }
8213#endif
8214
Bram Moolenaar071d4272004-06-13 20:20:40 +00008215 else if ((int *)varp == &curbuf->b_p_ro)
8216 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008217 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8219 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008220
8221 /* when 'readonly' is set may give W10 again */
8222 if (curbuf->b_p_ro)
8223 curbuf->b_did_warn = FALSE;
8224
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008226 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008227#endif
8228 }
8229
Bram Moolenaar9c449722010-07-20 18:44:27 +02008230#ifdef FEAT_GUI
8231 else if ((int *)varp == &p_mh)
8232 {
8233 if (!p_mh)
8234 gui_mch_mousehide(FALSE);
8235 }
8236#endif
8237
Bram Moolenaara539df02010-08-01 14:35:05 +02008238 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008240 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008241# ifdef FEAT_TERMINAL
8242 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008243 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8244 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008245 {
8246 curbuf->b_p_ma = FALSE;
8247 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8248 }
8249# endif
8250# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008251 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008252# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008253 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008254#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255 /* when 'endofline' is changed, redraw the window title */
8256 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008257 {
8258 redraw_titles();
8259 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008260 /* when 'fixeol' is changed, redraw the window title */
8261 else if ((int *)varp == &curbuf->b_p_fixeol)
8262 {
8263 redraw_titles();
8264 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008265# ifdef FEAT_MBYTE
8266 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008267 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008268 {
8269 redraw_titles();
8270 }
8271# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272#endif
8273
8274 /* when 'bin' is set also set some other options */
8275 else if ((int *)varp == &curbuf->b_p_bin)
8276 {
8277 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8278#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008279 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008280#endif
8281 }
8282
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283 /* when 'buflisted' changes, trigger autocommands */
8284 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8285 {
8286 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8287 NULL, NULL, TRUE, curbuf);
8288 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289
8290 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8291 else if ((int *)varp == &curbuf->b_p_swf)
8292 {
8293 if (curbuf->b_p_swf && p_uc)
8294 ml_open_file(curbuf); /* create the swap file */
8295 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008296 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8297 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008298 mf_close_file(curbuf, TRUE); /* remove the swap file */
8299 }
8300
8301 /* when 'terse' is set change 'shortmess' */
8302 else if ((int *)varp == &p_terse)
8303 {
8304 char_u *p;
8305
8306 p = vim_strchr(p_shm, SHM_SEARCH);
8307
8308 /* insert 's' in p_shm */
8309 if (p_terse && p == NULL)
8310 {
8311 STRCPY(IObuff, p_shm);
8312 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008313 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 }
8315 /* remove 's' from p_shm */
8316 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008317 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318 }
8319
8320 /* when 'paste' is set or reset also change other options */
8321 else if ((int *)varp == &p_paste)
8322 {
8323 paste_option_changed();
8324 }
8325
8326 /* when 'insertmode' is set from an autocommand need to do work here */
8327 else if ((int *)varp == &p_im)
8328 {
8329 if (p_im)
8330 {
8331 if ((State & INSERT) == 0)
8332 need_start_insertmode = TRUE;
8333 stop_insert_mode = FALSE;
8334 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008335 /* only reset if it was set previously */
8336 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337 {
8338 need_start_insertmode = FALSE;
8339 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008340 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008341 clear_cmdline = TRUE; /* remove "(insert)" */
8342 restart_edit = 0;
8343 }
8344 }
8345
8346 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8347 else if ((int *)varp == &p_ic && p_hls)
8348 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008349 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350 }
8351
8352#ifdef FEAT_SEARCH_EXTRA
8353 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8354 else if ((int *)varp == &p_hls)
8355 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008356 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008357 }
8358#endif
8359
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8361 * at the end of normal_cmd() */
8362 else if ((int *)varp == &curwin->w_p_scb)
8363 {
8364 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008365 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008366 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008367 curwin->w_scbind_pos = curwin->w_topline;
8368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370
Bram Moolenaar4033c552017-09-16 20:54:51 +02008371#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 /* There can be only one window with 'previewwindow' set. */
8373 else if ((int *)varp == &curwin->w_p_pvw)
8374 {
8375 if (curwin->w_p_pvw)
8376 {
8377 win_T *win;
8378
Bram Moolenaar29323592016-07-24 22:04:11 +02008379 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 if (win->w_p_pvw && win != curwin)
8381 {
8382 curwin->w_p_pvw = FALSE;
8383 return (char_u *)N_("E590: A preview window already exists");
8384 }
8385 }
8386 }
8387#endif
8388
8389 /* when 'textmode' is set or reset also change 'fileformat' */
8390 else if ((int *)varp == &curbuf->b_p_tx)
8391 {
8392 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8393 }
8394
8395 /* when 'textauto' is set or reset also change 'fileformats' */
8396 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397 set_string_option_direct((char_u *)"ffs", -1,
8398 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008399 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400
8401 /*
8402 * When 'lisp' option changes include/exclude '-' in
8403 * keyword characters.
8404 */
8405#ifdef FEAT_LISP
8406 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8407 {
8408 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8409 }
8410#endif
8411
8412#ifdef FEAT_TITLE
8413 /* when 'title' changed, may need to change the title; same for 'icon' */
8414 else if ((int *)varp == &p_title)
8415 {
8416 did_set_title(FALSE);
8417 }
8418
8419 else if ((int *)varp == &p_icon)
8420 {
8421 did_set_title(TRUE);
8422 }
8423#endif
8424
8425 else if ((int *)varp == &curbuf->b_changed)
8426 {
8427 if (!value)
8428 save_file_ff(curbuf); /* Buffer is unchanged */
8429#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008430 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008432 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433 }
8434
8435#ifdef BACKSLASH_IN_FILENAME
8436 else if ((int *)varp == &p_ssl)
8437 {
8438 if (p_ssl)
8439 {
8440 psepc = '/';
8441 psepcN = '\\';
8442 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443 }
8444 else
8445 {
8446 psepc = '\\';
8447 psepcN = '/';
8448 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449 }
8450
8451 /* need to adjust the file name arguments and buffer names. */
8452 buflist_slash_adjust();
8453 alist_slash_adjust();
8454# ifdef FEAT_EVAL
8455 scriptnames_slash_adjust();
8456# endif
8457 }
8458#endif
8459
8460 /* If 'wrap' is set, set w_leftcol to zero. */
8461 else if ((int *)varp == &curwin->w_p_wrap)
8462 {
8463 if (curwin->w_p_wrap)
8464 curwin->w_leftcol = 0;
8465 }
8466
Bram Moolenaar071d4272004-06-13 20:20:40 +00008467 else if ((int *)varp == &p_ea)
8468 {
8469 if (p_ea && !old_value)
8470 win_equal(curwin, FALSE, 0);
8471 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008472
8473 else if ((int *)varp == &p_wiv)
8474 {
8475 /*
8476 * When 'weirdinvert' changed, set/reset 't_xs'.
8477 * Then set 'weirdinvert' according to value of 't_xs'.
8478 */
8479 if (p_wiv && !old_value)
8480 T_XS = (char_u *)"y";
8481 else if (!p_wiv && old_value)
8482 T_XS = empty_option;
8483 p_wiv = (*T_XS != NUL);
8484 }
8485
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008486#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008487 else if ((int *)varp == &p_beval)
8488 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008489 if (!balloonEvalForTerm)
8490 {
8491 if (p_beval && !old_value)
8492 gui_mch_enable_beval_area(balloonEval);
8493 else if (!p_beval && old_value)
8494 gui_mch_disable_beval_area(balloonEval);
8495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008496 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008497#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008498#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008499 else if ((int *)varp == &p_bevalterm)
8500 {
8501 mch_bevalterm_changed();
8502 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008503#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008504
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008505#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506 else if ((int *)varp == &p_acd)
8507 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008508 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008509 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 }
8511#endif
8512
8513#ifdef FEAT_DIFF
8514 /* 'diff' */
8515 else if ((int *)varp == &curwin->w_p_diff)
8516 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008517 /* May add or remove the buffer from the list of diff buffers. */
8518 diff_buf_adjust(curwin);
8519# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 if (foldmethodIsDiff(curwin))
8521 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008522# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008523 }
8524#endif
8525
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008526#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527 /* 'imdisable' */
8528 else if ((int *)varp == &p_imdisable)
8529 {
8530 /* Only de-activate it here, it will be enabled when changing mode. */
8531 if (p_imdisable)
8532 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008533 else if (State & INSERT)
8534 /* When the option is set from an autocommand, it may need to take
8535 * effect right away. */
8536 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008537 }
8538#endif
8539
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008540#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008541 /* 'spell' */
8542 else if ((int *)varp == &curwin->w_p_spell)
8543 {
8544 if (curwin->w_p_spell)
8545 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008546 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008547 if (errmsg != NULL)
8548 EMSG(_(errmsg));
8549 }
8550 }
8551#endif
8552
Bram Moolenaar071d4272004-06-13 20:20:40 +00008553#ifdef FEAT_FKMAP
8554 else if ((int *)varp == &p_altkeymap)
8555 {
8556 if (old_value != p_altkeymap)
8557 {
8558 if (!p_altkeymap)
8559 {
8560 p_hkmap = p_fkmap;
8561 p_fkmap = 0;
8562 }
8563 else
8564 {
8565 p_fkmap = p_hkmap;
8566 p_hkmap = 0;
8567 }
8568 (void)init_chartab();
8569 }
8570 }
8571
8572 /*
8573 * In case some second language keymapping options have changed, check
8574 * and correct the setting in a consistent way.
8575 */
8576
8577 /*
8578 * If hkmap or fkmap are set, reset Arabic keymapping.
8579 */
8580 if ((p_hkmap || p_fkmap) && p_altkeymap)
8581 {
8582 p_altkeymap = p_fkmap;
8583# ifdef FEAT_ARABIC
8584 curwin->w_p_arab = FALSE;
8585# endif
8586 (void)init_chartab();
8587 }
8588
8589 /*
8590 * If hkmap set, reset Farsi keymapping.
8591 */
8592 if (p_hkmap && p_altkeymap)
8593 {
8594 p_altkeymap = 0;
8595 p_fkmap = 0;
8596# ifdef FEAT_ARABIC
8597 curwin->w_p_arab = FALSE;
8598# endif
8599 (void)init_chartab();
8600 }
8601
8602 /*
8603 * If fkmap set, reset Hebrew keymapping.
8604 */
8605 if (p_fkmap && !p_altkeymap)
8606 {
8607 p_altkeymap = 1;
8608 p_hkmap = 0;
8609# ifdef FEAT_ARABIC
8610 curwin->w_p_arab = FALSE;
8611# endif
8612 (void)init_chartab();
8613 }
8614#endif
8615
8616#ifdef FEAT_ARABIC
8617 if ((int *)varp == &curwin->w_p_arab)
8618 {
8619 if (curwin->w_p_arab)
8620 {
8621 /*
8622 * 'arabic' is set, handle various sub-settings.
8623 */
8624 if (!p_tbidi)
8625 {
8626 /* set rightleft mode */
8627 if (!curwin->w_p_rl)
8628 {
8629 curwin->w_p_rl = TRUE;
8630 changed_window_setting();
8631 }
8632
8633 /* Enable Arabic shaping (major part of what Arabic requires) */
8634 if (!p_arshape)
8635 {
8636 p_arshape = TRUE;
8637 redraw_later_clear();
8638 }
8639 }
8640
8641 /* Arabic requires a utf-8 encoding, inform the user if its not
8642 * set. */
8643 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008644 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008645 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8646
Bram Moolenaar8820b482017-03-16 17:23:31 +01008647 msg_source(HL_ATTR(HLF_W));
8648 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008649#ifdef FEAT_EVAL
8650 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8651#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653
8654# ifdef FEAT_MBYTE
8655 /* set 'delcombine' */
8656 p_deco = TRUE;
8657# endif
8658
8659# ifdef FEAT_KEYMAP
8660 /* Force-set the necessary keymap for arabic */
8661 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8662 OPT_LOCAL);
8663# endif
8664# ifdef FEAT_FKMAP
8665 p_altkeymap = 0;
8666 p_hkmap = 0;
8667 p_fkmap = 0;
8668 (void)init_chartab();
8669# endif
8670 }
8671 else
8672 {
8673 /*
8674 * 'arabic' is reset, handle various sub-settings.
8675 */
8676 if (!p_tbidi)
8677 {
8678 /* reset rightleft mode */
8679 if (curwin->w_p_rl)
8680 {
8681 curwin->w_p_rl = FALSE;
8682 changed_window_setting();
8683 }
8684
8685 /* 'arabicshape' isn't reset, it is a global option and
8686 * another window may still need it "on". */
8687 }
8688
8689 /* 'delcombine' isn't reset, it is a global option and another
8690 * window may still want it "on". */
8691
8692# ifdef FEAT_KEYMAP
8693 /* Revert to the default keymap */
8694 curbuf->b_p_iminsert = B_IMODE_NONE;
8695 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8696# endif
8697 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008698 }
8699
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008700#endif
8701
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008702#ifdef FEAT_TERMGUICOLORS
8703 /* 'termguicolors' */
8704 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008705 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008706# ifdef FEAT_VTP
8707 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8708 if (!has_vtp_working())
8709 {
8710 p_tgc = 0;
8711 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8712 }
8713 swap_tcap();
8714# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008715# ifdef FEAT_GUI
8716 if (!gui.in_use && !gui.starting)
8717# endif
8718 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008719# ifdef FEAT_VTP
8720 control_console_color_rgb();
8721 /* reset t_Co */
8722 if (STRCMP(T_NAME, "win32") == 0)
8723 set_termname(T_NAME);
8724# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008725 }
8726#endif
8727
Bram Moolenaar071d4272004-06-13 20:20:40 +00008728 /*
8729 * End of handling side effects for bool options.
8730 */
8731
Bram Moolenaar53744302015-07-17 17:38:22 +02008732 /* after handling side effects, call autocommand */
8733
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734 options[opt_idx].flags |= P_WAS_SET;
8735
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008736#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008737 if (!starting)
8738 {
8739 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008740 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8741 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8742 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008743 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8744 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8745 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8746 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8747 reset_v_option_vars();
8748 }
8749#endif
8750
Bram Moolenaar071d4272004-06-13 20:20:40 +00008751 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008752 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008753 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008754 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 check_redraw(options[opt_idx].flags);
8756
8757 return NULL;
8758}
8759
8760/*
8761 * Set the value of a number option, and take care of side effects.
8762 * Returns NULL for success, or an error message for an error.
8763 */
8764 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008765set_num_option(
8766 int opt_idx, /* index in options[] table */
8767 char_u *varp, /* pointer to the option variable */
8768 long value, /* new value */
8769 char_u *errbuf, /* buffer for error messages */
8770 size_t errbuflen, /* length of "errbuf" */
8771 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 OPT_MODELINE */
8773{
8774 char_u *errmsg = NULL;
8775 long old_value = *(long *)varp;
8776 long old_Rows = Rows; /* remember old Rows */
8777 long old_Columns = Columns; /* remember old Columns */
8778 long *pp = (long *)varp;
8779
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008780 /* Disallow changing some options from secure mode. */
8781 if ((secure
8782#ifdef HAVE_SANDBOX
8783 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008785 ) && (options[opt_idx].flags & P_SECURE))
8786 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787
8788 *pp = value;
8789#ifdef FEAT_EVAL
8790 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008791 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008792#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008793#ifdef FEAT_GUI
8794 need_mouse_correct = TRUE;
8795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796
Bram Moolenaar14f24742012-08-08 18:01:05 +02008797 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798 {
8799 errmsg = e_positive;
8800 curbuf->b_p_sw = curbuf->b_p_ts;
8801 }
8802
8803 /*
8804 * Number options that need some action when changed
8805 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806 if (pp == &p_wh || pp == &p_hh)
8807 {
8808 if (p_wh < 1)
8809 {
8810 errmsg = e_positive;
8811 p_wh = 1;
8812 }
8813 if (p_wmh > p_wh)
8814 {
8815 errmsg = e_winheight;
8816 p_wh = p_wmh;
8817 }
8818 if (p_hh < 0)
8819 {
8820 errmsg = e_positive;
8821 p_hh = 0;
8822 }
8823
8824 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008825 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008826 {
8827 if (pp == &p_wh && curwin->w_height < p_wh)
8828 win_setheight((int)p_wh);
8829 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8830 win_setheight((int)p_hh);
8831 }
8832 }
8833
8834 /* 'winminheight' */
8835 else if (pp == &p_wmh)
8836 {
8837 if (p_wmh < 0)
8838 {
8839 errmsg = e_positive;
8840 p_wmh = 0;
8841 }
8842 if (p_wmh > p_wh)
8843 {
8844 errmsg = e_winheight;
8845 p_wmh = p_wh;
8846 }
8847 win_setminheight();
8848 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008849 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008850 {
8851 if (p_wiw < 1)
8852 {
8853 errmsg = e_positive;
8854 p_wiw = 1;
8855 }
8856 if (p_wmw > p_wiw)
8857 {
8858 errmsg = e_winwidth;
8859 p_wiw = p_wmw;
8860 }
8861
8862 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008863 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864 win_setwidth((int)p_wiw);
8865 }
8866
8867 /* 'winminwidth' */
8868 else if (pp == &p_wmw)
8869 {
8870 if (p_wmw < 0)
8871 {
8872 errmsg = e_positive;
8873 p_wmw = 0;
8874 }
8875 if (p_wmw > p_wiw)
8876 {
8877 errmsg = e_winwidth;
8878 p_wmw = p_wiw;
8879 }
8880 win_setminheight();
8881 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008882
Bram Moolenaar071d4272004-06-13 20:20:40 +00008883 /* (re)set last window status line */
8884 else if (pp == &p_ls)
8885 {
8886 last_status(FALSE);
8887 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008888
8889 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008890 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008891 {
8892 shell_new_rows(); /* recompute window positions and heights */
8893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008894
8895#ifdef FEAT_GUI
8896 else if (pp == &p_linespace)
8897 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008898 /* Recompute gui.char_height and resize the Vim window to keep the
8899 * same number of lines. */
8900 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008901 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902 }
8903#endif
8904
8905#ifdef FEAT_FOLDING
8906 /* 'foldlevel' */
8907 else if (pp == &curwin->w_p_fdl)
8908 {
8909 if (curwin->w_p_fdl < 0)
8910 curwin->w_p_fdl = 0;
8911 newFoldLevel();
8912 }
8913
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008914 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008915 else if (pp == &curwin->w_p_fml)
8916 {
8917 foldUpdateAll(curwin);
8918 }
8919
8920 /* 'foldnestmax' */
8921 else if (pp == &curwin->w_p_fdn)
8922 {
8923 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8924 foldUpdateAll(curwin);
8925 }
8926
8927 /* 'foldcolumn' */
8928 else if (pp == &curwin->w_p_fdc)
8929 {
8930 if (curwin->w_p_fdc < 0)
8931 {
8932 errmsg = e_positive;
8933 curwin->w_p_fdc = 0;
8934 }
8935 else if (curwin->w_p_fdc > 12)
8936 {
8937 errmsg = e_invarg;
8938 curwin->w_p_fdc = 12;
8939 }
8940 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008941#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008943#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944 /* 'shiftwidth' or 'tabstop' */
8945 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8946 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008947# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008948 if (foldmethodIsIndent(curwin))
8949 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008950# endif
8951# ifdef FEAT_CINDENT
8952 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8953 * parse 'cinoptions'. */
8954 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8955 parse_cino(curbuf);
8956# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008957 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008958#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008959
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008960#ifdef FEAT_MBYTE
8961 /* 'maxcombine' */
8962 else if (pp == &p_mco)
8963 {
8964 if (p_mco > MAX_MCO)
8965 p_mco = MAX_MCO;
8966 else if (p_mco < 0)
8967 p_mco = 0;
8968 screenclear(); /* will re-allocate the screen */
8969 }
8970#endif
8971
Bram Moolenaar071d4272004-06-13 20:20:40 +00008972 else if (pp == &curbuf->b_p_iminsert)
8973 {
8974 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8975 {
8976 errmsg = e_invarg;
8977 curbuf->b_p_iminsert = B_IMODE_NONE;
8978 }
8979 p_iminsert = curbuf->b_p_iminsert;
8980 if (termcap_active) /* don't do this in the alternate screen */
8981 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008982#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008983 /* Show/unshow value of 'keymap' in status lines. */
8984 status_redraw_curbuf();
8985#endif
8986 }
8987
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008988#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8989 /* 'imstyle' */
8990 else if (pp == &p_imst)
8991 {
8992 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8993 errmsg = e_invarg;
8994 }
8995#endif
8996
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008997 else if (pp == &p_window)
8998 {
8999 if (p_window < 1)
9000 p_window = 1;
9001 else if (p_window >= Rows)
9002 p_window = Rows - 1;
9003 }
9004
Bram Moolenaar071d4272004-06-13 20:20:40 +00009005 else if (pp == &curbuf->b_p_imsearch)
9006 {
9007 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9008 {
9009 errmsg = e_invarg;
9010 curbuf->b_p_imsearch = B_IMODE_NONE;
9011 }
9012 p_imsearch = curbuf->b_p_imsearch;
9013 }
9014
9015#ifdef FEAT_TITLE
9016 /* if 'titlelen' has changed, redraw the title */
9017 else if (pp == &p_titlelen)
9018 {
9019 if (p_titlelen < 0)
9020 {
9021 errmsg = e_positive;
9022 p_titlelen = 85;
9023 }
9024 if (starting != NO_SCREEN && old_value != p_titlelen)
9025 need_maketitle = TRUE;
9026 }
9027#endif
9028
9029 /* if p_ch changed value, change the command line height */
9030 else if (pp == &p_ch)
9031 {
9032 if (p_ch < 1)
9033 {
9034 errmsg = e_positive;
9035 p_ch = 1;
9036 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009037 if (p_ch > Rows - min_rows() + 1)
9038 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009039
9040 /* Only compute the new window layout when startup has been
9041 * completed. Otherwise the frame sizes may be wrong. */
9042 if (p_ch != old_value && full_screen
9043#ifdef FEAT_GUI
9044 && !gui.starting
9045#endif
9046 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009047 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009048 }
9049
9050 /* when 'updatecount' changes from zero to non-zero, open swap files */
9051 else if (pp == &p_uc)
9052 {
9053 if (p_uc < 0)
9054 {
9055 errmsg = e_positive;
9056 p_uc = 100;
9057 }
9058 if (p_uc && !old_value)
9059 ml_open_files();
9060 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009061#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009062 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009063 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009064 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009065 {
9066 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009067 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009068 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009069 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009070 {
9071 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009072 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009073 }
9074 }
9075#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009076#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009077 else if (pp == &p_mzq)
9078 mzvim_reset_timer();
9079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009081#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9082 /* 'pyxversion' */
9083 else if (pp == &p_pyx)
9084 {
9085 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9086 errmsg = e_invarg;
9087 }
9088#endif
9089
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090 /* sync undo before 'undolevels' changes */
9091 else if (pp == &p_ul)
9092 {
9093 /* use the old value, otherwise u_sync() may not work properly */
9094 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009095 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 p_ul = value;
9097 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009098 else if (pp == &curbuf->b_p_ul)
9099 {
9100 /* use the old value, otherwise u_sync() may not work properly */
9101 curbuf->b_p_ul = old_value;
9102 u_sync(TRUE);
9103 curbuf->b_p_ul = value;
9104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009106#ifdef FEAT_LINEBREAK
9107 /* 'numberwidth' must be positive */
9108 else if (pp == &curwin->w_p_nuw)
9109 {
9110 if (curwin->w_p_nuw < 1)
9111 {
9112 errmsg = e_positive;
9113 curwin->w_p_nuw = 1;
9114 }
9115 if (curwin->w_p_nuw > 10)
9116 {
9117 errmsg = e_invarg;
9118 curwin->w_p_nuw = 10;
9119 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009120 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009121 }
9122#endif
9123
Bram Moolenaar1a384422010-07-14 19:53:30 +02009124 else if (pp == &curbuf->b_p_tw)
9125 {
9126 if (curbuf->b_p_tw < 0)
9127 {
9128 errmsg = e_positive;
9129 curbuf->b_p_tw = 0;
9130 }
9131#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009132 {
9133 win_T *wp;
9134 tabpage_T *tp;
9135
9136 FOR_ALL_TAB_WINDOWS(tp, wp)
9137 check_colorcolumn(wp);
9138 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009139#endif
9140 }
9141
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 /*
9143 * Check the bounds for numeric options here
9144 */
9145 if (Rows < min_rows() && full_screen)
9146 {
9147 if (errbuf != NULL)
9148 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009149 vim_snprintf((char *)errbuf, errbuflen,
9150 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009151 errmsg = errbuf;
9152 }
9153 Rows = min_rows();
9154 }
9155 if (Columns < MIN_COLUMNS && full_screen)
9156 {
9157 if (errbuf != NULL)
9158 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009159 vim_snprintf((char *)errbuf, errbuflen,
9160 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009161 errmsg = errbuf;
9162 }
9163 Columns = MIN_COLUMNS;
9164 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009165 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009166
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 /*
9168 * If the screen (shell) height has been changed, assume it is the
9169 * physical screenheight.
9170 */
9171 if (old_Rows != Rows || old_Columns != Columns)
9172 {
9173 /* Changing the screen size is not allowed while updating the screen. */
9174 if (updating_screen)
9175 *pp = old_value;
9176 else if (full_screen
9177#ifdef FEAT_GUI
9178 && !gui.starting
9179#endif
9180 )
9181 set_shellsize((int)Columns, (int)Rows, TRUE);
9182 else
9183 {
9184 /* Postpone the resizing; check the size and cmdline position for
9185 * messages. */
9186 check_shellsize();
9187 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9188 cmdline_row = Rows - p_ch;
9189 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009190 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009191 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192 }
9193
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194 if (curbuf->b_p_ts <= 0)
9195 {
9196 errmsg = e_positive;
9197 curbuf->b_p_ts = 8;
9198 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009199 if (p_tm < 0)
9200 {
9201 errmsg = e_positive;
9202 p_tm = 0;
9203 }
9204 if ((curwin->w_p_scr <= 0
9205 || (curwin->w_p_scr > curwin->w_height
9206 && curwin->w_height > 0))
9207 && full_screen)
9208 {
9209 if (pp == &(curwin->w_p_scr))
9210 {
9211 if (curwin->w_p_scr != 0)
9212 errmsg = e_scroll;
9213 win_comp_scroll(curwin);
9214 }
9215 /* If 'scroll' became invalid because of a side effect silently adjust
9216 * it. */
9217 else if (curwin->w_p_scr <= 0)
9218 curwin->w_p_scr = 1;
9219 else /* curwin->w_p_scr > curwin->w_height */
9220 curwin->w_p_scr = curwin->w_height;
9221 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009222 if (p_hi < 0)
9223 {
9224 errmsg = e_positive;
9225 p_hi = 0;
9226 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009227 else if (p_hi > 10000)
9228 {
9229 errmsg = e_invarg;
9230 p_hi = 10000;
9231 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009232 if (p_re < 0 || p_re > 2)
9233 {
9234 errmsg = e_invarg;
9235 p_re = 0;
9236 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237 if (p_report < 0)
9238 {
9239 errmsg = e_positive;
9240 p_report = 1;
9241 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009242 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 {
9244 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9245 p_sj = Rows / 2;
9246 else
9247 {
9248 errmsg = e_scroll;
9249 p_sj = 1;
9250 }
9251 }
9252 if (p_so < 0 && full_screen)
9253 {
9254 errmsg = e_scroll;
9255 p_so = 0;
9256 }
9257 if (p_siso < 0 && full_screen)
9258 {
9259 errmsg = e_positive;
9260 p_siso = 0;
9261 }
9262#ifdef FEAT_CMDWIN
9263 if (p_cwh < 1)
9264 {
9265 errmsg = e_positive;
9266 p_cwh = 1;
9267 }
9268#endif
9269 if (p_ut < 0)
9270 {
9271 errmsg = e_positive;
9272 p_ut = 2000;
9273 }
9274 if (p_ss < 0)
9275 {
9276 errmsg = e_positive;
9277 p_ss = 0;
9278 }
9279
9280 /* May set global value for local option. */
9281 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9282 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9283
9284 options[opt_idx].flags |= P_WAS_SET;
9285
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009286#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009287 if (!starting && errmsg == NULL)
9288 {
9289 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009290 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9291 vim_snprintf((char *)buf_new, 10, "%ld", value);
9292 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009293 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9294 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9295 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9296 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9297 reset_v_option_vars();
9298 }
9299#endif
9300
Bram Moolenaar071d4272004-06-13 20:20:40 +00009301 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009302 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009303 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009304 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305 check_redraw(options[opt_idx].flags);
9306
9307 return errmsg;
9308}
9309
9310/*
9311 * Called after an option changed: check if something needs to be redrawn.
9312 */
9313 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009314check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009315{
9316 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009317 int doclear = (flags & P_RCLR) == P_RCLR;
9318 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009319
Bram Moolenaar071d4272004-06-13 20:20:40 +00009320 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9321 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009322
9323 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9324 changed_window_setting();
9325 if (flags & P_RBUF)
9326 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009327 if (flags & P_RWINONLY)
9328 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009329 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009330 redraw_all_later(CLEAR);
9331 else if (all)
9332 redraw_all_later(NOT_VALID);
9333}
9334
9335/*
9336 * Find index for option 'arg'.
9337 * Return -1 if not found.
9338 */
9339 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009340findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341{
9342 int opt_idx;
9343 char *s, *p;
9344 static short quick_tab[27] = {0, 0}; /* quick access table */
9345 int is_term_opt;
9346
9347 /*
9348 * For first call: Initialize the quick-access table.
9349 * It contains the index for the first option that starts with a certain
9350 * letter. There are 26 letters, plus the first "t_" option.
9351 */
9352 if (quick_tab[1] == 0)
9353 {
9354 p = options[0].fullname;
9355 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9356 {
9357 if (s[0] != p[0])
9358 {
9359 if (s[0] == 't' && s[1] == '_')
9360 quick_tab[26] = opt_idx;
9361 else
9362 quick_tab[CharOrdLow(s[0])] = opt_idx;
9363 }
9364 p = s;
9365 }
9366 }
9367
9368 /*
9369 * Check for name starting with an illegal character.
9370 */
9371#ifdef EBCDIC
9372 if (!islower(arg[0]))
9373#else
9374 if (arg[0] < 'a' || arg[0] > 'z')
9375#endif
9376 return -1;
9377
9378 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9379 if (is_term_opt)
9380 opt_idx = quick_tab[26];
9381 else
9382 opt_idx = quick_tab[CharOrdLow(arg[0])];
9383 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9384 {
9385 if (STRCMP(arg, s) == 0) /* match full name */
9386 break;
9387 }
9388 if (s == NULL && !is_term_opt)
9389 {
9390 opt_idx = quick_tab[CharOrdLow(arg[0])];
9391 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9392 {
9393 s = options[opt_idx].shortname;
9394 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9395 break;
9396 s = NULL;
9397 }
9398 }
9399 if (s == NULL)
9400 opt_idx = -1;
9401 return opt_idx;
9402}
9403
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009404#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009405/*
9406 * Get the value for an option.
9407 *
9408 * Returns:
9409 * Number or Toggle option: 1, *numval gets value.
9410 * String option: 0, *stringval gets allocated string.
9411 * Hidden Number or Toggle option: -1.
9412 * hidden String option: -2.
9413 * unknown option: -3.
9414 */
9415 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009416get_option_value(
9417 char_u *name,
9418 long *numval,
9419 char_u **stringval, /* NULL when only checking existence */
9420 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009421{
9422 int opt_idx;
9423 char_u *varp;
9424
9425 opt_idx = findoption(name);
9426 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009427 {
9428 int key;
9429
9430 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9431 && (key = find_key_option(name)) != 0)
9432 {
9433 char_u key_name[2];
9434 char_u *p;
9435
9436 if (key < 0)
9437 {
9438 key_name[0] = KEY2TERMCAP0(key);
9439 key_name[1] = KEY2TERMCAP1(key);
9440 }
9441 else
9442 {
9443 key_name[0] = KS_KEY;
9444 key_name[1] = (key & 0xff);
9445 }
9446 p = find_termcode(key_name);
9447 if (p != NULL)
9448 {
9449 if (stringval != NULL)
9450 *stringval = vim_strsave(p);
9451 return 0;
9452 }
9453 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009455 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009456
9457 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9458
9459 if (options[opt_idx].flags & P_STRING)
9460 {
9461 if (varp == NULL) /* hidden option */
9462 return -2;
9463 if (stringval != NULL)
9464 {
9465#ifdef FEAT_CRYPT
9466 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009467 if ((char_u **)varp == &curbuf->b_p_key
9468 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009469 *stringval = vim_strsave((char_u *)"*****");
9470 else
9471#endif
9472 *stringval = vim_strsave(*(char_u **)(varp));
9473 }
9474 return 0;
9475 }
9476
9477 if (varp == NULL) /* hidden option */
9478 return -1;
9479 if (options[opt_idx].flags & P_NUM)
9480 *numval = *(long *)varp;
9481 else
9482 {
9483 /* Special case: 'modified' is b_changed, but we also want to consider
9484 * it set when 'ff' or 'fenc' changed. */
9485 if ((int *)varp == &curbuf->b_changed)
9486 *numval = curbufIsChanged();
9487 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009488 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489 }
9490 return 1;
9491}
9492#endif
9493
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009494#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009495/*
9496 * Returns the option attributes and its value. Unlike the above function it
9497 * will return either global value or local value of the option depending on
9498 * what was requested, but it will never return global value if it was
9499 * requested to return local one and vice versa. Neither it will return
9500 * buffer-local value if it was requested to return window-local one.
9501 *
9502 * Pretends that option is absent if it is not present in the requested scope
9503 * (i.e. has no global, window-local or buffer-local value depending on
9504 * opt_type). Uses
9505 *
9506 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009507 * 0 hidden or unknown option, also option that does not have requested
9508 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009509 * see SOPT_* in vim.h for other flags
9510 *
9511 * Possible opt_type values: see SREQ_* in vim.h
9512 */
9513 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009514get_option_value_strict(
9515 char_u *name,
9516 long *numval,
9517 char_u **stringval, /* NULL when only obtaining attributes */
9518 int opt_type,
9519 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009520{
9521 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009522 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009523 struct vimoption *p;
9524 int r = 0;
9525
9526 opt_idx = findoption(name);
9527 if (opt_idx < 0)
9528 return 0;
9529
9530 p = &(options[opt_idx]);
9531
9532 /* Hidden option */
9533 if (p->var == NULL)
9534 return 0;
9535
9536 if (p->flags & P_BOOL)
9537 r |= SOPT_BOOL;
9538 else if (p->flags & P_NUM)
9539 r |= SOPT_NUM;
9540 else if (p->flags & P_STRING)
9541 r |= SOPT_STRING;
9542
9543 if (p->indir == PV_NONE)
9544 {
9545 if (opt_type == SREQ_GLOBAL)
9546 r |= SOPT_GLOBAL;
9547 else
9548 return 0; /* Did not request global-only option */
9549 }
9550 else
9551 {
9552 if (p->indir & PV_BOTH)
9553 r |= SOPT_GLOBAL;
9554 else if (opt_type == SREQ_GLOBAL)
9555 return 0; /* Requested global option */
9556
9557 if (p->indir & PV_WIN)
9558 {
9559 if (opt_type == SREQ_BUF)
9560 return 0; /* Did not request window-local option */
9561 else
9562 r |= SOPT_WIN;
9563 }
9564 else if (p->indir & PV_BUF)
9565 {
9566 if (opt_type == SREQ_WIN)
9567 return 0; /* Did not request buffer-local option */
9568 else
9569 r |= SOPT_BUF;
9570 }
9571 }
9572
9573 if (stringval == NULL)
9574 return r;
9575
9576 if (opt_type == SREQ_GLOBAL)
9577 varp = p->var;
9578 else
9579 {
9580 if (opt_type == SREQ_BUF)
9581 {
9582 /* Special case: 'modified' is b_changed, but we also want to
9583 * consider it set when 'ff' or 'fenc' changed. */
9584 if (p->indir == PV_MOD)
9585 {
9586 *numval = bufIsChanged((buf_T *) from);
9587 varp = NULL;
9588 }
9589#ifdef FEAT_CRYPT
9590 else if (p->indir == PV_KEY)
9591 {
9592 /* never return the value of the crypt key */
9593 *stringval = NULL;
9594 varp = NULL;
9595 }
9596#endif
9597 else
9598 {
9599 aco_save_T aco;
9600 aucmd_prepbuf(&aco, (buf_T *) from);
9601 varp = get_varp(p);
9602 aucmd_restbuf(&aco);
9603 }
9604 }
9605 else if (opt_type == SREQ_WIN)
9606 {
9607 win_T *save_curwin;
9608 save_curwin = curwin;
9609 curwin = (win_T *) from;
9610 curbuf = curwin->w_buffer;
9611 varp = get_varp(p);
9612 curwin = save_curwin;
9613 curbuf = curwin->w_buffer;
9614 }
9615 if (varp == p->var)
9616 return (r | SOPT_UNSET);
9617 }
9618
9619 if (varp != NULL)
9620 {
9621 if (p->flags & P_STRING)
9622 *stringval = vim_strsave(*(char_u **)(varp));
9623 else if (p->flags & P_NUM)
9624 *numval = *(long *) varp;
9625 else
9626 *numval = *(int *)varp;
9627 }
9628
9629 return r;
9630}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009631
9632/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009633 * Iterate over options. First argument is a pointer to a pointer to a
9634 * structure inside options[] array, second is option type like in the above
9635 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009636 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009637 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009638 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009639 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009640 * first argument to NULL.
9641 *
9642 * Returns full option name for current option on each call.
9643 */
9644 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009645option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009646{
9647 struct vimoption *ret = NULL;
9648 do
9649 {
9650 if (*option == NULL)
9651 *option = (void *) options;
9652 else if (((struct vimoption *) (*option))->fullname == NULL)
9653 {
9654 *option = NULL;
9655 return NULL;
9656 }
9657 else
9658 *option = (void *) (((struct vimoption *) (*option)) + 1);
9659
9660 ret = ((struct vimoption *) (*option));
9661
9662 /* Hidden option */
9663 if (ret->var == NULL)
9664 {
9665 ret = NULL;
9666 continue;
9667 }
9668
9669 switch (opt_type)
9670 {
9671 case SREQ_GLOBAL:
9672 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9673 ret = NULL;
9674 break;
9675 case SREQ_BUF:
9676 if (!(ret->indir & PV_BUF))
9677 ret = NULL;
9678 break;
9679 case SREQ_WIN:
9680 if (!(ret->indir & PV_WIN))
9681 ret = NULL;
9682 break;
9683 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009684 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009685 return NULL;
9686 }
9687 }
9688 while (ret == NULL);
9689
9690 return (char_u *)ret->fullname;
9691}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009692#endif
9693
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694/*
9695 * Set the value of option "name".
9696 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009697 *
9698 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009699 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009700 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009701set_option_value(
9702 char_u *name,
9703 long number,
9704 char_u *string,
9705 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009706{
9707 int opt_idx;
9708 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009709 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009710
9711 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009712 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009713 {
9714 int key;
9715
9716 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9717 && (key = find_key_option(name)) != 0)
9718 {
9719 char_u key_name[2];
9720
9721 if (key < 0)
9722 {
9723 key_name[0] = KEY2TERMCAP0(key);
9724 key_name[1] = KEY2TERMCAP1(key);
9725 }
9726 else
9727 {
9728 key_name[0] = KS_KEY;
9729 key_name[1] = (key & 0xff);
9730 }
9731 add_termcode(key_name, string, FALSE);
9732 if (full_screen)
9733 ttest(FALSE);
9734 redraw_all_later(CLEAR);
9735 return NULL;
9736 }
9737
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009739 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 else
9741 {
9742 flags = options[opt_idx].flags;
9743#ifdef HAVE_SANDBOX
9744 /* Disallow changing some options in the sandbox */
9745 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009746 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009748 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009751 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009752 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009753 else
9754 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009755 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756 if (varp != NULL) /* hidden option is not changed */
9757 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009758 if (number == 0 && string != NULL)
9759 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009760 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009761
9762 /* Either we are given a string or we are setting option
9763 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009764 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009765 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009766 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009767 {
9768 /* There's another character after zeros or the string
9769 * is empty. In both cases, we are trying to set a
9770 * num option using a string. */
9771 EMSG3(_("E521: Number required: &%s = '%s'"),
9772 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009773 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009774
9775 }
9776 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009777 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009778 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009779 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009780 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009781 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009782 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783 }
9784 }
9785 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009786 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009787}
9788
9789/*
9790 * Get the terminal code for a terminal option.
9791 * Returns NULL when not found.
9792 */
9793 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009794get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795{
9796 int opt_idx;
9797 char_u *varp;
9798
9799 if (tname[0] != 't' || tname[1] != '_' ||
9800 tname[2] == NUL || tname[3] == NUL)
9801 return NULL;
9802 if ((opt_idx = findoption(tname)) >= 0)
9803 {
9804 varp = get_varp(&(options[opt_idx]));
9805 if (varp != NULL)
9806 varp = *(char_u **)(varp);
9807 return varp;
9808 }
9809 return find_termcode(tname + 2);
9810}
9811
9812 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009813get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009814{
9815 int i;
9816
9817 i = findoption((char_u *)"hl");
9818 if (i >= 0)
9819 return options[i].def_val[VI_DEFAULT];
9820 return (char_u *)NULL;
9821}
9822
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009823#if defined(FEAT_MBYTE) || defined(PROTO)
9824 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009825get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009826{
9827 int i;
9828
9829 i = findoption((char_u *)"enc");
9830 if (i >= 0)
9831 return options[i].def_val[VI_DEFAULT];
9832 return (char_u *)NULL;
9833}
9834#endif
9835
Bram Moolenaar071d4272004-06-13 20:20:40 +00009836/*
9837 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9838 */
9839 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009840find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009841{
9842 int key;
9843 int modifiers;
9844
9845 /*
9846 * Don't use get_special_key_code() for t_xx, we don't want it to call
9847 * add_termcap_entry().
9848 */
9849 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9850 key = TERMCAP2KEY(arg[2], arg[3]);
9851 else
9852 {
9853 --arg; /* put arg at the '<' */
9854 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009855 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856 if (modifiers) /* can't handle modifiers here */
9857 key = 0;
9858 }
9859 return key;
9860}
9861
9862/*
9863 * if 'all' == 0: show changed options
9864 * if 'all' == 1: show all normal options
9865 * if 'all' == 2: show all terminal options
9866 */
9867 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009868showoptions(
9869 int all,
9870 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009871{
9872 struct vimoption *p;
9873 int col;
9874 int isterm;
9875 char_u *varp;
9876 struct vimoption **items;
9877 int item_count;
9878 int run;
9879 int row, rows;
9880 int cols;
9881 int i;
9882 int len;
9883
9884#define INC 20
9885#define GAP 3
9886
9887 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9888 PARAM_COUNT));
9889 if (items == NULL)
9890 return;
9891
9892 /* Highlight title */
9893 if (all == 2)
9894 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9895 else if (opt_flags & OPT_GLOBAL)
9896 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9897 else if (opt_flags & OPT_LOCAL)
9898 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9899 else
9900 MSG_PUTS_TITLE(_("\n--- Options ---"));
9901
9902 /*
9903 * do the loop two times:
9904 * 1. display the short items
9905 * 2. display the long items (only strings and numbers)
9906 */
9907 for (run = 1; run <= 2 && !got_int; ++run)
9908 {
9909 /*
9910 * collect the items in items[]
9911 */
9912 item_count = 0;
9913 for (p = &options[0]; p->fullname != NULL; p++)
9914 {
9915 varp = NULL;
9916 isterm = istermoption(p);
9917 if (opt_flags != 0)
9918 {
9919 if (p->indir != PV_NONE && !isterm)
9920 varp = get_varp_scope(p, opt_flags);
9921 }
9922 else
9923 varp = get_varp(p);
9924 if (varp != NULL
9925 && ((all == 2 && isterm)
9926 || (all == 1 && !isterm)
9927 || (all == 0 && !optval_default(p, varp))))
9928 {
9929 if (p->flags & P_BOOL)
9930 len = 1; /* a toggle option fits always */
9931 else
9932 {
9933 option_value2string(p, opt_flags);
9934 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9935 }
9936 if ((len <= INC - GAP && run == 1) ||
9937 (len > INC - GAP && run == 2))
9938 items[item_count++] = p;
9939 }
9940 }
9941
9942 /*
9943 * display the items
9944 */
9945 if (run == 1)
9946 {
9947 cols = (Columns + GAP - 3) / INC;
9948 if (cols == 0)
9949 cols = 1;
9950 rows = (item_count + cols - 1) / cols;
9951 }
9952 else /* run == 2 */
9953 rows = item_count;
9954 for (row = 0; row < rows && !got_int; ++row)
9955 {
9956 msg_putchar('\n'); /* go to next line */
9957 if (got_int) /* 'q' typed in more */
9958 break;
9959 col = 0;
9960 for (i = row; i < item_count; i += rows)
9961 {
9962 msg_col = col; /* make columns */
9963 showoneopt(items[i], opt_flags);
9964 col += INC;
9965 }
9966 out_flush();
9967 ui_breakcheck();
9968 }
9969 }
9970 vim_free(items);
9971}
9972
9973/*
9974 * Return TRUE if option "p" has its default value.
9975 */
9976 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009977optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978{
9979 int dvi;
9980
9981 if (varp == NULL)
9982 return TRUE; /* hidden option is always at default */
9983 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9984 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009985 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009987 /* the cast to long is required for Manx C, long_i is
9988 * needed for MSVC */
9989 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009990 /* P_STRING */
9991 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9992}
9993
9994/*
9995 * showoneopt: show the value of one option
9996 * must not be called with a hidden option!
9997 */
9998 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009999showoneopt(
10000 struct vimoption *p,
10001 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010002{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010003 char_u *varp;
10004 int save_silent = silent_mode;
10005
10006 silent_mode = FALSE;
10007 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008
10009 varp = get_varp_scope(p, opt_flags);
10010
10011 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10012 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10013 ? !curbufIsChanged() : !*(int *)varp))
10014 MSG_PUTS("no");
10015 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10016 MSG_PUTS("--");
10017 else
10018 MSG_PUTS(" ");
10019 MSG_PUTS(p->fullname);
10020 if (!(p->flags & P_BOOL))
10021 {
10022 msg_putchar('=');
10023 /* put value string in NameBuff */
10024 option_value2string(p, opt_flags);
10025 msg_outtrans(NameBuff);
10026 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010027
10028 silent_mode = save_silent;
10029 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030}
10031
10032/*
10033 * Write modified options as ":set" commands to a file.
10034 *
10035 * There are three values for "opt_flags":
10036 * OPT_GLOBAL: Write global option values and fresh values of
10037 * buffer-local options (used for start of a session
10038 * file).
10039 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10040 * curwin (used for a vimrc file).
10041 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10042 * and local values for window-local options of
10043 * curwin. Local values are also written when at the
10044 * default value, because a modeline or autocommand
10045 * may have set them when doing ":edit file" and the
10046 * user has set them back at the default or fresh
10047 * value.
10048 * When "local_only" is TRUE, don't write fresh
10049 * values, only local values (for ":mkview").
10050 * (fresh value = value used for a new buffer or window for a local option).
10051 *
10052 * Return FAIL on error, OK otherwise.
10053 */
10054 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010055makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056{
10057 struct vimoption *p;
10058 char_u *varp; /* currently used value */
10059 char_u *varp_fresh; /* local value */
10060 char_u *varp_local = NULL; /* fresh value */
10061 char *cmd;
10062 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010063 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010064
10065 /*
10066 * The options that don't have a default (terminal name, columns, lines)
10067 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010068 * Do the loop over "options[]" twice: once for options with the
10069 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010071 for (pri = 1; pri >= 0; --pri)
10072 {
10073 for (p = &options[0]; !istermoption(p); p++)
10074 if (!(p->flags & P_NO_MKRC)
10075 && !istermoption(p)
10076 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010077 {
10078 /* skip global option when only doing locals */
10079 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10080 continue;
10081
10082 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10083 * file, they are always buffer-specific. */
10084 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10085 continue;
10086
10087 /* Global values are only written when not at the default value. */
10088 varp = get_varp_scope(p, opt_flags);
10089 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10090 continue;
10091
10092 round = 2;
10093 if (p->indir != PV_NONE)
10094 {
10095 if (p->var == VAR_WIN)
10096 {
10097 /* skip window-local option when only doing globals */
10098 if (!(opt_flags & OPT_LOCAL))
10099 continue;
10100 /* When fresh value of window-local option is not at the
10101 * default, need to write it too. */
10102 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10103 {
10104 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10105 if (!optval_default(p, varp_fresh))
10106 {
10107 round = 1;
10108 varp_local = varp;
10109 varp = varp_fresh;
10110 }
10111 }
10112 }
10113 }
10114
10115 /* Round 1: fresh value for window-local options.
10116 * Round 2: other values */
10117 for ( ; round <= 2; varp = varp_local, ++round)
10118 {
10119 if (round == 1 || (opt_flags & OPT_GLOBAL))
10120 cmd = "set";
10121 else
10122 cmd = "setlocal";
10123
10124 if (p->flags & P_BOOL)
10125 {
10126 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10127 return FAIL;
10128 }
10129 else if (p->flags & P_NUM)
10130 {
10131 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10132 return FAIL;
10133 }
10134 else /* P_STRING */
10135 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010136 int do_endif = FALSE;
10137
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138 /* Don't set 'syntax' and 'filetype' again if the value is
10139 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010140 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010141#if defined(FEAT_SYN_HL)
10142 p->indir == PV_SYN ||
10143#endif
10144 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145 {
10146 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10147 *(char_u **)(varp)) < 0
10148 || put_eol(fd) < 0)
10149 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010150 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151 }
10152 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10153 (p->flags & P_EXPAND) != 0) == FAIL)
10154 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010155 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010156 {
10157 if (put_line(fd, "endif") == FAIL)
10158 return FAIL;
10159 }
10160 }
10161 }
10162 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010163 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164 return OK;
10165}
10166
10167#if defined(FEAT_FOLDING) || defined(PROTO)
10168/*
10169 * Generate set commands for the local fold options only. Used when
10170 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10171 */
10172 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010173makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174{
10175 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10176# ifdef FEAT_EVAL
10177 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10178 == FAIL
10179# endif
10180 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10181 == FAIL
10182 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10183 == FAIL
10184 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10185 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10186 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10187 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10188 )
10189 return FAIL;
10190
10191 return OK;
10192}
10193#endif
10194
10195 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010196put_setstring(
10197 FILE *fd,
10198 char *cmd,
10199 char *name,
10200 char_u **valuep,
10201 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202{
10203 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010204 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205
10206 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10207 return FAIL;
10208 if (*valuep != NULL)
10209 {
10210 /* Output 'pastetoggle' as key names. For other
10211 * options some characters have to be escaped with
10212 * CTRL-V or backslash */
10213 if (valuep == &p_pt)
10214 {
10215 s = *valuep;
10216 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010217 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 return FAIL;
10219 }
10220 else if (expand)
10221 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010222 buf = alloc(MAXPATHL);
10223 if (buf == NULL)
10224 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10226 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010227 {
10228 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010230 }
10231 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232 }
10233 else if (put_escstr(fd, *valuep, 2) == FAIL)
10234 return FAIL;
10235 }
10236 if (put_eol(fd) < 0)
10237 return FAIL;
10238 return OK;
10239}
10240
10241 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010242put_setnum(
10243 FILE *fd,
10244 char *cmd,
10245 char *name,
10246 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247{
10248 long wc;
10249
10250 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10251 return FAIL;
10252 if (wc_use_keyname((char_u *)valuep, &wc))
10253 {
10254 /* print 'wildchar' and 'wildcharm' as a key name */
10255 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10256 return FAIL;
10257 }
10258 else if (fprintf(fd, "%ld", *valuep) < 0)
10259 return FAIL;
10260 if (put_eol(fd) < 0)
10261 return FAIL;
10262 return OK;
10263}
10264
10265 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010266put_setbool(
10267 FILE *fd,
10268 char *cmd,
10269 char *name,
10270 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271{
Bram Moolenaar893de922007-10-02 18:40:57 +000010272 if (value < 0) /* global/local option using global value */
10273 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10275 || put_eol(fd) < 0)
10276 return FAIL;
10277 return OK;
10278}
10279
10280/*
10281 * Clear all the terminal options.
10282 * If the option has been allocated, free the memory.
10283 * Terminal options are never hidden or indirect.
10284 */
10285 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010286clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010287{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010288 /*
10289 * Reset a few things before clearing the old options. This may cause
10290 * outputting a few things that the terminal doesn't understand, but the
10291 * screen will be cleared later, so this is OK.
10292 */
10293#ifdef FEAT_MOUSE_TTY
10294 mch_setmouse(FALSE); /* switch mouse off */
10295#endif
10296#ifdef FEAT_TITLE
10297 mch_restore_title(3); /* restore window titles */
10298#endif
10299#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10300 /* When starting the GUI close the display opened for the clipboard.
10301 * After restoring the title, because that will need the display. */
10302 if (gui.starting)
10303 clear_xterm_clip();
10304#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010305 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010307 free_termoptions();
10308}
10309
10310 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010311free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010312{
10313 struct vimoption *p;
10314
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 for (p = &options[0]; p->fullname != NULL; p++)
10316 if (istermoption(p))
10317 {
10318 if (p->flags & P_ALLOCED)
10319 free_string_option(*(char_u **)(p->var));
10320 if (p->flags & P_DEF_ALLOCED)
10321 free_string_option(p->def_val[VI_DEFAULT]);
10322 *(char_u **)(p->var) = empty_option;
10323 p->def_val[VI_DEFAULT] = empty_option;
10324 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10325 }
10326 clear_termcodes();
10327}
10328
10329/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010330 * Free the string for one term option, if it was allocated.
10331 * Set the string to empty_option and clear allocated flag.
10332 * "var" points to the option value.
10333 */
10334 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010335free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010336{
10337 struct vimoption *p;
10338
10339 for (p = &options[0]; p->fullname != NULL; p++)
10340 if (p->var == var)
10341 {
10342 if (p->flags & P_ALLOCED)
10343 free_string_option(*(char_u **)(p->var));
10344 *(char_u **)(p->var) = empty_option;
10345 p->flags &= ~P_ALLOCED;
10346 break;
10347 }
10348}
10349
10350/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351 * Set the terminal option defaults to the current value.
10352 * Used after setting the terminal name.
10353 */
10354 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010355set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356{
10357 struct vimoption *p;
10358
10359 for (p = &options[0]; p->fullname != NULL; p++)
10360 {
10361 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10362 {
10363 if (p->flags & P_DEF_ALLOCED)
10364 {
10365 free_string_option(p->def_val[VI_DEFAULT]);
10366 p->flags &= ~P_DEF_ALLOCED;
10367 }
10368 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10369 if (p->flags & P_ALLOCED)
10370 {
10371 p->flags |= P_DEF_ALLOCED;
10372 p->flags &= ~P_ALLOCED; /* don't free the value now */
10373 }
10374 }
10375 }
10376}
10377
10378/*
10379 * return TRUE if 'p' starts with 't_'
10380 */
10381 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010382istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383{
10384 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10385}
10386
10387/*
10388 * Compute columns for ruler and shown command. 'sc_col' is also used to
10389 * decide what the maximum length of a message on the status line can be.
10390 * If there is a status line for the last window, 'sc_col' is independent
10391 * of 'ru_col'.
10392 */
10393
10394#define COL_RULER 17 /* columns needed by standard ruler */
10395
10396 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010397comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010399#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010400 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401
10402 sc_col = 0;
10403 ru_col = 0;
10404 if (p_ru)
10405 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010406# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010408# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010409 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010410# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010411 /* no last status line, adjust sc_col */
10412 if (!last_has_status)
10413 sc_col = ru_col;
10414 }
10415 if (p_sc)
10416 {
10417 sc_col += SHOWCMD_COLS;
10418 if (!p_ru || last_has_status) /* no need for separating space */
10419 ++sc_col;
10420 }
10421 sc_col = Columns - sc_col;
10422 ru_col = Columns - ru_col;
10423 if (sc_col <= 0) /* screen too narrow, will become a mess */
10424 sc_col = 1;
10425 if (ru_col <= 0)
10426 ru_col = 1;
10427#else
10428 sc_col = Columns;
10429 ru_col = Columns;
10430#endif
10431}
10432
10433/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434 * Unset local option value, similar to ":set opt<".
10435 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010436 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010437unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010438{
10439 struct vimoption *p;
10440 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010441 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010442
10443 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010444 if (opt_idx < 0)
10445 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010446 p = &(options[opt_idx]);
10447
10448 switch ((int)p->indir)
10449 {
10450 /* global option with local value: use local value if it's been set */
10451 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010452 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010453 break;
10454 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010455 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010456 break;
10457 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010458 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010459 break;
10460 case PV_AR:
10461 buf->b_p_ar = -1;
10462 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010463 case PV_BKC:
10464 clear_string_option(&buf->b_p_bkc);
10465 buf->b_bkc_flags = 0;
10466 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010467 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010468 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010469 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010470 case PV_TC:
10471 clear_string_option(&buf->b_p_tc);
10472 buf->b_tc_flags = 0;
10473 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010474#ifdef FEAT_FIND_ID
10475 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010476 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010477 break;
10478 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010479 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010480 break;
10481#endif
10482#ifdef FEAT_INS_EXPAND
10483 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010484 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010485 break;
10486 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010487 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010488 break;
10489#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010490 case PV_FP:
10491 clear_string_option(&buf->b_p_fp);
10492 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010493#ifdef FEAT_QUICKFIX
10494 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010495 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010496 break;
10497 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010498 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010499 break;
10500 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010501 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010502 break;
10503#endif
10504#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10505 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010506 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010507 break;
10508#endif
10509#if defined(FEAT_CRYPT)
10510 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010511 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010512 break;
10513#endif
10514#ifdef FEAT_STL_OPT
10515 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010516 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010517 break;
10518#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010519 case PV_UL:
10520 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10521 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010522#ifdef FEAT_LISP
10523 case PV_LW:
10524 clear_string_option(&buf->b_p_lw);
10525 break;
10526#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010527#ifdef FEAT_MBYTE
10528 case PV_MENC:
10529 clear_string_option(&buf->b_p_menc);
10530 break;
10531#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010532 }
10533}
10534
10535/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 * Get pointer to option variable, depending on local or global scope.
10537 */
10538 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010539get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540{
10541 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10542 {
10543 if (p->var == VAR_WIN)
10544 return (char_u *)GLOBAL_WO(get_varp(p));
10545 return p->var;
10546 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010547 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548 {
10549 switch ((int)p->indir)
10550 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010551 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010553 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10554 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10555 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010557 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10558 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10559 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010560 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010561 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010562 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010564 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10565 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566#endif
10567#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010568 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10569 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010571#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10572 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10573#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010574#if defined(FEAT_CRYPT)
10575 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10576#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010577#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010578 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010579#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010580 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010581#ifdef FEAT_LISP
10582 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10583#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010584 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010585#ifdef FEAT_MBYTE
10586 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10587#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 }
10589 return NULL; /* "cannot happen" */
10590 }
10591 return get_varp(p);
10592}
10593
10594/*
10595 * Get pointer to option variable.
10596 */
10597 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010598get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599{
10600 /* hidden option, always return NULL */
10601 if (p->var == NULL)
10602 return NULL;
10603
10604 switch ((int)p->indir)
10605 {
10606 case PV_NONE: return p->var;
10607
10608 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010609 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010611 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010613 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010615 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010617 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010619 case PV_TC: return *curbuf->b_p_tc != NUL
10620 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010621 case PV_BKC: return *curbuf->b_p_bkc != NUL
10622 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010623#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010624 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010626 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010627 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10628#endif
10629#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010630 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010632 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10634#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010635 case PV_FP: return *curbuf->b_p_fp != NUL
10636 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010637#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010638 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010640 case PV_GP: return *curbuf->b_p_gp != NUL
10641 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10642 case PV_MP: return *curbuf->b_p_mp != NUL
10643 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010645#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10646 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10647 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10648#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010649#if defined(FEAT_CRYPT)
10650 case PV_CM: return *curbuf->b_p_cm != NUL
10651 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10652#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010653#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010654 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010655 ? (char_u *)&(curwin->w_p_stl) : p->var;
10656#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010657 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10658 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010659#ifdef FEAT_LISP
10660 case PV_LW: return *curbuf->b_p_lw != NUL
10661 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10662#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010663#ifdef FEAT_MBYTE
10664 case PV_MENC: return *curbuf->b_p_menc != NUL
10665 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010667
10668#ifdef FEAT_ARABIC
10669 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10670#endif
10671 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010672#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010673 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10674#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010675#ifdef FEAT_SYN_HL
10676 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10677 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010678 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010679#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680#ifdef FEAT_DIFF
10681 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10682#endif
10683#ifdef FEAT_FOLDING
10684 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10685 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10686 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10687 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10688 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10689 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10690 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10691# ifdef FEAT_EVAL
10692 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10693 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10694# endif
10695 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10696#endif
10697 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010698 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010699#ifdef FEAT_LINEBREAK
10700 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010702 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010703 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010704#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10706#endif
10707#ifdef FEAT_RIGHTLEFT
10708 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10709 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10710#endif
10711 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10712 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10713#ifdef FEAT_LINEBREAK
10714 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010715 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10716 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010719 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010720#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010721 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10722 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10723#endif
10724#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010725 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10726 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10727 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729
10730 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10731 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10732#ifdef FEAT_MBYTE
10733 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10734#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10736 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10738 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10739#ifdef FEAT_CINDENT
10740 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10741 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10742 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10743#endif
10744#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10745 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10746#endif
10747#ifdef FEAT_COMMENTS
10748 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10749#endif
10750#ifdef FEAT_FOLDING
10751 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10752#endif
10753#ifdef FEAT_INS_EXPAND
10754 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10755#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010756#ifdef FEAT_COMPL_FUNC
10757 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010758 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010759#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010761 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10763#ifdef FEAT_MBYTE
10764 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10765#endif
10766 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010769 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10771 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10772 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10773 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10774#ifdef FEAT_FIND_ID
10775# ifdef FEAT_EVAL
10776 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10777# endif
10778#endif
10779#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10780 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10781 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10782#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010783#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010784 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786#ifdef FEAT_CRYPT
10787 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10788#endif
10789#ifdef FEAT_LISP
10790 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10791#endif
10792 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10793 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10794 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10795 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10796 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010798#ifdef FEAT_TEXTOBJ
10799 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10802#ifdef FEAT_SMARTINDENT
10803 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10804#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010805 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10807#ifdef FEAT_SEARCHPATH
10808 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10809#endif
10810 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10811#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010812 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010813 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10814#endif
10815#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010816 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10817 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10818 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819#endif
10820 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10821 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10822 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10823 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010824#ifdef FEAT_PERSISTENT_UNDO
10825 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10828#ifdef FEAT_KEYMAP
10829 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10830#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010831#ifdef FEAT_SIGNS
10832 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10833#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010834 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835 }
10836 /* always return a valid pointer to avoid a crash! */
10837 return (char_u *)&(curbuf->b_p_wm);
10838}
10839
10840/*
10841 * Get the value of 'equalprg', either the buffer-local one or the global one.
10842 */
10843 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010844get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845{
10846 if (*curbuf->b_p_ep == NUL)
10847 return p_ep;
10848 return curbuf->b_p_ep;
10849}
10850
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851/*
10852 * Copy options from one window to another.
10853 * Used when splitting a window.
10854 */
10855 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010856win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857{
10858 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10859 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10860# ifdef FEAT_RIGHTLEFT
10861# ifdef FEAT_FKMAP
10862 /* Is this right? */
10863 wp_to->w_farsi = wp_from->w_farsi;
10864# endif
10865# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010866#if defined(FEAT_LINEBREAK)
10867 briopt_check(wp_to);
10868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870
10871/*
10872 * Copy the options from one winopt_T to another.
10873 * Doesn't free the old option values in "to", use clear_winopt() for that.
10874 * The 'scroll' option is not copied, because it depends on the window height.
10875 * The 'previewwindow' option is reset, there can be only one preview window.
10876 */
10877 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010878copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879{
10880#ifdef FEAT_ARABIC
10881 to->wo_arab = from->wo_arab;
10882#endif
10883 to->wo_list = from->wo_list;
10884 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010885 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010886#ifdef FEAT_LINEBREAK
10887 to->wo_nuw = from->wo_nuw;
10888#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010889#ifdef FEAT_RIGHTLEFT
10890 to->wo_rl = from->wo_rl;
10891 to->wo_rlc = vim_strsave(from->wo_rlc);
10892#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010893#ifdef FEAT_STL_OPT
10894 to->wo_stl = vim_strsave(from->wo_stl);
10895#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010897#ifdef FEAT_DIFF
10898 to->wo_wrap_save = from->wo_wrap_save;
10899#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900#ifdef FEAT_LINEBREAK
10901 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010902 to->wo_bri = from->wo_bri;
10903 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010906 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010907 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010908 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010909#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010910 to->wo_spell = from->wo_spell;
10911#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010912#ifdef FEAT_SYN_HL
10913 to->wo_cuc = from->wo_cuc;
10914 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010915 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010916#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010917#ifdef FEAT_DIFF
10918 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010919 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010921#ifdef FEAT_CONCEAL
10922 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010923 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010924#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010925#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010926 to->wo_twk = vim_strsave(from->wo_twk);
10927 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929#ifdef FEAT_FOLDING
10930 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010931 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010933 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010934 to->wo_fdi = vim_strsave(from->wo_fdi);
10935 to->wo_fml = from->wo_fml;
10936 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010937 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010939 to->wo_fdm_save = from->wo_diff_saved
10940 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941 to->wo_fdn = from->wo_fdn;
10942# ifdef FEAT_EVAL
10943 to->wo_fde = vim_strsave(from->wo_fde);
10944 to->wo_fdt = vim_strsave(from->wo_fdt);
10945# endif
10946 to->wo_fmr = vim_strsave(from->wo_fmr);
10947#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010948#ifdef FEAT_SIGNS
10949 to->wo_scl = vim_strsave(from->wo_scl);
10950#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010951 check_winopt(to); /* don't want NULL pointers */
10952}
10953
10954/*
10955 * Check string options in a window for a NULL value.
10956 */
10957 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010958check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010959{
10960 check_winopt(&win->w_onebuf_opt);
10961 check_winopt(&win->w_allbuf_opt);
10962}
10963
10964/*
10965 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10966 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010967 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010968check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010969{
10970#ifdef FEAT_FOLDING
10971 check_string_option(&wop->wo_fdi);
10972 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010973 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974# ifdef FEAT_EVAL
10975 check_string_option(&wop->wo_fde);
10976 check_string_option(&wop->wo_fdt);
10977# endif
10978 check_string_option(&wop->wo_fmr);
10979#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010980#ifdef FEAT_SIGNS
10981 check_string_option(&wop->wo_scl);
10982#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010983#ifdef FEAT_RIGHTLEFT
10984 check_string_option(&wop->wo_rlc);
10985#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010986#ifdef FEAT_STL_OPT
10987 check_string_option(&wop->wo_stl);
10988#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010989#ifdef FEAT_SYN_HL
10990 check_string_option(&wop->wo_cc);
10991#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010992#ifdef FEAT_CONCEAL
10993 check_string_option(&wop->wo_cocu);
10994#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010995#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010996 check_string_option(&wop->wo_twk);
10997 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010998#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010999#ifdef FEAT_LINEBREAK
11000 check_string_option(&wop->wo_briopt);
11001#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011002}
11003
11004/*
11005 * Free the allocated memory inside a winopt_T.
11006 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011007 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011008clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011009{
11010#ifdef FEAT_FOLDING
11011 clear_string_option(&wop->wo_fdi);
11012 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011013 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011014# ifdef FEAT_EVAL
11015 clear_string_option(&wop->wo_fde);
11016 clear_string_option(&wop->wo_fdt);
11017# endif
11018 clear_string_option(&wop->wo_fmr);
11019#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011020#ifdef FEAT_SIGNS
11021 clear_string_option(&wop->wo_scl);
11022#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011023#ifdef FEAT_LINEBREAK
11024 clear_string_option(&wop->wo_briopt);
11025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011026#ifdef FEAT_RIGHTLEFT
11027 clear_string_option(&wop->wo_rlc);
11028#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011029#ifdef FEAT_STL_OPT
11030 clear_string_option(&wop->wo_stl);
11031#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011032#ifdef FEAT_SYN_HL
11033 clear_string_option(&wop->wo_cc);
11034#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011035#ifdef FEAT_CONCEAL
11036 clear_string_option(&wop->wo_cocu);
11037#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011038#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011039 clear_string_option(&wop->wo_twk);
11040 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042}
11043
11044/*
11045 * Copy global option values to local options for one buffer.
11046 * Used when creating a new buffer and sometimes when entering a buffer.
11047 * flags:
11048 * BCO_ENTER We will enter the buf buffer.
11049 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11050 * appropriate.
11051 * BCO_NOHELP Don't copy the values to a help buffer.
11052 */
11053 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011054buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055{
11056 int should_copy = TRUE;
11057 char_u *save_p_isk = NULL; /* init for GCC */
11058 int dont_do_help;
11059 int did_isk = FALSE;
11060
11061 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011062 * Skip this when the option defaults have not been set yet. Happens when
11063 * main() allocates the first buffer.
11064 */
11065 if (p_cpo != NULL)
11066 {
11067 /*
11068 * Always copy when entering and 'cpo' contains 'S'.
11069 * Don't copy when already initialized.
11070 * Don't copy when 'cpo' contains 's' and not entering.
11071 * 'S' BCO_ENTER initialized 's' should_copy
11072 * yes yes X X TRUE
11073 * yes no yes X FALSE
11074 * no X yes X FALSE
11075 * X no no yes FALSE
11076 * X no no no TRUE
11077 * no yes no X TRUE
11078 */
11079 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11080 && (buf->b_p_initialized
11081 || (!(flags & BCO_ENTER)
11082 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11083 should_copy = FALSE;
11084
11085 if (should_copy || (flags & BCO_ALWAYS))
11086 {
11087 /* Don't copy the options specific to a help buffer when
11088 * BCO_NOHELP is given or the options were initialized already
11089 * (jumping back to a help file with CTRL-T or CTRL-O) */
11090 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11091 || buf->b_p_initialized;
11092 if (dont_do_help) /* don't free b_p_isk */
11093 {
11094 save_p_isk = buf->b_p_isk;
11095 buf->b_p_isk = NULL;
11096 }
11097 /*
11098 * Always free the allocated strings.
11099 * If not already initialized, set 'readonly' and copy 'fileformat'.
11100 */
11101 if (!buf->b_p_initialized)
11102 {
11103 free_buf_options(buf, TRUE);
11104 buf->b_p_ro = FALSE; /* don't copy readonly */
11105 buf->b_p_tx = p_tx;
11106#ifdef FEAT_MBYTE
11107 buf->b_p_fenc = vim_strsave(p_fenc);
11108#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011109 switch (*p_ffs)
11110 {
11111 case 'm':
11112 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11113 case 'd':
11114 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11115 case 'u':
11116 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11117 default:
11118 buf->b_p_ff = vim_strsave(p_ff);
11119 }
11120 if (buf->b_p_ff != NULL)
11121 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122 buf->b_p_bh = empty_option;
11123 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124 }
11125 else
11126 free_buf_options(buf, FALSE);
11127
11128 buf->b_p_ai = p_ai;
11129 buf->b_p_ai_nopaste = p_ai_nopaste;
11130 buf->b_p_sw = p_sw;
11131 buf->b_p_tw = p_tw;
11132 buf->b_p_tw_nopaste = p_tw_nopaste;
11133 buf->b_p_tw_nobin = p_tw_nobin;
11134 buf->b_p_wm = p_wm;
11135 buf->b_p_wm_nopaste = p_wm_nopaste;
11136 buf->b_p_wm_nobin = p_wm_nobin;
11137 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011138#ifdef FEAT_MBYTE
11139 buf->b_p_bomb = p_bomb;
11140#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011141 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142 buf->b_p_et = p_et;
11143 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011144 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145 buf->b_p_ml = p_ml;
11146 buf->b_p_ml_nobin = p_ml_nobin;
11147 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011148 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011149#ifdef FEAT_INS_EXPAND
11150 buf->b_p_cpt = vim_strsave(p_cpt);
11151#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011152#ifdef FEAT_COMPL_FUNC
11153 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011154 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011155#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156 buf->b_p_sts = p_sts;
11157 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011158 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011159#ifdef FEAT_COMMENTS
11160 buf->b_p_com = vim_strsave(p_com);
11161#endif
11162#ifdef FEAT_FOLDING
11163 buf->b_p_cms = vim_strsave(p_cms);
11164#endif
11165 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011166 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 buf->b_p_nf = vim_strsave(p_nf);
11168 buf->b_p_mps = vim_strsave(p_mps);
11169#ifdef FEAT_SMARTINDENT
11170 buf->b_p_si = p_si;
11171#endif
11172 buf->b_p_ci = p_ci;
11173#ifdef FEAT_CINDENT
11174 buf->b_p_cin = p_cin;
11175 buf->b_p_cink = vim_strsave(p_cink);
11176 buf->b_p_cino = vim_strsave(p_cino);
11177#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011178 /* Don't copy 'filetype', it must be detected */
11179 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180 buf->b_p_pi = p_pi;
11181#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11182 buf->b_p_cinw = vim_strsave(p_cinw);
11183#endif
11184#ifdef FEAT_LISP
11185 buf->b_p_lisp = p_lisp;
11186#endif
11187#ifdef FEAT_SYN_HL
11188 /* Don't copy 'syntax', it must be set */
11189 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011190 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011191 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011192#endif
11193#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011194 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011195 (void)compile_cap_prog(&buf->b_s);
11196 buf->b_s.b_p_spf = vim_strsave(p_spf);
11197 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011198#endif
11199#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11200 buf->b_p_inde = vim_strsave(p_inde);
11201 buf->b_p_indk = vim_strsave(p_indk);
11202#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011203 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011204#if defined(FEAT_EVAL)
11205 buf->b_p_fex = vim_strsave(p_fex);
11206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011207#ifdef FEAT_CRYPT
11208 buf->b_p_key = vim_strsave(p_key);
11209#endif
11210#ifdef FEAT_SEARCHPATH
11211 buf->b_p_sua = vim_strsave(p_sua);
11212#endif
11213#ifdef FEAT_KEYMAP
11214 buf->b_p_keymap = vim_strsave(p_keymap);
11215 buf->b_kmap_state |= KEYMAP_INIT;
11216#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011217#ifdef FEAT_TERMINAL
11218 buf->b_p_twsl = p_twsl;
11219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011220 /* This isn't really an option, but copying the langmap and IME
11221 * state from the current buffer is better than resetting it. */
11222 buf->b_p_iminsert = p_iminsert;
11223 buf->b_p_imsearch = p_imsearch;
11224
11225 /* options that are normally global but also have a local value
11226 * are not copied, start using the global value */
11227 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011228 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011229 buf->b_p_bkc = empty_option;
11230 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011231#ifdef FEAT_QUICKFIX
11232 buf->b_p_gp = empty_option;
11233 buf->b_p_mp = empty_option;
11234 buf->b_p_efm = empty_option;
11235#endif
11236 buf->b_p_ep = empty_option;
11237 buf->b_p_kp = empty_option;
11238 buf->b_p_path = empty_option;
11239 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011240 buf->b_p_tc = empty_option;
11241 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242#ifdef FEAT_FIND_ID
11243 buf->b_p_def = empty_option;
11244 buf->b_p_inc = empty_option;
11245# ifdef FEAT_EVAL
11246 buf->b_p_inex = vim_strsave(p_inex);
11247# endif
11248#endif
11249#ifdef FEAT_INS_EXPAND
11250 buf->b_p_dict = empty_option;
11251 buf->b_p_tsr = empty_option;
11252#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011253#ifdef FEAT_TEXTOBJ
11254 buf->b_p_qe = vim_strsave(p_qe);
11255#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011256#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11257 buf->b_p_bexpr = empty_option;
11258#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011259#if defined(FEAT_CRYPT)
11260 buf->b_p_cm = empty_option;
11261#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011262#ifdef FEAT_PERSISTENT_UNDO
11263 buf->b_p_udf = p_udf;
11264#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011265#ifdef FEAT_LISP
11266 buf->b_p_lw = empty_option;
11267#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011268#ifdef FEAT_MBYTE
11269 buf->b_p_menc = empty_option;
11270#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011271
11272 /*
11273 * Don't copy the options set by ex_help(), use the saved values,
11274 * when going from a help buffer to a non-help buffer.
11275 * Don't touch these at all when BCO_NOHELP is used and going from
11276 * or to a help buffer.
11277 */
11278 if (dont_do_help)
11279 buf->b_p_isk = save_p_isk;
11280 else
11281 {
11282 buf->b_p_isk = vim_strsave(p_isk);
11283 did_isk = TRUE;
11284 buf->b_p_ts = p_ts;
11285 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286 if (buf->b_p_bt[0] == 'h')
11287 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288 buf->b_p_ma = p_ma;
11289 }
11290 }
11291
11292 /*
11293 * When the options should be copied (ignoring BCO_ALWAYS), set the
11294 * flag that indicates that the options have been initialized.
11295 */
11296 if (should_copy)
11297 buf->b_p_initialized = TRUE;
11298 }
11299
11300 check_buf_options(buf); /* make sure we don't have NULLs */
11301 if (did_isk)
11302 (void)buf_init_chartab(buf, FALSE);
11303}
11304
11305/*
11306 * Reset the 'modifiable' option and its default value.
11307 */
11308 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011309reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310{
11311 int opt_idx;
11312
11313 curbuf->b_p_ma = FALSE;
11314 p_ma = FALSE;
11315 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011316 if (opt_idx >= 0)
11317 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011318}
11319
11320/*
11321 * Set the global value for 'iminsert' to the local value.
11322 */
11323 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011324set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011325{
11326 p_iminsert = curbuf->b_p_iminsert;
11327}
11328
11329/*
11330 * Set the global value for 'imsearch' to the local value.
11331 */
11332 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011333set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011334{
11335 p_imsearch = curbuf->b_p_imsearch;
11336}
11337
11338#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11339static int expand_option_idx = -1;
11340static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11341static int expand_option_flags = 0;
11342
11343 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011344set_context_in_set_cmd(
11345 expand_T *xp,
11346 char_u *arg,
11347 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348{
11349 int nextchar;
11350 long_u flags = 0; /* init for GCC */
11351 int opt_idx = 0; /* init for GCC */
11352 char_u *p;
11353 char_u *s;
11354 int is_term_option = FALSE;
11355 int key;
11356
11357 expand_option_flags = opt_flags;
11358
11359 xp->xp_context = EXPAND_SETTINGS;
11360 if (*arg == NUL)
11361 {
11362 xp->xp_pattern = arg;
11363 return;
11364 }
11365 p = arg + STRLEN(arg) - 1;
11366 if (*p == ' ' && *(p - 1) != '\\')
11367 {
11368 xp->xp_pattern = p + 1;
11369 return;
11370 }
11371 while (p > arg)
11372 {
11373 s = p;
11374 /* count number of backslashes before ' ' or ',' */
11375 if (*p == ' ' || *p == ',')
11376 {
11377 while (s > arg && *(s - 1) == '\\')
11378 --s;
11379 }
11380 /* break at a space with an even number of backslashes */
11381 if (*p == ' ' && ((p - s) & 1) == 0)
11382 {
11383 ++p;
11384 break;
11385 }
11386 --p;
11387 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011388 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389 {
11390 xp->xp_context = EXPAND_BOOL_SETTINGS;
11391 p += 2;
11392 }
11393 if (STRNCMP(p, "inv", 3) == 0)
11394 {
11395 xp->xp_context = EXPAND_BOOL_SETTINGS;
11396 p += 3;
11397 }
11398 xp->xp_pattern = arg = p;
11399 if (*arg == '<')
11400 {
11401 while (*p != '>')
11402 if (*p++ == NUL) /* expand terminal option name */
11403 return;
11404 key = get_special_key_code(arg + 1);
11405 if (key == 0) /* unknown name */
11406 {
11407 xp->xp_context = EXPAND_NOTHING;
11408 return;
11409 }
11410 nextchar = *++p;
11411 is_term_option = TRUE;
11412 expand_option_name[2] = KEY2TERMCAP0(key);
11413 expand_option_name[3] = KEY2TERMCAP1(key);
11414 }
11415 else
11416 {
11417 if (p[0] == 't' && p[1] == '_')
11418 {
11419 p += 2;
11420 if (*p != NUL)
11421 ++p;
11422 if (*p == NUL)
11423 return; /* expand option name */
11424 nextchar = *++p;
11425 is_term_option = TRUE;
11426 expand_option_name[2] = p[-2];
11427 expand_option_name[3] = p[-1];
11428 }
11429 else
11430 {
11431 /* Allow * wildcard */
11432 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11433 p++;
11434 if (*p == NUL)
11435 return;
11436 nextchar = *p;
11437 *p = NUL;
11438 opt_idx = findoption(arg);
11439 *p = nextchar;
11440 if (opt_idx == -1 || options[opt_idx].var == NULL)
11441 {
11442 xp->xp_context = EXPAND_NOTHING;
11443 return;
11444 }
11445 flags = options[opt_idx].flags;
11446 if (flags & P_BOOL)
11447 {
11448 xp->xp_context = EXPAND_NOTHING;
11449 return;
11450 }
11451 }
11452 }
11453 /* handle "-=" and "+=" */
11454 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11455 {
11456 ++p;
11457 nextchar = '=';
11458 }
11459 if ((nextchar != '=' && nextchar != ':')
11460 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11461 {
11462 xp->xp_context = EXPAND_UNSUCCESSFUL;
11463 return;
11464 }
11465 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11466 {
11467 xp->xp_context = EXPAND_OLD_SETTING;
11468 if (is_term_option)
11469 expand_option_idx = -1;
11470 else
11471 expand_option_idx = opt_idx;
11472 xp->xp_pattern = p + 1;
11473 return;
11474 }
11475 xp->xp_context = EXPAND_NOTHING;
11476 if (is_term_option || (flags & P_NUM))
11477 return;
11478
11479 xp->xp_pattern = p + 1;
11480
11481 if (flags & P_EXPAND)
11482 {
11483 p = options[opt_idx].var;
11484 if (p == (char_u *)&p_bdir
11485 || p == (char_u *)&p_dir
11486 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011487 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488 || p == (char_u *)&p_rtp
11489#ifdef FEAT_SEARCHPATH
11490 || p == (char_u *)&p_cdpath
11491#endif
11492#ifdef FEAT_SESSION
11493 || p == (char_u *)&p_vdir
11494#endif
11495 )
11496 {
11497 xp->xp_context = EXPAND_DIRECTORIES;
11498 if (p == (char_u *)&p_path
11499#ifdef FEAT_SEARCHPATH
11500 || p == (char_u *)&p_cdpath
11501#endif
11502 )
11503 xp->xp_backslash = XP_BS_THREE;
11504 else
11505 xp->xp_backslash = XP_BS_ONE;
11506 }
11507 else
11508 {
11509 xp->xp_context = EXPAND_FILES;
11510 /* for 'tags' need three backslashes for a space */
11511 if (p == (char_u *)&p_tags)
11512 xp->xp_backslash = XP_BS_THREE;
11513 else
11514 xp->xp_backslash = XP_BS_ONE;
11515 }
11516 }
11517
11518 /* For an option that is a list of file names, find the start of the
11519 * last file name. */
11520 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11521 {
11522 /* count number of backslashes before ' ' or ',' */
11523 if (*p == ' ' || *p == ',')
11524 {
11525 s = p;
11526 while (s > xp->xp_pattern && *(s - 1) == '\\')
11527 --s;
11528 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11529 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11530 {
11531 xp->xp_pattern = p + 1;
11532 break;
11533 }
11534 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011535
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011536#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011537 /* for 'spellsuggest' start at "file:" */
11538 if (options[opt_idx].var == (char_u *)&p_sps
11539 && STRNCMP(p, "file:", 5) == 0)
11540 {
11541 xp->xp_pattern = p + 5;
11542 break;
11543 }
11544#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011545 }
11546
11547 return;
11548}
11549
11550 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011551ExpandSettings(
11552 expand_T *xp,
11553 regmatch_T *regmatch,
11554 int *num_file,
11555 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011556{
11557 int num_normal = 0; /* Nr of matching non-term-code settings */
11558 int num_term = 0; /* Nr of matching terminal code settings */
11559 int opt_idx;
11560 int match;
11561 int count = 0;
11562 char_u *str;
11563 int loop;
11564 int is_term_opt;
11565 char_u name_buf[MAX_KEY_NAME_LEN];
11566 static char *(names[]) = {"all", "termcap"};
11567 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11568
11569 /* do this loop twice:
11570 * loop == 0: count the number of matching options
11571 * loop == 1: copy the matching options into allocated memory
11572 */
11573 for (loop = 0; loop <= 1; ++loop)
11574 {
11575 regmatch->rm_ic = ic;
11576 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11577 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011578 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11579 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11581 {
11582 if (loop == 0)
11583 num_normal++;
11584 else
11585 (*file)[count++] = vim_strsave((char_u *)names[match]);
11586 }
11587 }
11588 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11589 opt_idx++)
11590 {
11591 if (options[opt_idx].var == NULL)
11592 continue;
11593 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11594 && !(options[opt_idx].flags & P_BOOL))
11595 continue;
11596 is_term_opt = istermoption(&options[opt_idx]);
11597 if (is_term_opt && num_normal > 0)
11598 continue;
11599 match = FALSE;
11600 if (vim_regexec(regmatch, str, (colnr_T)0)
11601 || (options[opt_idx].shortname != NULL
11602 && vim_regexec(regmatch,
11603 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11604 match = TRUE;
11605 else if (is_term_opt)
11606 {
11607 name_buf[0] = '<';
11608 name_buf[1] = 't';
11609 name_buf[2] = '_';
11610 name_buf[3] = str[2];
11611 name_buf[4] = str[3];
11612 name_buf[5] = '>';
11613 name_buf[6] = NUL;
11614 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11615 {
11616 match = TRUE;
11617 str = name_buf;
11618 }
11619 }
11620 if (match)
11621 {
11622 if (loop == 0)
11623 {
11624 if (is_term_opt)
11625 num_term++;
11626 else
11627 num_normal++;
11628 }
11629 else
11630 (*file)[count++] = vim_strsave(str);
11631 }
11632 }
11633 /*
11634 * Check terminal key codes, these are not in the option table
11635 */
11636 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11637 {
11638 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11639 {
11640 if (!isprint(str[0]) || !isprint(str[1]))
11641 continue;
11642
11643 name_buf[0] = 't';
11644 name_buf[1] = '_';
11645 name_buf[2] = str[0];
11646 name_buf[3] = str[1];
11647 name_buf[4] = NUL;
11648
11649 match = FALSE;
11650 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11651 match = TRUE;
11652 else
11653 {
11654 name_buf[0] = '<';
11655 name_buf[1] = 't';
11656 name_buf[2] = '_';
11657 name_buf[3] = str[0];
11658 name_buf[4] = str[1];
11659 name_buf[5] = '>';
11660 name_buf[6] = NUL;
11661
11662 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11663 match = TRUE;
11664 }
11665 if (match)
11666 {
11667 if (loop == 0)
11668 num_term++;
11669 else
11670 (*file)[count++] = vim_strsave(name_buf);
11671 }
11672 }
11673
11674 /*
11675 * Check special key names.
11676 */
11677 regmatch->rm_ic = TRUE; /* ignore case here */
11678 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11679 {
11680 name_buf[0] = '<';
11681 STRCPY(name_buf + 1, str);
11682 STRCAT(name_buf, ">");
11683
11684 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11685 {
11686 if (loop == 0)
11687 num_term++;
11688 else
11689 (*file)[count++] = vim_strsave(name_buf);
11690 }
11691 }
11692 }
11693 if (loop == 0)
11694 {
11695 if (num_normal > 0)
11696 *num_file = num_normal;
11697 else if (num_term > 0)
11698 *num_file = num_term;
11699 else
11700 return OK;
11701 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11702 if (*file == NULL)
11703 {
11704 *file = (char_u **)"";
11705 return FAIL;
11706 }
11707 }
11708 }
11709 return OK;
11710}
11711
11712 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011713ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714{
11715 char_u *var = NULL; /* init for GCC */
11716 char_u *buf;
11717
11718 *num_file = 0;
11719 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11720 if (*file == NULL)
11721 return FAIL;
11722
11723 /*
11724 * For a terminal key code expand_option_idx is < 0.
11725 */
11726 if (expand_option_idx < 0)
11727 {
11728 var = find_termcode(expand_option_name + 2);
11729 if (var == NULL)
11730 expand_option_idx = findoption(expand_option_name);
11731 }
11732
11733 if (expand_option_idx >= 0)
11734 {
11735 /* put string of option value in NameBuff */
11736 option_value2string(&options[expand_option_idx], expand_option_flags);
11737 var = NameBuff;
11738 }
11739 else if (var == NULL)
11740 var = (char_u *)"";
11741
11742 /* A backslash is required before some characters. This is the reverse of
11743 * what happens in do_set(). */
11744 buf = vim_strsave_escaped(var, escape_chars);
11745
11746 if (buf == NULL)
11747 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011748 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749 return FAIL;
11750 }
11751
11752#ifdef BACKSLASH_IN_FILENAME
11753 /* For MS-Windows et al. we don't double backslashes at the start and
11754 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011755 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011756 if (var[0] == '\\' && var[1] == '\\'
11757 && expand_option_idx >= 0
11758 && (options[expand_option_idx].flags & P_EXPAND)
11759 && vim_isfilec(var[2])
11760 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011761 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762#endif
11763
11764 *file[0] = buf;
11765 *num_file = 1;
11766 return OK;
11767}
11768#endif
11769
11770/*
11771 * Get the value for the numeric or string option *opp in a nice format into
11772 * NameBuff[]. Must not be called with a hidden option!
11773 */
11774 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011775option_value2string(
11776 struct vimoption *opp,
11777 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011778{
11779 char_u *varp;
11780
11781 varp = get_varp_scope(opp, opt_flags);
11782
11783 if (opp->flags & P_NUM)
11784 {
11785 long wc = 0;
11786
11787 if (wc_use_keyname(varp, &wc))
11788 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11789 else if (wc != 0)
11790 STRCPY(NameBuff, transchar((int)wc));
11791 else
11792 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11793 }
11794 else /* P_STRING */
11795 {
11796 varp = *(char_u **)(varp);
11797 if (varp == NULL) /* just in case */
11798 NameBuff[0] = NUL;
11799#ifdef FEAT_CRYPT
11800 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011801 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802 STRCPY(NameBuff, "*****");
11803#endif
11804 else if (opp->flags & P_EXPAND)
11805 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11806 /* Translate 'pastetoggle' into special key names */
11807 else if ((char_u **)opp->var == &p_pt)
11808 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11809 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011810 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011811 }
11812}
11813
11814/*
11815 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11816 * printed as a keyname.
11817 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11818 */
11819 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011820wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011821{
11822 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11823 {
11824 *wcp = *(long *)varp;
11825 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11826 return TRUE;
11827 }
11828 return FALSE;
11829}
11830
Bram Moolenaar01615492015-02-03 13:00:38 +010011831#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011832/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011833 * Any character has an equivalent 'langmap' character. This is used for
11834 * keyboards that have a special language mode that sends characters above
11835 * 128 (although other characters can be translated too). The "to" field is a
11836 * Vim command character. This avoids having to switch the keyboard back to
11837 * ASCII mode when leaving Insert mode.
11838 *
11839 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11840 * commands.
11841 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11842 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11843 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011844 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011845# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011846/*
11847 * With multi-byte support use growarray for 'langmap' chars >= 256
11848 */
11849typedef struct
11850{
11851 int from;
11852 int to;
11853} langmap_entry_T;
11854
11855static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011856static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011857
11858/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011859 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11860 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011861 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011862 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011863langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011864{
11865 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011866 int a = 0;
11867 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011868
11869 /* Do a binary search for an existing entry. */
11870 while (a != b)
11871 {
11872 int i = (a + b) / 2;
11873 int d = entries[i].from - from;
11874
11875 if (d == 0)
11876 {
11877 entries[i].to = to;
11878 return;
11879 }
11880 if (d < 0)
11881 a = i + 1;
11882 else
11883 b = i;
11884 }
11885
11886 if (ga_grow(&langmap_mapga, 1) != OK)
11887 return; /* out of memory */
11888
11889 /* insert new entry at position "a" */
11890 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11891 mch_memmove(entries + 1, entries,
11892 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11893 ++langmap_mapga.ga_len;
11894 entries[0].from = from;
11895 entries[0].to = to;
11896}
11897
11898/*
11899 * Apply 'langmap' to multi-byte character "c" and return the result.
11900 */
11901 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011902langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011903{
11904 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11905 int a = 0;
11906 int b = langmap_mapga.ga_len;
11907
11908 while (a != b)
11909 {
11910 int i = (a + b) / 2;
11911 int d = entries[i].from - c;
11912
11913 if (d == 0)
11914 return entries[i].to; /* found matching entry */
11915 if (d < 0)
11916 a = i + 1;
11917 else
11918 b = i;
11919 }
11920 return c; /* no entry found, return "c" unmodified */
11921}
11922# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011923
11924 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011925langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926{
11927 int i;
11928
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011929 for (i = 0; i < 256; i++)
11930 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11931# ifdef FEAT_MBYTE
11932 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11933# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934}
11935
11936/*
11937 * Called when langmap option is set; the language map can be
11938 * changed at any time!
11939 */
11940 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011941langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942{
11943 char_u *p;
11944 char_u *p2;
11945 int from, to;
11946
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011947#ifdef FEAT_MBYTE
11948 ga_clear(&langmap_mapga); /* clear the previous map first */
11949#endif
11950 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951
11952 for (p = p_langmap; p[0] != NUL; )
11953 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011954 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011955 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956 {
11957 if (p2[0] == '\\' && p2[1] != NUL)
11958 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011959 }
11960 if (p2[0] == ';')
11961 ++p2; /* abcd;ABCD form, p2 points to A */
11962 else
11963 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11964 while (p[0])
11965 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011966 if (p[0] == ',')
11967 {
11968 ++p;
11969 break;
11970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011971 if (p[0] == '\\' && p[1] != NUL)
11972 ++p;
11973#ifdef FEAT_MBYTE
11974 from = (*mb_ptr2char)(p);
11975#else
11976 from = p[0];
11977#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011978 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979 if (p2 == NULL)
11980 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011981 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011982 if (p[0] != ',')
11983 {
11984 if (p[0] == '\\')
11985 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011986#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011987 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011988#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011989 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011990#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011992 }
11993 else
11994 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011995 if (p2[0] != ',')
11996 {
11997 if (p2[0] == '\\')
11998 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012000 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012002 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012003#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012004 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012005 }
12006 if (to == NUL)
12007 {
12008 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12009 transchar(from));
12010 return;
12011 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012012
12013#ifdef FEAT_MBYTE
12014 if (from >= 256)
12015 langmap_set_entry(from, to);
12016 else
12017#endif
12018 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012019
12020 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012021 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012022 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012024 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025 if (*p == ';')
12026 {
12027 p = p2;
12028 if (p[0] != NUL)
12029 {
12030 if (p[0] != ',')
12031 {
12032 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12033 return;
12034 }
12035 ++p;
12036 }
12037 break;
12038 }
12039 }
12040 }
12041 }
12042}
12043#endif
12044
12045/*
12046 * Return TRUE if format option 'x' is in effect.
12047 * Take care of no formatting when 'paste' is set.
12048 */
12049 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012050has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012051{
12052 if (p_paste)
12053 return FALSE;
12054 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12055}
12056
12057/*
12058 * Return TRUE if "x" is present in 'shortmess' option, or
12059 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12060 */
12061 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012062shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012064 return p_shm != NULL &&
12065 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066 || (vim_strchr(p_shm, 'a') != NULL
12067 && vim_strchr((char_u *)SHM_A, x) != NULL));
12068}
12069
12070/*
12071 * paste_option_changed() - Called after p_paste was set or reset.
12072 */
12073 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012074paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012075{
12076 static int old_p_paste = FALSE;
12077 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012078 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012079#ifdef FEAT_CMDL_INFO
12080 static int save_ru = 0;
12081#endif
12082#ifdef FEAT_RIGHTLEFT
12083 static int save_ri = 0;
12084 static int save_hkmap = 0;
12085#endif
12086 buf_T *buf;
12087
12088 if (p_paste)
12089 {
12090 /*
12091 * Paste switched from off to on.
12092 * Save the current values, so they can be restored later.
12093 */
12094 if (!old_p_paste)
12095 {
12096 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012097 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012098 {
12099 buf->b_p_tw_nopaste = buf->b_p_tw;
12100 buf->b_p_wm_nopaste = buf->b_p_wm;
12101 buf->b_p_sts_nopaste = buf->b_p_sts;
12102 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012103 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012104 }
12105
12106 /* save global options */
12107 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012108 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109#ifdef FEAT_CMDL_INFO
12110 save_ru = p_ru;
12111#endif
12112#ifdef FEAT_RIGHTLEFT
12113 save_ri = p_ri;
12114 save_hkmap = p_hkmap;
12115#endif
12116 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012117 p_ai_nopaste = p_ai;
12118 p_et_nopaste = p_et;
12119 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 p_tw_nopaste = p_tw;
12121 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012122 }
12123
12124 /*
12125 * Always set the option values, also when 'paste' is set when it is
12126 * already on.
12127 */
12128 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012129 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012130 {
12131 buf->b_p_tw = 0; /* textwidth is 0 */
12132 buf->b_p_wm = 0; /* wrapmargin is 0 */
12133 buf->b_p_sts = 0; /* softtabstop is 0 */
12134 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012135 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 }
12137
12138 /* set global options */
12139 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012140 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012142 if (p_ru)
12143 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012144 p_ru = 0; /* no ruler */
12145#endif
12146#ifdef FEAT_RIGHTLEFT
12147 p_ri = 0; /* no reverse insert */
12148 p_hkmap = 0; /* no Hebrew keyboard */
12149#endif
12150 /* set global values for local buffer options */
12151 p_tw = 0;
12152 p_wm = 0;
12153 p_sts = 0;
12154 p_ai = 0;
12155 }
12156
12157 /*
12158 * Paste switched from on to off: Restore saved values.
12159 */
12160 else if (old_p_paste)
12161 {
12162 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012163 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164 {
12165 buf->b_p_tw = buf->b_p_tw_nopaste;
12166 buf->b_p_wm = buf->b_p_wm_nopaste;
12167 buf->b_p_sts = buf->b_p_sts_nopaste;
12168 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012169 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170 }
12171
12172 /* restore global options */
12173 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012174 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176 if (p_ru != save_ru)
12177 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012178 p_ru = save_ru;
12179#endif
12180#ifdef FEAT_RIGHTLEFT
12181 p_ri = save_ri;
12182 p_hkmap = save_hkmap;
12183#endif
12184 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012185 p_ai = p_ai_nopaste;
12186 p_et = p_et_nopaste;
12187 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012188 p_tw = p_tw_nopaste;
12189 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012190 }
12191
12192 old_p_paste = p_paste;
12193}
12194
12195/*
12196 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12197 *
12198 * Reset 'compatible' and set the values for options that didn't get set yet
12199 * to the Vim defaults.
12200 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012201 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012202 */
12203 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012204vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012205{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012206 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012207 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012208 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209
12210 if (!option_was_set((char_u *)"cp"))
12211 {
12212 p_cp = FALSE;
12213 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12214 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12215 set_option_default(opt_idx, OPT_FREE, FALSE);
12216 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012217 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012218 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012219
12220 if (fname != NULL)
12221 {
12222 p = vim_getenv(envname, &dofree);
12223 if (p == NULL)
12224 {
12225 /* Set $MYVIMRC to the first vimrc file found. */
12226 p = FullName_save(fname, FALSE);
12227 if (p != NULL)
12228 {
12229 vim_setenv(envname, p);
12230 vim_free(p);
12231 }
12232 }
12233 else if (dofree)
12234 vim_free(p);
12235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236}
12237
12238/*
12239 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12240 */
12241 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012242change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012243{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012244 int opt_idx;
12245
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246 if (p_cp != on)
12247 {
12248 p_cp = on;
12249 compatible_set();
12250 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012251 opt_idx = findoption((char_u *)"cp");
12252 if (opt_idx >= 0)
12253 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254}
12255
12256/*
12257 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012258 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259 */
12260 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012261option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012262{
12263 int idx;
12264
12265 idx = findoption(name);
12266 if (idx < 0) /* unknown option */
12267 return FALSE;
12268 if (options[idx].flags & P_WAS_SET)
12269 return TRUE;
12270 return FALSE;
12271}
12272
12273/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012274 * Reset the flag indicating option "name" was set.
12275 */
12276 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012277reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012278{
12279 int idx = findoption(name);
12280
12281 if (idx >= 0)
12282 options[idx].flags &= ~P_WAS_SET;
12283}
12284
12285/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012286 * compatible_set() - Called when 'compatible' has been set or unset.
12287 *
12288 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12289 * flag) to a Vi compatible value.
12290 * When 'compatible' is unset: Set all options that have a different default
12291 * for Vim (without the P_VI_DEF flag) to that default.
12292 */
12293 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012294compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295{
12296 int opt_idx;
12297
12298 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12299 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12300 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12301 set_option_default(opt_idx, OPT_FREE, p_cp);
12302 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012303 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012304}
12305
12306#ifdef FEAT_LINEBREAK
12307
12308# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12309 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012310 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012311# endif
12312
12313/*
12314 * fill_breakat_flags() -- called when 'breakat' changes value.
12315 */
12316 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012317fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012318{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012319 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012320 int i;
12321
12322 for (i = 0; i < 256; i++)
12323 breakat_flags[i] = FALSE;
12324
12325 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012326 for (p = p_breakat; *p; p++)
12327 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012328}
12329
12330# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012331 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012332# endif
12333
12334#endif
12335
12336/*
12337 * Check an option that can be a range of string values.
12338 *
12339 * Return OK for correct value, FAIL otherwise.
12340 * Empty is always OK.
12341 */
12342 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012343check_opt_strings(
12344 char_u *val,
12345 char **values,
12346 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012347{
12348 return opt_strings_flags(val, values, NULL, list);
12349}
12350
12351/*
12352 * Handle an option that can be a range of string values.
12353 * Set a flag in "*flagp" for each string present.
12354 *
12355 * Return OK for correct value, FAIL otherwise.
12356 * Empty is always OK.
12357 */
12358 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012359opt_strings_flags(
12360 char_u *val, /* new value */
12361 char **values, /* array of valid string values */
12362 unsigned *flagp,
12363 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012364{
12365 int i;
12366 int len;
12367 unsigned new_flags = 0;
12368
12369 while (*val)
12370 {
12371 for (i = 0; ; ++i)
12372 {
12373 if (values[i] == NULL) /* val not found in values[] */
12374 return FAIL;
12375
12376 len = (int)STRLEN(values[i]);
12377 if (STRNCMP(values[i], val, len) == 0
12378 && ((list && val[len] == ',') || val[len] == NUL))
12379 {
12380 val += len + (val[len] == ',');
12381 new_flags |= (1 << i);
12382 break; /* check next item in val list */
12383 }
12384 }
12385 }
12386 if (flagp != NULL)
12387 *flagp = new_flags;
12388
12389 return OK;
12390}
12391
12392/*
12393 * Read the 'wildmode' option, fill wim_flags[].
12394 */
12395 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012396check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012397{
12398 char_u new_wim_flags[4];
12399 char_u *p;
12400 int i;
12401 int idx = 0;
12402
12403 for (i = 0; i < 4; ++i)
12404 new_wim_flags[i] = 0;
12405
12406 for (p = p_wim; *p; ++p)
12407 {
12408 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12409 ;
12410 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12411 return FAIL;
12412 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12413 new_wim_flags[idx] |= WIM_LONGEST;
12414 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12415 new_wim_flags[idx] |= WIM_FULL;
12416 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12417 new_wim_flags[idx] |= WIM_LIST;
12418 else
12419 return FAIL;
12420 p += i;
12421 if (*p == NUL)
12422 break;
12423 if (*p == ',')
12424 {
12425 if (idx == 3)
12426 return FAIL;
12427 ++idx;
12428 }
12429 }
12430
12431 /* fill remaining entries with last flag */
12432 while (idx < 3)
12433 {
12434 new_wim_flags[idx + 1] = new_wim_flags[idx];
12435 ++idx;
12436 }
12437
12438 /* only when there are no errors, wim_flags[] is changed */
12439 for (i = 0; i < 4; ++i)
12440 wim_flags[i] = new_wim_flags[i];
12441 return OK;
12442}
12443
12444/*
12445 * Check if backspacing over something is allowed.
12446 */
12447 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012448can_bs(
12449 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012450{
12451 switch (*p_bs)
12452 {
12453 case '2': return TRUE;
12454 case '1': return (what != BS_START);
12455 case '0': return FALSE;
12456 }
12457 return vim_strchr(p_bs, what) != NULL;
12458}
12459
12460/*
12461 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12462 * the file must be considered changed when the value is different.
12463 */
12464 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012465save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012466{
12467 buf->b_start_ffc = *buf->b_p_ff;
12468 buf->b_start_eol = buf->b_p_eol;
12469#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012470 buf->b_start_bomb = buf->b_p_bomb;
12471
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472 /* Only use free/alloc when necessary, they take time. */
12473 if (buf->b_start_fenc == NULL
12474 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12475 {
12476 vim_free(buf->b_start_fenc);
12477 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12478 }
12479#endif
12480}
12481
12482/*
12483 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12484 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012485 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12486 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012487 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012488 * When "ignore_empty" is true don't consider a new, empty buffer to be
12489 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012490 */
12491 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012492file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012493{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012494 /* In a buffer that was never loaded the options are not valid. */
12495 if (buf->b_flags & BF_NEVERLOADED)
12496 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012497 if (ignore_empty
12498 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012499 && buf->b_ml.ml_line_count == 1
12500 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12501 return FALSE;
12502 if (buf->b_start_ffc != *buf->b_p_ff)
12503 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012504 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012505 return TRUE;
12506#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012507 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12508 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012509 if (buf->b_start_fenc == NULL)
12510 return (*buf->b_p_fenc != NUL);
12511 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12512#else
12513 return FALSE;
12514#endif
12515}
12516
12517/*
12518 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12519 */
12520 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012521check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012522{
12523 return check_opt_strings(p, p_ff_values, FALSE);
12524}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012525
12526/*
12527 * Return the effective shiftwidth value for current buffer, using the
12528 * 'tabstop' value when 'shiftwidth' is zero.
12529 */
12530 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012531get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012532{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012533 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012534}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012535
12536/*
12537 * Return the effective softtabstop value for the current buffer, using the
12538 * 'tabstop' value when 'softtabstop' is negative.
12539 */
12540 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012541get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012542{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012543 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012544}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012545
12546/*
12547 * Check matchpairs option for "*initc".
12548 * If there is a match set "*initc" to the matching character and "*findc" to
12549 * the opposite character. Set "*backwards" to the direction.
12550 * When "switchit" is TRUE swap the direction.
12551 */
12552 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012553find_mps_values(
12554 int *initc,
12555 int *findc,
12556 int *backwards,
12557 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012558{
12559 char_u *ptr;
12560
12561 ptr = curbuf->b_p_mps;
12562 while (*ptr != NUL)
12563 {
12564#ifdef FEAT_MBYTE
12565 if (has_mbyte)
12566 {
12567 char_u *prev;
12568
12569 if (mb_ptr2char(ptr) == *initc)
12570 {
12571 if (switchit)
12572 {
12573 *findc = *initc;
12574 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12575 *backwards = TRUE;
12576 }
12577 else
12578 {
12579 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12580 *backwards = FALSE;
12581 }
12582 return;
12583 }
12584 prev = ptr;
12585 ptr += mb_ptr2len(ptr) + 1;
12586 if (mb_ptr2char(ptr) == *initc)
12587 {
12588 if (switchit)
12589 {
12590 *findc = *initc;
12591 *initc = mb_ptr2char(prev);
12592 *backwards = FALSE;
12593 }
12594 else
12595 {
12596 *findc = mb_ptr2char(prev);
12597 *backwards = TRUE;
12598 }
12599 return;
12600 }
12601 ptr += mb_ptr2len(ptr);
12602 }
12603 else
12604#endif
12605 {
12606 if (*ptr == *initc)
12607 {
12608 if (switchit)
12609 {
12610 *backwards = TRUE;
12611 *findc = *initc;
12612 *initc = ptr[2];
12613 }
12614 else
12615 {
12616 *backwards = FALSE;
12617 *findc = ptr[2];
12618 }
12619 return;
12620 }
12621 ptr += 2;
12622 if (*ptr == *initc)
12623 {
12624 if (switchit)
12625 {
12626 *backwards = FALSE;
12627 *findc = *initc;
12628 *initc = ptr[-2];
12629 }
12630 else
12631 {
12632 *backwards = TRUE;
12633 *findc = ptr[-2];
12634 }
12635 return;
12636 }
12637 ++ptr;
12638 }
12639 if (*ptr == ',')
12640 ++ptr;
12641 }
12642}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012643
12644#if defined(FEAT_LINEBREAK) || defined(PROTO)
12645/*
12646 * This is called when 'breakindentopt' is changed and when a window is
12647 * initialized.
12648 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012649 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012650briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012651{
12652 char_u *p;
12653 int bri_shift = 0;
12654 long bri_min = 20;
12655 int bri_sbr = FALSE;
12656
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012657 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012658 while (*p != NUL)
12659 {
12660 if (STRNCMP(p, "shift:", 6) == 0
12661 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12662 {
12663 p += 6;
12664 bri_shift = getdigits(&p);
12665 }
12666 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12667 {
12668 p += 4;
12669 bri_min = getdigits(&p);
12670 }
12671 else if (STRNCMP(p, "sbr", 3) == 0)
12672 {
12673 p += 3;
12674 bri_sbr = TRUE;
12675 }
12676 if (*p != ',' && *p != NUL)
12677 return FAIL;
12678 if (*p == ',')
12679 ++p;
12680 }
12681
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012682 wp->w_p_brishift = bri_shift;
12683 wp->w_p_brimin = bri_min;
12684 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012685
12686 return OK;
12687}
12688#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012689
12690/*
12691 * Get the local or global value of 'backupcopy'.
12692 */
12693 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012694get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012695{
12696 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12697}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012698
12699#if defined(FEAT_SIGNS) || defined(PROTO)
12700/*
12701 * Return TRUE when window "wp" has a column to draw signs in.
12702 */
12703 int
12704signcolumn_on(win_T *wp)
12705{
12706 if (*wp->w_p_scl == 'n')
12707 return FALSE;
12708 if (*wp->w_p_scl == 'y')
12709 return TRUE;
12710 return (wp->w_buffer->b_signlist != NULL
12711# ifdef FEAT_NETBEANS_INTG
12712 || wp->w_buffer->b_has_sign_column
12713# endif
12714 );
12715}
12716#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012717
12718#if defined(FEAT_EVAL) || defined(PROTO)
12719/*
12720 * Get window or buffer local options.
12721 */
12722 dict_T *
12723get_winbuf_options(int bufopt)
12724{
12725 dict_T *d;
12726 int opt_idx;
12727
12728 d = dict_alloc();
12729 if (d == NULL)
12730 return NULL;
12731
12732 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12733 {
12734 struct vimoption *opt = &options[opt_idx];
12735
12736 if ((bufopt && (opt->indir & PV_BUF))
12737 || (!bufopt && (opt->indir & PV_WIN)))
12738 {
12739 char_u *varp = get_varp(opt);
12740
12741 if (varp != NULL)
12742 {
12743 if (opt->flags & P_STRING)
12744 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012745 else if (opt->flags & P_NUM)
12746 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012747 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012748 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012749 }
12750 }
12751 }
12752
12753 return d;
12754}
12755#endif