blob: cac031e18419586b35b95e69dc35ce17a3c0d5f0 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
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.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * 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 Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000143#ifdef FEAT_COMPL_FUNC
144# define PV_OFU OPT_BUF(BV_OFU)
145#endif
146#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
147#define PV_PI OPT_BUF(BV_PI)
148#ifdef FEAT_TEXTOBJ
149# define PV_QE OPT_BUF(BV_QE)
150#endif
151#define PV_RO OPT_BUF(BV_RO)
152#ifdef FEAT_SMARTINDENT
153# define PV_SI OPT_BUF(BV_SI)
154#endif
155#ifndef SHORT_FNAME
156# define PV_SN OPT_BUF(BV_SN)
157#endif
158#ifdef FEAT_SYN_HL
159# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000160# define PV_SYN OPT_BUF(BV_SYN)
161#endif
162#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163# define PV_SPC OPT_BUF(BV_SPC)
164# define PV_SPF OPT_BUF(BV_SPF)
165# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166#endif
167#define PV_STS OPT_BUF(BV_STS)
168#ifdef FEAT_SEARCHPATH
169# define PV_SUA OPT_BUF(BV_SUA)
170#endif
171#define PV_SW OPT_BUF(BV_SW)
172#define PV_SWF OPT_BUF(BV_SWF)
173#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
174#define PV_TS OPT_BUF(BV_TS)
175#define PV_TW OPT_BUF(BV_TW)
176#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200177#ifdef FEAT_PERSISTENT_UNDO
178# define PV_UDF OPT_BUF(BV_UDF)
179#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000181
182/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183 * Definition of the PV_ values for window-local options.
184 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186#define PV_LIST OPT_WIN(WV_LIST)
187#ifdef FEAT_ARABIC
188# define PV_ARAB OPT_WIN(WV_ARAB)
189#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000190#ifdef FEAT_DIFF
191# define PV_DIFF OPT_WIN(WV_DIFF)
192#endif
193#ifdef FEAT_FOLDING
194# define PV_FDC OPT_WIN(WV_FDC)
195# define PV_FEN OPT_WIN(WV_FEN)
196# define PV_FDI OPT_WIN(WV_FDI)
197# define PV_FDL OPT_WIN(WV_FDL)
198# define PV_FDM OPT_WIN(WV_FDM)
199# define PV_FML OPT_WIN(WV_FML)
200# define PV_FDN OPT_WIN(WV_FDN)
201# ifdef FEAT_EVAL
202# define PV_FDE OPT_WIN(WV_FDE)
203# define PV_FDT OPT_WIN(WV_FDT)
204# endif
205# define PV_FMR OPT_WIN(WV_FMR)
206#endif
207#ifdef FEAT_LINEBREAK
208# define PV_LBR OPT_WIN(WV_LBR)
209#endif
210#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200211#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000212#ifdef FEAT_LINEBREAK
213# define PV_NUW OPT_WIN(WV_NUW)
214#endif
215#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
216# define PV_PVW OPT_WIN(WV_PVW)
217#endif
218#ifdef FEAT_RIGHTLEFT
219# define PV_RL OPT_WIN(WV_RL)
220# define PV_RLC OPT_WIN(WV_RLC)
221#endif
222#ifdef FEAT_SCROLLBIND
223# define PV_SCBIND OPT_WIN(WV_SCBIND)
224#endif
225#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000226#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000227# define PV_SPELL OPT_WIN(WV_SPELL)
228#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000229#ifdef FEAT_SYN_HL
230# define PV_CUC OPT_WIN(WV_CUC)
231# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200232# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234#ifdef FEAT_STL_OPT
235# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
236#endif
237#ifdef FEAT_WINDOWS
238# define PV_WFH OPT_WIN(WV_WFH)
239#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000240#ifdef FEAT_VERTSPLIT
241# define PV_WFW OPT_WIN(WV_WFW)
242#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000243#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200244#ifdef FEAT_CURSORBIND
245# define PV_CRBIND OPT_WIN(WV_CRBIND)
246#endif
247#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200248# define PV_COCU OPT_WIN(WV_COCU)
249# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200250#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000251
252/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253typedef enum
254{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000255 PV_NONE = 0,
256 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257} idopt_T;
258
259/*
260 * Options local to a window have a value local to a buffer and global to all
261 * buffers. Indicate this by setting "var" to VAR_WIN.
262 */
263#define VAR_WIN ((char_u *)-1)
264
265/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000266 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267 * Only to be used in option.c!
268 */
269static int p_ai;
270static int p_bin;
271#ifdef FEAT_MBYTE
272static int p_bomb;
273#endif
274#if defined(FEAT_QUICKFIX)
275static char_u *p_bh;
276static char_u *p_bt;
277#endif
278static int p_bl;
279static int p_ci;
280#ifdef FEAT_CINDENT
281static int p_cin;
282static char_u *p_cink;
283static char_u *p_cino;
284#endif
285#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
286static char_u *p_cinw;
287#endif
288#ifdef FEAT_COMMENTS
289static char_u *p_com;
290#endif
291#ifdef FEAT_FOLDING
292static char_u *p_cms;
293#endif
294#ifdef FEAT_INS_EXPAND
295static char_u *p_cpt;
296#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000297#ifdef FEAT_COMPL_FUNC
298static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000299static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000301static int p_eol;
302static int p_et;
303#ifdef FEAT_MBYTE
304static char_u *p_fenc;
305#endif
306static char_u *p_ff;
307static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000308static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309#ifdef FEAT_AUTOCMD
310static char_u *p_ft;
311#endif
312static long p_iminsert;
313static long p_imsearch;
314#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
315static char_u *p_inex;
316#endif
317#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
318static char_u *p_inde;
319static char_u *p_indk;
320#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000321#if defined(FEAT_EVAL)
322static char_u *p_fex;
323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324static int p_inf;
325static char_u *p_isk;
326#ifdef FEAT_CRYPT
327static char_u *p_key;
328#endif
329#ifdef FEAT_LISP
330static int p_lisp;
331#endif
332static int p_ml;
333static int p_ma;
334static int p_mod;
335static char_u *p_mps;
336static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000338#ifdef FEAT_TEXTOBJ
339static char_u *p_qe;
340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000341static int p_ro;
342#ifdef FEAT_SMARTINDENT
343static int p_si;
344#endif
345#ifndef SHORT_FNAME
346static int p_sn;
347#endif
348static long p_sts;
349#if defined(FEAT_SEARCHPATH)
350static char_u *p_sua;
351#endif
352static long p_sw;
353static int p_swf;
354#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000355static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000357#endif
358#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000359static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000360static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000361static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362#endif
363static long p_ts;
364static long p_tw;
365static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200366#ifdef FEAT_PERSISTENT_UNDO
367static int p_udf;
368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static long p_wm;
370#ifdef FEAT_KEYMAP
371static char_u *p_keymap;
372#endif
373
374/* Saved values for when 'bin' is set. */
375static int p_et_nobin;
376static int p_ml_nobin;
377static long p_tw_nobin;
378static long p_wm_nobin;
379
380/* Saved values for when 'paste' is set */
381static long p_tw_nopaste;
382static long p_wm_nopaste;
383static long p_sts_nopaste;
384static int p_ai_nopaste;
385
386struct vimoption
387{
388 char *fullname; /* full option name */
389 char *shortname; /* permissible abbreviation */
390 long_u flags; /* see below */
391 char_u *var; /* global option: pointer to variable;
392 * window-local option: VAR_WIN;
393 * buffer-local option: global value */
394 idopt_T indir; /* global option: PV_NONE;
395 * local option: indirect option index */
396 char_u *def_val[2]; /* default values for variable (vi and vim) */
397#ifdef FEAT_EVAL
398 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000399# define SCRIPTID_INIT , 0
400#else
401# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402#endif
403};
404
405#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
406#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
407
408/*
409 * Flags
410 */
411#define P_BOOL 0x01 /* the option is boolean */
412#define P_NUM 0x02 /* the option is numeric */
413#define P_STRING 0x04 /* the option is a string */
414#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000415 must use free_string_option() when
416 assigning new value. Not set if default is
417 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000418#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
419 never be used for local or hidden options! */
420#define P_NODEFAULT 0x40 /* don't set to default value */
421#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
422 use vim_free() when assigning new value */
423#define P_WAS_SET 0x100 /* option has been set/reset */
424#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
425#define P_VI_DEF 0x400 /* Use Vi default for Vim */
426#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
427
428 /* when option changed, what to display: */
429#define P_RSTAT 0x1000 /* redraw status lines */
430#define P_RWIN 0x2000 /* redraw current window */
431#define P_RBUF 0x4000 /* redraw current buffer */
432#define P_RALL 0x6000 /* redraw all windows */
433#define P_RCLR 0x7000 /* clear and redraw all */
434
435#define P_COMMA 0x8000 /* comma separated list */
436#define P_NODUP 0x10000L/* don't allow duplicate strings */
437#define P_FLAGLIST 0x20000L/* list of single-char flags */
438
439#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
440#define P_GETTEXT 0x80000L/* expand default value with _() */
441#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000442#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000443#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000444#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
445 side effects) */
Bram Moolenaar865242e2010-07-14 21:12:05 +0200446#define P_NO_ML 0x1000000L/* not allowed in modeline */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000447
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000448#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
449
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000450/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
451 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000452#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000453# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000454#else
455# define ISP_LATIN1 (char_u *)"@,161-255"
456#endif
457
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000458/* The 16 bit MS-DOS version is low on space, make the string as short as
459 * possible when compiling with few features. */
460#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
461 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200462 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200463# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,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"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000464#else
465# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
466#endif
467
Bram Moolenaar071d4272004-06-13 20:20:40 +0000468/*
469 * options[] is initialized here.
470 * The order of the options MUST be alphabetic for ":set all" and findoption().
471 * All option names MUST start with a lowercase letter (for findoption()).
472 * Exception: "t_" options are at the end.
473 * The options with a NULL variable are 'hidden': a set command for them is
474 * ignored and they are not printed.
475 */
476static struct vimoption
477#ifdef FEAT_GUI_W16
478 _far
479#endif
480 options[] =
481{
482 {"aleph", "al", P_NUM|P_VI_DEF,
483#ifdef FEAT_RIGHTLEFT
484 (char_u *)&p_aleph, PV_NONE,
485#else
486 (char_u *)NULL, PV_NONE,
487#endif
488 {
489#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
490 (char_u *)128L,
491#else
492 (char_u *)224L,
493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000494 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000495 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
496#if defined(FEAT_GUI) && defined(MACOS_X)
497 (char_u *)&p_antialias, PV_NONE,
498 {(char_u *)FALSE, (char_u *)FALSE}
499#else
500 (char_u *)NULL, PV_NONE,
501 {(char_u *)FALSE, (char_u *)FALSE}
502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000503 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
505#ifdef FEAT_ARABIC
506 (char_u *)VAR_WIN, PV_ARAB,
507#else
508 (char_u *)NULL, PV_NONE,
509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000510 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
512#ifdef FEAT_ARABIC
513 (char_u *)&p_arshape, PV_NONE,
514#else
515 (char_u *)NULL, PV_NONE,
516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000517 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
519#ifdef FEAT_RIGHTLEFT
520 (char_u *)&p_ari, PV_NONE,
521#else
522 (char_u *)NULL, PV_NONE,
523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000524 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
526#ifdef FEAT_FKMAP
527 (char_u *)&p_altkeymap, PV_NONE,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
533#if defined(FEAT_MBYTE)
534 (char_u *)&p_ambw, PV_NONE,
535 {(char_u *)"single", (char_u *)0L}
536#else
537 (char_u *)NULL, PV_NONE,
538 {(char_u *)0L, (char_u *)0L}
539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000540 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000541#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"autochdir", "acd", P_BOOL|P_VI_DEF,
543 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545#endif
546 {"autoindent", "ai", P_BOOL|P_VI_DEF,
547 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"autoprint", "ap", P_BOOL|P_VI_DEF,
550 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000553 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 {"autowrite", "aw", P_BOOL|P_VI_DEF,
556 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autowriteall","awa", P_BOOL|P_VI_DEF,
559 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
562 (char_u *)&p_bg, PV_NONE,
563 {
564#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
565 (char_u *)"dark",
566#else
567 (char_u *)"light",
568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
571 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
574 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
577 (char_u *)&p_bkc, PV_NONE,
578#ifdef UNIX
579 {(char_u *)"yes", (char_u *)"auto"}
580#else
581 {(char_u *)"auto", (char_u *)"auto"}
582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
585 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000587 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 (char_u *)&p_bex, PV_NONE,
589 {
590#ifdef VMS
591 (char_u *)"_",
592#else
593 (char_u *)"~",
594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000595 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
597#ifdef FEAT_WILDIGN
598 (char_u *)&p_bsk, PV_NONE,
599 {(char_u *)"", (char_u *)0L}
600#else
601 (char_u *)NULL, PV_NONE,
602 {(char_u *)0L, (char_u *)0L}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605#ifdef FEAT_BEVAL
606 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
607 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
610 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000612# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000613 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000614 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000616# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617#endif
618 {"beautify", "bf", P_BOOL|P_VI_DEF,
619 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
622 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
625#ifdef MSDOS
626 (char_u *)&p_biosk, PV_NONE,
627#else
628 (char_u *)NULL, PV_NONE,
629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000630 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
632#ifdef FEAT_MBYTE
633 (char_u *)&p_bomb, PV_BOMB,
634#else
635 (char_u *)NULL, PV_NONE,
636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
639#ifdef FEAT_LINEBREAK
640 (char_u *)&p_breakat, PV_NONE,
641 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
648#ifdef FEAT_BROWSE
649 (char_u *)&p_bsdir, PV_NONE,
650 {(char_u *)"last", (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000655 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
657#if defined(FEAT_QUICKFIX)
658 (char_u *)&p_bh, PV_BH,
659 {(char_u *)"", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
666 (char_u *)&p_bl, PV_BL,
667 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000668 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
670#if defined(FEAT_QUICKFIX)
671 (char_u *)&p_bt, PV_BT,
672 {(char_u *)"", (char_u *)0L}
673#else
674 (char_u *)NULL, PV_NONE,
675 {(char_u *)0L, (char_u *)0L}
676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000677 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000679#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 (char_u *)&p_cmp, PV_NONE,
681 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000682#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 Moolenaar071d4272004-06-13 20:20:40 +0000687 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
688#ifdef FEAT_SEARCHPATH
689 (char_u *)&p_cdpath, PV_NONE,
690 {(char_u *)",,", (char_u *)0L}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 {"cedit", NULL, P_STRING,
697#ifdef FEAT_CMDWIN
698 (char_u *)&p_cedit, PV_NONE,
699 {(char_u *)"", (char_u *)CTRL_F_STR}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)0L, (char_u *)0L}
703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
706#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
707 (char_u *)&p_ccv, PV_NONE,
708 {(char_u *)"", (char_u *)0L}
709#else
710 (char_u *)NULL, PV_NONE,
711 {(char_u *)0L, (char_u *)0L}
712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
715#ifdef FEAT_CINDENT
716 (char_u *)&p_cin, PV_CIN,
717#else
718 (char_u *)NULL, PV_NONE,
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
722#ifdef FEAT_CINDENT
723 (char_u *)&p_cink, PV_CINK,
724 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
725#else
726 (char_u *)NULL, PV_NONE,
727 {(char_u *)0L, (char_u *)0L}
728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
731#ifdef FEAT_CINDENT
732 (char_u *)&p_cino, PV_CINO,
733#else
734 (char_u *)NULL, PV_NONE,
735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000736 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
738#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
739 (char_u *)&p_cinw, PV_CINW,
740 {(char_u *)"if,else,while,do,for,switch",
741 (char_u *)0L}
742#else
743 (char_u *)NULL, PV_NONE,
744 {(char_u *)0L, (char_u *)0L}
745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000746 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
748#ifdef FEAT_CLIPBOARD
749 (char_u *)&p_cb, PV_NONE,
750# ifdef FEAT_XCLIPBOARD
751 {(char_u *)"autoselect,exclude:cons\\|linux",
752 (char_u *)0L}
753# else
754 {(char_u *)"", (char_u *)0L}
755# endif
756#else
757 (char_u *)NULL, PV_NONE,
758 {(char_u *)"", (char_u *)0L}
759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000760 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
762 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000763 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
765#ifdef FEAT_CMDWIN
766 (char_u *)&p_cwh, PV_NONE,
767#else
768 (char_u *)NULL, PV_NONE,
769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000770 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200771 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
772#ifdef FEAT_SYN_HL
773 (char_u *)VAR_WIN, PV_CC,
774#else
775 (char_u *)NULL, PV_NONE,
776#endif
777 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
779 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000780 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000781 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
782#ifdef FEAT_COMMENTS
783 (char_u *)&p_com, PV_COM,
784 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
785 (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
792#ifdef FEAT_FOLDING
793 (char_u *)&p_cms, PV_CMS,
794 {(char_u *)"/*%s*/", (char_u *)0L}
795#else
796 (char_u *)NULL, PV_NONE,
797 {(char_u *)0L, (char_u *)0L}
798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000799 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000800 /* P_PRI_MKRC isn't needed here, optval_default()
801 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802 {"compatible", "cp", P_BOOL|P_RALL,
803 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
806#ifdef FEAT_INS_EXPAND
807 (char_u *)&p_cpt, PV_CPT,
808 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
809#else
810 (char_u *)NULL, PV_NONE,
811 {(char_u *)0L, (char_u *)0L}
812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000813 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200814 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200815#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200816 (char_u *)VAR_WIN, PV_COCU,
817 {(char_u *)"", (char_u *)NULL}
818#else
819 (char_u *)NULL, PV_NONE,
820 {(char_u *)NULL, (char_u *)0L}
821#endif
822 SCRIPTID_INIT},
823 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
824#ifdef FEAT_CONCEAL
825 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200826#else
827 (char_u *)NULL, PV_NONE,
828#endif
829 {(char_u *)0L, (char_u *)0L}
830 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000831 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
832#ifdef FEAT_COMPL_FUNC
833 (char_u *)&p_cfu, PV_CFU,
834 {(char_u *)"", (char_u *)0L}
835#else
836 (char_u *)NULL, PV_NONE,
837 {(char_u *)0L, (char_u *)0L}
838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000840 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
841#ifdef FEAT_INS_EXPAND
842 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000843 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000844#else
845 (char_u *)NULL, PV_NONE,
846 {(char_u *)0L, (char_u *)0L}
847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000848 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849 {"confirm", "cf", P_BOOL|P_VI_DEF,
850#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
851 (char_u *)&p_confirm, PV_NONE,
852#else
853 (char_u *)NULL, PV_NONE,
854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856 {"conskey", "consk",P_BOOL|P_VI_DEF,
857#ifdef MSDOS
858 (char_u *)&p_consk, PV_NONE,
859#else
860 (char_u *)NULL, PV_NONE,
861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000863 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
864 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000865 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000866 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
867 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000868 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
869 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200870 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200871#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200872 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200873 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200874#else
875 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200876 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200877#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000879 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
880#ifdef FEAT_CSCOPE
881 (char_u *)&p_cspc, PV_NONE,
882#else
883 (char_u *)NULL, PV_NONE,
884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
887#ifdef FEAT_CSCOPE
888 (char_u *)&p_csprg, PV_NONE,
889 {(char_u *)"cscope", (char_u *)0L}
890#else
891 (char_u *)NULL, PV_NONE,
892 {(char_u *)0L, (char_u *)0L}
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
896#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
897 (char_u *)&p_csqf, PV_NONE,
898 {(char_u *)"", (char_u *)0L}
899#else
900 (char_u *)NULL, PV_NONE,
901 {(char_u *)0L, (char_u *)0L}
902#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200904 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
905#ifdef FEAT_CSCOPE
906 (char_u *)&p_csre, PV_NONE,
907#else
908 (char_u *)NULL, PV_NONE,
909#endif
910 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
912#ifdef FEAT_CSCOPE
913 (char_u *)&p_cst, PV_NONE,
914#else
915 (char_u *)NULL, PV_NONE,
916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
919#ifdef FEAT_CSCOPE
920 (char_u *)&p_csto, PV_NONE,
921#else
922 (char_u *)NULL, PV_NONE,
923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000924 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
926#ifdef FEAT_CSCOPE
927 (char_u *)&p_csverbose, 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 Moolenaar860cae12010-06-05 23:22:07 +0200932 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
933#ifdef FEAT_CURSORBIND
934 (char_u *)VAR_WIN, PV_CRBIND,
935#else
936 (char_u *)NULL, PV_NONE,
937#endif
938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000939 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
940#ifdef FEAT_SYN_HL
941 (char_u *)VAR_WIN, PV_CUC,
942#else
943 (char_u *)NULL, PV_NONE,
944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000945 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000946 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
947#ifdef FEAT_SYN_HL
948 (char_u *)VAR_WIN, PV_CUL,
949#else
950 (char_u *)NULL, PV_NONE,
951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000952 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"debug", NULL, P_STRING|P_VI_DEF,
954 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000955 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
957#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000958 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000959 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960#else
961 (char_u *)NULL, PV_NONE,
962 {(char_u *)NULL, (char_u *)0L}
963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000964 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000965 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
966#ifdef FEAT_MBYTE
967 (char_u *)&p_deco, PV_NONE,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000971 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000972 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
973#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000974 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000978 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
980#ifdef FEAT_DIFF
981 (char_u *)VAR_WIN, PV_DIFF,
982#else
983 (char_u *)NULL, PV_NONE,
984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000985 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
987#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
988 (char_u *)&p_dex, PV_NONE,
989 {(char_u *)"", (char_u *)0L}
990#else
991 (char_u *)NULL, PV_NONE,
992 {(char_u *)0L, (char_u *)0L}
993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
996#ifdef FEAT_DIFF
997 (char_u *)&p_dip, PV_NONE,
998 {(char_u *)"filler", (char_u *)NULL}
999#else
1000 (char_u *)NULL, PV_NONE,
1001 {(char_u *)"", (char_u *)NULL}
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1005#ifdef FEAT_DIGRAPHS
1006 (char_u *)&p_dg, PV_NONE,
1007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1012 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1015 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"eadirection", "ead", P_STRING|P_VI_DEF,
1018#ifdef FEAT_VERTSPLIT
1019 (char_u *)&p_ead, PV_NONE,
1020 {(char_u *)"both", (char_u *)0L}
1021#else
1022 (char_u *)NULL, PV_NONE,
1023 {(char_u *)NULL, (char_u *)0L}
1024#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001025 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1027 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001028 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001029 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030#ifdef FEAT_MBYTE
1031 (char_u *)&p_enc, PV_NONE,
1032 {(char_u *)ENC_DFLT, (char_u *)0L}
1033#else
1034 (char_u *)NULL, PV_NONE,
1035 {(char_u *)0L, (char_u *)0L}
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1039 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001040 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1042 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001045 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1048 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001049 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1051#ifdef FEAT_QUICKFIX
1052 (char_u *)&p_ef, PV_NONE,
1053 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1054#else
1055 (char_u *)NULL, PV_NONE,
1056 {(char_u *)NULL, (char_u *)0L}
1057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001058 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1060#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001061 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063#else
1064 (char_u *)NULL, PV_NONE,
1065 {(char_u *)NULL, (char_u *)0L}
1066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"esckeys", "ek", P_BOOL|P_VIM,
1069 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1072#ifdef FEAT_AUTOCMD
1073 (char_u *)&p_ei, PV_NONE,
1074#else
1075 (char_u *)NULL, PV_NONE,
1076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1079 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1082 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1085#ifdef FEAT_MBYTE
1086 (char_u *)&p_fenc, PV_FENC,
1087 {(char_u *)"", (char_u *)0L}
1088#else
1089 (char_u *)NULL, PV_NONE,
1090 {(char_u *)0L, (char_u *)0L}
1091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001092 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1094#ifdef FEAT_MBYTE
1095 (char_u *)&p_fencs, PV_NONE,
1096 {(char_u *)"ucs-bom", (char_u *)0L}
1097#else
1098 (char_u *)NULL, PV_NONE,
1099 {(char_u *)0L, (char_u *)0L}
1100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1103 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1106 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1108 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001109 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110#ifdef FEAT_AUTOCMD
1111 (char_u *)&p_ft, PV_FT,
1112 {(char_u *)"", (char_u *)0L}
1113#else
1114 (char_u *)NULL, PV_NONE,
1115 {(char_u *)0L, (char_u *)0L}
1116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1119#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1120 (char_u *)&p_fcs, PV_NONE,
1121 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1122#else
1123 (char_u *)NULL, PV_NONE,
1124 {(char_u *)"", (char_u *)0L}
1125#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1128#ifdef FEAT_FKMAP
1129 (char_u *)&p_fkmap, PV_NONE,
1130#else
1131 (char_u *)NULL, PV_NONE,
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"flash", "fl", P_BOOL|P_VI_DEF,
1135 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137#ifdef FEAT_FOLDING
1138 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1139 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1142 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1145 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1148# ifdef FEAT_EVAL
1149 (char_u *)VAR_WIN, PV_FDE,
1150 {(char_u *)"0", (char_u *)NULL}
1151# else
1152 (char_u *)NULL, PV_NONE,
1153 {(char_u *)NULL, (char_u *)0L}
1154# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001155 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1157 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001158 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1160 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001161 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1163 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001164 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1166 P_RWIN|P_COMMA|P_NODUP,
1167 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)"{{{,}}}", (char_u *)NULL}
1169 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001170 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1171 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1174 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1177 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1180 (char_u *)&p_fdo, PV_NONE,
1181 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001182 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1184# ifdef FEAT_EVAL
1185 (char_u *)VAR_WIN, PV_FDT,
1186 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001187# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001190# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001193 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001194#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001195 (char_u *)&p_fex, PV_FEX,
1196 {(char_u *)"", (char_u *)0L}
1197#else
1198 (char_u *)NULL, PV_NONE,
1199 {(char_u *)0L, (char_u *)0L}
1200#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001202 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1203 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001204 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1205 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001206 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1207 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001208 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1209 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1211 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001213 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1214#ifdef HAVE_FSYNC
1215 (char_u *)&p_fs, PV_NONE,
1216 {(char_u *)TRUE, (char_u *)0L}
1217#else
1218 (char_u *)NULL, PV_NONE,
1219 {(char_u *)FALSE, (char_u *)0L}
1220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1223 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001224 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 {"graphic", "gr", P_BOOL|P_VI_DEF,
1226 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1229#ifdef FEAT_QUICKFIX
1230 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001231 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232#else
1233 (char_u *)NULL, PV_NONE,
1234 {(char_u *)NULL, (char_u *)0L}
1235#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1238#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001239 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 {
1241# ifdef WIN3264
1242 /* may be changed to "grep -n" in os_win32.c */
1243 (char_u *)"findstr /n",
1244# else
1245# ifdef UNIX
1246 /* Add an extra file name so that grep will always
1247 * insert a file name in the match line. */
1248 (char_u *)"grep -n $* /dev/null",
1249# else
1250# ifdef VMS
1251 (char_u *)"SEARCH/NUMBERS ",
1252# else
1253 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001254# endif
1255# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001257 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258#else
1259 (char_u *)NULL, PV_NONE,
1260 {(char_u *)NULL, (char_u *)0L}
1261#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001262 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1264#ifdef CURSOR_SHAPE
1265 (char_u *)&p_guicursor, PV_NONE,
1266 {
1267# ifdef FEAT_GUI
1268 (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",
1269# else /* MSDOS or Win32 console */
1270 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1271# endif
1272 (char_u *)0L}
1273#else
1274 (char_u *)NULL, PV_NONE,
1275 {(char_u *)NULL, (char_u *)0L}
1276#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001277 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001278 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1279#ifdef FEAT_GUI
1280 (char_u *)&p_guifont, PV_NONE,
1281 {(char_u *)"", (char_u *)0L}
1282#else
1283 (char_u *)NULL, PV_NONE,
1284 {(char_u *)NULL, (char_u *)0L}
1285#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1288#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1289 (char_u *)&p_guifontset, PV_NONE,
1290 {(char_u *)"", (char_u *)0L}
1291#else
1292 (char_u *)NULL, PV_NONE,
1293 {(char_u *)NULL, (char_u *)0L}
1294#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001295 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001296 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1297#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1298 (char_u *)&p_guifontwide, PV_NONE,
1299 {(char_u *)"", (char_u *)0L}
1300#else
1301 (char_u *)NULL, PV_NONE,
1302 {(char_u *)NULL, (char_u *)0L}
1303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001304 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001306#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307 (char_u *)&p_ghr, PV_NONE,
1308#else
1309 (char_u *)NULL, PV_NONE,
1310#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001311 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001313#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 (char_u *)&p_go, PV_NONE,
1315# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001316 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001318 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319# endif
1320#else
1321 (char_u *)NULL, PV_NONE,
1322 {(char_u *)NULL, (char_u *)0L}
1323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001324 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {"guipty", NULL, P_BOOL|P_VI_DEF,
1326#if defined(FEAT_GUI)
1327 (char_u *)&p_guipty, PV_NONE,
1328#else
1329 (char_u *)NULL, PV_NONE,
1330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001332 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001333#if defined(FEAT_GUI_TABLINE)
1334 (char_u *)&p_gtl, PV_NONE,
1335 {(char_u *)"", (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)NULL, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001341 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001342#if defined(FEAT_GUI_TABLINE)
1343 (char_u *)&p_gtt, PV_NONE,
1344 {(char_u *)"", (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)NULL, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1351 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1354 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1356 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 {"helpheight", "hh", P_NUM|P_VI_DEF,
1358#ifdef FEAT_WINDOWS
1359 (char_u *)&p_hh, PV_NONE,
1360#else
1361 (char_u *)NULL, PV_NONE,
1362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001363 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1365#ifdef FEAT_MULTI_LANG
1366 (char_u *)&p_hlg, PV_NONE,
1367 {(char_u *)"", (char_u *)0L}
1368#else
1369 (char_u *)NULL, PV_NONE,
1370 {(char_u *)0L, (char_u *)0L}
1371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001372 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373 {"hidden", "hid", P_BOOL|P_VI_DEF,
1374 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1377 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001378 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1379 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {"history", "hi", P_NUM|P_VIM,
1381 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1384#ifdef FEAT_RIGHTLEFT
1385 (char_u *)&p_hkmap, PV_NONE,
1386#else
1387 (char_u *)NULL, PV_NONE,
1388#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001389 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1391#ifdef FEAT_RIGHTLEFT
1392 (char_u *)&p_hkmapp, PV_NONE,
1393#else
1394 (char_u *)NULL, PV_NONE,
1395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001396 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001397 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1398 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001400 {"icon", NULL, P_BOOL|P_VI_DEF,
1401#ifdef FEAT_TITLE
1402 (char_u *)&p_icon, PV_NONE,
1403#else
1404 (char_u *)NULL, PV_NONE,
1405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407 {"iconstring", NULL, P_STRING|P_VI_DEF,
1408#ifdef FEAT_TITLE
1409 (char_u *)&p_iconstring, PV_NONE,
1410#else
1411 (char_u *)NULL, PV_NONE,
1412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001413 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1415 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001416 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001418#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 (char_u *)&p_imak, PV_NONE,
1420#else
1421 (char_u *)NULL, PV_NONE,
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1425#ifdef USE_IM_CONTROL
1426 (char_u *)&p_imcmdline, PV_NONE,
1427#else
1428 (char_u *)NULL, PV_NONE,
1429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001430 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1432#ifdef USE_IM_CONTROL
1433 (char_u *)&p_imdisable, PV_NONE,
1434#else
1435 (char_u *)NULL, PV_NONE,
1436#endif
1437#ifdef __sgi
1438 {(char_u *)TRUE, (char_u *)0L}
1439#else
1440 {(char_u *)FALSE, (char_u *)0L}
1441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001442 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443 {"iminsert", "imi", P_NUM|P_VI_DEF,
1444 (char_u *)&p_iminsert, PV_IMI,
1445#ifdef B_IMODE_IM
1446 {(char_u *)B_IMODE_IM, (char_u *)0L}
1447#else
1448 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"imsearch", "ims", P_NUM|P_VI_DEF,
1452 (char_u *)&p_imsearch, PV_IMS,
1453#ifdef B_IMODE_IM
1454 {(char_u *)B_IMODE_IM, (char_u *)0L}
1455#else
1456 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1460#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001461 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1463#else
1464 (char_u *)NULL, PV_NONE,
1465 {(char_u *)0L, (char_u *)0L}
1466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1469#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1470 (char_u *)&p_inex, PV_INEX,
1471 {(char_u *)"", (char_u *)0L}
1472#else
1473 (char_u *)NULL, PV_NONE,
1474 {(char_u *)0L, (char_u *)0L}
1475#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001476 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1478 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001479 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1481#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1482 (char_u *)&p_inde, PV_INDE,
1483 {(char_u *)"", (char_u *)0L}
1484#else
1485 (char_u *)NULL, PV_NONE,
1486 {(char_u *)0L, (char_u *)0L}
1487#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001488 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1490#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1491 (char_u *)&p_indk, PV_INDK,
1492 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1493#else
1494 (char_u *)NULL, PV_NONE,
1495 {(char_u *)0L, (char_u *)0L}
1496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001497 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {"infercase", "inf", P_BOOL|P_VI_DEF,
1499 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001500 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1502 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1505 (char_u *)&p_isf, PV_NONE,
1506 {
1507#ifdef BACKSLASH_IN_FILENAME
1508 /* Excluded are: & and ^ are special in cmd.exe
1509 * ( and ) are used in text separating fnames */
1510 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1511#else
1512# ifdef AMIGA
1513 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1514# else
1515# ifdef VMS
1516 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1517# else /* UNIX et al. */
1518# ifdef EBCDIC
1519 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1520# else
1521 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1522# endif
1523# endif
1524# endif
1525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001526 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001527 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1528 (char_u *)&p_isi, PV_NONE,
1529 {
1530#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1531 (char_u *)"@,48-57,_,128-167,224-235",
1532#else
1533# ifdef EBCDIC
1534 /* TODO: EBCDIC Check this! @ == isalpha()*/
1535 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1536 "112-120,128,140-142,156,158,172,"
1537 "174,186,191,203-207,219-225,235-239,"
1538 "251-254",
1539# else
1540 (char_u *)"@,48-57,_,192-255",
1541# endif
1542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001543 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1545 (char_u *)&p_isk, PV_ISK,
1546 {
1547#ifdef EBCDIC
1548 (char_u *)"@,240-249,_",
1549 /* TODO: EBCDIC Check this! @ == isalpha()*/
1550 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1551 "112-120,128,140-142,156,158,172,"
1552 "174,186,191,203-207,219-225,235-239,"
1553 "251-254",
1554#else
1555 (char_u *)"@,48-57,_",
1556# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1557 (char_u *)"@,48-57,_,128-167,224-235"
1558# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001559 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001560# endif
1561#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1564 (char_u *)&p_isp, PV_NONE,
1565 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001566#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1567 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 || defined(VMS)
1569 (char_u *)"@,~-255",
1570#else
1571# ifdef EBCDIC
1572 /* all chars above 63 are printable */
1573 (char_u *)"63-255",
1574# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001575 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576# endif
1577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001578 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1580 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001581 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001582 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1583#ifdef FEAT_CRYPT
1584 (char_u *)&p_key, PV_KEY,
1585 {(char_u *)"", (char_u *)0L}
1586#else
1587 (char_u *)NULL, PV_NONE,
1588 {(char_u *)0L, (char_u *)0L}
1589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001590 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001591 {"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 +00001592#ifdef FEAT_KEYMAP
1593 (char_u *)&p_keymap, PV_KMAP,
1594 {(char_u *)"", (char_u *)0L}
1595#else
1596 (char_u *)NULL, PV_NONE,
1597 {(char_u *)"", (char_u *)0L}
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1601#ifdef FEAT_VISUAL
1602 (char_u *)&p_km, PV_NONE,
1603#else
1604 (char_u *)NULL, PV_NONE,
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001608 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001609 {
1610#if defined(MSDOS) || defined(MSWIN)
1611 (char_u *)":help",
1612#else
1613#ifdef VMS
1614 (char_u *)"help",
1615#else
1616# if defined(OS2)
1617 (char_u *)"view /",
1618# else
1619# ifdef USEMAN_S
1620 (char_u *)"man -s",
1621# else
1622 (char_u *)"man",
1623# endif
1624# endif
1625#endif
1626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001627 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001628 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1629#ifdef FEAT_LANGMAP
1630 (char_u *)&p_langmap, PV_NONE,
1631 {(char_u *)"", /* unmatched } */
1632#else
1633 (char_u *)NULL, PV_NONE,
1634 {(char_u *)NULL,
1635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001636 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001637 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1639 (char_u *)&p_lm, PV_NONE,
1640#else
1641 (char_u *)NULL, PV_NONE,
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1645#ifdef FEAT_WINDOWS
1646 (char_u *)&p_ls, PV_NONE,
1647#else
1648 (char_u *)NULL, PV_NONE,
1649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001650 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1652 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001653 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1655#ifdef FEAT_LINEBREAK
1656 (char_u *)VAR_WIN, PV_LBR,
1657#else
1658 (char_u *)NULL, PV_NONE,
1659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001660 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1662 (char_u *)&Rows, PV_NONE,
1663 {
1664#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1665 (char_u *)25L,
1666#else
1667 (char_u *)24L,
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1671#ifdef FEAT_GUI
1672 (char_u *)&p_linespace, PV_NONE,
1673#else
1674 (char_u *)NULL, PV_NONE,
1675#endif
1676#ifdef FEAT_GUI_W32
1677 {(char_u *)1L, (char_u *)0L}
1678#else
1679 {(char_u *)0L, (char_u *)0L}
1680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {"lisp", NULL, P_BOOL|P_VI_DEF,
1683#ifdef FEAT_LISP
1684 (char_u *)&p_lisp, PV_LISP,
1685#else
1686 (char_u *)NULL, PV_NONE,
1687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001688 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1690#ifdef FEAT_LISP
1691 (char_u *)&p_lispwords, PV_NONE,
1692 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1693#else
1694 (char_u *)NULL, PV_NONE,
1695 {(char_u *)"", (char_u *)0L}
1696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001697 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1699 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1702 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001703 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1705 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001706 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001707#ifdef FEAT_GUI_MAC
1708 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1709 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"magic", NULL, P_BOOL|P_VI_DEF,
1713 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001715 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716#ifdef FEAT_QUICKFIX
1717 (char_u *)&p_mef, PV_NONE,
1718 {(char_u *)"", (char_u *)0L}
1719#else
1720 (char_u *)NULL, PV_NONE,
1721 {(char_u *)NULL, (char_u *)0L}
1722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001723 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1725#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001726 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727# ifdef VMS
1728 {(char_u *)"MMS", (char_u *)0L}
1729# else
1730 {(char_u *)"make", (char_u *)0L}
1731# endif
1732#else
1733 (char_u *)NULL, PV_NONE,
1734 {(char_u *)NULL, (char_u *)0L}
1735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001736 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1738 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001739 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1740 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {"matchtime", "mat", P_NUM|P_VI_DEF,
1742 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001744 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1745#ifdef FEAT_MBYTE
1746 (char_u *)&p_mco, PV_NONE,
1747#else
1748 (char_u *)NULL, PV_NONE,
1749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001750 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1752#ifdef FEAT_EVAL
1753 (char_u *)&p_mfd, PV_NONE,
1754#else
1755 (char_u *)NULL, PV_NONE,
1756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001757 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1759 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"maxmem", "mm", P_NUM|P_VI_DEF,
1762 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1764 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001765 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1766 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1769 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1771 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"menuitems", "mis", P_NUM|P_VI_DEF,
1773#ifdef FEAT_MENU
1774 (char_u *)&p_mis, PV_NONE,
1775#else
1776 (char_u *)NULL, PV_NONE,
1777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001778 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {"mesg", NULL, P_BOOL|P_VI_DEF,
1780 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001781 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001782 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001783#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001784 (char_u *)&p_msm, PV_NONE,
1785 {(char_u *)"460000,2000,500", (char_u *)0L}
1786#else
1787 (char_u *)NULL, PV_NONE,
1788 {(char_u *)0L, (char_u *)0L}
1789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"modeline", "ml", P_BOOL|P_VIM,
1792 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"modelines", "mls", P_NUM|P_VI_DEF,
1795 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1798 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001799 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1801 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001802 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"more", NULL, P_BOOL|P_VIM,
1804 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001805 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001806 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1807 (char_u *)&p_mouse, PV_NONE,
1808 {
1809#if defined(MSDOS) || defined(WIN3264)
1810 (char_u *)"a",
1811#else
1812 (char_u *)"",
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1816#ifdef FEAT_GUI
1817 (char_u *)&p_mousef, PV_NONE,
1818#else
1819 (char_u *)NULL, PV_NONE,
1820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1823#ifdef FEAT_GUI
1824 (char_u *)&p_mh, PV_NONE,
1825#else
1826 (char_u *)NULL, PV_NONE,
1827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1830 (char_u *)&p_mousem, PV_NONE,
1831 {
1832#if defined(MSDOS) || defined(MSWIN)
1833 (char_u *)"popup",
1834#else
1835# if defined(MACOS)
1836 (char_u *)"popup_setpos",
1837# else
1838 (char_u *)"extend",
1839# endif
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1843#ifdef FEAT_MOUSESHAPE
1844 (char_u *)&p_mouseshape, PV_NONE,
1845 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1846#else
1847 (char_u *)NULL, PV_NONE,
1848 {(char_u *)NULL, (char_u *)0L}
1849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1852 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001854 {"mzquantum", "mzq", P_NUM,
1855#ifdef FEAT_MZSCHEME
1856 (char_u *)&p_mzq, PV_NONE,
1857#else
1858 (char_u *)NULL, PV_NONE,
1859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"novice", NULL, P_BOOL|P_VI_DEF,
1862 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1865 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)"octal,hex", (char_u *)0L}
1867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1869 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001871 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1872#ifdef FEAT_LINEBREAK
1873 (char_u *)VAR_WIN, PV_NUW,
1874#else
1875 (char_u *)NULL, PV_NONE,
1876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001878 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001879#ifdef FEAT_COMPL_FUNC
1880 (char_u *)&p_ofu, PV_OFU,
1881 {(char_u *)"", (char_u *)0L}
1882#else
1883 (char_u *)NULL, PV_NONE,
1884 {(char_u *)0L, (char_u *)0L}
1885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001886 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001887 {"open", NULL, P_BOOL|P_VI_DEF,
1888 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001889 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001890 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1891#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1892 (char_u *)&p_odev, PV_NONE,
1893#else
1894 (char_u *)NULL, PV_NONE,
1895#endif
1896 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001897 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001898 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1899 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001900 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901 {"optimize", "opt", P_BOOL|P_VI_DEF,
1902 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001903 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001904 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001906 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 {"paragraphs", "para", P_STRING|P_VI_DEF,
1908 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001909 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001910 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001911 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1915 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001916 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1918#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1919 (char_u *)&p_pex, PV_NONE,
1920 {(char_u *)"", (char_u *)0L}
1921#else
1922 (char_u *)NULL, PV_NONE,
1923 {(char_u *)0L, (char_u *)0L}
1924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001926 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001930 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {
1932#if defined AMIGA || defined MSDOS || defined MSWIN
1933 (char_u *)".,,",
1934#else
1935# if defined(__EMX__)
1936 (char_u *)".,/emx/include,,",
1937# else /* Unix, probably */
1938 (char_u *)".,/usr/include,,",
1939# endif
1940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1943 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001945 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001946#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1947 (char_u *)&p_pvh, PV_NONE,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1953#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1954 (char_u *)VAR_WIN, PV_PVW,
1955#else
1956 (char_u *)NULL, PV_NONE,
1957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001959 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001960#ifdef FEAT_PRINTER
1961 (char_u *)&p_pdev, PV_NONE,
1962 {(char_u *)"", (char_u *)0L}
1963#else
1964 (char_u *)NULL, PV_NONE,
1965 {(char_u *)NULL, (char_u *)0L}
1966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"printencoding", "penc", P_STRING|P_VI_DEF,
1969#ifdef FEAT_POSTSCRIPT
1970 (char_u *)&p_penc, PV_NONE,
1971 {(char_u *)"", (char_u *)0L}
1972#else
1973 (char_u *)NULL, PV_NONE,
1974 {(char_u *)NULL, (char_u *)0L}
1975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001976 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1978#ifdef FEAT_POSTSCRIPT
1979 (char_u *)&p_pexpr, PV_NONE,
1980 {(char_u *)"", (char_u *)0L}
1981#else
1982 (char_u *)NULL, PV_NONE,
1983 {(char_u *)NULL, (char_u *)0L}
1984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"printfont", "pfn", P_STRING|P_VI_DEF,
1987#ifdef FEAT_PRINTER
1988 (char_u *)&p_pfn, PV_NONE,
1989 {
1990# ifdef MSWIN
1991 (char_u *)"Courier_New:h10",
1992# else
1993 (char_u *)"courier",
1994# endif
1995 (char_u *)0L}
1996#else
1997 (char_u *)NULL, PV_NONE,
1998 {(char_u *)NULL, (char_u *)0L}
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2002#ifdef FEAT_PRINTER
2003 (char_u *)&p_header, PV_NONE,
2004 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2005#else
2006 (char_u *)NULL, PV_NONE,
2007 {(char_u *)NULL, (char_u *)0L}
2008#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002009 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002010 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2011#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2012 (char_u *)&p_pmcs, PV_NONE,
2013 {(char_u *)"", (char_u *)0L}
2014#else
2015 (char_u *)NULL, PV_NONE,
2016 {(char_u *)NULL, (char_u *)0L}
2017#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002019 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2020#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2021 (char_u *)&p_pmfn, PV_NONE,
2022 {(char_u *)"", (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)NULL, (char_u *)0L}
2026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002027 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2029#ifdef FEAT_PRINTER
2030 (char_u *)&p_popt, PV_NONE,
2031 {(char_u *)"", (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)NULL, (char_u *)0L}
2035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002038 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002040 {"pumheight", "ph", P_NUM|P_VI_DEF,
2041#ifdef FEAT_INS_EXPAND
2042 (char_u *)&p_ph, PV_NONE,
2043#else
2044 (char_u *)NULL, PV_NONE,
2045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002047 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2048#ifdef FEAT_TEXTOBJ
2049 (char_u *)&p_qe, PV_QE,
2050 {(char_u *)"\\", (char_u *)0L}
2051#else
2052 (char_u *)NULL, PV_NONE,
2053 {(char_u *)NULL, (char_u *)0L}
2054#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002055 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2057 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 {"redraw", NULL, P_BOOL|P_VI_DEF,
2060 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002062 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2063#ifdef FEAT_RELTIME
2064 (char_u *)&p_rdt, PV_NONE,
2065#else
2066 (char_u *)NULL, PV_NONE,
2067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002068 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002069 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2070 (char_u *)VAR_WIN, PV_RNU,
2071 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 {"remap", NULL, P_BOOL|P_VI_DEF,
2073 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {"report", NULL, P_NUM|P_VI_DEF,
2076 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2079#ifdef WIN3264
2080 (char_u *)&p_rs, PV_NONE,
2081#else
2082 (char_u *)NULL, PV_NONE,
2083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2086#ifdef FEAT_RIGHTLEFT
2087 (char_u *)&p_ri, PV_NONE,
2088#else
2089 (char_u *)NULL, PV_NONE,
2090#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2093#ifdef FEAT_RIGHTLEFT
2094 (char_u *)VAR_WIN, PV_RL,
2095#else
2096 (char_u *)NULL, PV_NONE,
2097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2100#ifdef FEAT_RIGHTLEFT
2101 (char_u *)VAR_WIN, PV_RLC,
2102 {(char_u *)"search", (char_u *)NULL}
2103#else
2104 (char_u *)NULL, PV_NONE,
2105 {(char_u *)NULL, (char_u *)0L}
2106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2109#ifdef FEAT_CMDL_INFO
2110 (char_u *)&p_ru, PV_NONE,
2111#else
2112 (char_u *)NULL, PV_NONE,
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2116#ifdef FEAT_STL_OPT
2117 (char_u *)&p_ruf, PV_NONE,
2118#else
2119 (char_u *)NULL, PV_NONE,
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2123 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2125 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2127 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2130#ifdef FEAT_SCROLLBIND
2131 (char_u *)VAR_WIN, PV_SCBIND,
2132#else
2133 (char_u *)NULL, PV_NONE,
2134#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002135 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2137 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002138 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2140 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002141 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2143#ifdef FEAT_SCROLLBIND
2144 (char_u *)&p_sbo, PV_NONE,
2145 {(char_u *)"ver,jump", (char_u *)0L}
2146#else
2147 (char_u *)NULL, PV_NONE,
2148 {(char_u *)0L, (char_u *)0L}
2149#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 {"sections", "sect", P_STRING|P_VI_DEF,
2152 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2154 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2156 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 {"selection", "sel", P_STRING|P_VI_DEF,
2159#ifdef FEAT_VISUAL
2160 (char_u *)&p_sel, PV_NONE,
2161#else
2162 (char_u *)NULL, PV_NONE,
2163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002164 {(char_u *)"inclusive", (char_u *)0L}
2165 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2167#ifdef FEAT_VISUAL
2168 (char_u *)&p_slm, PV_NONE,
2169#else
2170 (char_u *)NULL, PV_NONE,
2171#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002172 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2174#ifdef FEAT_SESSION
2175 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002176 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 (char_u *)0L}
2178#else
2179 (char_u *)NULL, PV_NONE,
2180 {(char_u *)0L, (char_u *)0L}
2181#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002182 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2184 (char_u *)&p_sh, PV_NONE,
2185 {
2186#ifdef VMS
2187 (char_u *)"-",
2188#else
2189# if defined(MSDOS)
2190 (char_u *)"command",
2191# else
2192# if defined(WIN16)
2193 (char_u *)"command.com",
2194# else
2195# if defined(WIN3264)
2196 (char_u *)"", /* set in set_init_1() */
2197# else
2198# if defined(OS2)
2199 (char_u *)"cmd.exe",
2200# else
2201# if defined(ARCHIE)
2202 (char_u *)"gos",
2203# else
2204 (char_u *)"sh",
2205# endif
2206# endif
2207# endif
2208# endif
2209# endif
2210#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2213 (char_u *)&p_shcf, PV_NONE,
2214 {
2215#if defined(MSDOS) || defined(MSWIN)
2216 (char_u *)"/c",
2217#else
2218# if defined(OS2)
2219 (char_u *)"/c",
2220# else
2221 (char_u *)"-c",
2222# endif
2223#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002224 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002225 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2226#ifdef FEAT_QUICKFIX
2227 (char_u *)&p_sp, PV_NONE,
2228 {
2229#if defined(UNIX) || defined(OS2)
2230# ifdef ARCHIE
2231 (char_u *)"2>",
2232# else
2233 (char_u *)"| tee",
2234# endif
2235#else
2236 (char_u *)">",
2237#endif
2238 (char_u *)0L}
2239#else
2240 (char_u *)NULL, PV_NONE,
2241 {(char_u *)0L, (char_u *)0L}
2242#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2245 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2248 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002249 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2251#ifdef BACKSLASH_IN_FILENAME
2252 (char_u *)&p_ssl, PV_NONE,
2253#else
2254 (char_u *)NULL, PV_NONE,
2255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002256 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002257 {"shelltemp", "stmp", P_BOOL,
2258 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002259 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 {"shelltype", "st", P_NUM|P_VI_DEF,
2261#ifdef AMIGA
2262 (char_u *)&p_st, PV_NONE,
2263#else
2264 (char_u *)NULL, PV_NONE,
2265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002266 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2268 (char_u *)&p_sxq, PV_NONE,
2269 {
2270#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2271 (char_u *)"\"",
2272#else
2273 (char_u *)"",
2274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2277 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2280 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002281 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2283 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002284 {(char_u *)"", (char_u *)"filnxtToO"}
2285 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"shortname", "sn", P_BOOL|P_VI_DEF,
2287#ifdef SHORT_FNAME
2288 (char_u *)NULL, PV_NONE,
2289#else
2290 (char_u *)&p_sn, PV_SN,
2291#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2294#ifdef FEAT_LINEBREAK
2295 (char_u *)&p_sbr, PV_NONE,
2296#else
2297 (char_u *)NULL, PV_NONE,
2298#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002299 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"showcmd", "sc", P_BOOL|P_VIM,
2301#ifdef FEAT_CMDL_INFO
2302 (char_u *)&p_sc, PV_NONE,
2303#else
2304 (char_u *)NULL, PV_NONE,
2305#endif
2306 {(char_u *)FALSE,
2307#ifdef UNIX
2308 (char_u *)FALSE
2309#else
2310 (char_u *)TRUE
2311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002312 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2314 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2317 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002318 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"showmode", "smd", P_BOOL|P_VIM,
2320 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002322 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2323#ifdef FEAT_WINDOWS
2324 (char_u *)&p_stal, PV_NONE,
2325#else
2326 (char_u *)NULL, PV_NONE,
2327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2330 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2333 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002334 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2336 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2339 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2342#ifdef FEAT_SMARTINDENT
2343 (char_u *)&p_si, PV_SI,
2344#else
2345 (char_u *)NULL, PV_NONE,
2346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2349 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002350 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2352 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002353 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2355 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002357 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002358#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002359 (char_u *)VAR_WIN, PV_SPELL,
2360#else
2361 (char_u *)NULL, PV_NONE,
2362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002364 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002366 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002367 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002368#else
2369 (char_u *)NULL, PV_NONE,
2370 {(char_u *)0L, (char_u *)0L}
2371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002372 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002373 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002374#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002375 (char_u *)&p_spf, PV_SPF,
2376 {(char_u *)"", (char_u *)0L}
2377#else
2378 (char_u *)NULL, PV_NONE,
2379 {(char_u *)0L, (char_u *)0L}
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002382 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002383#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002384 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002385 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002386#else
2387 (char_u *)NULL, PV_NONE,
2388 {(char_u *)0L, (char_u *)0L}
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002391 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002392#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002393 (char_u *)&p_sps, PV_NONE,
2394 {(char_u *)"best", (char_u *)0L}
2395#else
2396 (char_u *)NULL, PV_NONE,
2397 {(char_u *)0L, (char_u *)0L}
2398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2401#ifdef FEAT_WINDOWS
2402 (char_u *)&p_sb, PV_NONE,
2403#else
2404 (char_u *)NULL, PV_NONE,
2405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"splitright", "spr", P_BOOL|P_VI_DEF,
2408#ifdef FEAT_VERTSPLIT
2409 (char_u *)&p_spr, PV_NONE,
2410#else
2411 (char_u *)NULL, PV_NONE,
2412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2415 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2418#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002419 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420#else
2421 (char_u *)NULL, PV_NONE,
2422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2425 (char_u *)&p_su, PV_NONE,
2426 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002427 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002429#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 (char_u *)&p_sua, PV_SUA,
2431 {(char_u *)"", (char_u *)0L}
2432#else
2433 (char_u *)NULL, PV_NONE,
2434 {(char_u *)0L, (char_u *)0L}
2435#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2438 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"swapsync", "sws", P_STRING|P_VI_DEF,
2441 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2444 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002446 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2447#ifdef FEAT_SYN_HL
2448 (char_u *)&p_smc, PV_SMC,
2449 {(char_u *)3000L, (char_u *)0L}
2450#else
2451 (char_u *)NULL, PV_NONE,
2452 {(char_u *)0L, (char_u *)0L}
2453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002455 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456#ifdef FEAT_SYN_HL
2457 (char_u *)&p_syn, PV_SYN,
2458 {(char_u *)"", (char_u *)0L}
2459#else
2460 (char_u *)NULL, PV_NONE,
2461 {(char_u *)0L, (char_u *)0L}
2462#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002463 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002464 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2465#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002466 (char_u *)&p_tal, PV_NONE,
2467#else
2468 (char_u *)NULL, PV_NONE,
2469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002471 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2472#ifdef FEAT_WINDOWS
2473 (char_u *)&p_tpm, PV_NONE,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2479 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002480 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2482 (char_u *)&p_tbs, PV_NONE,
2483#ifdef VMS /* binary searching doesn't appear to work on VMS */
2484 {(char_u *)0L, (char_u *)0L}
2485#else
2486 {(char_u *)TRUE, (char_u *)0L}
2487#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002488 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 {"taglength", "tl", P_NUM|P_VI_DEF,
2490 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002491 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {"tagrelative", "tr", P_BOOL|P_VIM,
2493 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002494 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002496 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {
2498#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2499 (char_u *)"./tags,./TAGS,tags,TAGS",
2500#else
2501 (char_u *)"./tags,tags",
2502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2505 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2508 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2511#ifdef FEAT_ARABIC
2512 (char_u *)&p_tbidi, PV_NONE,
2513#else
2514 (char_u *)NULL, PV_NONE,
2515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2518#ifdef FEAT_MBYTE
2519 (char_u *)&p_tenc, PV_NONE,
2520 {(char_u *)"", (char_u *)0L}
2521#else
2522 (char_u *)NULL, PV_NONE,
2523 {(char_u *)0L, (char_u *)0L}
2524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"terse", NULL, P_BOOL|P_VI_DEF,
2527 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"textauto", "ta", P_BOOL|P_VIM,
2530 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2532 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002533 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2534 (char_u *)&p_tx, PV_TX,
2535 {
2536#ifdef USE_CRNL
2537 (char_u *)TRUE,
2538#else
2539 (char_u *)FALSE,
2540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002542 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2546#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002547 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548#else
2549 (char_u *)NULL, PV_NONE,
2550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2553 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 {"timeout", "to", P_BOOL|P_VI_DEF,
2556 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2559 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"title", NULL, P_BOOL|P_VI_DEF,
2562#ifdef FEAT_TITLE
2563 (char_u *)&p_title, PV_NONE,
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 {"titlelen", NULL, P_NUM|P_VI_DEF,
2569#ifdef FEAT_TITLE
2570 (char_u *)&p_titlelen, PV_NONE,
2571#else
2572 (char_u *)NULL, PV_NONE,
2573#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002575 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576#ifdef FEAT_TITLE
2577 (char_u *)&p_titleold, PV_NONE,
2578 {(char_u *)N_("Thanks for flying Vim"),
2579 (char_u *)0L}
2580#else
2581 (char_u *)NULL, PV_NONE,
2582 {(char_u *)0L, (char_u *)0L}
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 {"titlestring", NULL, P_STRING|P_VI_DEF,
2586#ifdef FEAT_TITLE
2587 (char_u *)&p_titlestring, PV_NONE,
2588#else
2589 (char_u *)NULL, PV_NONE,
2590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2593 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2594 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 {(char_u *)"icons,tooltips", (char_u *)0L}
2596 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002598#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2600 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602#endif
2603 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2604 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2607 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2610 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2613 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2616#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2617 (char_u *)&p_ttym, PV_NONE,
2618#else
2619 (char_u *)NULL, PV_NONE,
2620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2623 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2626 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002628 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2629#ifdef FEAT_PERSISTENT_UNDO
2630 (char_u *)&p_udir, PV_NONE,
2631 {(char_u *)".", (char_u *)0L}
2632#else
2633 (char_u *)NULL, PV_NONE,
2634 {(char_u *)0L, (char_u *)0L}
2635#endif
2636 SCRIPTID_INIT},
2637 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2638#ifdef FEAT_PERSISTENT_UNDO
2639 (char_u *)&p_udf, PV_UDF,
2640#else
2641 (char_u *)NULL, PV_NONE,
2642#endif
2643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"undolevels", "ul", P_NUM|P_VI_DEF,
2645 (char_u *)&p_ul, PV_NONE,
2646 {
2647#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2648 (char_u *)1000L,
2649#else
2650 (char_u *)100L,
2651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002653 {"undoreload", "ur", P_NUM|P_VI_DEF,
2654 (char_u *)&p_ur, PV_NONE,
2655 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {"updatecount", "uc", P_NUM|P_VI_DEF,
2657 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {"updatetime", "ut", P_NUM|P_VI_DEF,
2660 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 {"verbose", "vbs", P_NUM|P_VI_DEF,
2663 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002665 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2666 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2669#ifdef FEAT_SESSION
2670 (char_u *)&p_vdir, PV_NONE,
2671 {(char_u *)DFLT_VDIR, (char_u *)0L}
2672#else
2673 (char_u *)NULL, PV_NONE,
2674 {(char_u *)0L, (char_u *)0L}
2675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2678#ifdef FEAT_SESSION
2679 (char_u *)&p_vop, PV_NONE,
2680 {(char_u *)"folds,options,cursor", (char_u *)0L}
2681#else
2682 (char_u *)NULL, PV_NONE,
2683 {(char_u *)0L, (char_u *)0L}
2684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002685 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2687#ifdef FEAT_VIMINFO
2688 (char_u *)&p_viminfo, PV_NONE,
2689#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002690 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691#else
2692# ifdef AMIGA
2693 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002694 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002696 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697# endif
2698#endif
2699#else
2700 (char_u *)NULL, PV_NONE,
2701 {(char_u *)0L, (char_u *)0L}
2702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2705#ifdef FEAT_VIRTUALEDIT
2706 (char_u *)&p_ve, PV_NONE,
2707 {(char_u *)"", (char_u *)""}
2708#else
2709 (char_u *)NULL, PV_NONE,
2710 {(char_u *)0L, (char_u *)0L}
2711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2714 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"w300", NULL, P_NUM|P_VI_DEF,
2717 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"w1200", NULL, P_NUM|P_VI_DEF,
2720 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"w9600", NULL, P_NUM|P_VI_DEF,
2723 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"warn", NULL, P_BOOL|P_VI_DEF,
2726 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2729 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2732 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002733 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {"wildchar", "wc", P_NUM|P_VIM,
2735 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002736 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2737 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002738 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002741 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2742#ifdef FEAT_WILDIGN
2743 (char_u *)&p_wig, PV_NONE,
2744#else
2745 (char_u *)NULL, PV_NONE,
2746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002748 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2749 (char_u *)&p_wic, PV_NONE,
2750 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2752#ifdef FEAT_WILDMENU
2753 (char_u *)&p_wmnu, PV_NONE,
2754#else
2755 (char_u *)NULL, PV_NONE,
2756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002757 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2759 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002760 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002761 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2762#ifdef FEAT_CMDL_COMPL
2763 (char_u *)&p_wop, PV_NONE,
2764 {(char_u *)"", (char_u *)0L}
2765#else
2766 (char_u *)NULL, PV_NONE,
2767 {(char_u *)NULL, (char_u *)0L}
2768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002769 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2771#ifdef FEAT_WAK
2772 (char_u *)&p_wak, PV_NONE,
2773 {(char_u *)"menu", (char_u *)0L}
2774#else
2775 (char_u *)NULL, PV_NONE,
2776 {(char_u *)NULL, (char_u *)0L}
2777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002780 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002781 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"winheight", "wh", P_NUM|P_VI_DEF,
2783#ifdef FEAT_WINDOWS
2784 (char_u *)&p_wh, PV_NONE,
2785#else
2786 (char_u *)NULL, PV_NONE,
2787#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002790#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 (char_u *)VAR_WIN, PV_WFH,
2792#else
2793 (char_u *)NULL, PV_NONE,
2794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002796 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2797#ifdef FEAT_VERTSPLIT
2798 (char_u *)VAR_WIN, PV_WFW,
2799#else
2800 (char_u *)NULL, PV_NONE,
2801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2804#ifdef FEAT_WINDOWS
2805 (char_u *)&p_wmh, PV_NONE,
2806#else
2807 (char_u *)NULL, PV_NONE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2811#ifdef FEAT_VERTSPLIT
2812 (char_u *)&p_wmw, PV_NONE,
2813#else
2814 (char_u *)NULL, PV_NONE,
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2818#ifdef FEAT_VERTSPLIT
2819 (char_u *)&p_wiw, PV_NONE,
2820#else
2821 (char_u *)NULL, PV_NONE,
2822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002823 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2825 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2828 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2831 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"write", NULL, P_BOOL|P_VI_DEF,
2834 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"writeany", "wa", P_BOOL|P_VI_DEF,
2837 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2840 (char_u *)&p_wb, PV_NONE,
2841 {
2842#ifdef FEAT_WRITEBACKUP
2843 (char_u *)TRUE,
2844#else
2845 (char_u *)FALSE,
2846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002847 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 {"writedelay", "wd", P_NUM|P_VI_DEF,
2849 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851
2852/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002853#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856
2857 p_term("t_AB", T_CAB)
2858 p_term("t_AF", T_CAF)
2859 p_term("t_AL", T_CAL)
2860 p_term("t_al", T_AL)
2861 p_term("t_bc", T_BC)
2862 p_term("t_cd", T_CD)
2863 p_term("t_ce", T_CE)
2864 p_term("t_cl", T_CL)
2865 p_term("t_cm", T_CM)
2866 p_term("t_Co", T_CCO)
2867 p_term("t_CS", T_CCS)
2868 p_term("t_cs", T_CS)
2869#ifdef FEAT_VERTSPLIT
2870 p_term("t_CV", T_CSV)
2871#endif
2872 p_term("t_ut", T_UT)
2873 p_term("t_da", T_DA)
2874 p_term("t_db", T_DB)
2875 p_term("t_DL", T_CDL)
2876 p_term("t_dl", T_DL)
2877 p_term("t_fs", T_FS)
2878 p_term("t_IE", T_CIE)
2879 p_term("t_IS", T_CIS)
2880 p_term("t_ke", T_KE)
2881 p_term("t_ks", T_KS)
2882 p_term("t_le", T_LE)
2883 p_term("t_mb", T_MB)
2884 p_term("t_md", T_MD)
2885 p_term("t_me", T_ME)
2886 p_term("t_mr", T_MR)
2887 p_term("t_ms", T_MS)
2888 p_term("t_nd", T_ND)
2889 p_term("t_op", T_OP)
2890 p_term("t_RI", T_CRI)
2891 p_term("t_RV", T_CRV)
2892 p_term("t_Sb", T_CSB)
2893 p_term("t_Sf", T_CSF)
2894 p_term("t_se", T_SE)
2895 p_term("t_so", T_SO)
2896 p_term("t_sr", T_SR)
2897 p_term("t_ts", T_TS)
2898 p_term("t_te", T_TE)
2899 p_term("t_ti", T_TI)
2900 p_term("t_ue", T_UE)
2901 p_term("t_us", T_US)
2902 p_term("t_vb", T_VB)
2903 p_term("t_ve", T_VE)
2904 p_term("t_vi", T_VI)
2905 p_term("t_vs", T_VS)
2906 p_term("t_WP", T_CWP)
2907 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002908 p_term("t_SI", T_CSI)
2909 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 p_term("t_xs", T_XS)
2911 p_term("t_ZH", T_CZH)
2912 p_term("t_ZR", T_CZR)
2913
2914/* terminal key codes are not in here */
2915
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 /* end marker */
2917 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918};
2919
2920#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2921
2922#ifdef FEAT_MBYTE
2923static char *(p_ambw_values[]) = {"single", "double", NULL};
2924#endif
2925static char *(p_bg_values[]) = {"light", "dark", NULL};
2926static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2927static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002928#ifdef FEAT_CRYPT
2929static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2930#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002931#ifdef FEAT_CMDL_COMPL
2932static char *(p_wop_values[]) = {"tagfile", NULL};
2933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934#ifdef FEAT_WAK
2935static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2936#endif
2937static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2938#ifdef FEAT_VISUAL
2939static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2940static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2941#endif
2942#ifdef FEAT_VISUAL
2943static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2944#endif
2945#ifdef FEAT_BROWSE
2946static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2947#endif
2948#ifdef FEAT_SCROLLBIND
2949static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2950#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002951static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952#ifdef FEAT_VERTSPLIT
2953static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2954#endif
2955#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002956# ifdef FEAT_AUTOCMD
2957static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2958# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002960# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2962#endif
2963static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2964#ifdef FEAT_FOLDING
2965static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002966# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002968# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 NULL};
2970static char *(p_fcl_values[]) = {"all", NULL};
2971#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002972#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002973static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975
2976static void set_option_default __ARGS((int, int opt_flags, int compatible));
2977static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002978static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002979static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980static char_u *illegal_char __ARGS((char_u *, int));
2981static int string_to_key __ARGS((char_u *arg));
2982#ifdef FEAT_CMDWIN
2983static char_u *check_cedit __ARGS((void));
2984#endif
2985#ifdef FEAT_TITLE
2986static void did_set_title __ARGS((int icon));
2987#endif
2988static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2989static void didset_options __ARGS((void));
2990static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002991#if defined(FEAT_EVAL) || defined(PROTO)
2992static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2993#else
2994# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2995#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2997static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2998static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
2999static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003000#ifdef FEAT_SYN_HL
3001static int int_cmp __ARGS((const void *a, const void *b));
3002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003#ifdef FEAT_CLIPBOARD
3004static char_u *check_clipboard_option __ARGS((void));
3005#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003006#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003007static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003008#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003009#ifdef FEAT_EVAL
3010static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3011#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003013static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014static void check_redraw __ARGS((long_u flags));
3015static int findoption __ARGS((char_u *));
3016static int find_key_option __ARGS((char_u *));
3017static void showoptions __ARGS((int all, int opt_flags));
3018static int optval_default __ARGS((struct vimoption *, char_u *varp));
3019static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3020static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3021static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3022static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3023static int istermoption __ARGS((struct vimoption *));
3024static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3025static char_u *get_varp __ARGS((struct vimoption *));
3026static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3027static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3028#ifdef FEAT_LANGMAP
3029static void langmap_init __ARGS((void));
3030static void langmap_set __ARGS((void));
3031#endif
3032static void paste_option_changed __ARGS((void));
3033static void compatible_set __ARGS((void));
3034#ifdef FEAT_LINEBREAK
3035static void fill_breakat_flags __ARGS((void));
3036#endif
3037static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3038static int check_opt_strings __ARGS((char_u *val, char **values, int));
3039static int check_opt_wim __ARGS((void));
3040
3041/*
3042 * Initialize the options, first part.
3043 *
3044 * Called only once from main(), just after creating the first buffer.
3045 */
3046 void
3047set_init_1()
3048{
3049 char_u *p;
3050 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003051 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052
3053#ifdef FEAT_LANGMAP
3054 langmap_init();
3055#endif
3056
3057 /* Be Vi compatible by default */
3058 p_cp = TRUE;
3059
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003060 /* Use POSIX compatibility when $VIM_POSIX is set. */
3061 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003062 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003063 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003064 set_string_default("shm", (char_u *)"A");
3065 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003066
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 /*
3068 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003069 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003071 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3073# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003074 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003076 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003078 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079# endif
3080#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003081 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 set_string_default("sh", p);
3083
3084#ifdef FEAT_WILDIGN
3085 /*
3086 * Set the default for 'backupskip' to include environment variables for
3087 * temp files.
3088 */
3089 {
3090# ifdef UNIX
3091 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3092# else
3093 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3094# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003095 int len;
3096 garray_T ga;
3097 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098
3099 ga_init2(&ga, 1, 100);
3100 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3101 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003102 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103# ifdef UNIX
3104 if (*names[n] == NUL)
3105 p = (char_u *)"/tmp";
3106 else
3107# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003108 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 if (p != NULL && *p != NUL)
3110 {
3111 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003112 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 if (ga_grow(&ga, len) == OK)
3114 {
3115 if (ga.ga_len > 0)
3116 STRCAT(ga.ga_data, ",");
3117 STRCAT(ga.ga_data, p);
3118 add_pathsep(ga.ga_data);
3119 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120 ga.ga_len += len;
3121 }
3122 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003123 if (mustfree)
3124 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 }
3126 if (ga.ga_data != NULL)
3127 {
3128 set_string_default("bsk", ga.ga_data);
3129 vim_free(ga.ga_data);
3130 }
3131 }
3132#endif
3133
3134 /*
3135 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3136 */
3137 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003138 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003140#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3141 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3142#endif
3143 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003145 /* Use amount of memory available at this moment. */
3146 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147#else
3148# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003149 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003150 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003152 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153# endif
3154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003156 opt_idx = findoption((char_u *)"maxmem");
3157 if (opt_idx >= 0)
3158 {
3159#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3160 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3161 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3162#endif
3163 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3164 }
3165 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 }
3167
3168#ifdef FEAT_GUI_W32
3169 /* force 'shortname' for Win32s */
3170 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003171 {
3172 opt_idx = findoption((char_u *)"shortname");
3173 if (opt_idx >= 0)
3174 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3175 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176#endif
3177
3178#ifdef FEAT_SEARCHPATH
3179 {
3180 char_u *cdpath;
3181 char_u *buf;
3182 int i;
3183 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003184 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185
3186 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003187 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 if (cdpath != NULL)
3189 {
3190 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3191 if (buf != NULL)
3192 {
3193 buf[0] = ','; /* start with ",", current dir first */
3194 j = 1;
3195 for (i = 0; cdpath[i] != NUL; ++i)
3196 {
3197 if (vim_ispathlistsep(cdpath[i]))
3198 buf[j++] = ',';
3199 else
3200 {
3201 if (cdpath[i] == ' ' || cdpath[i] == ',')
3202 buf[j++] = '\\';
3203 buf[j++] = cdpath[i];
3204 }
3205 }
3206 buf[j] = NUL;
3207 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003208 if (opt_idx >= 0)
3209 {
3210 options[opt_idx].def_val[VI_DEFAULT] = buf;
3211 options[opt_idx].flags |= P_DEF_ALLOCED;
3212 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003213 else
3214 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003216 if (mustfree)
3217 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 }
3219 }
3220#endif
3221
3222#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3223 /* Set print encoding on platforms that don't default to latin1 */
3224 set_string_default("penc",
3225# if defined(MSWIN) || defined(OS2)
3226 (char_u *)"cp1252"
3227# else
3228# ifdef VMS
3229 (char_u *)"dec-mcs"
3230# else
3231# ifdef EBCDIC
3232 (char_u *)"ebcdic-uk"
3233# else
3234# ifdef MAC
3235 (char_u *)"mac-roman"
3236# else /* HPUX */
3237 (char_u *)"hp-roman8"
3238# endif
3239# endif
3240# endif
3241# endif
3242 );
3243#endif
3244
3245#ifdef FEAT_POSTSCRIPT
3246 /* 'printexpr' must be allocated to be able to evaluate it. */
3247 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003248# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3249 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250# else
3251# ifdef VMS
3252 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3253
3254# else
3255 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3256# endif
3257# endif
3258 );
3259#endif
3260
3261 /*
3262 * Set all the options (except the terminal options) to their default
3263 * value. Also set the global value for local options.
3264 */
3265 set_options_default(0);
3266
3267#ifdef FEAT_GUI
3268 if (found_reverse_arg)
3269 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3270#endif
3271
3272 curbuf->b_p_initialized = TRUE;
3273 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3274 check_buf_options(curbuf);
3275 check_win_options(curwin);
3276 check_options();
3277
3278 /* Must be before option_expand(), because that one needs vim_isIDc() */
3279 didset_options();
3280
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003281#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003282 /* Use the current chartab for the generic chartab. */
3283 init_spell_chartab();
3284#endif
3285
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#ifdef FEAT_LINEBREAK
3287 /*
3288 * initialize the table for 'breakat'.
3289 */
3290 fill_breakat_flags();
3291#endif
3292
3293 /*
3294 * Expand environment variables and things like "~" for the defaults.
3295 * If option_expand() returns non-NULL the variable is expanded. This can
3296 * only happen for non-indirect options.
3297 * Also set the default to the expanded value, so ":set" does not list
3298 * them.
3299 * Don't set the P_ALLOCED flag, because we don't want to free the
3300 * default.
3301 */
3302 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3303 {
3304 if ((options[opt_idx].flags & P_GETTEXT)
3305 && options[opt_idx].var != NULL)
3306 p = (char_u *)_(*(char **)options[opt_idx].var);
3307 else
3308 p = option_expand(opt_idx, NULL);
3309 if (p != NULL && (p = vim_strsave(p)) != NULL)
3310 {
3311 *(char_u **)options[opt_idx].var = p;
3312 /* VIMEXP
3313 * Defaults for all expanded options are currently the same for Vi
3314 * and Vim. When this changes, add some code here! Also need to
3315 * split P_DEF_ALLOCED in two.
3316 */
3317 if (options[opt_idx].flags & P_DEF_ALLOCED)
3318 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3319 options[opt_idx].def_val[VI_DEFAULT] = p;
3320 options[opt_idx].flags |= P_DEF_ALLOCED;
3321 }
3322 }
3323
3324 /* Initialize the highlight_attr[] table. */
3325 highlight_changed();
3326
3327 save_file_ff(curbuf); /* Buffer is unchanged */
3328
3329 /* Parse default for 'wildmode' */
3330 check_opt_wim();
3331
3332#if defined(FEAT_ARABIC)
3333 /* Detect use of mlterm.
3334 * Mlterm is a terminal emulator akin to xterm that has some special
3335 * abilities (bidi namely).
3336 * NOTE: mlterm's author is being asked to 'set' a variable
3337 * instead of an environment variable due to inheritance.
3338 */
3339 if (mch_getenv((char_u *)"MLTERM") != NULL)
3340 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3341#endif
3342
3343#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3344 /* Parse default for 'fillchars'. */
3345 (void)set_chars_option(&p_fcs);
3346#endif
3347
3348#ifdef FEAT_CLIPBOARD
3349 /* Parse default for 'clipboard' */
3350 (void)check_clipboard_option();
3351#endif
3352
3353#ifdef FEAT_MBYTE
3354# if defined(WIN3264) && defined(FEAT_GETTEXT)
3355 /*
3356 * If $LANG isn't set, try to get a good value for it. This makes the
3357 * right language be used automatically. Don't do this for English.
3358 */
3359 if (mch_getenv((char_u *)"LANG") == NULL)
3360 {
3361 char buf[20];
3362
3363 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3364 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3365 * only the first two. */
3366 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3367 (LPTSTR)buf, 20);
3368 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3369 {
3370 /* There are a few exceptions (probably more) */
3371 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3372 STRCPY(buf, "zh_TW");
3373 else if (STRNICMP(buf, "chs", 3) == 0
3374 || STRNICMP(buf, "zhc", 3) == 0)
3375 STRCPY(buf, "zh_CN");
3376 else if (STRNICMP(buf, "jp", 2) == 0)
3377 STRCPY(buf, "ja");
3378 else
3379 buf[2] = NUL; /* truncate to two-letter code */
3380 vim_setenv("LANG", buf);
3381 }
3382 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003383# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003384# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003385 /* Moved to os_mac_conv.c to avoid dependency problems. */
3386 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003387# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388# endif
3389
3390 /* enc_locale() will try to find the encoding of the current locale. */
3391 p = enc_locale();
3392 if (p != NULL)
3393 {
3394 char_u *save_enc;
3395
3396 /* Try setting 'encoding' and check if the value is valid.
3397 * If not, go back to the default "latin1". */
3398 save_enc = p_enc;
3399 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003400 if (STRCMP(p_enc, "gb18030") == 0)
3401 {
3402 /* We don't support "gb18030", but "cp936" is a good substitute
3403 * for practical purposes, thus use that. It's not an alias to
3404 * still support conversion between gb18030 and utf-8. */
3405 p_enc = vim_strsave((char_u *)"cp936");
3406 vim_free(p);
3407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408 if (mb_init() == NULL)
3409 {
3410 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003411 if (opt_idx >= 0)
3412 {
3413 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3414 options[opt_idx].flags |= P_DEF_ALLOCED;
3415 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003417#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3418 || defined(VMS)
3419 if (STRCMP(p_enc, "latin1") == 0
3420# ifdef FEAT_MBYTE
3421 || enc_utf8
3422# endif
3423 )
3424 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003425 /* Adjust the default for 'isprint' and 'iskeyword' to match
3426 * latin1. Also set the defaults for when 'nocompatible' is
3427 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003428 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003429 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003430 set_string_option_direct((char_u *)"isk", -1,
3431 ISK_LATIN1, OPT_FREE, SID_NONE);
3432 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003433 if (opt_idx >= 0)
3434 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003435 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003436 if (opt_idx >= 0)
3437 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003438 (void)init_chartab();
3439 }
3440#endif
3441
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442# if defined(WIN3264) && !defined(FEAT_GUI)
3443 /* Win32 console: When GetACP() returns a different value from
3444 * GetConsoleCP() set 'termencoding'. */
3445 if (GetACP() != GetConsoleCP())
3446 {
3447 char buf[50];
3448
3449 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3450 p_tenc = vim_strsave((char_u *)buf);
3451 if (p_tenc != NULL)
3452 {
3453 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003454 if (opt_idx >= 0)
3455 {
3456 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3457 options[opt_idx].flags |= P_DEF_ALLOCED;
3458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 convert_setup(&input_conv, p_tenc, p_enc);
3460 convert_setup(&output_conv, p_enc, p_tenc);
3461 }
3462 else
3463 p_tenc = empty_option;
3464 }
3465# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003466# if defined(WIN3264) && defined(FEAT_MBYTE)
3467 /* $HOME may have characters in active code page. */
3468 init_homedir();
3469# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470 }
3471 else
3472 {
3473 vim_free(p_enc);
3474 p_enc = save_enc;
3475 }
3476 }
3477#endif
3478
3479#ifdef FEAT_MULTI_LANG
3480 /* Set the default for 'helplang'. */
3481 set_helplang_default(get_mess_lang());
3482#endif
3483}
3484
3485/*
3486 * Set an option to its default value.
3487 * This does not take care of side effects!
3488 */
3489 static void
3490set_option_default(opt_idx, opt_flags, compatible)
3491 int opt_idx;
3492 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3493 int compatible; /* use Vi default value */
3494{
3495 char_u *varp; /* pointer to variable for current option */
3496 int dvi; /* index in def_val[] */
3497 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003498 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3500
3501 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3502 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003503 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504 {
3505 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3506 if (flags & P_STRING)
3507 {
3508 /* Use set_string_option_direct() for local options to handle
3509 * freeing and allocating the value. */
3510 if (options[opt_idx].indir != PV_NONE)
3511 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003512 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 else
3514 {
3515 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3516 free_string_option(*(char_u **)(varp));
3517 *(char_u **)varp = options[opt_idx].def_val[dvi];
3518 options[opt_idx].flags &= ~P_ALLOCED;
3519 }
3520 }
3521 else if (flags & P_NUM)
3522 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003523 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524 win_comp_scroll(curwin);
3525 else
3526 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003527 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 /* May also set global value for local option. */
3529 if (both)
3530 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3531 *(long *)varp;
3532 }
3533 }
3534 else /* P_BOOL */
3535 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003536 /* the cast to long is required for Manx C, long_i is needed for
3537 * MSVC */
3538 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003539#ifdef UNIX
3540 /* 'modeline' defaults to off for root */
3541 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3542 *(int *)varp = FALSE;
3543#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544 /* May also set global value for local option. */
3545 if (both)
3546 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3547 *(int *)varp;
3548 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003549
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003550 /* The default value is not insecure. */
3551 flagsp = insecure_flag(opt_idx, opt_flags);
3552 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 }
3554
3555#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003556 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557#endif
3558}
3559
3560/*
3561 * Set all options (except terminal options) to their default value.
3562 */
3563 static void
3564set_options_default(opt_flags)
3565 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3566{
3567 int i;
3568#ifdef FEAT_WINDOWS
3569 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003570 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571#endif
3572
3573 for (i = 0; !istermoption(&options[i]); i++)
3574 if (!(options[i].flags & P_NODEFAULT))
3575 set_option_default(i, opt_flags, p_cp);
3576
3577#ifdef FEAT_WINDOWS
3578 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003579 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580 win_comp_scroll(wp);
3581#else
3582 win_comp_scroll(curwin);
3583#endif
3584}
3585
3586/*
3587 * Set the Vi-default value of a string option.
3588 * Used for 'sh', 'backupskip' and 'term'.
3589 */
3590 void
3591set_string_default(name, val)
3592 char *name;
3593 char_u *val;
3594{
3595 char_u *p;
3596 int opt_idx;
3597
3598 p = vim_strsave(val);
3599 if (p != NULL) /* we don't want a NULL */
3600 {
3601 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003602 if (opt_idx >= 0)
3603 {
3604 if (options[opt_idx].flags & P_DEF_ALLOCED)
3605 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3606 options[opt_idx].def_val[VI_DEFAULT] = p;
3607 options[opt_idx].flags |= P_DEF_ALLOCED;
3608 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 }
3610}
3611
3612/*
3613 * Set the Vi-default value of a number option.
3614 * Used for 'lines' and 'columns'.
3615 */
3616 void
3617set_number_default(name, val)
3618 char *name;
3619 long val;
3620{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003621 int opt_idx;
3622
3623 opt_idx = findoption((char_u *)name);
3624 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003625 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626}
3627
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003628#if defined(EXITFREE) || defined(PROTO)
3629/*
3630 * Free all options.
3631 */
3632 void
3633free_all_options()
3634{
3635 int i;
3636
3637 for (i = 0; !istermoption(&options[i]); i++)
3638 {
3639 if (options[i].indir == PV_NONE)
3640 {
3641 /* global option: free value and default value. */
3642 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3643 free_string_option(*(char_u **)options[i].var);
3644 if (options[i].flags & P_DEF_ALLOCED)
3645 free_string_option(options[i].def_val[VI_DEFAULT]);
3646 }
3647 else if (options[i].var != VAR_WIN
3648 && (options[i].flags & P_STRING))
3649 /* buffer-local option: free global value */
3650 free_string_option(*(char_u **)options[i].var);
3651 }
3652}
3653#endif
3654
3655
Bram Moolenaar071d4272004-06-13 20:20:40 +00003656/*
3657 * Initialize the options, part two: After getting Rows and Columns and
3658 * setting 'term'.
3659 */
3660 void
3661set_init_2()
3662{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003663 int idx;
3664
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665 /*
3666 * 'scroll' defaults to half the window height. Note that this default is
3667 * wrong when the window height changes.
3668 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003669 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003670 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003671 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003672 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003673 comp_col();
3674
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003675 /*
3676 * 'window' is only for backwards compatibility with Vi.
3677 * Default is Rows - 1.
3678 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003679 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003680 p_window = Rows - 1;
3681 set_number_default("window", Rows - 1);
3682
Bram Moolenaarf740b292006-02-16 22:11:02 +00003683 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003685 /*
3686 * If 'background' wasn't set by the user, try guessing the value,
3687 * depending on the terminal name. Only need to check for terminals
3688 * with a dark background, that can handle color.
3689 */
3690 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003691 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3692 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003694 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003695 /* don't mark it as set, when starting the GUI it may be
3696 * changed again */
3697 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 }
3699#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003700
3701#ifdef CURSOR_SHAPE
3702 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3703#endif
3704#ifdef FEAT_MOUSESHAPE
3705 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3706#endif
3707#ifdef FEAT_PRINTER
3708 (void)parse_printoptions(); /* parse 'printoptions' default value */
3709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710}
3711
3712/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003713 * Return "dark" or "light" depending on the kind of terminal.
3714 * This is just guessing! Recognized are:
3715 * "linux" Linux console
3716 * "screen.linux" Linux console with screen
3717 * "cygwin" Cygwin shell
3718 * "putty" Putty program
3719 * We also check the COLORFGBG environment variable, which is set by
3720 * rxvt and derivatives. This variable contains either two or three
3721 * values separated by semicolons; we want the last value in either
3722 * case. If this value is 0-6 or 8, our background is dark.
3723 */
3724 static char_u *
3725term_bg_default()
3726{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003727#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3728 /* DOS console nearly always black */
3729 return (char_u *)"dark";
3730#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003731 char_u *p;
3732
Bram Moolenaarf740b292006-02-16 22:11:02 +00003733 if (STRCMP(T_NAME, "linux") == 0
3734 || STRCMP(T_NAME, "screen.linux") == 0
3735 || STRCMP(T_NAME, "cygwin") == 0
3736 || STRCMP(T_NAME, "putty") == 0
3737 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3738 && (p = vim_strrchr(p, ';')) != NULL
3739 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3740 && p[2] == NUL))
3741 return (char_u *)"dark";
3742 return (char_u *)"light";
3743#endif
3744}
3745
3746/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747 * Initialize the options, part three: After reading the .vimrc
3748 */
3749 void
3750set_init_3()
3751{
3752#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3753/*
3754 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3755 * This is done after other initializations, where 'shell' might have been
3756 * set, but only if they have not been set before.
3757 */
3758 char_u *p;
3759 int idx_srr;
3760 int do_srr;
3761#ifdef FEAT_QUICKFIX
3762 int idx_sp;
3763 int do_sp;
3764#endif
3765
3766 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003767 if (idx_srr < 0)
3768 do_srr = FALSE;
3769 else
3770 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771#ifdef FEAT_QUICKFIX
3772 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003773 if (idx_sp < 0)
3774 do_sp = FALSE;
3775 else
3776 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777#endif
3778
3779 /*
3780 * Isolate the name of the shell:
3781 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3782 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003783 * But don't allow a space in the path, so that this works:
3784 * "/usr/bin/csh --rcfile ~/.cshrc"
3785 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003786 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003787#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 p = gettail(p_sh);
3789 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003790#else
3791 p = skiptowhite(p_sh);
3792 if (*p == NUL)
3793 {
3794 /* No white space, use the tail. */
3795 p = vim_strsave(gettail(p_sh));
3796 }
3797 else
3798 {
3799 char_u *p1, *p2;
3800
3801 /* Find the last path separator before the space. */
3802 p1 = p_sh;
3803 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3804 if (vim_ispathsep(*p2))
3805 p1 = p2 + 1;
3806 p = vim_strnsave(p1, (int)(p - p1));
3807 }
3808#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 if (p != NULL)
3810 {
3811 /*
3812 * Default for p_sp is "| tee", for p_srr is ">".
3813 * For known shells it is changed here to include stderr.
3814 */
3815 if ( fnamecmp(p, "csh") == 0
3816 || fnamecmp(p, "tcsh") == 0
3817# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3818 || fnamecmp(p, "csh.exe") == 0
3819 || fnamecmp(p, "tcsh.exe") == 0
3820# endif
3821 )
3822 {
3823#if defined(FEAT_QUICKFIX)
3824 if (do_sp)
3825 {
3826# ifdef WIN3264
3827 p_sp = (char_u *)">&";
3828# else
3829 p_sp = (char_u *)"|& tee";
3830# endif
3831 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3832 }
3833#endif
3834 if (do_srr)
3835 {
3836 p_srr = (char_u *)">&";
3837 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3838 }
3839 }
3840 else
3841# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3842 if ( fnamecmp(p, "sh") == 0
3843 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003844 || fnamecmp(p, "mksh") == 0
3845 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003847 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 || fnamecmp(p, "bash") == 0
3849# ifdef WIN3264
3850 || fnamecmp(p, "cmd") == 0
3851 || fnamecmp(p, "sh.exe") == 0
3852 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003853 || fnamecmp(p, "mksh.exe") == 0
3854 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003856 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857 || fnamecmp(p, "bash.exe") == 0
3858 || fnamecmp(p, "cmd.exe") == 0
3859# endif
3860 )
3861# endif
3862 {
3863#if defined(FEAT_QUICKFIX)
3864 if (do_sp)
3865 {
3866# ifdef WIN3264
3867 p_sp = (char_u *)">%s 2>&1";
3868# else
3869 p_sp = (char_u *)"2>&1| tee";
3870# endif
3871 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3872 }
3873#endif
3874 if (do_srr)
3875 {
3876 p_srr = (char_u *)">%s 2>&1";
3877 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3878 }
3879 }
3880 vim_free(p);
3881 }
3882#endif
3883
3884#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3885 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003886 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3887 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 * This is done after other initializations, where 'shell' might have been
3889 * set, but only if they have not been set before. Default for p_shcf is
3890 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3891 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3892 * command.com. And for Win32 we need to set p_sxq instead.
3893 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003894 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 {
3896 int idx3;
3897
3898 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003899 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 {
3901 p_shcf = (char_u *)"-c";
3902 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3903 }
3904
3905# ifndef DJGPP
3906# ifdef WIN3264
3907 /* Somehow Win32 requires the quotes around the redirection too */
3908 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003909 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 {
3911 p_sxq = (char_u *)"\"";
3912 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3913 }
3914# else
3915 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003916 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 {
3918 p_shq = (char_u *)"\"";
3919 options[idx3].def_val[VI_DEFAULT] = p_shq;
3920 }
3921# endif
3922# endif
3923 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003924 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3925 {
3926 int idx3;
3927
3928 /*
3929 * cmd.exe on Windows will strip the first and last double quote given
3930 * on the command line, e.g. most of the time things like:
3931 * cmd /c "my path/to/echo" "my args to echo"
3932 * become:
3933 * my path/to/echo" "my args to echo
3934 * when executed.
3935 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003936 * To avoid this, set shellxquote to surround the command in
3937 * parenthesis. This appears to make most commands work, without
3938 * breaking commands that worked previously, such as
3939 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003940 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003941 idx3 = findoption((char_u *)"sxq");
3942 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3943 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003944 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003945 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3946 }
3947
Bram Moolenaara64ba222012-02-12 23:23:31 +01003948 idx3 = findoption((char_u *)"shcf");
3949 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3950 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003951 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003952 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3953 }
3954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955#endif
3956
3957#ifdef FEAT_TITLE
3958 set_title_defaults();
3959#endif
3960}
3961
3962#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3963/*
3964 * When 'helplang' is still at its default value, set it to "lang".
3965 * Only the first two characters of "lang" are used.
3966 */
3967 void
3968set_helplang_default(lang)
3969 char_u *lang;
3970{
3971 int idx;
3972
3973 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3974 return;
3975 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003976 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 {
3978 if (options[idx].flags & P_ALLOCED)
3979 free_string_option(p_hlg);
3980 p_hlg = vim_strsave(lang);
3981 if (p_hlg == NULL)
3982 p_hlg = empty_option;
3983 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003984 {
3985 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3986 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3987 {
3988 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3989 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993 options[idx].flags |= P_ALLOCED;
3994 }
3995}
3996#endif
3997
3998#ifdef FEAT_GUI
3999static char_u *gui_bg_default __ARGS((void));
4000
4001 static char_u *
4002gui_bg_default()
4003{
4004 if (gui_get_lightness(gui.back_pixel) < 127)
4005 return (char_u *)"dark";
4006 return (char_u *)"light";
4007}
4008
4009/*
4010 * Option initializations that can only be done after opening the GUI window.
4011 */
4012 void
4013init_gui_options()
4014{
4015 /* Set the 'background' option according to the lightness of the
4016 * background color, unless the user has set it already. */
4017 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4018 {
4019 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4020 highlight_changed();
4021 }
4022}
4023#endif
4024
4025#ifdef FEAT_TITLE
4026/*
4027 * 'title' and 'icon' only default to true if they have not been set or reset
4028 * in .vimrc and we can read the old value.
4029 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4030 * they can be reset. This reduces startup time when using X on a remote
4031 * machine.
4032 */
4033 void
4034set_title_defaults()
4035{
4036 int idx1;
4037 long val;
4038
4039 /*
4040 * If GUI is (going to be) used, we can always set the window title and
4041 * icon name. Saves a bit of time, because the X11 display server does
4042 * not need to be contacted.
4043 */
4044 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004045 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 {
4047#ifdef FEAT_GUI
4048 if (gui.starting || gui.in_use)
4049 val = TRUE;
4050 else
4051#endif
4052 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004053 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 p_title = val;
4055 }
4056 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004057 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 {
4059#ifdef FEAT_GUI
4060 if (gui.starting || gui.in_use)
4061 val = TRUE;
4062 else
4063#endif
4064 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004065 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 p_icon = val;
4067 }
4068}
4069#endif
4070
4071/*
4072 * Parse 'arg' for option settings.
4073 *
4074 * 'arg' may be IObuff, but only when no errors can be present and option
4075 * does not need to be expanded with option_expand().
4076 * "opt_flags":
4077 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004078 * OPT_GLOBAL for ":setglobal"
4079 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004081 * OPT_WINONLY to only set window-local options
4082 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 *
4084 * returns FAIL if an error is detected, OK otherwise
4085 */
4086 int
4087do_set(arg, opt_flags)
4088 char_u *arg; /* option string (may be written to!) */
4089 int opt_flags;
4090{
4091 int opt_idx;
4092 char_u *errmsg;
4093 char_u errbuf[80];
4094 char_u *startarg;
4095 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4096 int nextchar; /* next non-white char after option name */
4097 int afterchar; /* character just after option name */
4098 int len;
4099 int i;
4100 long value;
4101 int key;
4102 long_u flags; /* flags for current option */
4103 char_u *varp = NULL; /* pointer to variable for current option */
4104 int did_show = FALSE; /* already showed one value */
4105 int adding; /* "opt+=arg" */
4106 int prepending; /* "opt^=arg" */
4107 int removing; /* "opt-=arg" */
4108 int cp_val = 0;
4109 char_u key_name[2];
4110
4111 if (*arg == NUL)
4112 {
4113 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004114 did_show = TRUE;
4115 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 }
4117
4118 while (*arg != NUL) /* loop to process all options */
4119 {
4120 errmsg = NULL;
4121 startarg = arg; /* remember for error message */
4122
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004123 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4124 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 {
4126 /*
4127 * ":set all" show all options.
4128 * ":set all&" set all options to their default value.
4129 */
4130 arg += 3;
4131 if (*arg == '&')
4132 {
4133 ++arg;
4134 /* Only for :set command set global value of local options. */
4135 set_options_default(OPT_FREE | opt_flags);
4136 }
4137 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004138 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004140 did_show = TRUE;
4141 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004143 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 {
4145 showoptions(2, opt_flags);
4146 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004147 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 arg += 7;
4149 }
4150 else
4151 {
4152 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004153 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 {
4155 prefix = 0;
4156 arg += 2;
4157 }
4158 else if (STRNCMP(arg, "inv", 3) == 0)
4159 {
4160 prefix = 2;
4161 arg += 3;
4162 }
4163
4164 /* find end of name */
4165 key = 0;
4166 if (*arg == '<')
4167 {
4168 nextchar = 0;
4169 opt_idx = -1;
4170 /* look out for <t_>;> */
4171 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4172 len = 5;
4173 else
4174 {
4175 len = 1;
4176 while (arg[len] != NUL && arg[len] != '>')
4177 ++len;
4178 }
4179 if (arg[len] != '>')
4180 {
4181 errmsg = e_invarg;
4182 goto skip;
4183 }
4184 arg[len] = NUL; /* put NUL after name */
4185 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4186 opt_idx = findoption(arg + 1);
4187 arg[len++] = '>'; /* restore '>' */
4188 if (opt_idx == -1)
4189 key = find_key_option(arg + 1);
4190 }
4191 else
4192 {
4193 len = 0;
4194 /*
4195 * The two characters after "t_" may not be alphanumeric.
4196 */
4197 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4198 len = 4;
4199 else
4200 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4201 ++len;
4202 nextchar = arg[len];
4203 arg[len] = NUL; /* put NUL after name */
4204 opt_idx = findoption(arg);
4205 arg[len] = nextchar; /* restore nextchar */
4206 if (opt_idx == -1)
4207 key = find_key_option(arg);
4208 }
4209
4210 /* remember character after option name */
4211 afterchar = arg[len];
4212
4213 /* skip white space, allow ":set ai ?" */
4214 while (vim_iswhite(arg[len]))
4215 ++len;
4216
4217 adding = FALSE;
4218 prepending = FALSE;
4219 removing = FALSE;
4220 if (arg[len] != NUL && arg[len + 1] == '=')
4221 {
4222 if (arg[len] == '+')
4223 {
4224 adding = TRUE; /* "+=" */
4225 ++len;
4226 }
4227 else if (arg[len] == '^')
4228 {
4229 prepending = TRUE; /* "^=" */
4230 ++len;
4231 }
4232 else if (arg[len] == '-')
4233 {
4234 removing = TRUE; /* "-=" */
4235 ++len;
4236 }
4237 }
4238 nextchar = arg[len];
4239
4240 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4241 {
4242 errmsg = (char_u *)N_("E518: Unknown option");
4243 goto skip;
4244 }
4245
4246 if (opt_idx >= 0)
4247 {
4248 if (options[opt_idx].var == NULL) /* hidden option: skip */
4249 {
4250 /* Only give an error message when requesting the value of
4251 * a hidden option, ignore setting it. */
4252 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4253 && (!(options[opt_idx].flags & P_BOOL)
4254 || nextchar == '?'))
4255 errmsg = (char_u *)N_("E519: Option not supported");
4256 goto skip;
4257 }
4258
4259 flags = options[opt_idx].flags;
4260 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4261 }
4262 else
4263 {
4264 flags = P_STRING;
4265 if (key < 0)
4266 {
4267 key_name[0] = KEY2TERMCAP0(key);
4268 key_name[1] = KEY2TERMCAP1(key);
4269 }
4270 else
4271 {
4272 key_name[0] = KS_KEY;
4273 key_name[1] = (key & 0xff);
4274 }
4275 }
4276
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004277 /* Skip all options that are not window-local (used when showing
4278 * an already loaded buffer in a window). */
4279 if ((opt_flags & OPT_WINONLY)
4280 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4281 goto skip;
4282
Bram Moolenaara3227e22006-03-08 21:32:40 +00004283 /* Skip all options that are window-local (used for :vimgrep). */
4284 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4285 && options[opt_idx].var == VAR_WIN)
4286 goto skip;
4287
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004288 /* Disallow changing some options from modelines. */
4289 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004291 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004292 {
4293 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4294 goto skip;
4295 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004296#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004297 /* In diff mode some options are overruled. This avoids that
4298 * 'foldmethod' becomes "marker" instead of "diff" and that
4299 * "wrap" gets set. */
4300 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004301 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004302 && (options[opt_idx].indir == PV_FDM
4303 || options[opt_idx].indir == PV_WRAP))
4304 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004306 }
4307
4308#ifdef HAVE_SANDBOX
4309 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004310 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311 {
4312 errmsg = (char_u *)_(e_sandbox);
4313 goto skip;
4314 }
4315#endif
4316
4317 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4318 {
4319 arg += len;
4320 cp_val = p_cp;
4321 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4322 {
4323 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4324 {
4325 cp_val = FALSE;
4326 arg += 3;
4327 }
4328 else /* "opt&vi": set to Vi default */
4329 {
4330 cp_val = TRUE;
4331 arg += 2;
4332 }
4333 }
4334 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4335 && arg[1] != NUL && !vim_iswhite(arg[1]))
4336 {
4337 errmsg = e_trailing;
4338 goto skip;
4339 }
4340 }
4341
4342 /*
4343 * allow '=' and ':' as MSDOS command.com allows only one
4344 * '=' character per "set" command line. grrr. (jw)
4345 */
4346 if (nextchar == '?'
4347 || (prefix == 1
4348 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4349 && !(flags & P_BOOL)))
4350 {
4351 /*
4352 * print value
4353 */
4354 if (did_show)
4355 msg_putchar('\n'); /* cursor below last one */
4356 else
4357 {
4358 gotocmdline(TRUE); /* cursor at status line */
4359 did_show = TRUE; /* remember that we did a line */
4360 }
4361 if (opt_idx >= 0)
4362 {
4363 showoneopt(&options[opt_idx], opt_flags);
4364#ifdef FEAT_EVAL
4365 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004366 {
4367 /* Mention where the option was last set. */
4368 if (varp == options[opt_idx].var)
4369 last_set_msg(options[opt_idx].scriptID);
4370 else if ((int)options[opt_idx].indir & PV_WIN)
4371 last_set_msg(curwin->w_p_scriptID[
4372 (int)options[opt_idx].indir & PV_MASK]);
4373 else if ((int)options[opt_idx].indir & PV_BUF)
4374 last_set_msg(curbuf->b_p_scriptID[
4375 (int)options[opt_idx].indir & PV_MASK]);
4376 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377#endif
4378 }
4379 else
4380 {
4381 char_u *p;
4382
4383 p = find_termcode(key_name);
4384 if (p == NULL)
4385 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004386 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387 goto skip;
4388 }
4389 else
4390 (void)show_one_termcode(key_name, p, TRUE);
4391 }
4392 if (nextchar != '?'
4393 && nextchar != NUL && !vim_iswhite(afterchar))
4394 errmsg = e_trailing;
4395 }
4396 else
4397 {
4398 if (flags & P_BOOL) /* boolean */
4399 {
4400 if (nextchar == '=' || nextchar == ':')
4401 {
4402 errmsg = e_invarg;
4403 goto skip;
4404 }
4405
4406 /*
4407 * ":set opt!": invert
4408 * ":set opt&": reset to default value
4409 * ":set opt<": reset to global value
4410 */
4411 if (nextchar == '!')
4412 value = *(int *)(varp) ^ 1;
4413 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004414 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415 ((flags & P_VI_DEF) || cp_val)
4416 ? VI_DEFAULT : VIM_DEFAULT];
4417 else if (nextchar == '<')
4418 {
4419 /* For 'autoread' -1 means to use global value. */
4420 if ((int *)varp == &curbuf->b_p_ar
4421 && opt_flags == OPT_LOCAL)
4422 value = -1;
4423 else
4424 value = *(int *)get_varp_scope(&(options[opt_idx]),
4425 OPT_GLOBAL);
4426 }
4427 else
4428 {
4429 /*
4430 * ":set invopt": invert
4431 * ":set opt" or ":set noopt": set or reset
4432 */
4433 if (nextchar != NUL && !vim_iswhite(afterchar))
4434 {
4435 errmsg = e_trailing;
4436 goto skip;
4437 }
4438 if (prefix == 2) /* inv */
4439 value = *(int *)(varp) ^ 1;
4440 else
4441 value = prefix;
4442 }
4443
4444 errmsg = set_bool_option(opt_idx, varp, (int)value,
4445 opt_flags);
4446 }
4447 else /* numeric or string */
4448 {
4449 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4450 || prefix != 1)
4451 {
4452 errmsg = e_invarg;
4453 goto skip;
4454 }
4455
4456 if (flags & P_NUM) /* numeric */
4457 {
4458 /*
4459 * Different ways to set a number option:
4460 * & set to default value
4461 * < set to global value
4462 * <xx> accept special key codes for 'wildchar'
4463 * c accept any non-digit for 'wildchar'
4464 * [-]0-9 set number
4465 * other error
4466 */
4467 ++arg;
4468 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004469 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004470 ((flags & P_VI_DEF) || cp_val)
4471 ? VI_DEFAULT : VIM_DEFAULT];
4472 else if (nextchar == '<')
4473 value = *(long *)get_varp_scope(&(options[opt_idx]),
4474 OPT_GLOBAL);
4475 else if (((long *)varp == &p_wc
4476 || (long *)varp == &p_wcm)
4477 && (*arg == '<'
4478 || *arg == '^'
4479 || ((!arg[1] || vim_iswhite(arg[1]))
4480 && !VIM_ISDIGIT(*arg))))
4481 {
4482 value = string_to_key(arg);
4483 if (value == 0 && (long *)varp != &p_wcm)
4484 {
4485 errmsg = e_invarg;
4486 goto skip;
4487 }
4488 }
4489 /* allow negative numbers (for 'undolevels') */
4490 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4491 {
4492 i = 0;
4493 if (*arg == '-')
4494 i = 1;
4495#ifdef HAVE_STRTOL
4496 value = strtol((char *)arg, NULL, 0);
4497 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4498 i += 2;
4499#else
4500 value = atol((char *)arg);
4501#endif
4502 while (VIM_ISDIGIT(arg[i]))
4503 ++i;
4504 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4505 {
4506 errmsg = e_invarg;
4507 goto skip;
4508 }
4509 }
4510 else
4511 {
4512 errmsg = (char_u *)N_("E521: Number required after =");
4513 goto skip;
4514 }
4515
4516 if (adding)
4517 value = *(long *)varp + value;
4518 if (prepending)
4519 value = *(long *)varp * value;
4520 if (removing)
4521 value = *(long *)varp - value;
4522 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004523 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004524 }
4525 else if (opt_idx >= 0) /* string */
4526 {
4527 char_u *save_arg = NULL;
4528 char_u *s = NULL;
4529 char_u *oldval; /* previous value if *varp */
4530 char_u *newval;
4531 char_u *origval;
4532 unsigned newlen;
4533 int comma;
4534 int bs;
4535 int new_value_alloced; /* new string option
4536 was allocated */
4537
4538 /* When using ":set opt=val" for a global option
4539 * with a local value the local value will be
4540 * reset, use the global value here. */
4541 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004542 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004543 varp = options[opt_idx].var;
4544
4545 /* The old value is kept until we are sure that the
4546 * new value is valid. */
4547 oldval = *(char_u **)varp;
4548 if (nextchar == '&') /* set to default val */
4549 {
4550 newval = options[opt_idx].def_val[
4551 ((flags & P_VI_DEF) || cp_val)
4552 ? VI_DEFAULT : VIM_DEFAULT];
4553 if ((char_u **)varp == &p_bg)
4554 {
4555 /* guess the value of 'background' */
4556#ifdef FEAT_GUI
4557 if (gui.in_use)
4558 newval = gui_bg_default();
4559 else
4560#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004561 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 }
4563
4564 /* expand environment variables and ~ (since the
4565 * default value was already expanded, only
4566 * required when an environment variable was set
4567 * later */
4568 if (newval == NULL)
4569 newval = empty_option;
4570 else
4571 {
4572 s = option_expand(opt_idx, newval);
4573 if (s == NULL)
4574 s = newval;
4575 newval = vim_strsave(s);
4576 }
4577 new_value_alloced = TRUE;
4578 }
4579 else if (nextchar == '<') /* set to global val */
4580 {
4581 newval = vim_strsave(*(char_u **)get_varp_scope(
4582 &(options[opt_idx]), OPT_GLOBAL));
4583 new_value_alloced = TRUE;
4584 }
4585 else
4586 {
4587 ++arg; /* jump to after the '=' or ':' */
4588
4589 /*
4590 * Set 'keywordprg' to ":help" if an empty
4591 * value was passed to :set by the user.
4592 * Misuse errbuf[] for the resulting string.
4593 */
4594 if (varp == (char_u *)&p_kp
4595 && (*arg == NUL || *arg == ' '))
4596 {
4597 STRCPY(errbuf, ":help");
4598 save_arg = arg;
4599 arg = errbuf;
4600 }
4601 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004602 * Convert 'backspace' number to string, for
4603 * adding, prepending and removing string.
4604 */
4605 else if (varp == (char_u *)&p_bs
4606 && VIM_ISDIGIT(**(char_u **)varp))
4607 {
4608 i = getdigits((char_u **)varp);
4609 switch (i)
4610 {
4611 case 0:
4612 *(char_u **)varp = empty_option;
4613 break;
4614 case 1:
4615 *(char_u **)varp = vim_strsave(
4616 (char_u *)"indent,eol");
4617 break;
4618 case 2:
4619 *(char_u **)varp = vim_strsave(
4620 (char_u *)"indent,eol,start");
4621 break;
4622 }
4623 vim_free(oldval);
4624 oldval = *(char_u **)varp;
4625 }
4626 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004627 * Convert 'whichwrap' number to string, for
4628 * backwards compatibility with Vim 3.0.
4629 * Misuse errbuf[] for the resulting string.
4630 */
4631 else if (varp == (char_u *)&p_ww
4632 && VIM_ISDIGIT(*arg))
4633 {
4634 *errbuf = NUL;
4635 i = getdigits(&arg);
4636 if (i & 1)
4637 STRCAT(errbuf, "b,");
4638 if (i & 2)
4639 STRCAT(errbuf, "s,");
4640 if (i & 4)
4641 STRCAT(errbuf, "h,l,");
4642 if (i & 8)
4643 STRCAT(errbuf, "<,>,");
4644 if (i & 16)
4645 STRCAT(errbuf, "[,],");
4646 if (*errbuf != NUL) /* remove trailing , */
4647 errbuf[STRLEN(errbuf) - 1] = NUL;
4648 save_arg = arg;
4649 arg = errbuf;
4650 }
4651 /*
4652 * Remove '>' before 'dir' and 'bdir', for
4653 * backwards compatibility with version 3.0
4654 */
4655 else if ( *arg == '>'
4656 && (varp == (char_u *)&p_dir
4657 || varp == (char_u *)&p_bdir))
4658 {
4659 ++arg;
4660 }
4661
4662 /* When setting the local value of a global
4663 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004664 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004665 && (opt_flags & OPT_LOCAL))
4666 origval = *(char_u **)get_varp(
4667 &options[opt_idx]);
4668 else
4669 origval = oldval;
4670
4671 /*
4672 * Copy the new string into allocated memory.
4673 * Can't use set_string_option_direct(), because
4674 * we need to remove the backslashes.
4675 */
4676 /* get a bit too much */
4677 newlen = (unsigned)STRLEN(arg) + 1;
4678 if (adding || prepending || removing)
4679 newlen += (unsigned)STRLEN(origval) + 1;
4680 newval = alloc(newlen);
4681 if (newval == NULL) /* out of mem, don't change */
4682 break;
4683 s = newval;
4684
4685 /*
4686 * Copy the string, skip over escaped chars.
4687 * For MS-DOS and WIN32 backslashes before normal
4688 * file name characters are not removed, and keep
4689 * backslash at start, for "\\machine\path", but
4690 * do remove it for "\\\\machine\\path".
4691 * The reverse is found in ExpandOldSetting().
4692 */
4693 while (*arg && !vim_iswhite(*arg))
4694 {
4695 if (*arg == '\\' && arg[1] != NUL
4696#ifdef BACKSLASH_IN_FILENAME
4697 && !((flags & P_EXPAND)
4698 && vim_isfilec(arg[1])
4699 && (arg[1] != '\\'
4700 || (s == newval
4701 && arg[2] != '\\')))
4702#endif
4703 )
4704 ++arg; /* remove backslash */
4705#ifdef FEAT_MBYTE
4706 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004707 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004708 {
4709 /* copy multibyte char */
4710 mch_memmove(s, arg, (size_t)i);
4711 arg += i;
4712 s += i;
4713 }
4714 else
4715#endif
4716 *s++ = *arg++;
4717 }
4718 *s = NUL;
4719
4720 /*
4721 * Expand environment variables and ~.
4722 * Don't do it when adding without inserting a
4723 * comma.
4724 */
4725 if (!(adding || prepending || removing)
4726 || (flags & P_COMMA))
4727 {
4728 s = option_expand(opt_idx, newval);
4729 if (s != NULL)
4730 {
4731 vim_free(newval);
4732 newlen = (unsigned)STRLEN(s) + 1;
4733 if (adding || prepending || removing)
4734 newlen += (unsigned)STRLEN(origval) + 1;
4735 newval = alloc(newlen);
4736 if (newval == NULL)
4737 break;
4738 STRCPY(newval, s);
4739 }
4740 }
4741
4742 /* locate newval[] in origval[] when removing it
4743 * and when adding to avoid duplicates */
4744 i = 0; /* init for GCC */
4745 if (removing || (flags & P_NODUP))
4746 {
4747 i = (int)STRLEN(newval);
4748 bs = 0;
4749 for (s = origval; *s; ++s)
4750 {
4751 if ((!(flags & P_COMMA)
4752 || s == origval
4753 || (s[-1] == ',' && !(bs & 1)))
4754 && STRNCMP(s, newval, i) == 0
4755 && (!(flags & P_COMMA)
4756 || s[i] == ','
4757 || s[i] == NUL))
4758 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004759 /* Count backslashes. Only a comma with an
4760 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004761 * recognized as a separator */
4762 if (s > origval && s[-1] == '\\')
4763 ++bs;
4764 else
4765 bs = 0;
4766 }
4767
4768 /* do not add if already there */
4769 if ((adding || prepending) && *s)
4770 {
4771 prepending = FALSE;
4772 adding = FALSE;
4773 STRCPY(newval, origval);
4774 }
4775 }
4776
4777 /* concatenate the two strings; add a ',' if
4778 * needed */
4779 if (adding || prepending)
4780 {
4781 comma = ((flags & P_COMMA) && *origval != NUL
4782 && *newval != NUL);
4783 if (adding)
4784 {
4785 i = (int)STRLEN(origval);
4786 mch_memmove(newval + i + comma, newval,
4787 STRLEN(newval) + 1);
4788 mch_memmove(newval, origval, (size_t)i);
4789 }
4790 else
4791 {
4792 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004793 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004794 }
4795 if (comma)
4796 newval[i] = ',';
4797 }
4798
4799 /* Remove newval[] from origval[]. (Note: "i" has
4800 * been set above and is used here). */
4801 if (removing)
4802 {
4803 STRCPY(newval, origval);
4804 if (*s)
4805 {
4806 /* may need to remove a comma */
4807 if (flags & P_COMMA)
4808 {
4809 if (s == origval)
4810 {
4811 /* include comma after string */
4812 if (s[i] == ',')
4813 ++i;
4814 }
4815 else
4816 {
4817 /* include comma before string */
4818 --s;
4819 ++i;
4820 }
4821 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004822 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004823 }
4824 }
4825
4826 if (flags & P_FLAGLIST)
4827 {
4828 /* Remove flags that appear twice. */
4829 for (s = newval; *s; ++s)
4830 if ((!(flags & P_COMMA) || *s != ',')
4831 && vim_strchr(s + 1, *s) != NULL)
4832 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004833 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004834 --s;
4835 }
4836 }
4837
4838 if (save_arg != NULL) /* number for 'whichwrap' */
4839 arg = save_arg;
4840 new_value_alloced = TRUE;
4841 }
4842
4843 /* Set the new value. */
4844 *(char_u **)(varp) = newval;
4845
4846 /* Handle side effects, and set the global value for
4847 * ":set" on local options. */
4848 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4849 new_value_alloced, oldval, errbuf, opt_flags);
4850
4851 /* If error detected, print the error message. */
4852 if (errmsg != NULL)
4853 goto skip;
4854 }
4855 else /* key code option */
4856 {
4857 char_u *p;
4858
4859 if (nextchar == '&')
4860 {
4861 if (add_termcap_entry(key_name, TRUE) == FAIL)
4862 errmsg = (char_u *)N_("E522: Not found in termcap");
4863 }
4864 else
4865 {
4866 ++arg; /* jump to after the '=' or ':' */
4867 for (p = arg; *p && !vim_iswhite(*p); ++p)
4868 if (*p == '\\' && p[1] != NUL)
4869 ++p;
4870 nextchar = *p;
4871 *p = NUL;
4872 add_termcode(key_name, arg, FALSE);
4873 *p = nextchar;
4874 }
4875 if (full_screen)
4876 ttest(FALSE);
4877 redraw_all_later(CLEAR);
4878 }
4879 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004880
Bram Moolenaar071d4272004-06-13 20:20:40 +00004881 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004882 did_set_option(opt_idx, opt_flags,
4883 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004884 }
4885
4886skip:
4887 /*
4888 * Advance to next argument.
4889 * - skip until a blank found, taking care of backslashes
4890 * - skip blanks
4891 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4892 */
4893 for (i = 0; i < 2 ; ++i)
4894 {
4895 while (*arg != NUL && !vim_iswhite(*arg))
4896 if (*arg++ == '\\' && *arg != NUL)
4897 ++arg;
4898 arg = skipwhite(arg);
4899 if (*arg != '=')
4900 break;
4901 }
4902 }
4903
4904 if (errmsg != NULL)
4905 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004906 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004907 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004908 if (i + (arg - startarg) < IOSIZE)
4909 {
4910 /* append the argument with the error */
4911 STRCAT(IObuff, ": ");
4912 mch_memmove(IObuff + i, startarg, (arg - startarg));
4913 IObuff[i + (arg - startarg)] = NUL;
4914 }
4915 /* make sure all characters are printable */
4916 trans_characters(IObuff, IOSIZE);
4917
4918 ++no_wait_return; /* wait_return done later */
4919 emsg(IObuff); /* show error highlighted */
4920 --no_wait_return;
4921
4922 return FAIL;
4923 }
4924
4925 arg = skipwhite(arg);
4926 }
4927
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004928theend:
4929 if (silent_mode && did_show)
4930 {
4931 /* After displaying option values in silent mode. */
4932 silent_mode = FALSE;
4933 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4934 msg_putchar('\n');
4935 cursor_on(); /* msg_start() switches it off */
4936 out_flush();
4937 silent_mode = TRUE;
4938 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4939 }
4940
Bram Moolenaar071d4272004-06-13 20:20:40 +00004941 return OK;
4942}
4943
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004944/*
4945 * Call this when an option has been given a new value through a user command.
4946 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4947 */
4948 static void
4949did_set_option(opt_idx, opt_flags, new_value)
4950 int opt_idx;
4951 int opt_flags; /* possibly with OPT_MODELINE */
4952 int new_value; /* value was replaced completely */
4953{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004954 long_u *p;
4955
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004956 options[opt_idx].flags |= P_WAS_SET;
4957
4958 /* When an option is set in the sandbox, from a modeline or in secure mode
4959 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004960 * flag. */
4961 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004962 if (secure
4963#ifdef HAVE_SANDBOX
4964 || sandbox != 0
4965#endif
4966 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004967 *p = *p | P_INSECURE;
4968 else if (new_value)
4969 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004970}
4971
Bram Moolenaar071d4272004-06-13 20:20:40 +00004972 static char_u *
4973illegal_char(errbuf, c)
4974 char_u *errbuf;
4975 int c;
4976{
4977 if (errbuf == NULL)
4978 return (char_u *)"";
4979 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004980 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004981 return errbuf;
4982}
4983
4984/*
4985 * Convert a key name or string into a key value.
4986 * Used for 'wildchar' and 'cedit' options.
4987 */
4988 static int
4989string_to_key(arg)
4990 char_u *arg;
4991{
4992 if (*arg == '<')
4993 return find_key_option(arg + 1);
4994 if (*arg == '^')
4995 return Ctrl_chr(arg[1]);
4996 return *arg;
4997}
4998
4999#ifdef FEAT_CMDWIN
5000/*
5001 * Check value of 'cedit' and set cedit_key.
5002 * Returns NULL if value is OK, error message otherwise.
5003 */
5004 static char_u *
5005check_cedit()
5006{
5007 int n;
5008
5009 if (*p_cedit == NUL)
5010 cedit_key = -1;
5011 else
5012 {
5013 n = string_to_key(p_cedit);
5014 if (vim_isprintc(n))
5015 return e_invarg;
5016 cedit_key = n;
5017 }
5018 return NULL;
5019}
5020#endif
5021
5022#ifdef FEAT_TITLE
5023/*
5024 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5025 * maketitle() to create and display it.
5026 * When switching the title or icon off, call mch_restore_title() to get
5027 * the old value back.
5028 */
5029 static void
5030did_set_title(icon)
5031 int icon; /* Did set icon instead of title */
5032{
5033 if (starting != NO_SCREEN
5034#ifdef FEAT_GUI
5035 && !gui.starting
5036#endif
5037 )
5038 {
5039 maketitle();
5040 if (icon)
5041 {
5042 if (!p_icon)
5043 mch_restore_title(2);
5044 }
5045 else
5046 {
5047 if (!p_title)
5048 mch_restore_title(1);
5049 }
5050 }
5051}
5052#endif
5053
5054/*
5055 * set_options_bin - called when 'bin' changes value.
5056 */
5057 void
5058set_options_bin(oldval, newval, opt_flags)
5059 int oldval;
5060 int newval;
5061 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5062{
5063 /*
5064 * The option values that are changed when 'bin' changes are
5065 * copied when 'bin is set and restored when 'bin' is reset.
5066 */
5067 if (newval)
5068 {
5069 if (!oldval) /* switched on */
5070 {
5071 if (!(opt_flags & OPT_GLOBAL))
5072 {
5073 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5074 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5075 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5076 curbuf->b_p_et_nobin = curbuf->b_p_et;
5077 }
5078 if (!(opt_flags & OPT_LOCAL))
5079 {
5080 p_tw_nobin = p_tw;
5081 p_wm_nobin = p_wm;
5082 p_ml_nobin = p_ml;
5083 p_et_nobin = p_et;
5084 }
5085 }
5086
5087 if (!(opt_flags & OPT_GLOBAL))
5088 {
5089 curbuf->b_p_tw = 0; /* no automatic line wrap */
5090 curbuf->b_p_wm = 0; /* no automatic line wrap */
5091 curbuf->b_p_ml = 0; /* no modelines */
5092 curbuf->b_p_et = 0; /* no expandtab */
5093 }
5094 if (!(opt_flags & OPT_LOCAL))
5095 {
5096 p_tw = 0;
5097 p_wm = 0;
5098 p_ml = FALSE;
5099 p_et = FALSE;
5100 p_bin = TRUE; /* needed when called for the "-b" argument */
5101 }
5102 }
5103 else if (oldval) /* switched off */
5104 {
5105 if (!(opt_flags & OPT_GLOBAL))
5106 {
5107 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5108 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5109 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5110 curbuf->b_p_et = curbuf->b_p_et_nobin;
5111 }
5112 if (!(opt_flags & OPT_LOCAL))
5113 {
5114 p_tw = p_tw_nobin;
5115 p_wm = p_wm_nobin;
5116 p_ml = p_ml_nobin;
5117 p_et = p_et_nobin;
5118 }
5119 }
5120}
5121
5122#ifdef FEAT_VIMINFO
5123/*
5124 * Find the parameter represented by the given character (eg ', :, ", or /),
5125 * and return its associated value in the 'viminfo' string.
5126 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005127 * If the parameter is not specified in the string or there is no following
5128 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005129 */
5130 int
5131get_viminfo_parameter(type)
5132 int type;
5133{
5134 char_u *p;
5135
5136 p = find_viminfo_parameter(type);
5137 if (p != NULL && VIM_ISDIGIT(*p))
5138 return atoi((char *)p);
5139 return -1;
5140}
5141
5142/*
5143 * Find the parameter represented by the given character (eg ''', ':', '"', or
5144 * '/') in the 'viminfo' option and return a pointer to the string after it.
5145 * Return NULL if the parameter is not specified in the string.
5146 */
5147 char_u *
5148find_viminfo_parameter(type)
5149 int type;
5150{
5151 char_u *p;
5152
5153 for (p = p_viminfo; *p; ++p)
5154 {
5155 if (*p == type)
5156 return p + 1;
5157 if (*p == 'n') /* 'n' is always the last one */
5158 break;
5159 p = vim_strchr(p, ','); /* skip until next ',' */
5160 if (p == NULL) /* hit the end without finding parameter */
5161 break;
5162 }
5163 return NULL;
5164}
5165#endif
5166
5167/*
5168 * Expand environment variables for some string options.
5169 * These string options cannot be indirect!
5170 * If "val" is NULL expand the current value of the option.
5171 * Return pointer to NameBuff, or NULL when not expanded.
5172 */
5173 static char_u *
5174option_expand(opt_idx, val)
5175 int opt_idx;
5176 char_u *val;
5177{
5178 /* if option doesn't need expansion nothing to do */
5179 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5180 return NULL;
5181
5182 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5183 * expand_env() would truncate the string. */
5184 if (val != NULL && STRLEN(val) > MAXPATHL)
5185 return NULL;
5186
5187 if (val == NULL)
5188 val = *(char_u **)options[opt_idx].var;
5189
5190 /*
5191 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5192 * Escape spaces when expanding 'tags', they are used to separate file
5193 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005194 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 */
5196 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005197 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005198#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005199 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5200#endif
5201 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005202 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5203 return NULL;
5204
5205 return NameBuff;
5206}
5207
5208/*
5209 * After setting various option values: recompute variables that depend on
5210 * option values.
5211 */
5212 static void
5213didset_options()
5214{
5215 /* initialize the table for 'iskeyword' et.al. */
5216 (void)init_chartab();
5217
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005218#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5222#ifdef FEAT_SESSION
5223 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5224 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5225#endif
5226#ifdef FEAT_FOLDING
5227 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5228#endif
5229 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5230#ifdef FEAT_VIRTUALEDIT
5231 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5232#endif
5233#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5234 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5235#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005236#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005237 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005238 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005239 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005240#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005241#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5242 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5243#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005244#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5246#endif
5247#ifdef FEAT_CMDWIN
5248 /* set cedit_key */
5249 (void)check_cedit();
5250#endif
5251}
5252
5253/*
5254 * Check for string options that are NULL (normally only termcap options).
5255 */
5256 void
5257check_options()
5258{
5259 int opt_idx;
5260
5261 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5262 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5263 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5264}
5265
5266/*
5267 * Check string options in a buffer for NULL value.
5268 */
5269 void
5270check_buf_options(buf)
5271 buf_T *buf;
5272{
5273#if defined(FEAT_QUICKFIX)
5274 check_string_option(&buf->b_p_bh);
5275 check_string_option(&buf->b_p_bt);
5276#endif
5277#ifdef FEAT_MBYTE
5278 check_string_option(&buf->b_p_fenc);
5279#endif
5280 check_string_option(&buf->b_p_ff);
5281#ifdef FEAT_FIND_ID
5282 check_string_option(&buf->b_p_def);
5283 check_string_option(&buf->b_p_inc);
5284# ifdef FEAT_EVAL
5285 check_string_option(&buf->b_p_inex);
5286# endif
5287#endif
5288#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5289 check_string_option(&buf->b_p_inde);
5290 check_string_option(&buf->b_p_indk);
5291#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005292#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5293 check_string_option(&buf->b_p_bexpr);
5294#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005295#if defined(FEAT_CRYPT)
5296 check_string_option(&buf->b_p_cm);
5297#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005298#if defined(FEAT_EVAL)
5299 check_string_option(&buf->b_p_fex);
5300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005301#ifdef FEAT_CRYPT
5302 check_string_option(&buf->b_p_key);
5303#endif
5304 check_string_option(&buf->b_p_kp);
5305 check_string_option(&buf->b_p_mps);
5306 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005307 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308 check_string_option(&buf->b_p_isk);
5309#ifdef FEAT_COMMENTS
5310 check_string_option(&buf->b_p_com);
5311#endif
5312#ifdef FEAT_FOLDING
5313 check_string_option(&buf->b_p_cms);
5314#endif
5315 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005316#ifdef FEAT_TEXTOBJ
5317 check_string_option(&buf->b_p_qe);
5318#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319#ifdef FEAT_SYN_HL
5320 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005321#endif
5322#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005323 check_string_option(&buf->b_s.b_p_spc);
5324 check_string_option(&buf->b_s.b_p_spf);
5325 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326#endif
5327#ifdef FEAT_SEARCHPATH
5328 check_string_option(&buf->b_p_sua);
5329#endif
5330#ifdef FEAT_CINDENT
5331 check_string_option(&buf->b_p_cink);
5332 check_string_option(&buf->b_p_cino);
5333#endif
5334#ifdef FEAT_AUTOCMD
5335 check_string_option(&buf->b_p_ft);
5336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5338 check_string_option(&buf->b_p_cinw);
5339#endif
5340#ifdef FEAT_INS_EXPAND
5341 check_string_option(&buf->b_p_cpt);
5342#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005343#ifdef FEAT_COMPL_FUNC
5344 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005345 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005347#ifdef FEAT_KEYMAP
5348 check_string_option(&buf->b_p_keymap);
5349#endif
5350#ifdef FEAT_QUICKFIX
5351 check_string_option(&buf->b_p_gp);
5352 check_string_option(&buf->b_p_mp);
5353 check_string_option(&buf->b_p_efm);
5354#endif
5355 check_string_option(&buf->b_p_ep);
5356 check_string_option(&buf->b_p_path);
5357 check_string_option(&buf->b_p_tags);
5358#ifdef FEAT_INS_EXPAND
5359 check_string_option(&buf->b_p_dict);
5360 check_string_option(&buf->b_p_tsr);
5361#endif
5362}
5363
5364/*
5365 * Free the string allocated for an option.
5366 * Checks for the string being empty_option. This may happen if we're out of
5367 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5368 * check_options().
5369 * Does NOT check for P_ALLOCED flag!
5370 */
5371 void
5372free_string_option(p)
5373 char_u *p;
5374{
5375 if (p != empty_option)
5376 vim_free(p);
5377}
5378
5379 void
5380clear_string_option(pp)
5381 char_u **pp;
5382{
5383 if (*pp != empty_option)
5384 vim_free(*pp);
5385 *pp = empty_option;
5386}
5387
5388 static void
5389check_string_option(pp)
5390 char_u **pp;
5391{
5392 if (*pp == NULL)
5393 *pp = empty_option;
5394}
5395
5396/*
5397 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5398 */
5399 void
5400set_term_option_alloced(p)
5401 char_u **p;
5402{
5403 int opt_idx;
5404
5405 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5406 if (options[opt_idx].var == (char_u *)p)
5407 {
5408 options[opt_idx].flags |= P_ALLOCED;
5409 return;
5410 }
5411 return; /* cannot happen: didn't find it! */
5412}
5413
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005414#if defined(FEAT_EVAL) || defined(PROTO)
5415/*
5416 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5417 * Return FALSE when it wasn't.
5418 * Return -1 for an unknown option.
5419 */
5420 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005421was_set_insecurely(opt, opt_flags)
5422 char_u *opt;
5423 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005424{
5425 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005426 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005427
5428 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005429 {
5430 flagp = insecure_flag(idx, opt_flags);
5431 return (*flagp & P_INSECURE) != 0;
5432 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005433 EMSG2(_(e_intern2), "was_set_insecurely()");
5434 return -1;
5435}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005436
5437/*
5438 * Get a pointer to the flags used for the P_INSECURE flag of option
5439 * "opt_idx". For some local options a local flags field is used.
5440 */
5441 static long_u *
5442insecure_flag(opt_idx, opt_flags)
5443 int opt_idx;
5444 int opt_flags;
5445{
5446 if (opt_flags & OPT_LOCAL)
5447 switch ((int)options[opt_idx].indir)
5448 {
5449#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005450 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005451#endif
5452#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005453# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005454 case PV_FDE: return &curwin->w_p_fde_flags;
5455 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005456# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005457# ifdef FEAT_BEVAL
5458 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5459# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005460# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005461 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005462# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005463 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005464# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005465 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005466# endif
5467#endif
5468 }
5469
5470 /* Nothing special, return global flags field. */
5471 return &options[opt_idx].flags;
5472}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005473#endif
5474
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005475#ifdef FEAT_TITLE
5476static void redraw_titles __ARGS((void));
5477
5478/*
5479 * Redraw the window title and/or tab page text later.
5480 */
5481static void redraw_titles()
5482{
5483 need_maketitle = TRUE;
5484# ifdef FEAT_WINDOWS
5485 redraw_tabline = TRUE;
5486# endif
5487}
5488#endif
5489
Bram Moolenaar071d4272004-06-13 20:20:40 +00005490/*
5491 * Set a string option to a new value (without checking the effect).
5492 * The string is copied into allocated memory.
5493 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005494 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005495 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496 */
5497 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005498set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499 char_u *name;
5500 int opt_idx;
5501 char_u *val;
5502 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005503 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504{
5505 char_u *s;
5506 char_u **varp;
5507 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005508 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509
Bram Moolenaar89d40322006-08-29 15:30:07 +00005510 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005512 idx = findoption(name);
5513 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005514 {
5515 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518 }
5519
Bram Moolenaar89d40322006-08-29 15:30:07 +00005520 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521 return;
5522
5523 s = vim_strsave(val);
5524 if (s != NULL)
5525 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005526 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005528 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529 free_string_option(*varp);
5530 *varp = s;
5531
5532 /* For buffer/window local option may also set the global value. */
5533 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005534 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535
Bram Moolenaar89d40322006-08-29 15:30:07 +00005536 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537
5538 /* When setting both values of a global option with a local value,
5539 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005540 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541 {
5542 free_string_option(*varp);
5543 *varp = empty_option;
5544 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005545# ifdef FEAT_EVAL
5546 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005547 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005548 set_sid == 0 ? current_SID : set_sid);
5549# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550 }
5551}
5552
5553/*
5554 * Set global value for string option when it's a local option.
5555 */
5556 static void
5557set_string_option_global(opt_idx, varp)
5558 int opt_idx; /* option index */
5559 char_u **varp; /* pointer to option variable */
5560{
5561 char_u **p, *s;
5562
5563 /* the global value is always allocated */
5564 if (options[opt_idx].var == VAR_WIN)
5565 p = (char_u **)GLOBAL_WO(varp);
5566 else
5567 p = (char_u **)options[opt_idx].var;
5568 if (options[opt_idx].indir != PV_NONE
5569 && p != varp
5570 && (s = vim_strsave(*varp)) != NULL)
5571 {
5572 free_string_option(*p);
5573 *p = s;
5574 }
5575}
5576
5577/*
5578 * Set a string option to a new value, and handle the effects.
5579 */
5580 static void
5581set_string_option(opt_idx, value, opt_flags)
5582 int opt_idx;
5583 char_u *value;
5584 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5585{
5586 char_u *s;
5587 char_u **varp;
5588 char_u *oldval;
5589
5590 if (options[opt_idx].var == NULL) /* don't set hidden option */
5591 return;
5592
5593 s = vim_strsave(value);
5594 if (s != NULL)
5595 {
5596 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5597 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005598 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005599 ? OPT_GLOBAL : OPT_LOCAL)
5600 : opt_flags);
5601 oldval = *varp;
5602 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005603 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5604 opt_flags) == NULL)
5605 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005606 }
5607}
5608
5609/*
5610 * Handle string options that need some action to perform when changed.
5611 * Returns NULL for success, or an error message for an error.
5612 */
5613 static char_u *
5614did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5615 opt_flags)
5616 int opt_idx; /* index in options[] table */
5617 char_u **varp; /* pointer to the option variable */
5618 int new_value_alloced; /* new value was allocated */
5619 char_u *oldval; /* previous value of the option */
5620 char_u *errbuf; /* buffer for errors, or NULL */
5621 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5622{
5623 char_u *errmsg = NULL;
5624 char_u *s, *p;
5625 int did_chartab = FALSE;
5626 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005627 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005628#ifdef FEAT_GUI
5629 /* set when changing an option that only requires a redraw in the GUI */
5630 int redraw_gui_only = FALSE;
5631#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005632
5633 /* Get the global option to compare with, otherwise we would have to check
5634 * two values for all local options. */
5635 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5636
5637 /* Disallow changing some options from secure mode */
5638 if ((secure
5639#ifdef HAVE_SANDBOX
5640 || sandbox != 0
5641#endif
5642 ) && (options[opt_idx].flags & P_SECURE))
5643 {
5644 errmsg = e_secure;
5645 }
5646
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005647 /* Check for a "normal" file name in some options. Disallow a path
5648 * separator (slash and/or backslash), wildcards and characters that are
5649 * often illegal in a file name. */
5650 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005651 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005652 {
5653 errmsg = e_invarg;
5654 }
5655
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656 /* 'term' */
5657 else if (varp == &T_NAME)
5658 {
5659 if (T_NAME[0] == NUL)
5660 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5661#ifdef FEAT_GUI
5662 if (gui.in_use)
5663 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5664 else if (term_is_gui(T_NAME))
5665 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5666#endif
5667 else if (set_termname(T_NAME) == FAIL)
5668 errmsg = (char_u *)N_("E522: Not found in termcap");
5669 else
5670 /* Screen colors may have changed. */
5671 redraw_later_clear();
5672 }
5673
5674 /* 'backupcopy' */
5675 else if (varp == &p_bkc)
5676 {
5677 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5678 errmsg = e_invarg;
5679 if (((bkc_flags & BKC_AUTO) != 0)
5680 + ((bkc_flags & BKC_YES) != 0)
5681 + ((bkc_flags & BKC_NO) != 0) != 1)
5682 {
5683 /* Must have exactly one of "auto", "yes" and "no". */
5684 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5685 errmsg = e_invarg;
5686 }
5687 }
5688
5689 /* 'backupext' and 'patchmode' */
5690 else if (varp == &p_bex || varp == &p_pm)
5691 {
5692 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5693 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5694 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5695 }
5696
5697 /*
5698 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5699 * If the new option is invalid, use old value. 'lisp' option: refill
5700 * chartab[] for '-' char
5701 */
5702 else if ( varp == &p_isi
5703 || varp == &(curbuf->b_p_isk)
5704 || varp == &p_isp
5705 || varp == &p_isf)
5706 {
5707 if (init_chartab() == FAIL)
5708 {
5709 did_chartab = TRUE; /* need to restore it below */
5710 errmsg = e_invarg; /* error in value */
5711 }
5712 }
5713
5714 /* 'helpfile' */
5715 else if (varp == &p_hf)
5716 {
5717 /* May compute new values for $VIM and $VIMRUNTIME */
5718 if (didset_vim)
5719 {
5720 vim_setenv((char_u *)"VIM", (char_u *)"");
5721 didset_vim = FALSE;
5722 }
5723 if (didset_vimruntime)
5724 {
5725 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5726 didset_vimruntime = FALSE;
5727 }
5728 }
5729
Bram Moolenaar1a384422010-07-14 19:53:30 +02005730#ifdef FEAT_SYN_HL
5731 /* 'colorcolumn' */
5732 else if (varp == &curwin->w_p_cc)
5733 errmsg = check_colorcolumn(curwin);
5734#endif
5735
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736#ifdef FEAT_MULTI_LANG
5737 /* 'helplang' */
5738 else if (varp == &p_hlg)
5739 {
5740 /* Check for "", "ab", "ab,cd", etc. */
5741 for (s = p_hlg; *s != NUL; s += 3)
5742 {
5743 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5744 {
5745 errmsg = e_invarg;
5746 break;
5747 }
5748 if (s[2] == NUL)
5749 break;
5750 }
5751 }
5752#endif
5753
5754 /* 'highlight' */
5755 else if (varp == &p_hl)
5756 {
5757 if (highlight_changed() == FAIL)
5758 errmsg = e_invarg; /* invalid flags */
5759 }
5760
5761 /* 'nrformats' */
5762 else if (gvarp == &p_nf)
5763 {
5764 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5765 errmsg = e_invarg;
5766 }
5767
5768#ifdef FEAT_SESSION
5769 /* 'sessionoptions' */
5770 else if (varp == &p_ssop)
5771 {
5772 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5773 errmsg = e_invarg;
5774 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5775 {
5776 /* Don't allow both "sesdir" and "curdir". */
5777 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5778 errmsg = e_invarg;
5779 }
5780 }
5781 /* 'viewoptions' */
5782 else if (varp == &p_vop)
5783 {
5784 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5785 errmsg = e_invarg;
5786 }
5787#endif
5788
5789 /* 'scrollopt' */
5790#ifdef FEAT_SCROLLBIND
5791 else if (varp == &p_sbo)
5792 {
5793 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5794 errmsg = e_invarg;
5795 }
5796#endif
5797
5798 /* 'ambiwidth' */
5799#ifdef FEAT_MBYTE
5800 else if (varp == &p_ambw)
5801 {
5802 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5803 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005804 else if (set_chars_option(&p_lcs) != NULL)
5805 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5806# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5807 else if (set_chars_option(&p_fcs) != NULL)
5808 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5809# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005810 }
5811#endif
5812
5813 /* 'background' */
5814 else if (varp == &p_bg)
5815 {
5816 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5817 {
5818#ifdef FEAT_EVAL
5819 int dark = (*p_bg == 'd');
5820#endif
5821
5822 init_highlight(FALSE, FALSE);
5823
5824#ifdef FEAT_EVAL
5825 if (dark != (*p_bg == 'd')
5826 && get_var_value((char_u *)"g:colors_name") != NULL)
5827 {
5828 /* The color scheme must have set 'background' back to another
5829 * value, that's not what we want here. Disable the color
5830 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005831 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005832 free_string_option(p_bg);
5833 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5834 check_string_option(&p_bg);
5835 init_highlight(FALSE, FALSE);
5836 }
5837#endif
5838 }
5839 else
5840 errmsg = e_invarg;
5841 }
5842
5843 /* 'wildmode' */
5844 else if (varp == &p_wim)
5845 {
5846 if (check_opt_wim() == FAIL)
5847 errmsg = e_invarg;
5848 }
5849
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005850#ifdef FEAT_CMDL_COMPL
5851 /* 'wildoptions' */
5852 else if (varp == &p_wop)
5853 {
5854 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5855 errmsg = e_invarg;
5856 }
5857#endif
5858
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859#ifdef FEAT_WAK
5860 /* 'winaltkeys' */
5861 else if (varp == &p_wak)
5862 {
5863 if (*p_wak == NUL
5864 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5865 errmsg = e_invarg;
5866# ifdef FEAT_MENU
5867# ifdef FEAT_GUI_MOTIF
5868 else if (gui.in_use)
5869 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5870# else
5871# ifdef FEAT_GUI_GTK
5872 else if (gui.in_use)
5873 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5874# endif
5875# endif
5876# endif
5877 }
5878#endif
5879
5880#ifdef FEAT_AUTOCMD
5881 /* 'eventignore' */
5882 else if (varp == &p_ei)
5883 {
5884 if (check_ei() == FAIL)
5885 errmsg = e_invarg;
5886 }
5887#endif
5888
5889#ifdef FEAT_MBYTE
5890 /* 'encoding' and 'fileencoding' */
5891 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5892 {
5893 if (gvarp == &p_fenc)
5894 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005895 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 errmsg = e_modifiable;
5897 else if (vim_strchr(*varp, ',') != NULL)
5898 /* No comma allowed in 'fileencoding'; catches confusing it
5899 * with 'fileencodings'. */
5900 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005902 {
5903# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005905 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005907 /* Add 'fileencoding' to the swap file. */
5908 ml_setflags(curbuf);
5909 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 }
5911 if (errmsg == NULL)
5912 {
5913 /* canonize the value, so that STRCMP() can be used on it */
5914 p = enc_canonize(*varp);
5915 if (p != NULL)
5916 {
5917 vim_free(*varp);
5918 *varp = p;
5919 }
5920 if (varp == &p_enc)
5921 {
5922 errmsg = mb_init();
5923# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005924 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925# endif
5926 }
5927 }
5928
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005929# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5931 {
5932 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5933 if (STRCMP(p_tenc, "utf-8") != 0)
5934 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5935 }
5936# endif
5937
5938 if (errmsg == NULL)
5939 {
5940# ifdef FEAT_KEYMAP
5941 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5942 * (with another encoding). */
5943 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5944 (void)keymap_init();
5945# endif
5946
5947 /* When 'termencoding' is not empty and 'encoding' changes or when
5948 * 'termencoding' changes, need to setup for keyboard input and
5949 * display output conversion. */
5950 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5951 {
5952 convert_setup(&input_conv, p_tenc, p_enc);
5953 convert_setup(&output_conv, p_enc, p_tenc);
5954 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005955
5956# if defined(WIN3264) && defined(FEAT_MBYTE)
5957 /* $HOME may have characters in active code page. */
5958 if (varp == &p_enc)
5959 init_homedir();
5960# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005961 }
5962 }
5963#endif
5964
5965#if defined(FEAT_POSTSCRIPT)
5966 else if (varp == &p_penc)
5967 {
5968 /* Canonize printencoding if VIM standard one */
5969 p = enc_canonize(p_penc);
5970 if (p != NULL)
5971 {
5972 vim_free(p_penc);
5973 p_penc = p;
5974 }
5975 else
5976 {
5977 /* Ensure lower case and '-' for '_' */
5978 for (s = p_penc; *s != NUL; s++)
5979 {
5980 if (*s == '_')
5981 *s = '-';
5982 else
5983 *s = TOLOWER_ASC(*s);
5984 }
5985 }
5986 }
5987#endif
5988
Bram Moolenaar9372a112005-12-06 19:59:18 +00005989#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990 else if (varp == &p_imak)
5991 {
5992 if (gui.in_use && !im_xim_isvalid_imactivate())
5993 errmsg = e_invarg;
5994 }
5995#endif
5996
5997#ifdef FEAT_KEYMAP
5998 else if (varp == &curbuf->b_p_keymap)
5999 {
6000 /* load or unload key mapping tables */
6001 errmsg = keymap_init();
6002
Bram Moolenaarfab06232009-03-04 03:13:35 +00006003 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006004 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006005 if (*curbuf->b_p_keymap != NUL)
6006 {
6007 /* Installed a new keymap, switch on using it. */
6008 curbuf->b_p_iminsert = B_IMODE_LMAP;
6009 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6010 curbuf->b_p_imsearch = B_IMODE_LMAP;
6011 }
6012 else
6013 {
6014 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6015 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6016 curbuf->b_p_iminsert = B_IMODE_NONE;
6017 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6018 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6019 }
6020 if ((opt_flags & OPT_LOCAL) == 0)
6021 {
6022 set_iminsert_global();
6023 set_imsearch_global();
6024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006025# ifdef FEAT_WINDOWS
6026 status_redraw_curbuf();
6027# endif
6028 }
6029 }
6030#endif
6031
6032 /* 'fileformat' */
6033 else if (gvarp == &p_ff)
6034 {
6035 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6036 errmsg = e_modifiable;
6037 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6038 errmsg = e_invarg;
6039 else
6040 {
6041 /* may also change 'textmode' */
6042 if (get_fileformat(curbuf) == EOL_DOS)
6043 curbuf->b_p_tx = TRUE;
6044 else
6045 curbuf->b_p_tx = FALSE;
6046#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006047 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006049 /* update flag in swap file */
6050 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006051 /* Redraw needed when switching to/from "mac": a CR in the text
6052 * will be displayed differently. */
6053 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6054 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006055 }
6056 }
6057
6058 /* 'fileformats' */
6059 else if (varp == &p_ffs)
6060 {
6061 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6062 errmsg = e_invarg;
6063 else
6064 {
6065 /* also change 'textauto' */
6066 if (*p_ffs == NUL)
6067 p_ta = FALSE;
6068 else
6069 p_ta = TRUE;
6070 }
6071 }
6072
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006073#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074 /* 'cryptkey' */
6075 else if (gvarp == &p_key)
6076 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006077# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006078 /* Make sure the ":set" command doesn't show the new value in the
6079 * history. */
6080 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006081# endif
6082 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6083 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006084 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6085 }
6086
6087 else if (gvarp == &p_cm)
6088 {
6089 if (opt_flags & OPT_LOCAL)
6090 p = curbuf->b_p_cm;
6091 else
6092 p = p_cm;
6093 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6094 errmsg = e_invarg;
6095 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6096 errmsg = e_invarg;
6097 else
6098 {
6099 /* When setting the global value to empty, make it "zip". */
6100 if (*p_cm == NUL)
6101 {
6102 if (new_value_alloced)
6103 free_string_option(p_cm);
6104 p_cm = vim_strsave((char_u *)"zip");
6105 new_value_alloced = TRUE;
6106 }
6107
6108 /* Need to update the swapfile when the effective method changed.
6109 * Set "s" to the effective old value, "p" to the effective new
6110 * method and compare. */
6111 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6112 s = p_cm; /* was previously using the global value */
6113 else
6114 s = oldval;
6115 if (*curbuf->b_p_cm == NUL)
6116 p = p_cm; /* is now using the global value */
6117 else
6118 p = curbuf->b_p_cm;
6119 if (STRCMP(s, p) != 0)
6120 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6121 crypt_method_from_string(s));
6122
6123 /* If the global value changes need to update the swapfile for all
6124 * buffers using that value. */
6125 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6126 {
6127 buf_T *buf;
6128
6129 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6130 if (buf != curbuf && *buf->b_p_cm == NUL)
6131 ml_set_crypt_key(buf, buf->b_p_key,
6132 crypt_method_from_string(oldval));
6133 }
6134 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135 }
6136#endif
6137
6138 /* 'matchpairs' */
6139 else if (gvarp == &p_mps)
6140 {
6141 /* Check for "x:y,x:y" */
6142 for (p = *varp; *p != NUL; p += 4)
6143 {
6144 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6145 {
6146 errmsg = e_invarg;
6147 break;
6148 }
6149 if (p[3] == NUL)
6150 break;
6151 }
6152 }
6153
6154#ifdef FEAT_COMMENTS
6155 /* 'comments' */
6156 else if (gvarp == &p_com)
6157 {
6158 for (s = *varp; *s; )
6159 {
6160 while (*s && *s != ':')
6161 {
6162 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6163 && !VIM_ISDIGIT(*s) && *s != '-')
6164 {
6165 errmsg = illegal_char(errbuf, *s);
6166 break;
6167 }
6168 ++s;
6169 }
6170 if (*s++ == NUL)
6171 errmsg = (char_u *)N_("E524: Missing colon");
6172 else if (*s == ',' || *s == NUL)
6173 errmsg = (char_u *)N_("E525: Zero length string");
6174 if (errmsg != NULL)
6175 break;
6176 while (*s && *s != ',')
6177 {
6178 if (*s == '\\' && s[1] != NUL)
6179 ++s;
6180 ++s;
6181 }
6182 s = skip_to_option_part(s);
6183 }
6184 }
6185#endif
6186
6187 /* 'listchars' */
6188 else if (varp == &p_lcs)
6189 {
6190 errmsg = set_chars_option(varp);
6191 }
6192
6193#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6194 /* 'fillchars' */
6195 else if (varp == &p_fcs)
6196 {
6197 errmsg = set_chars_option(varp);
6198 }
6199#endif
6200
6201#ifdef FEAT_CMDWIN
6202 /* 'cedit' */
6203 else if (varp == &p_cedit)
6204 {
6205 errmsg = check_cedit();
6206 }
6207#endif
6208
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006209 /* 'verbosefile' */
6210 else if (varp == &p_vfile)
6211 {
6212 verbose_stop();
6213 if (*p_vfile != NUL && verbose_open() == FAIL)
6214 errmsg = e_invarg;
6215 }
6216
Bram Moolenaar071d4272004-06-13 20:20:40 +00006217#ifdef FEAT_VIMINFO
6218 /* 'viminfo' */
6219 else if (varp == &p_viminfo)
6220 {
6221 for (s = p_viminfo; *s;)
6222 {
6223 /* Check it's a valid character */
6224 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6225 {
6226 errmsg = illegal_char(errbuf, *s);
6227 break;
6228 }
6229 if (*s == 'n') /* name is always last one */
6230 {
6231 break;
6232 }
6233 else if (*s == 'r') /* skip until next ',' */
6234 {
6235 while (*++s && *s != ',')
6236 ;
6237 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006238 else if (*s == '%')
6239 {
6240 /* optional number */
6241 while (vim_isdigit(*++s))
6242 ;
6243 }
6244 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006245 ++s; /* no extra chars */
6246 else /* must have a number */
6247 {
6248 while (vim_isdigit(*++s))
6249 ;
6250
6251 if (!VIM_ISDIGIT(*(s - 1)))
6252 {
6253 if (errbuf != NULL)
6254 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006255 sprintf((char *)errbuf,
6256 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006257 transchar_byte(*(s - 1)));
6258 errmsg = errbuf;
6259 }
6260 else
6261 errmsg = (char_u *)"";
6262 break;
6263 }
6264 }
6265 if (*s == ',')
6266 ++s;
6267 else if (*s)
6268 {
6269 if (errbuf != NULL)
6270 errmsg = (char_u *)N_("E527: Missing comma");
6271 else
6272 errmsg = (char_u *)"";
6273 break;
6274 }
6275 }
6276 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6277 errmsg = (char_u *)N_("E528: Must specify a ' value");
6278 }
6279#endif /* FEAT_VIMINFO */
6280
6281 /* terminal options */
6282 else if (istermoption(&options[opt_idx]) && full_screen)
6283 {
6284 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6285 if (varp == &T_CCO)
6286 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006287 int colors = atoi((char *)T_CCO);
6288
6289 /* Only reinitialize colors if t_Co value has really changed to
6290 * avoid expensive reload of colorscheme if t_Co is set to the
6291 * same value multiple times. */
6292 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006294 t_colors = colors;
6295 if (t_colors <= 1)
6296 {
6297 if (new_value_alloced)
6298 vim_free(T_CCO);
6299 T_CCO = empty_option;
6300 }
6301 /* We now have a different color setup, initialize it again. */
6302 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006304 }
6305 ttest(FALSE);
6306 if (varp == &T_ME)
6307 {
6308 out_str(T_ME);
6309 redraw_later(CLEAR);
6310#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6311 /* Since t_me has been set, this probably means that the user
6312 * wants to use this as default colors. Need to reset default
6313 * background/foreground colors. */
6314 mch_set_normal_colors();
6315#endif
6316 }
6317 }
6318
6319#ifdef FEAT_LINEBREAK
6320 /* 'showbreak' */
6321 else if (varp == &p_sbr)
6322 {
6323 for (s = p_sbr; *s; )
6324 {
6325 if (ptr2cells(s) != 1)
6326 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006327 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006328 }
6329 }
6330#endif
6331
6332#ifdef FEAT_GUI
6333 /* 'guifont' */
6334 else if (varp == &p_guifont)
6335 {
6336 if (gui.in_use)
6337 {
6338 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006339# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006340 /*
6341 * Put up a font dialog and let the user select a new value.
6342 * If this is cancelled go back to the old value but don't
6343 * give an error message.
6344 */
6345 if (STRCMP(p, "*") == 0)
6346 {
6347 p = gui_mch_font_dialog(oldval);
6348
6349 if (new_value_alloced)
6350 free_string_option(p_guifont);
6351
6352 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6353 new_value_alloced = TRUE;
6354 }
6355# endif
6356 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6357 {
6358# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6359 if (STRCMP(p_guifont, "*") == 0)
6360 {
6361 /* Dialog was cancelled: Keep the old value without giving
6362 * an error message. */
6363 if (new_value_alloced)
6364 free_string_option(p_guifont);
6365 p_guifont = vim_strsave(oldval);
6366 new_value_alloced = TRUE;
6367 }
6368 else
6369# endif
6370 errmsg = (char_u *)N_("E596: Invalid font(s)");
6371 }
6372 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006373 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374 }
6375# ifdef FEAT_XFONTSET
6376 else if (varp == &p_guifontset)
6377 {
6378 if (STRCMP(p_guifontset, "*") == 0)
6379 errmsg = (char_u *)N_("E597: can't select fontset");
6380 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6381 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006382 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 }
6384# endif
6385# ifdef FEAT_MBYTE
6386 else if (varp == &p_guifontwide)
6387 {
6388 if (STRCMP(p_guifontwide, "*") == 0)
6389 errmsg = (char_u *)N_("E533: can't select wide font");
6390 else if (gui_get_wide_font() == FAIL)
6391 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006392 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393 }
6394# endif
6395#endif
6396
6397#ifdef CURSOR_SHAPE
6398 /* 'guicursor' */
6399 else if (varp == &p_guicursor)
6400 errmsg = parse_shape_opt(SHAPE_CURSOR);
6401#endif
6402
6403#ifdef FEAT_MOUSESHAPE
6404 /* 'mouseshape' */
6405 else if (varp == &p_mouseshape)
6406 {
6407 errmsg = parse_shape_opt(SHAPE_MOUSE);
6408 update_mouseshape(-1);
6409 }
6410#endif
6411
6412#ifdef FEAT_PRINTER
6413 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006414 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006415# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006416 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006417 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006418# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006419#endif
6420
6421#ifdef FEAT_LANGMAP
6422 /* 'langmap' */
6423 else if (varp == &p_langmap)
6424 langmap_set();
6425#endif
6426
6427#ifdef FEAT_LINEBREAK
6428 /* 'breakat' */
6429 else if (varp == &p_breakat)
6430 fill_breakat_flags();
6431#endif
6432
6433#ifdef FEAT_TITLE
6434 /* 'titlestring' and 'iconstring' */
6435 else if (varp == &p_titlestring || varp == &p_iconstring)
6436 {
6437# ifdef FEAT_STL_OPT
6438 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6439
6440 /* NULL => statusline syntax */
6441 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6442 stl_syntax |= flagval;
6443 else
6444 stl_syntax &= ~flagval;
6445# endif
6446 did_set_title(varp == &p_iconstring);
6447
6448 }
6449#endif
6450
6451#ifdef FEAT_GUI
6452 /* 'guioptions' */
6453 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006454 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006455 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006456 redraw_gui_only = TRUE;
6457 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458#endif
6459
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006460#if defined(FEAT_GUI_TABLINE)
6461 /* 'guitablabel' */
6462 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006463 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006464 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006465 redraw_gui_only = TRUE;
6466 }
6467 /* 'guitabtooltip' */
6468 else if (varp == &p_gtt)
6469 {
6470 redraw_gui_only = TRUE;
6471 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006472#endif
6473
Bram Moolenaar071d4272004-06-13 20:20:40 +00006474#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6475 /* 'ttymouse' */
6476 else if (varp == &p_ttym)
6477 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006478 /* Switch the mouse off before changing the escape sequences used for
6479 * that. */
6480 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006481 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6482 errmsg = e_invarg;
6483 else
6484 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006485 if (termcap_active)
6486 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487 }
6488#endif
6489
6490#ifdef FEAT_VISUAL
6491 /* 'selection' */
6492 else if (varp == &p_sel)
6493 {
6494 if (*p_sel == NUL
6495 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6496 errmsg = e_invarg;
6497 }
6498
6499 /* 'selectmode' */
6500 else if (varp == &p_slm)
6501 {
6502 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6503 errmsg = e_invarg;
6504 }
6505#endif
6506
6507#ifdef FEAT_BROWSE
6508 /* 'browsedir' */
6509 else if (varp == &p_bsdir)
6510 {
6511 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6512 && !mch_isdir(p_bsdir))
6513 errmsg = e_invarg;
6514 }
6515#endif
6516
6517#ifdef FEAT_VISUAL
6518 /* 'keymodel' */
6519 else if (varp == &p_km)
6520 {
6521 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6522 errmsg = e_invarg;
6523 else
6524 {
6525 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6526 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6527 }
6528 }
6529#endif
6530
6531 /* 'mousemodel' */
6532 else if (varp == &p_mousem)
6533 {
6534 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6535 errmsg = e_invarg;
6536#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6537 else if (*p_mousem != *oldval)
6538 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6539 * to create or delete the popup menus. */
6540 gui_motif_update_mousemodel(root_menu);
6541#endif
6542 }
6543
6544 /* 'switchbuf' */
6545 else if (varp == &p_swb)
6546 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006547 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 errmsg = e_invarg;
6549 }
6550
6551 /* 'debug' */
6552 else if (varp == &p_debug)
6553 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006554 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 errmsg = e_invarg;
6556 }
6557
6558 /* 'display' */
6559 else if (varp == &p_dy)
6560 {
6561 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6562 errmsg = e_invarg;
6563 else
6564 (void)init_chartab();
6565
6566 }
6567
6568#ifdef FEAT_VERTSPLIT
6569 /* 'eadirection' */
6570 else if (varp == &p_ead)
6571 {
6572 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6573 errmsg = e_invarg;
6574 }
6575#endif
6576
6577#ifdef FEAT_CLIPBOARD
6578 /* 'clipboard' */
6579 else if (varp == &p_cb)
6580 errmsg = check_clipboard_option();
6581#endif
6582
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006583#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006584 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6585 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006586 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006587 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006588 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006589 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006590
Bram Moolenaar860cae12010-06-05 23:22:07 +02006591 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006592 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006593 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6594 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006595 ".add") != 0))
6596 errmsg = e_invarg;
6597 }
6598
6599 if (errmsg == NULL)
6600 {
6601 FOR_ALL_WINDOWS(wp)
6602 if (wp->w_buffer == curbuf && wp->w_p_spell)
6603 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006604 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006605# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006606 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006607# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006608 }
6609 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006610 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006611 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006612 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006613 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006614 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006615 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006616 /* 'spellsuggest' */
6617 else if (varp == &p_sps)
6618 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006619 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006620 errmsg = e_invarg;
6621 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006622 /* 'mkspellmem' */
6623 else if (varp == &p_msm)
6624 {
6625 if (spell_check_msm() != OK)
6626 errmsg = e_invarg;
6627 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006628#endif
6629
Bram Moolenaar071d4272004-06-13 20:20:40 +00006630#ifdef FEAT_QUICKFIX
6631 /* When 'bufhidden' is set, check for valid value. */
6632 else if (gvarp == &p_bh)
6633 {
6634 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6635 errmsg = e_invarg;
6636 }
6637
6638 /* When 'buftype' is set, check for valid value. */
6639 else if (gvarp == &p_bt)
6640 {
6641 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6642 errmsg = e_invarg;
6643 else
6644 {
6645# ifdef FEAT_WINDOWS
6646 if (curwin->w_status_height)
6647 {
6648 curwin->w_redr_status = TRUE;
6649 redraw_later(VALID);
6650 }
6651# endif
6652 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006653# ifdef FEAT_TITLE
6654 redraw_titles();
6655# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006656 }
6657 }
6658#endif
6659
6660#ifdef FEAT_STL_OPT
6661 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006662 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006663 {
6664 int wid;
6665
6666 if (varp == &p_ruf) /* reset ru_wid first */
6667 ru_wid = 0;
6668 s = *varp;
6669 if (varp == &p_ruf && *s == '%')
6670 {
6671 /* set ru_wid if 'ruf' starts with "%99(" */
6672 if (*++s == '-') /* ignore a '-' */
6673 s++;
6674 wid = getdigits(&s);
6675 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6676 ru_wid = wid;
6677 else
6678 errmsg = check_stl_option(p_ruf);
6679 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006680 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006681 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006682 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006683 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006684 comp_col();
6685 }
6686#endif
6687
6688#ifdef FEAT_INS_EXPAND
6689 /* check if it is a valid value for 'complete' -- Acevedo */
6690 else if (gvarp == &p_cpt)
6691 {
6692 for (s = *varp; *s;)
6693 {
6694 while(*s == ',' || *s == ' ')
6695 s++;
6696 if (!*s)
6697 break;
6698 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6699 {
6700 errmsg = illegal_char(errbuf, *s);
6701 break;
6702 }
6703 if (*++s != NUL && *s != ',' && *s != ' ')
6704 {
6705 if (s[-1] == 'k' || s[-1] == 's')
6706 {
6707 /* skip optional filename after 'k' and 's' */
6708 while (*s && *s != ',' && *s != ' ')
6709 {
6710 if (*s == '\\')
6711 ++s;
6712 ++s;
6713 }
6714 }
6715 else
6716 {
6717 if (errbuf != NULL)
6718 {
6719 sprintf((char *)errbuf,
6720 _("E535: Illegal character after <%c>"),
6721 *--s);
6722 errmsg = errbuf;
6723 }
6724 else
6725 errmsg = (char_u *)"";
6726 break;
6727 }
6728 }
6729 }
6730 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006731
6732 /* 'completeopt' */
6733 else if (varp == &p_cot)
6734 {
6735 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6736 errmsg = e_invarg;
6737 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006738#endif /* FEAT_INS_EXPAND */
6739
6740
6741#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6742 else if (varp == &p_toolbar)
6743 {
6744 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6745 &toolbar_flags, TRUE) != OK)
6746 errmsg = e_invarg;
6747 else
6748 {
6749 out_flush();
6750 gui_mch_show_toolbar((toolbar_flags &
6751 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6752 }
6753 }
6754#endif
6755
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006756#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 /* 'toolbariconsize': GTK+ 2 only */
6758 else if (varp == &p_tbis)
6759 {
6760 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6761 errmsg = e_invarg;
6762 else
6763 {
6764 out_flush();
6765 gui_mch_show_toolbar((toolbar_flags &
6766 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6767 }
6768 }
6769#endif
6770
6771 /* 'pastetoggle': translate key codes like in a mapping */
6772 else if (varp == &p_pt)
6773 {
6774 if (*p_pt)
6775 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006776 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 if (p != NULL)
6778 {
6779 if (new_value_alloced)
6780 free_string_option(p_pt);
6781 p_pt = p;
6782 new_value_alloced = TRUE;
6783 }
6784 }
6785 }
6786
6787 /* 'backspace' */
6788 else if (varp == &p_bs)
6789 {
6790 if (VIM_ISDIGIT(*p_bs))
6791 {
6792 if (*p_bs >'2' || p_bs[1] != NUL)
6793 errmsg = e_invarg;
6794 }
6795 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6796 errmsg = e_invarg;
6797 }
6798
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006799#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006800 /* 'casemap' */
6801 else if (varp == &p_cmp)
6802 {
6803 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6804 errmsg = e_invarg;
6805 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807
6808#ifdef FEAT_DIFF
6809 /* 'diffopt' */
6810 else if (varp == &p_dip)
6811 {
6812 if (diffopt_changed() == FAIL)
6813 errmsg = e_invarg;
6814 }
6815#endif
6816
6817#ifdef FEAT_FOLDING
6818 /* 'foldmethod' */
6819 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6820 {
6821 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6822 || *curwin->w_p_fdm == NUL)
6823 errmsg = e_invarg;
6824 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006825 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006826 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006827 if (foldmethodIsDiff(curwin))
6828 newFoldLevel();
6829 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006830 }
6831# ifdef FEAT_EVAL
6832 /* 'foldexpr' */
6833 else if (varp == &curwin->w_p_fde)
6834 {
6835 if (foldmethodIsExpr(curwin))
6836 foldUpdateAll(curwin);
6837 }
6838# endif
6839 /* 'foldmarker' */
6840 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6841 {
6842 p = vim_strchr(*varp, ',');
6843 if (p == NULL)
6844 errmsg = (char_u *)N_("E536: comma required");
6845 else if (p == *varp || p[1] == NUL)
6846 errmsg = e_invarg;
6847 else if (foldmethodIsMarker(curwin))
6848 foldUpdateAll(curwin);
6849 }
6850 /* 'commentstring' */
6851 else if (gvarp == &p_cms)
6852 {
6853 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6854 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6855 }
6856 /* 'foldopen' */
6857 else if (varp == &p_fdo)
6858 {
6859 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6860 errmsg = e_invarg;
6861 }
6862 /* 'foldclose' */
6863 else if (varp == &p_fcl)
6864 {
6865 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6866 errmsg = e_invarg;
6867 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006868 /* 'foldignore' */
6869 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6870 {
6871 if (foldmethodIsIndent(curwin))
6872 foldUpdateAll(curwin);
6873 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006874#endif
6875
6876#ifdef FEAT_VIRTUALEDIT
6877 /* 'virtualedit' */
6878 else if (varp == &p_ve)
6879 {
6880 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6881 errmsg = e_invarg;
6882 else if (STRCMP(p_ve, oldval) != 0)
6883 {
6884 /* Recompute cursor position in case the new 've' setting
6885 * changes something. */
6886 validate_virtcol();
6887 coladvance(curwin->w_virtcol);
6888 }
6889 }
6890#endif
6891
6892#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6893 else if (varp == &p_csqf)
6894 {
6895 if (p_csqf != NULL)
6896 {
6897 p = p_csqf;
6898 while (*p != NUL)
6899 {
6900 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6901 || p[1] == NUL
6902 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6903 || (p[2] != NUL && p[2] != ','))
6904 {
6905 errmsg = e_invarg;
6906 break;
6907 }
6908 else if (p[2] == NUL)
6909 break;
6910 else
6911 p += 3;
6912 }
6913 }
6914 }
6915#endif
6916
6917 /* Options that are a list of flags. */
6918 else
6919 {
6920 p = NULL;
6921 if (varp == &p_ww)
6922 p = (char_u *)WW_ALL;
6923 if (varp == &p_shm)
6924 p = (char_u *)SHM_ALL;
6925 else if (varp == &(p_cpo))
6926 p = (char_u *)CPO_ALL;
6927 else if (varp == &(curbuf->b_p_fo))
6928 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02006929#ifdef FEAT_CONCEAL
6930 else if (varp == &curwin->w_p_cocu)
6931 p = (char_u *)COCU_ALL;
6932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006933 else if (varp == &p_mouse)
6934 {
6935#ifdef FEAT_MOUSE
6936 p = (char_u *)MOUSE_ALL;
6937#else
6938 if (*p_mouse != NUL)
6939 errmsg = (char_u *)N_("E538: No mouse support");
6940#endif
6941 }
6942#if defined(FEAT_GUI)
6943 else if (varp == &p_go)
6944 p = (char_u *)GO_ALL;
6945#endif
6946 if (p != NULL)
6947 {
6948 for (s = *varp; *s; ++s)
6949 if (vim_strchr(p, *s) == NULL)
6950 {
6951 errmsg = illegal_char(errbuf, *s);
6952 break;
6953 }
6954 }
6955 }
6956
6957 /*
6958 * If error detected, restore the previous value.
6959 */
6960 if (errmsg != NULL)
6961 {
6962 if (new_value_alloced)
6963 free_string_option(*varp);
6964 *varp = oldval;
6965 /*
6966 * When resetting some values, need to act on it.
6967 */
6968 if (did_chartab)
6969 (void)init_chartab();
6970 if (varp == &p_hl)
6971 (void)highlight_changed();
6972 }
6973 else
6974 {
6975#ifdef FEAT_EVAL
6976 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006977 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006978#endif
6979 /*
6980 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006981 * Use "free_oldval", because recursiveness may change the flags under
6982 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006984 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985 free_string_option(oldval);
6986 if (new_value_alloced)
6987 options[opt_idx].flags |= P_ALLOCED;
6988 else
6989 options[opt_idx].flags &= ~P_ALLOCED;
6990
6991 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006992 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 {
6994 /* global option with local value set to use global value; free
6995 * the local value and make it empty */
6996 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6997 free_string_option(*(char_u **)p);
6998 *(char_u **)p = empty_option;
6999 }
7000
7001 /* May set global value for local option. */
7002 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7003 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007004
7005#ifdef FEAT_AUTOCMD
7006 /*
7007 * Trigger the autocommand only after setting the flags.
7008 */
7009# ifdef FEAT_SYN_HL
7010 /* When 'syntax' is set, load the syntax of that name */
7011 if (varp == &(curbuf->b_p_syn))
7012 {
7013 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7014 curbuf->b_fname, TRUE, curbuf);
7015 }
7016# endif
7017 else if (varp == &(curbuf->b_p_ft))
7018 {
7019 /* 'filetype' is set, trigger the FileType autocommand */
7020 did_filetype = TRUE;
7021 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7022 curbuf->b_fname, TRUE, curbuf);
7023 }
7024#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007025#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007026 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007027 {
7028 char_u fname[200];
7029
7030 /*
7031 * Source the spell/LANG.vim in 'runtimepath'.
7032 * They could set 'spellcapcheck' depending on the language.
7033 * Use the first name in 'spelllang' up to '_region' or
7034 * '.encoding'.
7035 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007036 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007037 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7038 break;
7039 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02007040 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007041 source_runtime(fname, TRUE);
7042 }
7043#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044 }
7045
7046#ifdef FEAT_MOUSE
7047 if (varp == &p_mouse)
7048 {
7049# ifdef FEAT_MOUSE_TTY
7050 if (*p_mouse == NUL)
7051 mch_setmouse(FALSE); /* switch mouse off */
7052 else
7053# endif
7054 setmouse(); /* in case 'mouse' changed */
7055 }
7056#endif
7057
7058 if (curwin->w_curswant != MAXCOL)
7059 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007060#ifdef FEAT_GUI
7061 /* check redraw when it's not a GUI option or the GUI is active. */
7062 if (!redraw_gui_only || gui.in_use)
7063#endif
7064 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007065
7066 return errmsg;
7067}
7068
Bram Moolenaar1a384422010-07-14 19:53:30 +02007069#ifdef FEAT_SYN_HL
7070/*
7071 * Simple int comparison function for use with qsort()
7072 */
7073 static int
7074int_cmp(a, b)
7075 const void *a;
7076 const void *b;
7077{
7078 return *(const int *)a - *(const int *)b;
7079}
7080
7081/*
7082 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7083 * Returns error message, NULL if it's OK.
7084 */
7085 char_u *
7086check_colorcolumn(wp)
7087 win_T *wp;
7088{
7089 char_u *s;
7090 int col;
7091 int count = 0;
7092 int color_cols[256];
7093 int i;
7094 int j = 0;
7095
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007096 if (wp->w_buffer == NULL)
7097 return NULL; /* buffer was closed */
7098
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007099 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007100 {
7101 if (*s == '-' || *s == '+')
7102 {
7103 /* -N and +N: add to 'textwidth' */
7104 col = (*s == '-') ? -1 : 1;
7105 ++s;
7106 if (!VIM_ISDIGIT(*s))
7107 return e_invarg;
7108 col = col * getdigits(&s);
7109 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007110 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007111 col += wp->w_buffer->b_p_tw;
7112 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007113 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007114 }
7115 else if (VIM_ISDIGIT(*s))
7116 col = getdigits(&s);
7117 else
7118 return e_invarg;
7119 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007120skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007121 if (*s == NUL)
7122 break;
7123 if (*s != ',')
7124 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007125 if (*++s == NUL)
7126 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007127 }
7128
7129 vim_free(wp->w_p_cc_cols);
7130 if (count == 0)
7131 wp->w_p_cc_cols = NULL;
7132 else
7133 {
7134 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7135 if (wp->w_p_cc_cols != NULL)
7136 {
7137 /* sort the columns for faster usage on screen redraw inside
7138 * win_line() */
7139 qsort(color_cols, count, sizeof(int), int_cmp);
7140
7141 for (i = 0; i < count; ++i)
7142 /* skip duplicates */
7143 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7144 wp->w_p_cc_cols[j++] = color_cols[i];
7145 wp->w_p_cc_cols[j] = -1; /* end marker */
7146 }
7147 }
7148
7149 return NULL; /* no error */
7150}
7151#endif
7152
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153/*
7154 * Handle setting 'listchars' or 'fillchars'.
7155 * Returns error message, NULL if it's OK.
7156 */
7157 static char_u *
7158set_chars_option(varp)
7159 char_u **varp;
7160{
7161 int round, i, len, entries;
7162 char_u *p, *s;
7163 int c1, c2 = 0;
7164 struct charstab
7165 {
7166 int *cp;
7167 char *name;
7168 };
7169#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7170 static struct charstab filltab[] =
7171 {
7172 {&fill_stl, "stl"},
7173 {&fill_stlnc, "stlnc"},
7174 {&fill_vert, "vert"},
7175 {&fill_fold, "fold"},
7176 {&fill_diff, "diff"},
7177 };
7178#endif
7179 static struct charstab lcstab[] =
7180 {
7181 {&lcs_eol, "eol"},
7182 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007183 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 {&lcs_prec, "precedes"},
7185 {&lcs_tab2, "tab"},
7186 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007187#ifdef FEAT_CONCEAL
7188 {&lcs_conceal, "conceal"},
7189#else
7190 {NULL, "conceal"},
7191#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007192 };
7193 struct charstab *tab;
7194
7195#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7196 if (varp == &p_lcs)
7197#endif
7198 {
7199 tab = lcstab;
7200 entries = sizeof(lcstab) / sizeof(struct charstab);
7201 }
7202#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7203 else
7204 {
7205 tab = filltab;
7206 entries = sizeof(filltab) / sizeof(struct charstab);
7207 }
7208#endif
7209
7210 /* first round: check for valid value, second round: assign values */
7211 for (round = 0; round <= 1; ++round)
7212 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007213 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007214 {
7215 /* After checking that the value is valid: set defaults: space for
7216 * 'fillchars', NUL for 'listchars' */
7217 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007218 if (tab[i].cp != NULL)
7219 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220 if (varp == &p_lcs)
7221 lcs_tab1 = NUL;
7222#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7223 else
7224 fill_diff = '-';
7225#endif
7226 }
7227 p = *varp;
7228 while (*p)
7229 {
7230 for (i = 0; i < entries; ++i)
7231 {
7232 len = (int)STRLEN(tab[i].name);
7233 if (STRNCMP(p, tab[i].name, len) == 0
7234 && p[len] == ':'
7235 && p[len + 1] != NUL)
7236 {
7237 s = p + len + 1;
7238#ifdef FEAT_MBYTE
7239 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007240 if (mb_char2cells(c1) > 1)
7241 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242#else
7243 c1 = *s++;
7244#endif
7245 if (tab[i].cp == &lcs_tab2)
7246 {
7247 if (*s == NUL)
7248 continue;
7249#ifdef FEAT_MBYTE
7250 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007251 if (mb_char2cells(c2) > 1)
7252 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007253#else
7254 c2 = *s++;
7255#endif
7256 }
7257 if (*s == ',' || *s == NUL)
7258 {
7259 if (round)
7260 {
7261 if (tab[i].cp == &lcs_tab2)
7262 {
7263 lcs_tab1 = c1;
7264 lcs_tab2 = c2;
7265 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007266 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007267 *(tab[i].cp) = c1;
7268
7269 }
7270 p = s;
7271 break;
7272 }
7273 }
7274 }
7275
7276 if (i == entries)
7277 return e_invarg;
7278 if (*p == ',')
7279 ++p;
7280 }
7281 }
7282
7283 return NULL; /* no error */
7284}
7285
7286#ifdef FEAT_STL_OPT
7287/*
7288 * Check validity of options with the 'statusline' format.
7289 * Return error message or NULL.
7290 */
7291 char_u *
7292check_stl_option(s)
7293 char_u *s;
7294{
7295 int itemcnt = 0;
7296 int groupdepth = 0;
7297 static char_u errbuf[80];
7298
7299 while (*s && itemcnt < STL_MAX_ITEM)
7300 {
7301 /* Check for valid keys after % sequences */
7302 while (*s && *s != '%')
7303 s++;
7304 if (!*s)
7305 break;
7306 s++;
7307 if (*s != '%' && *s != ')')
7308 ++itemcnt;
7309 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7310 {
7311 s++;
7312 continue;
7313 }
7314 if (*s == ')')
7315 {
7316 s++;
7317 if (--groupdepth < 0)
7318 break;
7319 continue;
7320 }
7321 if (*s == '-')
7322 s++;
7323 while (VIM_ISDIGIT(*s))
7324 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007325 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007326 continue;
7327 if (*s == '.')
7328 {
7329 s++;
7330 while (*s && VIM_ISDIGIT(*s))
7331 s++;
7332 }
7333 if (*s == '(')
7334 {
7335 groupdepth++;
7336 continue;
7337 }
7338 if (vim_strchr(STL_ALL, *s) == NULL)
7339 {
7340 return illegal_char(errbuf, *s);
7341 }
7342 if (*s == '{')
7343 {
7344 s++;
7345 while (*s != '}' && *s)
7346 s++;
7347 if (*s != '}')
7348 return (char_u *)N_("E540: Unclosed expression sequence");
7349 }
7350 }
7351 if (itemcnt >= STL_MAX_ITEM)
7352 return (char_u *)N_("E541: too many items");
7353 if (groupdepth != 0)
7354 return (char_u *)N_("E542: unbalanced groups");
7355 return NULL;
7356}
7357#endif
7358
7359#ifdef FEAT_CLIPBOARD
7360/*
7361 * Extract the items in the 'clipboard' option and set global values.
7362 */
7363 static char_u *
7364check_clipboard_option()
7365{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007366 int new_unnamed = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007367 int new_autoselect = FALSE;
7368 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007369 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007370 regprog_T *new_exclude_prog = NULL;
7371 char_u *errmsg = NULL;
7372 char_u *p;
7373
7374 for (p = p_cb; *p != NUL; )
7375 {
7376 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7377 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007378 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007379 p += 7;
7380 }
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007381 else if (STRNCMP(p, "unnamedplus", 11) == 0
7382 && (p[11] == ',' || p[11] == NUL))
7383 {
7384 new_unnamed |= CLIP_UNNAMED_PLUS;
7385 p += 11;
7386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007387 else if (STRNCMP(p, "autoselect", 10) == 0
7388 && (p[10] == ',' || p[10] == NUL))
7389 {
7390 new_autoselect = TRUE;
7391 p += 10;
7392 }
7393 else if (STRNCMP(p, "autoselectml", 12) == 0
7394 && (p[12] == ',' || p[12] == NUL))
7395 {
7396 new_autoselectml = TRUE;
7397 p += 12;
7398 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007399 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7400 {
7401 new_html = TRUE;
7402 p += 4;
7403 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007404 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7405 {
7406 p += 8;
7407 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7408 if (new_exclude_prog == NULL)
7409 errmsg = e_invarg;
7410 break;
7411 }
7412 else
7413 {
7414 errmsg = e_invarg;
7415 break;
7416 }
7417 if (*p == ',')
7418 ++p;
7419 }
7420 if (errmsg == NULL)
7421 {
7422 clip_unnamed = new_unnamed;
7423 clip_autoselect = new_autoselect;
7424 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007425 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007426 vim_free(clip_exclude_prog);
7427 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007428#ifdef FEAT_GUI_GTK
7429 if (gui.in_use)
7430 {
7431 gui_gtk_set_selection_targets();
7432 gui_gtk_set_dnd_targets();
7433 }
7434#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007435 }
7436 else
7437 vim_free(new_exclude_prog);
7438
7439 return errmsg;
7440}
7441#endif
7442
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007443#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007444/*
7445 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7446 * Return error message when failed, NULL when OK.
7447 */
7448 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007449compile_cap_prog(synblock)
7450 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007451{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007452 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007453 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007454
Bram Moolenaar860cae12010-06-05 23:22:07 +02007455 if (*synblock->b_p_spc == NUL)
7456 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007457 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007458 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007459 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007460 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007461 if (re != NULL)
7462 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007463 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7464 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007465 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007466 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007467 return e_invarg;
7468 }
7469 vim_free(re);
7470 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007471 }
7472
7473 vim_free(rp);
7474 return NULL;
7475}
7476#endif
7477
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007478#if defined(FEAT_EVAL) || defined(PROTO)
7479/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007480 * Set the scriptID for an option, taking care of setting the buffer- or
7481 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007482 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007483 static void
7484set_option_scriptID_idx(opt_idx, opt_flags, id)
7485 int opt_idx;
7486 int opt_flags;
7487 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007488{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007489 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7490 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007491
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007492 /* Remember where the option was set. For local options need to do that
7493 * in the buffer or window structure. */
7494 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007495 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007496 if (both || (opt_flags & OPT_LOCAL))
7497 {
7498 if (indir & PV_BUF)
7499 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7500 else if (indir & PV_WIN)
7501 curwin->w_p_scriptID[indir & PV_MASK] = id;
7502 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007503}
7504#endif
7505
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506/*
7507 * Set the value of a boolean option, and take care of side effects.
7508 * Returns NULL for success, or an error message for an error.
7509 */
7510 static char_u *
7511set_bool_option(opt_idx, varp, value, opt_flags)
7512 int opt_idx; /* index in options[] table */
7513 char_u *varp; /* pointer to the option variable */
7514 int value; /* new value */
7515 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7516{
7517 int old_value = *(int *)varp;
7518
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 /* Disallow changing some options from secure mode */
7520 if ((secure
7521#ifdef HAVE_SANDBOX
7522 || sandbox != 0
7523#endif
7524 ) && (options[opt_idx].flags & P_SECURE))
7525 return e_secure;
7526
7527 *(int *)varp = value; /* set the new value */
7528#ifdef FEAT_EVAL
7529 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007530 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007531#endif
7532
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007533#ifdef FEAT_GUI
7534 need_mouse_correct = TRUE;
7535#endif
7536
Bram Moolenaar071d4272004-06-13 20:20:40 +00007537 /* May set global value for local option. */
7538 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7539 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7540
7541 /*
7542 * Handle side effects of changing a bool option.
7543 */
7544
7545 /* 'compatible' */
7546 if ((int *)varp == &p_cp)
7547 {
7548 compatible_set();
7549 }
7550
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007551#ifdef FEAT_PERSISTENT_UNDO
7552 /* 'undofile' */
7553 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7554 {
7555 char_u hash[UNDO_HASH_SIZE];
7556 buf_T *save_curbuf = curbuf;
7557
7558 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
7559 {
7560 /* When 'undofile' is set globally: for every buffer, otherwise
7561 * only for the current buffer: Try to read in the undofile, if
Bram Moolenaar3c70f332012-01-28 18:03:35 +01007562 * one exists and the buffer wasn't changed and the buffer was
7563 * loaded. */
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007564 if ((curbuf == save_curbuf
7565 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
Bram Moolenaar3c70f332012-01-28 18:03:35 +01007566 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007567 {
7568 u_compute_hash(hash);
7569 u_read_undo(NULL, hash, curbuf->b_fname);
7570 }
7571 }
7572 curbuf = save_curbuf;
7573 }
7574#endif
7575
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007576 /* 'list', 'number' */
7577 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007578 || (int *)varp == &curwin->w_p_nu
7579 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007580 {
7581 if (curwin->w_curswant != MAXCOL)
7582 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007583
7584 /* If 'number' is set, reset 'relativenumber'. */
7585 /* If 'relativenumber' is set, reset 'number'. */
7586 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7587 curwin->w_p_rnu = FALSE;
7588 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7589 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007590 }
7591
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592 else if ((int *)varp == &curbuf->b_p_ro)
7593 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007594 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007595 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7596 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007597
7598 /* when 'readonly' is set may give W10 again */
7599 if (curbuf->b_p_ro)
7600 curbuf->b_did_warn = FALSE;
7601
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007603 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007604#endif
7605 }
7606
Bram Moolenaar9c449722010-07-20 18:44:27 +02007607#ifdef FEAT_GUI
7608 else if ((int *)varp == &p_mh)
7609 {
7610 if (!p_mh)
7611 gui_mch_mousehide(FALSE);
7612 }
7613#endif
7614
Bram Moolenaara539df02010-08-01 14:35:05 +02007615#ifdef FEAT_TITLE
7616 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007617 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007618 {
7619 redraw_titles();
7620 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621 /* when 'endofline' is changed, redraw the window title */
7622 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007623 {
7624 redraw_titles();
7625 }
7626# ifdef FEAT_MBYTE
7627 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007628 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007629 {
7630 redraw_titles();
7631 }
7632# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007633#endif
7634
7635 /* when 'bin' is set also set some other options */
7636 else if ((int *)varp == &curbuf->b_p_bin)
7637 {
7638 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7639#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007640 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007641#endif
7642 }
7643
7644#ifdef FEAT_AUTOCMD
7645 /* when 'buflisted' changes, trigger autocommands */
7646 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7647 {
7648 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7649 NULL, NULL, TRUE, curbuf);
7650 }
7651#endif
7652
7653 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7654 else if ((int *)varp == &curbuf->b_p_swf)
7655 {
7656 if (curbuf->b_p_swf && p_uc)
7657 ml_open_file(curbuf); /* create the swap file */
7658 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007659 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7660 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 mf_close_file(curbuf, TRUE); /* remove the swap file */
7662 }
7663
7664 /* when 'terse' is set change 'shortmess' */
7665 else if ((int *)varp == &p_terse)
7666 {
7667 char_u *p;
7668
7669 p = vim_strchr(p_shm, SHM_SEARCH);
7670
7671 /* insert 's' in p_shm */
7672 if (p_terse && p == NULL)
7673 {
7674 STRCPY(IObuff, p_shm);
7675 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007676 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677 }
7678 /* remove 's' from p_shm */
7679 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007680 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681 }
7682
7683 /* when 'paste' is set or reset also change other options */
7684 else if ((int *)varp == &p_paste)
7685 {
7686 paste_option_changed();
7687 }
7688
7689 /* when 'insertmode' is set from an autocommand need to do work here */
7690 else if ((int *)varp == &p_im)
7691 {
7692 if (p_im)
7693 {
7694 if ((State & INSERT) == 0)
7695 need_start_insertmode = TRUE;
7696 stop_insert_mode = FALSE;
7697 }
7698 else
7699 {
7700 need_start_insertmode = FALSE;
7701 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007702 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007703 clear_cmdline = TRUE; /* remove "(insert)" */
7704 restart_edit = 0;
7705 }
7706 }
7707
7708 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7709 else if ((int *)varp == &p_ic && p_hls)
7710 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007711 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 }
7713
7714#ifdef FEAT_SEARCH_EXTRA
7715 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7716 else if ((int *)varp == &p_hls)
7717 {
7718 no_hlsearch = FALSE;
7719 }
7720#endif
7721
7722#ifdef FEAT_SCROLLBIND
7723 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7724 * at the end of normal_cmd() */
7725 else if ((int *)varp == &curwin->w_p_scb)
7726 {
7727 if (curwin->w_p_scb)
7728 do_check_scrollbind(FALSE);
7729 }
7730#endif
7731
7732#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7733 /* There can be only one window with 'previewwindow' set. */
7734 else if ((int *)varp == &curwin->w_p_pvw)
7735 {
7736 if (curwin->w_p_pvw)
7737 {
7738 win_T *win;
7739
7740 for (win = firstwin; win != NULL; win = win->w_next)
7741 if (win->w_p_pvw && win != curwin)
7742 {
7743 curwin->w_p_pvw = FALSE;
7744 return (char_u *)N_("E590: A preview window already exists");
7745 }
7746 }
7747 }
7748#endif
7749
7750 /* when 'textmode' is set or reset also change 'fileformat' */
7751 else if ((int *)varp == &curbuf->b_p_tx)
7752 {
7753 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7754 }
7755
7756 /* when 'textauto' is set or reset also change 'fileformats' */
7757 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 set_string_option_direct((char_u *)"ffs", -1,
7759 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007760 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761
7762 /*
7763 * When 'lisp' option changes include/exclude '-' in
7764 * keyword characters.
7765 */
7766#ifdef FEAT_LISP
7767 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7768 {
7769 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7770 }
7771#endif
7772
7773#ifdef FEAT_TITLE
7774 /* when 'title' changed, may need to change the title; same for 'icon' */
7775 else if ((int *)varp == &p_title)
7776 {
7777 did_set_title(FALSE);
7778 }
7779
7780 else if ((int *)varp == &p_icon)
7781 {
7782 did_set_title(TRUE);
7783 }
7784#endif
7785
7786 else if ((int *)varp == &curbuf->b_changed)
7787 {
7788 if (!value)
7789 save_file_ff(curbuf); /* Buffer is unchanged */
7790#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007791 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792#endif
7793#ifdef FEAT_AUTOCMD
7794 modified_was_set = value;
7795#endif
7796 }
7797
7798#ifdef BACKSLASH_IN_FILENAME
7799 else if ((int *)varp == &p_ssl)
7800 {
7801 if (p_ssl)
7802 {
7803 psepc = '/';
7804 psepcN = '\\';
7805 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007806 }
7807 else
7808 {
7809 psepc = '\\';
7810 psepcN = '/';
7811 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007812 }
7813
7814 /* need to adjust the file name arguments and buffer names. */
7815 buflist_slash_adjust();
7816 alist_slash_adjust();
7817# ifdef FEAT_EVAL
7818 scriptnames_slash_adjust();
7819# endif
7820 }
7821#endif
7822
7823 /* If 'wrap' is set, set w_leftcol to zero. */
7824 else if ((int *)varp == &curwin->w_p_wrap)
7825 {
7826 if (curwin->w_p_wrap)
7827 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007828 if (curwin->w_curswant != MAXCOL)
7829 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830 }
7831
7832#ifdef FEAT_WINDOWS
7833 else if ((int *)varp == &p_ea)
7834 {
7835 if (p_ea && !old_value)
7836 win_equal(curwin, FALSE, 0);
7837 }
7838#endif
7839
7840 else if ((int *)varp == &p_wiv)
7841 {
7842 /*
7843 * When 'weirdinvert' changed, set/reset 't_xs'.
7844 * Then set 'weirdinvert' according to value of 't_xs'.
7845 */
7846 if (p_wiv && !old_value)
7847 T_XS = (char_u *)"y";
7848 else if (!p_wiv && old_value)
7849 T_XS = empty_option;
7850 p_wiv = (*T_XS != NUL);
7851 }
7852
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007853#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007854 else if ((int *)varp == &p_beval)
7855 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007856 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007857 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007858 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 gui_mch_disable_beval_area(balloonEval);
7860 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007861#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007862
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007863#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 else if ((int *)varp == &p_acd)
7865 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007866 /* Change directories when the 'acd' option is set now. */
7867 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868 }
7869#endif
7870
7871#ifdef FEAT_DIFF
7872 /* 'diff' */
7873 else if ((int *)varp == &curwin->w_p_diff)
7874 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007875 /* May add or remove the buffer from the list of diff buffers. */
7876 diff_buf_adjust(curwin);
7877# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007878 if (foldmethodIsDiff(curwin))
7879 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007880# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007881 }
7882#endif
7883
7884#ifdef USE_IM_CONTROL
7885 /* 'imdisable' */
7886 else if ((int *)varp == &p_imdisable)
7887 {
7888 /* Only de-activate it here, it will be enabled when changing mode. */
7889 if (p_imdisable)
7890 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007891 else if (State & INSERT)
7892 /* When the option is set from an autocommand, it may need to take
7893 * effect right away. */
7894 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895 }
7896#endif
7897
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007898#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007899 /* 'spell' */
7900 else if ((int *)varp == &curwin->w_p_spell)
7901 {
7902 if (curwin->w_p_spell)
7903 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007904 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007905 if (errmsg != NULL)
7906 EMSG(_(errmsg));
7907 }
7908 }
7909#endif
7910
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911#ifdef FEAT_FKMAP
7912 else if ((int *)varp == &p_altkeymap)
7913 {
7914 if (old_value != p_altkeymap)
7915 {
7916 if (!p_altkeymap)
7917 {
7918 p_hkmap = p_fkmap;
7919 p_fkmap = 0;
7920 }
7921 else
7922 {
7923 p_fkmap = p_hkmap;
7924 p_hkmap = 0;
7925 }
7926 (void)init_chartab();
7927 }
7928 }
7929
7930 /*
7931 * In case some second language keymapping options have changed, check
7932 * and correct the setting in a consistent way.
7933 */
7934
7935 /*
7936 * If hkmap or fkmap are set, reset Arabic keymapping.
7937 */
7938 if ((p_hkmap || p_fkmap) && p_altkeymap)
7939 {
7940 p_altkeymap = p_fkmap;
7941# ifdef FEAT_ARABIC
7942 curwin->w_p_arab = FALSE;
7943# endif
7944 (void)init_chartab();
7945 }
7946
7947 /*
7948 * If hkmap set, reset Farsi keymapping.
7949 */
7950 if (p_hkmap && p_altkeymap)
7951 {
7952 p_altkeymap = 0;
7953 p_fkmap = 0;
7954# ifdef FEAT_ARABIC
7955 curwin->w_p_arab = FALSE;
7956# endif
7957 (void)init_chartab();
7958 }
7959
7960 /*
7961 * If fkmap set, reset Hebrew keymapping.
7962 */
7963 if (p_fkmap && !p_altkeymap)
7964 {
7965 p_altkeymap = 1;
7966 p_hkmap = 0;
7967# ifdef FEAT_ARABIC
7968 curwin->w_p_arab = FALSE;
7969# endif
7970 (void)init_chartab();
7971 }
7972#endif
7973
7974#ifdef FEAT_ARABIC
7975 if ((int *)varp == &curwin->w_p_arab)
7976 {
7977 if (curwin->w_p_arab)
7978 {
7979 /*
7980 * 'arabic' is set, handle various sub-settings.
7981 */
7982 if (!p_tbidi)
7983 {
7984 /* set rightleft mode */
7985 if (!curwin->w_p_rl)
7986 {
7987 curwin->w_p_rl = TRUE;
7988 changed_window_setting();
7989 }
7990
7991 /* Enable Arabic shaping (major part of what Arabic requires) */
7992 if (!p_arshape)
7993 {
7994 p_arshape = TRUE;
7995 redraw_later_clear();
7996 }
7997 }
7998
7999 /* Arabic requires a utf-8 encoding, inform the user if its not
8000 * set. */
8001 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008002 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008003 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8004
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008005 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008006 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8007#ifdef FEAT_EVAL
8008 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8009#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008011
8012# ifdef FEAT_MBYTE
8013 /* set 'delcombine' */
8014 p_deco = TRUE;
8015# endif
8016
8017# ifdef FEAT_KEYMAP
8018 /* Force-set the necessary keymap for arabic */
8019 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8020 OPT_LOCAL);
8021# endif
8022# ifdef FEAT_FKMAP
8023 p_altkeymap = 0;
8024 p_hkmap = 0;
8025 p_fkmap = 0;
8026 (void)init_chartab();
8027# endif
8028 }
8029 else
8030 {
8031 /*
8032 * 'arabic' is reset, handle various sub-settings.
8033 */
8034 if (!p_tbidi)
8035 {
8036 /* reset rightleft mode */
8037 if (curwin->w_p_rl)
8038 {
8039 curwin->w_p_rl = FALSE;
8040 changed_window_setting();
8041 }
8042
8043 /* 'arabicshape' isn't reset, it is a global option and
8044 * another window may still need it "on". */
8045 }
8046
8047 /* 'delcombine' isn't reset, it is a global option and another
8048 * window may still want it "on". */
8049
8050# ifdef FEAT_KEYMAP
8051 /* Revert to the default keymap */
8052 curbuf->b_p_iminsert = B_IMODE_NONE;
8053 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8054# endif
8055 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008056 if (curwin->w_curswant != MAXCOL)
8057 curwin->w_set_curswant = TRUE;
8058 }
8059
8060 else if ((int *)varp == &p_arshape)
8061 {
8062 if (curwin->w_curswant != MAXCOL)
8063 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064 }
8065#endif
8066
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008067#ifdef FEAT_LINEBREAK
8068 if ((int *)varp == &curwin->w_p_lbr)
8069 {
8070 if (curwin->w_curswant != MAXCOL)
8071 curwin->w_set_curswant = TRUE;
8072 }
8073#endif
8074
8075#ifdef FEAT_RIGHTLEFT
8076 if ((int *)varp == &curwin->w_p_rl)
8077 {
8078 if (curwin->w_curswant != MAXCOL)
8079 curwin->w_set_curswant = TRUE;
8080 }
8081#endif
8082
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083 /*
8084 * End of handling side effects for bool options.
8085 */
8086
8087 options[opt_idx].flags |= P_WAS_SET;
8088
8089 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008090
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 check_redraw(options[opt_idx].flags);
8092
8093 return NULL;
8094}
8095
8096/*
8097 * Set the value of a number option, and take care of side effects.
8098 * Returns NULL for success, or an error message for an error.
8099 */
8100 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008101set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008102 int opt_idx; /* index in options[] table */
8103 char_u *varp; /* pointer to the option variable */
8104 long value; /* new value */
8105 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008106 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008107 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8108 OPT_MODELINE */
8109{
8110 char_u *errmsg = NULL;
8111 long old_value = *(long *)varp;
8112 long old_Rows = Rows; /* remember old Rows */
8113 long old_Columns = Columns; /* remember old Columns */
8114 long *pp = (long *)varp;
8115
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008116 /* Disallow changing some options from secure mode. */
8117 if ((secure
8118#ifdef HAVE_SANDBOX
8119 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008120#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008121 ) && (options[opt_idx].flags & P_SECURE))
8122 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123
8124 *pp = value;
8125#ifdef FEAT_EVAL
8126 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008127 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008129#ifdef FEAT_GUI
8130 need_mouse_correct = TRUE;
8131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132
8133 if (curbuf->b_p_sw <= 0)
8134 {
8135 errmsg = e_positive;
8136 curbuf->b_p_sw = curbuf->b_p_ts;
8137 }
8138
8139 /*
8140 * Number options that need some action when changed
8141 */
8142#ifdef FEAT_WINDOWS
8143 if (pp == &p_wh || pp == &p_hh)
8144 {
8145 if (p_wh < 1)
8146 {
8147 errmsg = e_positive;
8148 p_wh = 1;
8149 }
8150 if (p_wmh > p_wh)
8151 {
8152 errmsg = e_winheight;
8153 p_wh = p_wmh;
8154 }
8155 if (p_hh < 0)
8156 {
8157 errmsg = e_positive;
8158 p_hh = 0;
8159 }
8160
8161 /* Change window height NOW */
8162 if (lastwin != firstwin)
8163 {
8164 if (pp == &p_wh && curwin->w_height < p_wh)
8165 win_setheight((int)p_wh);
8166 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8167 win_setheight((int)p_hh);
8168 }
8169 }
8170
8171 /* 'winminheight' */
8172 else if (pp == &p_wmh)
8173 {
8174 if (p_wmh < 0)
8175 {
8176 errmsg = e_positive;
8177 p_wmh = 0;
8178 }
8179 if (p_wmh > p_wh)
8180 {
8181 errmsg = e_winheight;
8182 p_wmh = p_wh;
8183 }
8184 win_setminheight();
8185 }
8186
8187# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008188 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 {
8190 if (p_wiw < 1)
8191 {
8192 errmsg = e_positive;
8193 p_wiw = 1;
8194 }
8195 if (p_wmw > p_wiw)
8196 {
8197 errmsg = e_winwidth;
8198 p_wiw = p_wmw;
8199 }
8200
8201 /* Change window width NOW */
8202 if (lastwin != firstwin && curwin->w_width < p_wiw)
8203 win_setwidth((int)p_wiw);
8204 }
8205
8206 /* 'winminwidth' */
8207 else if (pp == &p_wmw)
8208 {
8209 if (p_wmw < 0)
8210 {
8211 errmsg = e_positive;
8212 p_wmw = 0;
8213 }
8214 if (p_wmw > p_wiw)
8215 {
8216 errmsg = e_winwidth;
8217 p_wmw = p_wiw;
8218 }
8219 win_setminheight();
8220 }
8221# endif
8222
8223#endif
8224
8225#ifdef FEAT_WINDOWS
8226 /* (re)set last window status line */
8227 else if (pp == &p_ls)
8228 {
8229 last_status(FALSE);
8230 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008231
8232 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008233 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008234 {
8235 shell_new_rows(); /* recompute window positions and heights */
8236 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237#endif
8238
8239#ifdef FEAT_GUI
8240 else if (pp == &p_linespace)
8241 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008242 /* Recompute gui.char_height and resize the Vim window to keep the
8243 * same number of lines. */
8244 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008245 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246 }
8247#endif
8248
8249#ifdef FEAT_FOLDING
8250 /* 'foldlevel' */
8251 else if (pp == &curwin->w_p_fdl)
8252 {
8253 if (curwin->w_p_fdl < 0)
8254 curwin->w_p_fdl = 0;
8255 newFoldLevel();
8256 }
8257
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008258 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008259 else if (pp == &curwin->w_p_fml)
8260 {
8261 foldUpdateAll(curwin);
8262 }
8263
8264 /* 'foldnestmax' */
8265 else if (pp == &curwin->w_p_fdn)
8266 {
8267 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8268 foldUpdateAll(curwin);
8269 }
8270
8271 /* 'foldcolumn' */
8272 else if (pp == &curwin->w_p_fdc)
8273 {
8274 if (curwin->w_p_fdc < 0)
8275 {
8276 errmsg = e_positive;
8277 curwin->w_p_fdc = 0;
8278 }
8279 else if (curwin->w_p_fdc > 12)
8280 {
8281 errmsg = e_invarg;
8282 curwin->w_p_fdc = 12;
8283 }
8284 }
8285
8286 /* 'shiftwidth' or 'tabstop' */
8287 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8288 {
8289 if (foldmethodIsIndent(curwin))
8290 foldUpdateAll(curwin);
8291 }
8292#endif /* FEAT_FOLDING */
8293
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008294#ifdef FEAT_MBYTE
8295 /* 'maxcombine' */
8296 else if (pp == &p_mco)
8297 {
8298 if (p_mco > MAX_MCO)
8299 p_mco = MAX_MCO;
8300 else if (p_mco < 0)
8301 p_mco = 0;
8302 screenclear(); /* will re-allocate the screen */
8303 }
8304#endif
8305
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 else if (pp == &curbuf->b_p_iminsert)
8307 {
8308 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8309 {
8310 errmsg = e_invarg;
8311 curbuf->b_p_iminsert = B_IMODE_NONE;
8312 }
8313 p_iminsert = curbuf->b_p_iminsert;
8314 if (termcap_active) /* don't do this in the alternate screen */
8315 showmode();
8316#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8317 /* Show/unshow value of 'keymap' in status lines. */
8318 status_redraw_curbuf();
8319#endif
8320 }
8321
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008322 else if (pp == &p_window)
8323 {
8324 if (p_window < 1)
8325 p_window = 1;
8326 else if (p_window >= Rows)
8327 p_window = Rows - 1;
8328 }
8329
Bram Moolenaar071d4272004-06-13 20:20:40 +00008330 else if (pp == &curbuf->b_p_imsearch)
8331 {
8332 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8333 {
8334 errmsg = e_invarg;
8335 curbuf->b_p_imsearch = B_IMODE_NONE;
8336 }
8337 p_imsearch = curbuf->b_p_imsearch;
8338 }
8339
8340#ifdef FEAT_TITLE
8341 /* if 'titlelen' has changed, redraw the title */
8342 else if (pp == &p_titlelen)
8343 {
8344 if (p_titlelen < 0)
8345 {
8346 errmsg = e_positive;
8347 p_titlelen = 85;
8348 }
8349 if (starting != NO_SCREEN && old_value != p_titlelen)
8350 need_maketitle = TRUE;
8351 }
8352#endif
8353
8354 /* if p_ch changed value, change the command line height */
8355 else if (pp == &p_ch)
8356 {
8357 if (p_ch < 1)
8358 {
8359 errmsg = e_positive;
8360 p_ch = 1;
8361 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008362 if (p_ch > Rows - min_rows() + 1)
8363 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364
8365 /* Only compute the new window layout when startup has been
8366 * completed. Otherwise the frame sizes may be wrong. */
8367 if (p_ch != old_value && full_screen
8368#ifdef FEAT_GUI
8369 && !gui.starting
8370#endif
8371 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008372 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008373 }
8374
8375 /* when 'updatecount' changes from zero to non-zero, open swap files */
8376 else if (pp == &p_uc)
8377 {
8378 if (p_uc < 0)
8379 {
8380 errmsg = e_positive;
8381 p_uc = 100;
8382 }
8383 if (p_uc && !old_value)
8384 ml_open_files();
8385 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008386#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008387 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008388 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008389 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008390 {
8391 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008392 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008393 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008394 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008395 {
8396 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008397 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008398 }
8399 }
8400#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008401#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008402 else if (pp == &p_mzq)
8403 mzvim_reset_timer();
8404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405
8406 /* sync undo before 'undolevels' changes */
8407 else if (pp == &p_ul)
8408 {
8409 /* use the old value, otherwise u_sync() may not work properly */
8410 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008411 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 p_ul = value;
8413 }
8414
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008415#ifdef FEAT_LINEBREAK
8416 /* 'numberwidth' must be positive */
8417 else if (pp == &curwin->w_p_nuw)
8418 {
8419 if (curwin->w_p_nuw < 1)
8420 {
8421 errmsg = e_positive;
8422 curwin->w_p_nuw = 1;
8423 }
8424 if (curwin->w_p_nuw > 10)
8425 {
8426 errmsg = e_invarg;
8427 curwin->w_p_nuw = 10;
8428 }
8429 curwin->w_nrwidth_line_count = 0;
8430 }
8431#endif
8432
Bram Moolenaar1a384422010-07-14 19:53:30 +02008433 else if (pp == &curbuf->b_p_tw)
8434 {
8435 if (curbuf->b_p_tw < 0)
8436 {
8437 errmsg = e_positive;
8438 curbuf->b_p_tw = 0;
8439 }
8440#ifdef FEAT_SYN_HL
8441# ifdef FEAT_WINDOWS
8442 {
8443 win_T *wp;
8444 tabpage_T *tp;
8445
8446 FOR_ALL_TAB_WINDOWS(tp, wp)
8447 check_colorcolumn(wp);
8448 }
8449# else
8450 check_colorcolumn(curwin);
8451# endif
8452#endif
8453 }
8454
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455 /*
8456 * Check the bounds for numeric options here
8457 */
8458 if (Rows < min_rows() && full_screen)
8459 {
8460 if (errbuf != NULL)
8461 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008462 vim_snprintf((char *)errbuf, errbuflen,
8463 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 errmsg = errbuf;
8465 }
8466 Rows = min_rows();
8467 }
8468 if (Columns < MIN_COLUMNS && full_screen)
8469 {
8470 if (errbuf != NULL)
8471 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008472 vim_snprintf((char *)errbuf, errbuflen,
8473 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 errmsg = errbuf;
8475 }
8476 Columns = MIN_COLUMNS;
8477 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008478 /* Limit the values to avoid an overflow in Rows * Columns. */
8479 if (Columns > 10000)
8480 Columns = 10000;
8481 if (Rows > 1000)
8482 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483
8484#ifdef DJGPP
8485 /* avoid a crash by checking for a too large value of 'columns' */
8486 if (old_Columns != Columns && full_screen && term_console)
8487 mch_check_columns();
8488#endif
8489
8490 /*
8491 * If the screen (shell) height has been changed, assume it is the
8492 * physical screenheight.
8493 */
8494 if (old_Rows != Rows || old_Columns != Columns)
8495 {
8496 /* Changing the screen size is not allowed while updating the screen. */
8497 if (updating_screen)
8498 *pp = old_value;
8499 else if (full_screen
8500#ifdef FEAT_GUI
8501 && !gui.starting
8502#endif
8503 )
8504 set_shellsize((int)Columns, (int)Rows, TRUE);
8505 else
8506 {
8507 /* Postpone the resizing; check the size and cmdline position for
8508 * messages. */
8509 check_shellsize();
8510 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8511 cmdline_row = Rows - p_ch;
8512 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008513 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008514 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008515 }
8516
8517 if (curbuf->b_p_sts < 0)
8518 {
8519 errmsg = e_positive;
8520 curbuf->b_p_sts = 0;
8521 }
8522 if (curbuf->b_p_ts <= 0)
8523 {
8524 errmsg = e_positive;
8525 curbuf->b_p_ts = 8;
8526 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527 if (p_tm < 0)
8528 {
8529 errmsg = e_positive;
8530 p_tm = 0;
8531 }
8532 if ((curwin->w_p_scr <= 0
8533 || (curwin->w_p_scr > curwin->w_height
8534 && curwin->w_height > 0))
8535 && full_screen)
8536 {
8537 if (pp == &(curwin->w_p_scr))
8538 {
8539 if (curwin->w_p_scr != 0)
8540 errmsg = e_scroll;
8541 win_comp_scroll(curwin);
8542 }
8543 /* If 'scroll' became invalid because of a side effect silently adjust
8544 * it. */
8545 else if (curwin->w_p_scr <= 0)
8546 curwin->w_p_scr = 1;
8547 else /* curwin->w_p_scr > curwin->w_height */
8548 curwin->w_p_scr = curwin->w_height;
8549 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008550 if (p_hi < 0)
8551 {
8552 errmsg = e_positive;
8553 p_hi = 0;
8554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555 if (p_report < 0)
8556 {
8557 errmsg = e_positive;
8558 p_report = 1;
8559 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008560 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561 {
8562 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8563 p_sj = Rows / 2;
8564 else
8565 {
8566 errmsg = e_scroll;
8567 p_sj = 1;
8568 }
8569 }
8570 if (p_so < 0 && full_screen)
8571 {
8572 errmsg = e_scroll;
8573 p_so = 0;
8574 }
8575 if (p_siso < 0 && full_screen)
8576 {
8577 errmsg = e_positive;
8578 p_siso = 0;
8579 }
8580#ifdef FEAT_CMDWIN
8581 if (p_cwh < 1)
8582 {
8583 errmsg = e_positive;
8584 p_cwh = 1;
8585 }
8586#endif
8587 if (p_ut < 0)
8588 {
8589 errmsg = e_positive;
8590 p_ut = 2000;
8591 }
8592 if (p_ss < 0)
8593 {
8594 errmsg = e_positive;
8595 p_ss = 0;
8596 }
8597
8598 /* May set global value for local option. */
8599 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8600 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8601
8602 options[opt_idx].flags |= P_WAS_SET;
8603
8604 comp_col(); /* in case 'columns' or 'ls' changed */
8605 if (curwin->w_curswant != MAXCOL)
8606 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8607 check_redraw(options[opt_idx].flags);
8608
8609 return errmsg;
8610}
8611
8612/*
8613 * Called after an option changed: check if something needs to be redrawn.
8614 */
8615 static void
8616check_redraw(flags)
8617 long_u flags;
8618{
8619 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008620 int doclear = (flags & P_RCLR) == P_RCLR;
8621 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622
8623#ifdef FEAT_WINDOWS
8624 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8625 status_redraw_all();
8626#endif
8627
8628 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8629 changed_window_setting();
8630 if (flags & P_RBUF)
8631 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008632 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633 redraw_all_later(CLEAR);
8634 else if (all)
8635 redraw_all_later(NOT_VALID);
8636}
8637
8638/*
8639 * Find index for option 'arg'.
8640 * Return -1 if not found.
8641 */
8642 static int
8643findoption(arg)
8644 char_u *arg;
8645{
8646 int opt_idx;
8647 char *s, *p;
8648 static short quick_tab[27] = {0, 0}; /* quick access table */
8649 int is_term_opt;
8650
8651 /*
8652 * For first call: Initialize the quick-access table.
8653 * It contains the index for the first option that starts with a certain
8654 * letter. There are 26 letters, plus the first "t_" option.
8655 */
8656 if (quick_tab[1] == 0)
8657 {
8658 p = options[0].fullname;
8659 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8660 {
8661 if (s[0] != p[0])
8662 {
8663 if (s[0] == 't' && s[1] == '_')
8664 quick_tab[26] = opt_idx;
8665 else
8666 quick_tab[CharOrdLow(s[0])] = opt_idx;
8667 }
8668 p = s;
8669 }
8670 }
8671
8672 /*
8673 * Check for name starting with an illegal character.
8674 */
8675#ifdef EBCDIC
8676 if (!islower(arg[0]))
8677#else
8678 if (arg[0] < 'a' || arg[0] > 'z')
8679#endif
8680 return -1;
8681
8682 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8683 if (is_term_opt)
8684 opt_idx = quick_tab[26];
8685 else
8686 opt_idx = quick_tab[CharOrdLow(arg[0])];
8687 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8688 {
8689 if (STRCMP(arg, s) == 0) /* match full name */
8690 break;
8691 }
8692 if (s == NULL && !is_term_opt)
8693 {
8694 opt_idx = quick_tab[CharOrdLow(arg[0])];
8695 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8696 {
8697 s = options[opt_idx].shortname;
8698 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8699 break;
8700 s = NULL;
8701 }
8702 }
8703 if (s == NULL)
8704 opt_idx = -1;
8705 return opt_idx;
8706}
8707
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008708#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709/*
8710 * Get the value for an option.
8711 *
8712 * Returns:
8713 * Number or Toggle option: 1, *numval gets value.
8714 * String option: 0, *stringval gets allocated string.
8715 * Hidden Number or Toggle option: -1.
8716 * hidden String option: -2.
8717 * unknown option: -3.
8718 */
8719 int
8720get_option_value(name, numval, stringval, opt_flags)
8721 char_u *name;
8722 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008723 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008724 int opt_flags;
8725{
8726 int opt_idx;
8727 char_u *varp;
8728
8729 opt_idx = findoption(name);
8730 if (opt_idx < 0) /* unknown option */
8731 return -3;
8732
8733 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8734
8735 if (options[opt_idx].flags & P_STRING)
8736 {
8737 if (varp == NULL) /* hidden option */
8738 return -2;
8739 if (stringval != NULL)
8740 {
8741#ifdef FEAT_CRYPT
8742 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008743 if ((char_u **)varp == &curbuf->b_p_key
8744 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 *stringval = vim_strsave((char_u *)"*****");
8746 else
8747#endif
8748 *stringval = vim_strsave(*(char_u **)(varp));
8749 }
8750 return 0;
8751 }
8752
8753 if (varp == NULL) /* hidden option */
8754 return -1;
8755 if (options[opt_idx].flags & P_NUM)
8756 *numval = *(long *)varp;
8757 else
8758 {
8759 /* Special case: 'modified' is b_changed, but we also want to consider
8760 * it set when 'ff' or 'fenc' changed. */
8761 if ((int *)varp == &curbuf->b_changed)
8762 *numval = curbufIsChanged();
8763 else
8764 *numval = *(int *)varp;
8765 }
8766 return 1;
8767}
8768#endif
8769
8770/*
8771 * Set the value of option "name".
8772 * Use "string" for string options, use "number" for other options.
8773 */
8774 void
8775set_option_value(name, number, string, opt_flags)
8776 char_u *name;
8777 long number;
8778 char_u *string;
8779 int opt_flags; /* OPT_LOCAL or 0 (both) */
8780{
8781 int opt_idx;
8782 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008783 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784
8785 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008786 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787 EMSG2(_("E355: Unknown option: %s"), name);
8788 else
8789 {
8790 flags = options[opt_idx].flags;
8791#ifdef HAVE_SANDBOX
8792 /* Disallow changing some options in the sandbox */
8793 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008794 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008796 return;
8797 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008799 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 set_string_option(opt_idx, string, opt_flags);
8801 else
8802 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008803 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 if (varp != NULL) /* hidden option is not changed */
8805 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008806 if (number == 0 && string != NULL)
8807 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008808 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008809
8810 /* Either we are given a string or we are setting option
8811 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008812 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008813 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008814 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008815 {
8816 /* There's another character after zeros or the string
8817 * is empty. In both cases, we are trying to set a
8818 * num option using a string. */
8819 EMSG3(_("E521: Number required: &%s = '%s'"),
8820 name, string);
8821 return; /* do nothing as we hit an error */
8822
8823 }
8824 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008826 (void)set_num_option(opt_idx, varp, number,
8827 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008829 (void)set_bool_option(opt_idx, varp, (int)number,
8830 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008831 }
8832 }
8833 }
8834}
8835
8836/*
8837 * Get the terminal code for a terminal option.
8838 * Returns NULL when not found.
8839 */
8840 char_u *
8841get_term_code(tname)
8842 char_u *tname;
8843{
8844 int opt_idx;
8845 char_u *varp;
8846
8847 if (tname[0] != 't' || tname[1] != '_' ||
8848 tname[2] == NUL || tname[3] == NUL)
8849 return NULL;
8850 if ((opt_idx = findoption(tname)) >= 0)
8851 {
8852 varp = get_varp(&(options[opt_idx]));
8853 if (varp != NULL)
8854 varp = *(char_u **)(varp);
8855 return varp;
8856 }
8857 return find_termcode(tname + 2);
8858}
8859
8860 char_u *
8861get_highlight_default()
8862{
8863 int i;
8864
8865 i = findoption((char_u *)"hl");
8866 if (i >= 0)
8867 return options[i].def_val[VI_DEFAULT];
8868 return (char_u *)NULL;
8869}
8870
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008871#if defined(FEAT_MBYTE) || defined(PROTO)
8872 char_u *
8873get_encoding_default()
8874{
8875 int i;
8876
8877 i = findoption((char_u *)"enc");
8878 if (i >= 0)
8879 return options[i].def_val[VI_DEFAULT];
8880 return (char_u *)NULL;
8881}
8882#endif
8883
Bram Moolenaar071d4272004-06-13 20:20:40 +00008884/*
8885 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8886 */
8887 static int
8888find_key_option(arg)
8889 char_u *arg;
8890{
8891 int key;
8892 int modifiers;
8893
8894 /*
8895 * Don't use get_special_key_code() for t_xx, we don't want it to call
8896 * add_termcap_entry().
8897 */
8898 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8899 key = TERMCAP2KEY(arg[2], arg[3]);
8900 else
8901 {
8902 --arg; /* put arg at the '<' */
8903 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008904 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905 if (modifiers) /* can't handle modifiers here */
8906 key = 0;
8907 }
8908 return key;
8909}
8910
8911/*
8912 * if 'all' == 0: show changed options
8913 * if 'all' == 1: show all normal options
8914 * if 'all' == 2: show all terminal options
8915 */
8916 static void
8917showoptions(all, opt_flags)
8918 int all;
8919 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8920{
8921 struct vimoption *p;
8922 int col;
8923 int isterm;
8924 char_u *varp;
8925 struct vimoption **items;
8926 int item_count;
8927 int run;
8928 int row, rows;
8929 int cols;
8930 int i;
8931 int len;
8932
8933#define INC 20
8934#define GAP 3
8935
8936 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8937 PARAM_COUNT));
8938 if (items == NULL)
8939 return;
8940
8941 /* Highlight title */
8942 if (all == 2)
8943 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8944 else if (opt_flags & OPT_GLOBAL)
8945 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8946 else if (opt_flags & OPT_LOCAL)
8947 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8948 else
8949 MSG_PUTS_TITLE(_("\n--- Options ---"));
8950
8951 /*
8952 * do the loop two times:
8953 * 1. display the short items
8954 * 2. display the long items (only strings and numbers)
8955 */
8956 for (run = 1; run <= 2 && !got_int; ++run)
8957 {
8958 /*
8959 * collect the items in items[]
8960 */
8961 item_count = 0;
8962 for (p = &options[0]; p->fullname != NULL; p++)
8963 {
8964 varp = NULL;
8965 isterm = istermoption(p);
8966 if (opt_flags != 0)
8967 {
8968 if (p->indir != PV_NONE && !isterm)
8969 varp = get_varp_scope(p, opt_flags);
8970 }
8971 else
8972 varp = get_varp(p);
8973 if (varp != NULL
8974 && ((all == 2 && isterm)
8975 || (all == 1 && !isterm)
8976 || (all == 0 && !optval_default(p, varp))))
8977 {
8978 if (p->flags & P_BOOL)
8979 len = 1; /* a toggle option fits always */
8980 else
8981 {
8982 option_value2string(p, opt_flags);
8983 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8984 }
8985 if ((len <= INC - GAP && run == 1) ||
8986 (len > INC - GAP && run == 2))
8987 items[item_count++] = p;
8988 }
8989 }
8990
8991 /*
8992 * display the items
8993 */
8994 if (run == 1)
8995 {
8996 cols = (Columns + GAP - 3) / INC;
8997 if (cols == 0)
8998 cols = 1;
8999 rows = (item_count + cols - 1) / cols;
9000 }
9001 else /* run == 2 */
9002 rows = item_count;
9003 for (row = 0; row < rows && !got_int; ++row)
9004 {
9005 msg_putchar('\n'); /* go to next line */
9006 if (got_int) /* 'q' typed in more */
9007 break;
9008 col = 0;
9009 for (i = row; i < item_count; i += rows)
9010 {
9011 msg_col = col; /* make columns */
9012 showoneopt(items[i], opt_flags);
9013 col += INC;
9014 }
9015 out_flush();
9016 ui_breakcheck();
9017 }
9018 }
9019 vim_free(items);
9020}
9021
9022/*
9023 * Return TRUE if option "p" has its default value.
9024 */
9025 static int
9026optval_default(p, varp)
9027 struct vimoption *p;
9028 char_u *varp;
9029{
9030 int dvi;
9031
9032 if (varp == NULL)
9033 return TRUE; /* hidden option is always at default */
9034 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9035 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009036 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009038 /* the cast to long is required for Manx C, long_i is
9039 * needed for MSVC */
9040 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041 /* P_STRING */
9042 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9043}
9044
9045/*
9046 * showoneopt: show the value of one option
9047 * must not be called with a hidden option!
9048 */
9049 static void
9050showoneopt(p, opt_flags)
9051 struct vimoption *p;
9052 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9053{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009054 char_u *varp;
9055 int save_silent = silent_mode;
9056
9057 silent_mode = FALSE;
9058 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059
9060 varp = get_varp_scope(p, opt_flags);
9061
9062 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9063 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9064 ? !curbufIsChanged() : !*(int *)varp))
9065 MSG_PUTS("no");
9066 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9067 MSG_PUTS("--");
9068 else
9069 MSG_PUTS(" ");
9070 MSG_PUTS(p->fullname);
9071 if (!(p->flags & P_BOOL))
9072 {
9073 msg_putchar('=');
9074 /* put value string in NameBuff */
9075 option_value2string(p, opt_flags);
9076 msg_outtrans(NameBuff);
9077 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009078
9079 silent_mode = save_silent;
9080 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081}
9082
9083/*
9084 * Write modified options as ":set" commands to a file.
9085 *
9086 * There are three values for "opt_flags":
9087 * OPT_GLOBAL: Write global option values and fresh values of
9088 * buffer-local options (used for start of a session
9089 * file).
9090 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9091 * curwin (used for a vimrc file).
9092 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9093 * and local values for window-local options of
9094 * curwin. Local values are also written when at the
9095 * default value, because a modeline or autocommand
9096 * may have set them when doing ":edit file" and the
9097 * user has set them back at the default or fresh
9098 * value.
9099 * When "local_only" is TRUE, don't write fresh
9100 * values, only local values (for ":mkview").
9101 * (fresh value = value used for a new buffer or window for a local option).
9102 *
9103 * Return FAIL on error, OK otherwise.
9104 */
9105 int
9106makeset(fd, opt_flags, local_only)
9107 FILE *fd;
9108 int opt_flags;
9109 int local_only;
9110{
9111 struct vimoption *p;
9112 char_u *varp; /* currently used value */
9113 char_u *varp_fresh; /* local value */
9114 char_u *varp_local = NULL; /* fresh value */
9115 char *cmd;
9116 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009117 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009118
9119 /*
9120 * The options that don't have a default (terminal name, columns, lines)
9121 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009122 * Do the loop over "options[]" twice: once for options with the
9123 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009124 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009125 for (pri = 1; pri >= 0; --pri)
9126 {
9127 for (p = &options[0]; !istermoption(p); p++)
9128 if (!(p->flags & P_NO_MKRC)
9129 && !istermoption(p)
9130 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009131 {
9132 /* skip global option when only doing locals */
9133 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9134 continue;
9135
9136 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9137 * file, they are always buffer-specific. */
9138 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9139 continue;
9140
9141 /* Global values are only written when not at the default value. */
9142 varp = get_varp_scope(p, opt_flags);
9143 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9144 continue;
9145
9146 round = 2;
9147 if (p->indir != PV_NONE)
9148 {
9149 if (p->var == VAR_WIN)
9150 {
9151 /* skip window-local option when only doing globals */
9152 if (!(opt_flags & OPT_LOCAL))
9153 continue;
9154 /* When fresh value of window-local option is not at the
9155 * default, need to write it too. */
9156 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9157 {
9158 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9159 if (!optval_default(p, varp_fresh))
9160 {
9161 round = 1;
9162 varp_local = varp;
9163 varp = varp_fresh;
9164 }
9165 }
9166 }
9167 }
9168
9169 /* Round 1: fresh value for window-local options.
9170 * Round 2: other values */
9171 for ( ; round <= 2; varp = varp_local, ++round)
9172 {
9173 if (round == 1 || (opt_flags & OPT_GLOBAL))
9174 cmd = "set";
9175 else
9176 cmd = "setlocal";
9177
9178 if (p->flags & P_BOOL)
9179 {
9180 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9181 return FAIL;
9182 }
9183 else if (p->flags & P_NUM)
9184 {
9185 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9186 return FAIL;
9187 }
9188 else /* P_STRING */
9189 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009190#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9191 int do_endif = FALSE;
9192
Bram Moolenaar071d4272004-06-13 20:20:40 +00009193 /* Don't set 'syntax' and 'filetype' again if the value is
9194 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009195 if (
9196# if defined(FEAT_SYN_HL)
9197 p->indir == PV_SYN
9198# if defined(FEAT_AUTOCMD)
9199 ||
9200# endif
9201# endif
9202# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009203 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009204# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009205 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206 {
9207 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9208 *(char_u **)(varp)) < 0
9209 || put_eol(fd) < 0)
9210 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009211 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009212 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009213#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9215 (p->flags & P_EXPAND) != 0) == FAIL)
9216 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009217#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9218 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009219 {
9220 if (put_line(fd, "endif") == FAIL)
9221 return FAIL;
9222 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009223#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224 }
9225 }
9226 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009227 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009228 return OK;
9229}
9230
9231#if defined(FEAT_FOLDING) || defined(PROTO)
9232/*
9233 * Generate set commands for the local fold options only. Used when
9234 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9235 */
9236 int
9237makefoldset(fd)
9238 FILE *fd;
9239{
9240 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9241# ifdef FEAT_EVAL
9242 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9243 == FAIL
9244# endif
9245 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9246 == FAIL
9247 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9248 == FAIL
9249 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9250 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9251 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9252 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9253 )
9254 return FAIL;
9255
9256 return OK;
9257}
9258#endif
9259
9260 static int
9261put_setstring(fd, cmd, name, valuep, expand)
9262 FILE *fd;
9263 char *cmd;
9264 char *name;
9265 char_u **valuep;
9266 int expand;
9267{
9268 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009269 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270
9271 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9272 return FAIL;
9273 if (*valuep != NULL)
9274 {
9275 /* Output 'pastetoggle' as key names. For other
9276 * options some characters have to be escaped with
9277 * CTRL-V or backslash */
9278 if (valuep == &p_pt)
9279 {
9280 s = *valuep;
9281 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009282 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009283 return FAIL;
9284 }
9285 else if (expand)
9286 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009287 buf = alloc(MAXPATHL);
9288 if (buf == NULL)
9289 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009290 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9291 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009292 {
9293 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009294 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009295 }
9296 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009297 }
9298 else if (put_escstr(fd, *valuep, 2) == FAIL)
9299 return FAIL;
9300 }
9301 if (put_eol(fd) < 0)
9302 return FAIL;
9303 return OK;
9304}
9305
9306 static int
9307put_setnum(fd, cmd, name, valuep)
9308 FILE *fd;
9309 char *cmd;
9310 char *name;
9311 long *valuep;
9312{
9313 long wc;
9314
9315 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9316 return FAIL;
9317 if (wc_use_keyname((char_u *)valuep, &wc))
9318 {
9319 /* print 'wildchar' and 'wildcharm' as a key name */
9320 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9321 return FAIL;
9322 }
9323 else if (fprintf(fd, "%ld", *valuep) < 0)
9324 return FAIL;
9325 if (put_eol(fd) < 0)
9326 return FAIL;
9327 return OK;
9328}
9329
9330 static int
9331put_setbool(fd, cmd, name, value)
9332 FILE *fd;
9333 char *cmd;
9334 char *name;
9335 int value;
9336{
Bram Moolenaar893de922007-10-02 18:40:57 +00009337 if (value < 0) /* global/local option using global value */
9338 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009339 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9340 || put_eol(fd) < 0)
9341 return FAIL;
9342 return OK;
9343}
9344
9345/*
9346 * Clear all the terminal options.
9347 * If the option has been allocated, free the memory.
9348 * Terminal options are never hidden or indirect.
9349 */
9350 void
9351clear_termoptions()
9352{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009353 /*
9354 * Reset a few things before clearing the old options. This may cause
9355 * outputting a few things that the terminal doesn't understand, but the
9356 * screen will be cleared later, so this is OK.
9357 */
9358#ifdef FEAT_MOUSE_TTY
9359 mch_setmouse(FALSE); /* switch mouse off */
9360#endif
9361#ifdef FEAT_TITLE
9362 mch_restore_title(3); /* restore window titles */
9363#endif
9364#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9365 /* When starting the GUI close the display opened for the clipboard.
9366 * After restoring the title, because that will need the display. */
9367 if (gui.starting)
9368 clear_xterm_clip();
9369#endif
9370#ifdef WIN3264
9371 /*
9372 * Check if this is allowed now.
9373 */
9374 if (can_end_termcap_mode(FALSE) == TRUE)
9375#endif
9376 stoptermcap(); /* stop termcap mode */
9377
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009378 free_termoptions();
9379}
9380
9381 void
9382free_termoptions()
9383{
9384 struct vimoption *p;
9385
Bram Moolenaar071d4272004-06-13 20:20:40 +00009386 for (p = &options[0]; p->fullname != NULL; p++)
9387 if (istermoption(p))
9388 {
9389 if (p->flags & P_ALLOCED)
9390 free_string_option(*(char_u **)(p->var));
9391 if (p->flags & P_DEF_ALLOCED)
9392 free_string_option(p->def_val[VI_DEFAULT]);
9393 *(char_u **)(p->var) = empty_option;
9394 p->def_val[VI_DEFAULT] = empty_option;
9395 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9396 }
9397 clear_termcodes();
9398}
9399
9400/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009401 * Free the string for one term option, if it was allocated.
9402 * Set the string to empty_option and clear allocated flag.
9403 * "var" points to the option value.
9404 */
9405 void
9406free_one_termoption(var)
9407 char_u *var;
9408{
9409 struct vimoption *p;
9410
9411 for (p = &options[0]; p->fullname != NULL; p++)
9412 if (p->var == var)
9413 {
9414 if (p->flags & P_ALLOCED)
9415 free_string_option(*(char_u **)(p->var));
9416 *(char_u **)(p->var) = empty_option;
9417 p->flags &= ~P_ALLOCED;
9418 break;
9419 }
9420}
9421
9422/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423 * Set the terminal option defaults to the current value.
9424 * Used after setting the terminal name.
9425 */
9426 void
9427set_term_defaults()
9428{
9429 struct vimoption *p;
9430
9431 for (p = &options[0]; p->fullname != NULL; p++)
9432 {
9433 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9434 {
9435 if (p->flags & P_DEF_ALLOCED)
9436 {
9437 free_string_option(p->def_val[VI_DEFAULT]);
9438 p->flags &= ~P_DEF_ALLOCED;
9439 }
9440 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9441 if (p->flags & P_ALLOCED)
9442 {
9443 p->flags |= P_DEF_ALLOCED;
9444 p->flags &= ~P_ALLOCED; /* don't free the value now */
9445 }
9446 }
9447 }
9448}
9449
9450/*
9451 * return TRUE if 'p' starts with 't_'
9452 */
9453 static int
9454istermoption(p)
9455 struct vimoption *p;
9456{
9457 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9458}
9459
9460/*
9461 * Compute columns for ruler and shown command. 'sc_col' is also used to
9462 * decide what the maximum length of a message on the status line can be.
9463 * If there is a status line for the last window, 'sc_col' is independent
9464 * of 'ru_col'.
9465 */
9466
9467#define COL_RULER 17 /* columns needed by standard ruler */
9468
9469 void
9470comp_col()
9471{
9472#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9473 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9474
9475 sc_col = 0;
9476 ru_col = 0;
9477 if (p_ru)
9478 {
9479#ifdef FEAT_STL_OPT
9480 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9481#else
9482 ru_col = COL_RULER + 1;
9483#endif
9484 /* no last status line, adjust sc_col */
9485 if (!last_has_status)
9486 sc_col = ru_col;
9487 }
9488 if (p_sc)
9489 {
9490 sc_col += SHOWCMD_COLS;
9491 if (!p_ru || last_has_status) /* no need for separating space */
9492 ++sc_col;
9493 }
9494 sc_col = Columns - sc_col;
9495 ru_col = Columns - ru_col;
9496 if (sc_col <= 0) /* screen too narrow, will become a mess */
9497 sc_col = 1;
9498 if (ru_col <= 0)
9499 ru_col = 1;
9500#else
9501 sc_col = Columns;
9502 ru_col = Columns;
9503#endif
9504}
9505
9506/*
9507 * Get pointer to option variable, depending on local or global scope.
9508 */
9509 static char_u *
9510get_varp_scope(p, opt_flags)
9511 struct vimoption *p;
9512 int opt_flags;
9513{
9514 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9515 {
9516 if (p->var == VAR_WIN)
9517 return (char_u *)GLOBAL_WO(get_varp(p));
9518 return p->var;
9519 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009520 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009521 {
9522 switch ((int)p->indir)
9523 {
9524#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009525 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9526 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9527 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009528#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009529 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9530 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9531 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009532 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009533 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009534#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009535 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9536 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537#endif
9538#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009539 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9540 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009541#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009542#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9543 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9544#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009545#if defined(FEAT_CRYPT)
9546 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9547#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009548#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009549 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551 }
9552 return NULL; /* "cannot happen" */
9553 }
9554 return get_varp(p);
9555}
9556
9557/*
9558 * Get pointer to option variable.
9559 */
9560 static char_u *
9561get_varp(p)
9562 struct vimoption *p;
9563{
9564 /* hidden option, always return NULL */
9565 if (p->var == NULL)
9566 return NULL;
9567
9568 switch ((int)p->indir)
9569 {
9570 case PV_NONE: return p->var;
9571
9572 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009573 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009574 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009575 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009577 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009578 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009579 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009580 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009581 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9583#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009584 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009586 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9588#endif
9589#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009590 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009591 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009592 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009593 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9594#endif
9595#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009596 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009597 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009598 case PV_GP: return *curbuf->b_p_gp != NUL
9599 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9600 case PV_MP: return *curbuf->b_p_mp != NUL
9601 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009602#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009603#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9604 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9605 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9606#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009607#if defined(FEAT_CRYPT)
9608 case PV_CM: return *curbuf->b_p_cm != NUL
9609 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9610#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009611#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009612 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009613 ? (char_u *)&(curwin->w_p_stl) : p->var;
9614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009615
9616#ifdef FEAT_ARABIC
9617 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9618#endif
9619 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009620#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009621 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9622#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009623#ifdef FEAT_SYN_HL
9624 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9625 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009626 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009628#ifdef FEAT_DIFF
9629 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9630#endif
9631#ifdef FEAT_FOLDING
9632 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9633 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9634 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9635 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9636 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9637 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9638 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9639# ifdef FEAT_EVAL
9640 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9641 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9642# endif
9643 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9644#endif
9645 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009646 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009647#ifdef FEAT_LINEBREAK
9648 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9649#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009650#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9652#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009653#ifdef FEAT_VERTSPLIT
9654 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9655#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9657 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9658#endif
9659#ifdef FEAT_RIGHTLEFT
9660 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9661 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9662#endif
9663 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9664 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9665#ifdef FEAT_LINEBREAK
9666 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9667#endif
9668#ifdef FEAT_SCROLLBIND
9669 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9670#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009671#ifdef FEAT_CURSORBIND
9672 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9673#endif
9674#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009675 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
9676 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +02009677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009678
9679 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9680 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9681#ifdef FEAT_MBYTE
9682 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9683#endif
9684#if defined(FEAT_QUICKFIX)
9685 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9686 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9687#endif
9688 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9689 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9690#ifdef FEAT_CINDENT
9691 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9692 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9693 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9694#endif
9695#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9696 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9697#endif
9698#ifdef FEAT_COMMENTS
9699 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9700#endif
9701#ifdef FEAT_FOLDING
9702 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9703#endif
9704#ifdef FEAT_INS_EXPAND
9705 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9706#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009707#ifdef FEAT_COMPL_FUNC
9708 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009709 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009711 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9712 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9713#ifdef FEAT_MBYTE
9714 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9715#endif
9716 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9717#ifdef FEAT_AUTOCMD
9718 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9719#endif
9720 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009721 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009722 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9723 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9724 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9725 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9726#ifdef FEAT_FIND_ID
9727# ifdef FEAT_EVAL
9728 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9729# endif
9730#endif
9731#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9732 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9733 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9734#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009735#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009736 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9737#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738#ifdef FEAT_CRYPT
9739 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9740#endif
9741#ifdef FEAT_LISP
9742 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9743#endif
9744 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9745 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9746 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9747 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9748 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009750#ifdef FEAT_TEXTOBJ
9751 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9752#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009753 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9754#ifdef FEAT_SMARTINDENT
9755 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9756#endif
9757#ifndef SHORT_FNAME
9758 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9759#endif
9760 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9761#ifdef FEAT_SEARCHPATH
9762 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9763#endif
9764 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9765#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009766 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009767 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9768#endif
9769#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009770 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9771 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9772 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009773#endif
9774 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9775 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9776 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9777 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009778#ifdef FEAT_PERSISTENT_UNDO
9779 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9780#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009781 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9782#ifdef FEAT_KEYMAP
9783 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9784#endif
9785 default: EMSG(_("E356: get_varp ERROR"));
9786 }
9787 /* always return a valid pointer to avoid a crash! */
9788 return (char_u *)&(curbuf->b_p_wm);
9789}
9790
9791/*
9792 * Get the value of 'equalprg', either the buffer-local one or the global one.
9793 */
9794 char_u *
9795get_equalprg()
9796{
9797 if (*curbuf->b_p_ep == NUL)
9798 return p_ep;
9799 return curbuf->b_p_ep;
9800}
9801
9802#if defined(FEAT_WINDOWS) || defined(PROTO)
9803/*
9804 * Copy options from one window to another.
9805 * Used when splitting a window.
9806 */
9807 void
9808win_copy_options(wp_from, wp_to)
9809 win_T *wp_from;
9810 win_T *wp_to;
9811{
9812 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9813 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9814# ifdef FEAT_RIGHTLEFT
9815# ifdef FEAT_FKMAP
9816 /* Is this right? */
9817 wp_to->w_farsi = wp_from->w_farsi;
9818# endif
9819# endif
9820}
9821#endif
9822
9823/*
9824 * Copy the options from one winopt_T to another.
9825 * Doesn't free the old option values in "to", use clear_winopt() for that.
9826 * The 'scroll' option is not copied, because it depends on the window height.
9827 * The 'previewwindow' option is reset, there can be only one preview window.
9828 */
9829 void
9830copy_winopt(from, to)
9831 winopt_T *from;
9832 winopt_T *to;
9833{
9834#ifdef FEAT_ARABIC
9835 to->wo_arab = from->wo_arab;
9836#endif
9837 to->wo_list = from->wo_list;
9838 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009839 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009840#ifdef FEAT_LINEBREAK
9841 to->wo_nuw = from->wo_nuw;
9842#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009843#ifdef FEAT_RIGHTLEFT
9844 to->wo_rl = from->wo_rl;
9845 to->wo_rlc = vim_strsave(from->wo_rlc);
9846#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009847#ifdef FEAT_STL_OPT
9848 to->wo_stl = vim_strsave(from->wo_stl);
9849#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009850 to->wo_wrap = from->wo_wrap;
9851#ifdef FEAT_LINEBREAK
9852 to->wo_lbr = from->wo_lbr;
9853#endif
9854#ifdef FEAT_SCROLLBIND
9855 to->wo_scb = from->wo_scb;
9856#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +01009857#ifdef FEAT_CURSORBIND
9858 to->wo_crb = from->wo_crb;
9859#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009860#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009861 to->wo_spell = from->wo_spell;
9862#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009863#ifdef FEAT_SYN_HL
9864 to->wo_cuc = from->wo_cuc;
9865 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +02009866 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009867#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009868#ifdef FEAT_DIFF
9869 to->wo_diff = from->wo_diff;
9870#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009871#ifdef FEAT_CONCEAL
9872 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +02009873 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009874#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009875#ifdef FEAT_FOLDING
9876 to->wo_fdc = from->wo_fdc;
9877 to->wo_fen = from->wo_fen;
9878 to->wo_fdi = vim_strsave(from->wo_fdi);
9879 to->wo_fml = from->wo_fml;
9880 to->wo_fdl = from->wo_fdl;
9881 to->wo_fdm = vim_strsave(from->wo_fdm);
9882 to->wo_fdn = from->wo_fdn;
9883# ifdef FEAT_EVAL
9884 to->wo_fde = vim_strsave(from->wo_fde);
9885 to->wo_fdt = vim_strsave(from->wo_fdt);
9886# endif
9887 to->wo_fmr = vim_strsave(from->wo_fmr);
9888#endif
9889 check_winopt(to); /* don't want NULL pointers */
9890}
9891
9892/*
9893 * Check string options in a window for a NULL value.
9894 */
9895 void
9896check_win_options(win)
9897 win_T *win;
9898{
9899 check_winopt(&win->w_onebuf_opt);
9900 check_winopt(&win->w_allbuf_opt);
9901}
9902
9903/*
9904 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9905 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009906 void
9907check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009908 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909{
9910#ifdef FEAT_FOLDING
9911 check_string_option(&wop->wo_fdi);
9912 check_string_option(&wop->wo_fdm);
9913# ifdef FEAT_EVAL
9914 check_string_option(&wop->wo_fde);
9915 check_string_option(&wop->wo_fdt);
9916# endif
9917 check_string_option(&wop->wo_fmr);
9918#endif
9919#ifdef FEAT_RIGHTLEFT
9920 check_string_option(&wop->wo_rlc);
9921#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009922#ifdef FEAT_STL_OPT
9923 check_string_option(&wop->wo_stl);
9924#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009925#ifdef FEAT_SYN_HL
9926 check_string_option(&wop->wo_cc);
9927#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009928#ifdef FEAT_CONCEAL
9929 check_string_option(&wop->wo_cocu);
9930#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931}
9932
9933/*
9934 * Free the allocated memory inside a winopt_T.
9935 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009936 void
9937clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009938 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009939{
9940#ifdef FEAT_FOLDING
9941 clear_string_option(&wop->wo_fdi);
9942 clear_string_option(&wop->wo_fdm);
9943# ifdef FEAT_EVAL
9944 clear_string_option(&wop->wo_fde);
9945 clear_string_option(&wop->wo_fdt);
9946# endif
9947 clear_string_option(&wop->wo_fmr);
9948#endif
9949#ifdef FEAT_RIGHTLEFT
9950 clear_string_option(&wop->wo_rlc);
9951#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009952#ifdef FEAT_STL_OPT
9953 clear_string_option(&wop->wo_stl);
9954#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009955#ifdef FEAT_SYN_HL
9956 clear_string_option(&wop->wo_cc);
9957#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009958#ifdef FEAT_CONCEAL
9959 clear_string_option(&wop->wo_cocu);
9960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961}
9962
9963/*
9964 * Copy global option values to local options for one buffer.
9965 * Used when creating a new buffer and sometimes when entering a buffer.
9966 * flags:
9967 * BCO_ENTER We will enter the buf buffer.
9968 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9969 * appropriate.
9970 * BCO_NOHELP Don't copy the values to a help buffer.
9971 */
9972 void
9973buf_copy_options(buf, flags)
9974 buf_T *buf;
9975 int flags;
9976{
9977 int should_copy = TRUE;
9978 char_u *save_p_isk = NULL; /* init for GCC */
9979 int dont_do_help;
9980 int did_isk = FALSE;
9981
9982 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +02009983 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984 */
9985 if (buf == NULL || !buf_valid(buf))
9986 return;
9987
9988 /*
9989 * Skip this when the option defaults have not been set yet. Happens when
9990 * main() allocates the first buffer.
9991 */
9992 if (p_cpo != NULL)
9993 {
9994 /*
9995 * Always copy when entering and 'cpo' contains 'S'.
9996 * Don't copy when already initialized.
9997 * Don't copy when 'cpo' contains 's' and not entering.
9998 * 'S' BCO_ENTER initialized 's' should_copy
9999 * yes yes X X TRUE
10000 * yes no yes X FALSE
10001 * no X yes X FALSE
10002 * X no no yes FALSE
10003 * X no no no TRUE
10004 * no yes no X TRUE
10005 */
10006 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10007 && (buf->b_p_initialized
10008 || (!(flags & BCO_ENTER)
10009 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10010 should_copy = FALSE;
10011
10012 if (should_copy || (flags & BCO_ALWAYS))
10013 {
10014 /* Don't copy the options specific to a help buffer when
10015 * BCO_NOHELP is given or the options were initialized already
10016 * (jumping back to a help file with CTRL-T or CTRL-O) */
10017 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10018 || buf->b_p_initialized;
10019 if (dont_do_help) /* don't free b_p_isk */
10020 {
10021 save_p_isk = buf->b_p_isk;
10022 buf->b_p_isk = NULL;
10023 }
10024 /*
10025 * Always free the allocated strings.
10026 * If not already initialized, set 'readonly' and copy 'fileformat'.
10027 */
10028 if (!buf->b_p_initialized)
10029 {
10030 free_buf_options(buf, TRUE);
10031 buf->b_p_ro = FALSE; /* don't copy readonly */
10032 buf->b_p_tx = p_tx;
10033#ifdef FEAT_MBYTE
10034 buf->b_p_fenc = vim_strsave(p_fenc);
10035#endif
10036 buf->b_p_ff = vim_strsave(p_ff);
10037#if defined(FEAT_QUICKFIX)
10038 buf->b_p_bh = empty_option;
10039 buf->b_p_bt = empty_option;
10040#endif
10041 }
10042 else
10043 free_buf_options(buf, FALSE);
10044
10045 buf->b_p_ai = p_ai;
10046 buf->b_p_ai_nopaste = p_ai_nopaste;
10047 buf->b_p_sw = p_sw;
10048 buf->b_p_tw = p_tw;
10049 buf->b_p_tw_nopaste = p_tw_nopaste;
10050 buf->b_p_tw_nobin = p_tw_nobin;
10051 buf->b_p_wm = p_wm;
10052 buf->b_p_wm_nopaste = p_wm_nopaste;
10053 buf->b_p_wm_nobin = p_wm_nobin;
10054 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010055#ifdef FEAT_MBYTE
10056 buf->b_p_bomb = p_bomb;
10057#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010058 buf->b_p_et = p_et;
10059 buf->b_p_et_nobin = p_et_nobin;
10060 buf->b_p_ml = p_ml;
10061 buf->b_p_ml_nobin = p_ml_nobin;
10062 buf->b_p_inf = p_inf;
10063 buf->b_p_swf = p_swf;
10064#ifdef FEAT_INS_EXPAND
10065 buf->b_p_cpt = vim_strsave(p_cpt);
10066#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010067#ifdef FEAT_COMPL_FUNC
10068 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010069 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010071 buf->b_p_sts = p_sts;
10072 buf->b_p_sts_nopaste = p_sts_nopaste;
10073#ifndef SHORT_FNAME
10074 buf->b_p_sn = p_sn;
10075#endif
10076#ifdef FEAT_COMMENTS
10077 buf->b_p_com = vim_strsave(p_com);
10078#endif
10079#ifdef FEAT_FOLDING
10080 buf->b_p_cms = vim_strsave(p_cms);
10081#endif
10082 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010083 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010084 buf->b_p_nf = vim_strsave(p_nf);
10085 buf->b_p_mps = vim_strsave(p_mps);
10086#ifdef FEAT_SMARTINDENT
10087 buf->b_p_si = p_si;
10088#endif
10089 buf->b_p_ci = p_ci;
10090#ifdef FEAT_CINDENT
10091 buf->b_p_cin = p_cin;
10092 buf->b_p_cink = vim_strsave(p_cink);
10093 buf->b_p_cino = vim_strsave(p_cino);
10094#endif
10095#ifdef FEAT_AUTOCMD
10096 /* Don't copy 'filetype', it must be detected */
10097 buf->b_p_ft = empty_option;
10098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099 buf->b_p_pi = p_pi;
10100#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10101 buf->b_p_cinw = vim_strsave(p_cinw);
10102#endif
10103#ifdef FEAT_LISP
10104 buf->b_p_lisp = p_lisp;
10105#endif
10106#ifdef FEAT_SYN_HL
10107 /* Don't copy 'syntax', it must be set */
10108 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010109 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010110#endif
10111#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010112 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010113 (void)compile_cap_prog(&buf->b_s);
10114 buf->b_s.b_p_spf = vim_strsave(p_spf);
10115 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116#endif
10117#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10118 buf->b_p_inde = vim_strsave(p_inde);
10119 buf->b_p_indk = vim_strsave(p_indk);
10120#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010121#if defined(FEAT_EVAL)
10122 buf->b_p_fex = vim_strsave(p_fex);
10123#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124#ifdef FEAT_CRYPT
10125 buf->b_p_key = vim_strsave(p_key);
10126#endif
10127#ifdef FEAT_SEARCHPATH
10128 buf->b_p_sua = vim_strsave(p_sua);
10129#endif
10130#ifdef FEAT_KEYMAP
10131 buf->b_p_keymap = vim_strsave(p_keymap);
10132 buf->b_kmap_state |= KEYMAP_INIT;
10133#endif
10134 /* This isn't really an option, but copying the langmap and IME
10135 * state from the current buffer is better than resetting it. */
10136 buf->b_p_iminsert = p_iminsert;
10137 buf->b_p_imsearch = p_imsearch;
10138
10139 /* options that are normally global but also have a local value
10140 * are not copied, start using the global value */
10141 buf->b_p_ar = -1;
10142#ifdef FEAT_QUICKFIX
10143 buf->b_p_gp = empty_option;
10144 buf->b_p_mp = empty_option;
10145 buf->b_p_efm = empty_option;
10146#endif
10147 buf->b_p_ep = empty_option;
10148 buf->b_p_kp = empty_option;
10149 buf->b_p_path = empty_option;
10150 buf->b_p_tags = empty_option;
10151#ifdef FEAT_FIND_ID
10152 buf->b_p_def = empty_option;
10153 buf->b_p_inc = empty_option;
10154# ifdef FEAT_EVAL
10155 buf->b_p_inex = vim_strsave(p_inex);
10156# endif
10157#endif
10158#ifdef FEAT_INS_EXPAND
10159 buf->b_p_dict = empty_option;
10160 buf->b_p_tsr = empty_option;
10161#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010162#ifdef FEAT_TEXTOBJ
10163 buf->b_p_qe = vim_strsave(p_qe);
10164#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010165#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10166 buf->b_p_bexpr = empty_option;
10167#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010168#if defined(FEAT_CRYPT)
10169 buf->b_p_cm = empty_option;
10170#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010171#ifdef FEAT_PERSISTENT_UNDO
10172 buf->b_p_udf = p_udf;
10173#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174
10175 /*
10176 * Don't copy the options set by ex_help(), use the saved values,
10177 * when going from a help buffer to a non-help buffer.
10178 * Don't touch these at all when BCO_NOHELP is used and going from
10179 * or to a help buffer.
10180 */
10181 if (dont_do_help)
10182 buf->b_p_isk = save_p_isk;
10183 else
10184 {
10185 buf->b_p_isk = vim_strsave(p_isk);
10186 did_isk = TRUE;
10187 buf->b_p_ts = p_ts;
10188 buf->b_help = FALSE;
10189#ifdef FEAT_QUICKFIX
10190 if (buf->b_p_bt[0] == 'h')
10191 clear_string_option(&buf->b_p_bt);
10192#endif
10193 buf->b_p_ma = p_ma;
10194 }
10195 }
10196
10197 /*
10198 * When the options should be copied (ignoring BCO_ALWAYS), set the
10199 * flag that indicates that the options have been initialized.
10200 */
10201 if (should_copy)
10202 buf->b_p_initialized = TRUE;
10203 }
10204
10205 check_buf_options(buf); /* make sure we don't have NULLs */
10206 if (did_isk)
10207 (void)buf_init_chartab(buf, FALSE);
10208}
10209
10210/*
10211 * Reset the 'modifiable' option and its default value.
10212 */
10213 void
10214reset_modifiable()
10215{
10216 int opt_idx;
10217
10218 curbuf->b_p_ma = FALSE;
10219 p_ma = FALSE;
10220 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010221 if (opt_idx >= 0)
10222 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010223}
10224
10225/*
10226 * Set the global value for 'iminsert' to the local value.
10227 */
10228 void
10229set_iminsert_global()
10230{
10231 p_iminsert = curbuf->b_p_iminsert;
10232}
10233
10234/*
10235 * Set the global value for 'imsearch' to the local value.
10236 */
10237 void
10238set_imsearch_global()
10239{
10240 p_imsearch = curbuf->b_p_imsearch;
10241}
10242
10243#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10244static int expand_option_idx = -1;
10245static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10246static int expand_option_flags = 0;
10247
10248 void
10249set_context_in_set_cmd(xp, arg, opt_flags)
10250 expand_T *xp;
10251 char_u *arg;
10252 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10253{
10254 int nextchar;
10255 long_u flags = 0; /* init for GCC */
10256 int opt_idx = 0; /* init for GCC */
10257 char_u *p;
10258 char_u *s;
10259 int is_term_option = FALSE;
10260 int key;
10261
10262 expand_option_flags = opt_flags;
10263
10264 xp->xp_context = EXPAND_SETTINGS;
10265 if (*arg == NUL)
10266 {
10267 xp->xp_pattern = arg;
10268 return;
10269 }
10270 p = arg + STRLEN(arg) - 1;
10271 if (*p == ' ' && *(p - 1) != '\\')
10272 {
10273 xp->xp_pattern = p + 1;
10274 return;
10275 }
10276 while (p > arg)
10277 {
10278 s = p;
10279 /* count number of backslashes before ' ' or ',' */
10280 if (*p == ' ' || *p == ',')
10281 {
10282 while (s > arg && *(s - 1) == '\\')
10283 --s;
10284 }
10285 /* break at a space with an even number of backslashes */
10286 if (*p == ' ' && ((p - s) & 1) == 0)
10287 {
10288 ++p;
10289 break;
10290 }
10291 --p;
10292 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010293 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294 {
10295 xp->xp_context = EXPAND_BOOL_SETTINGS;
10296 p += 2;
10297 }
10298 if (STRNCMP(p, "inv", 3) == 0)
10299 {
10300 xp->xp_context = EXPAND_BOOL_SETTINGS;
10301 p += 3;
10302 }
10303 xp->xp_pattern = arg = p;
10304 if (*arg == '<')
10305 {
10306 while (*p != '>')
10307 if (*p++ == NUL) /* expand terminal option name */
10308 return;
10309 key = get_special_key_code(arg + 1);
10310 if (key == 0) /* unknown name */
10311 {
10312 xp->xp_context = EXPAND_NOTHING;
10313 return;
10314 }
10315 nextchar = *++p;
10316 is_term_option = TRUE;
10317 expand_option_name[2] = KEY2TERMCAP0(key);
10318 expand_option_name[3] = KEY2TERMCAP1(key);
10319 }
10320 else
10321 {
10322 if (p[0] == 't' && p[1] == '_')
10323 {
10324 p += 2;
10325 if (*p != NUL)
10326 ++p;
10327 if (*p == NUL)
10328 return; /* expand option name */
10329 nextchar = *++p;
10330 is_term_option = TRUE;
10331 expand_option_name[2] = p[-2];
10332 expand_option_name[3] = p[-1];
10333 }
10334 else
10335 {
10336 /* Allow * wildcard */
10337 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10338 p++;
10339 if (*p == NUL)
10340 return;
10341 nextchar = *p;
10342 *p = NUL;
10343 opt_idx = findoption(arg);
10344 *p = nextchar;
10345 if (opt_idx == -1 || options[opt_idx].var == NULL)
10346 {
10347 xp->xp_context = EXPAND_NOTHING;
10348 return;
10349 }
10350 flags = options[opt_idx].flags;
10351 if (flags & P_BOOL)
10352 {
10353 xp->xp_context = EXPAND_NOTHING;
10354 return;
10355 }
10356 }
10357 }
10358 /* handle "-=" and "+=" */
10359 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10360 {
10361 ++p;
10362 nextchar = '=';
10363 }
10364 if ((nextchar != '=' && nextchar != ':')
10365 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10366 {
10367 xp->xp_context = EXPAND_UNSUCCESSFUL;
10368 return;
10369 }
10370 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10371 {
10372 xp->xp_context = EXPAND_OLD_SETTING;
10373 if (is_term_option)
10374 expand_option_idx = -1;
10375 else
10376 expand_option_idx = opt_idx;
10377 xp->xp_pattern = p + 1;
10378 return;
10379 }
10380 xp->xp_context = EXPAND_NOTHING;
10381 if (is_term_option || (flags & P_NUM))
10382 return;
10383
10384 xp->xp_pattern = p + 1;
10385
10386 if (flags & P_EXPAND)
10387 {
10388 p = options[opt_idx].var;
10389 if (p == (char_u *)&p_bdir
10390 || p == (char_u *)&p_dir
10391 || p == (char_u *)&p_path
10392 || p == (char_u *)&p_rtp
10393#ifdef FEAT_SEARCHPATH
10394 || p == (char_u *)&p_cdpath
10395#endif
10396#ifdef FEAT_SESSION
10397 || p == (char_u *)&p_vdir
10398#endif
10399 )
10400 {
10401 xp->xp_context = EXPAND_DIRECTORIES;
10402 if (p == (char_u *)&p_path
10403#ifdef FEAT_SEARCHPATH
10404 || p == (char_u *)&p_cdpath
10405#endif
10406 )
10407 xp->xp_backslash = XP_BS_THREE;
10408 else
10409 xp->xp_backslash = XP_BS_ONE;
10410 }
10411 else
10412 {
10413 xp->xp_context = EXPAND_FILES;
10414 /* for 'tags' need three backslashes for a space */
10415 if (p == (char_u *)&p_tags)
10416 xp->xp_backslash = XP_BS_THREE;
10417 else
10418 xp->xp_backslash = XP_BS_ONE;
10419 }
10420 }
10421
10422 /* For an option that is a list of file names, find the start of the
10423 * last file name. */
10424 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10425 {
10426 /* count number of backslashes before ' ' or ',' */
10427 if (*p == ' ' || *p == ',')
10428 {
10429 s = p;
10430 while (s > xp->xp_pattern && *(s - 1) == '\\')
10431 --s;
10432 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10433 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10434 {
10435 xp->xp_pattern = p + 1;
10436 break;
10437 }
10438 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010439
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010440#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010441 /* for 'spellsuggest' start at "file:" */
10442 if (options[opt_idx].var == (char_u *)&p_sps
10443 && STRNCMP(p, "file:", 5) == 0)
10444 {
10445 xp->xp_pattern = p + 5;
10446 break;
10447 }
10448#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010449 }
10450
10451 return;
10452}
10453
10454 int
10455ExpandSettings(xp, regmatch, num_file, file)
10456 expand_T *xp;
10457 regmatch_T *regmatch;
10458 int *num_file;
10459 char_u ***file;
10460{
10461 int num_normal = 0; /* Nr of matching non-term-code settings */
10462 int num_term = 0; /* Nr of matching terminal code settings */
10463 int opt_idx;
10464 int match;
10465 int count = 0;
10466 char_u *str;
10467 int loop;
10468 int is_term_opt;
10469 char_u name_buf[MAX_KEY_NAME_LEN];
10470 static char *(names[]) = {"all", "termcap"};
10471 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10472
10473 /* do this loop twice:
10474 * loop == 0: count the number of matching options
10475 * loop == 1: copy the matching options into allocated memory
10476 */
10477 for (loop = 0; loop <= 1; ++loop)
10478 {
10479 regmatch->rm_ic = ic;
10480 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10481 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010482 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10483 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10485 {
10486 if (loop == 0)
10487 num_normal++;
10488 else
10489 (*file)[count++] = vim_strsave((char_u *)names[match]);
10490 }
10491 }
10492 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10493 opt_idx++)
10494 {
10495 if (options[opt_idx].var == NULL)
10496 continue;
10497 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10498 && !(options[opt_idx].flags & P_BOOL))
10499 continue;
10500 is_term_opt = istermoption(&options[opt_idx]);
10501 if (is_term_opt && num_normal > 0)
10502 continue;
10503 match = FALSE;
10504 if (vim_regexec(regmatch, str, (colnr_T)0)
10505 || (options[opt_idx].shortname != NULL
10506 && vim_regexec(regmatch,
10507 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10508 match = TRUE;
10509 else if (is_term_opt)
10510 {
10511 name_buf[0] = '<';
10512 name_buf[1] = 't';
10513 name_buf[2] = '_';
10514 name_buf[3] = str[2];
10515 name_buf[4] = str[3];
10516 name_buf[5] = '>';
10517 name_buf[6] = NUL;
10518 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10519 {
10520 match = TRUE;
10521 str = name_buf;
10522 }
10523 }
10524 if (match)
10525 {
10526 if (loop == 0)
10527 {
10528 if (is_term_opt)
10529 num_term++;
10530 else
10531 num_normal++;
10532 }
10533 else
10534 (*file)[count++] = vim_strsave(str);
10535 }
10536 }
10537 /*
10538 * Check terminal key codes, these are not in the option table
10539 */
10540 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10541 {
10542 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10543 {
10544 if (!isprint(str[0]) || !isprint(str[1]))
10545 continue;
10546
10547 name_buf[0] = 't';
10548 name_buf[1] = '_';
10549 name_buf[2] = str[0];
10550 name_buf[3] = str[1];
10551 name_buf[4] = NUL;
10552
10553 match = FALSE;
10554 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10555 match = TRUE;
10556 else
10557 {
10558 name_buf[0] = '<';
10559 name_buf[1] = 't';
10560 name_buf[2] = '_';
10561 name_buf[3] = str[0];
10562 name_buf[4] = str[1];
10563 name_buf[5] = '>';
10564 name_buf[6] = NUL;
10565
10566 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10567 match = TRUE;
10568 }
10569 if (match)
10570 {
10571 if (loop == 0)
10572 num_term++;
10573 else
10574 (*file)[count++] = vim_strsave(name_buf);
10575 }
10576 }
10577
10578 /*
10579 * Check special key names.
10580 */
10581 regmatch->rm_ic = TRUE; /* ignore case here */
10582 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10583 {
10584 name_buf[0] = '<';
10585 STRCPY(name_buf + 1, str);
10586 STRCAT(name_buf, ">");
10587
10588 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10589 {
10590 if (loop == 0)
10591 num_term++;
10592 else
10593 (*file)[count++] = vim_strsave(name_buf);
10594 }
10595 }
10596 }
10597 if (loop == 0)
10598 {
10599 if (num_normal > 0)
10600 *num_file = num_normal;
10601 else if (num_term > 0)
10602 *num_file = num_term;
10603 else
10604 return OK;
10605 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10606 if (*file == NULL)
10607 {
10608 *file = (char_u **)"";
10609 return FAIL;
10610 }
10611 }
10612 }
10613 return OK;
10614}
10615
10616 int
10617ExpandOldSetting(num_file, file)
10618 int *num_file;
10619 char_u ***file;
10620{
10621 char_u *var = NULL; /* init for GCC */
10622 char_u *buf;
10623
10624 *num_file = 0;
10625 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10626 if (*file == NULL)
10627 return FAIL;
10628
10629 /*
10630 * For a terminal key code expand_option_idx is < 0.
10631 */
10632 if (expand_option_idx < 0)
10633 {
10634 var = find_termcode(expand_option_name + 2);
10635 if (var == NULL)
10636 expand_option_idx = findoption(expand_option_name);
10637 }
10638
10639 if (expand_option_idx >= 0)
10640 {
10641 /* put string of option value in NameBuff */
10642 option_value2string(&options[expand_option_idx], expand_option_flags);
10643 var = NameBuff;
10644 }
10645 else if (var == NULL)
10646 var = (char_u *)"";
10647
10648 /* A backslash is required before some characters. This is the reverse of
10649 * what happens in do_set(). */
10650 buf = vim_strsave_escaped(var, escape_chars);
10651
10652 if (buf == NULL)
10653 {
10654 vim_free(*file);
10655 *file = NULL;
10656 return FAIL;
10657 }
10658
10659#ifdef BACKSLASH_IN_FILENAME
10660 /* For MS-Windows et al. we don't double backslashes at the start and
10661 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010662 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663 if (var[0] == '\\' && var[1] == '\\'
10664 && expand_option_idx >= 0
10665 && (options[expand_option_idx].flags & P_EXPAND)
10666 && vim_isfilec(var[2])
10667 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010668 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010669#endif
10670
10671 *file[0] = buf;
10672 *num_file = 1;
10673 return OK;
10674}
10675#endif
10676
10677/*
10678 * Get the value for the numeric or string option *opp in a nice format into
10679 * NameBuff[]. Must not be called with a hidden option!
10680 */
10681 static void
10682option_value2string(opp, opt_flags)
10683 struct vimoption *opp;
10684 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10685{
10686 char_u *varp;
10687
10688 varp = get_varp_scope(opp, opt_flags);
10689
10690 if (opp->flags & P_NUM)
10691 {
10692 long wc = 0;
10693
10694 if (wc_use_keyname(varp, &wc))
10695 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10696 else if (wc != 0)
10697 STRCPY(NameBuff, transchar((int)wc));
10698 else
10699 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10700 }
10701 else /* P_STRING */
10702 {
10703 varp = *(char_u **)(varp);
10704 if (varp == NULL) /* just in case */
10705 NameBuff[0] = NUL;
10706#ifdef FEAT_CRYPT
10707 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010708 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 STRCPY(NameBuff, "*****");
10710#endif
10711 else if (opp->flags & P_EXPAND)
10712 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10713 /* Translate 'pastetoggle' into special key names */
10714 else if ((char_u **)opp->var == &p_pt)
10715 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10716 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010717 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 }
10719}
10720
10721/*
10722 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10723 * printed as a keyname.
10724 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10725 */
10726 static int
10727wc_use_keyname(varp, wcp)
10728 char_u *varp;
10729 long *wcp;
10730{
10731 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10732 {
10733 *wcp = *(long *)varp;
10734 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10735 return TRUE;
10736 }
10737 return FALSE;
10738}
10739
10740#ifdef FEAT_LANGMAP
10741/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010742 * Any character has an equivalent 'langmap' character. This is used for
10743 * keyboards that have a special language mode that sends characters above
10744 * 128 (although other characters can be translated too). The "to" field is a
10745 * Vim command character. This avoids having to switch the keyboard back to
10746 * ASCII mode when leaving Insert mode.
10747 *
10748 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10749 * commands.
10750 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10751 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10752 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010754# ifdef FEAT_MBYTE
10755/*
10756 * With multi-byte support use growarray for 'langmap' chars >= 256
10757 */
10758typedef struct
10759{
10760 int from;
10761 int to;
10762} langmap_entry_T;
10763
10764static garray_T langmap_mapga;
10765static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766
10767/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010768 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10769 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010771 static void
10772langmap_set_entry(from, to)
10773 int from;
10774 int to;
10775{
10776 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020010777 int a = 0;
10778 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010779
10780 /* Do a binary search for an existing entry. */
10781 while (a != b)
10782 {
10783 int i = (a + b) / 2;
10784 int d = entries[i].from - from;
10785
10786 if (d == 0)
10787 {
10788 entries[i].to = to;
10789 return;
10790 }
10791 if (d < 0)
10792 a = i + 1;
10793 else
10794 b = i;
10795 }
10796
10797 if (ga_grow(&langmap_mapga, 1) != OK)
10798 return; /* out of memory */
10799
10800 /* insert new entry at position "a" */
10801 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10802 mch_memmove(entries + 1, entries,
10803 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10804 ++langmap_mapga.ga_len;
10805 entries[0].from = from;
10806 entries[0].to = to;
10807}
10808
10809/*
10810 * Apply 'langmap' to multi-byte character "c" and return the result.
10811 */
10812 int
10813langmap_adjust_mb(c)
10814 int c;
10815{
10816 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10817 int a = 0;
10818 int b = langmap_mapga.ga_len;
10819
10820 while (a != b)
10821 {
10822 int i = (a + b) / 2;
10823 int d = entries[i].from - c;
10824
10825 if (d == 0)
10826 return entries[i].to; /* found matching entry */
10827 if (d < 0)
10828 a = i + 1;
10829 else
10830 b = i;
10831 }
10832 return c; /* no entry found, return "c" unmodified */
10833}
10834# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835
10836 static void
10837langmap_init()
10838{
10839 int i;
10840
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010841 for (i = 0; i < 256; i++)
10842 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10843# ifdef FEAT_MBYTE
10844 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10845# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846}
10847
10848/*
10849 * Called when langmap option is set; the language map can be
10850 * changed at any time!
10851 */
10852 static void
10853langmap_set()
10854{
10855 char_u *p;
10856 char_u *p2;
10857 int from, to;
10858
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010859#ifdef FEAT_MBYTE
10860 ga_clear(&langmap_mapga); /* clear the previous map first */
10861#endif
10862 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863
10864 for (p = p_langmap; p[0] != NUL; )
10865 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010866 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10867 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010868 {
10869 if (p2[0] == '\\' && p2[1] != NUL)
10870 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871 }
10872 if (p2[0] == ';')
10873 ++p2; /* abcd;ABCD form, p2 points to A */
10874 else
10875 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10876 while (p[0])
10877 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010878 if (p[0] == ',')
10879 {
10880 ++p;
10881 break;
10882 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883 if (p[0] == '\\' && p[1] != NUL)
10884 ++p;
10885#ifdef FEAT_MBYTE
10886 from = (*mb_ptr2char)(p);
10887#else
10888 from = p[0];
10889#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010890 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891 if (p2 == NULL)
10892 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010893 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010894 if (p[0] != ',')
10895 {
10896 if (p[0] == '\\')
10897 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010898#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010899 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010901 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010903 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904 }
10905 else
10906 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010907 if (p2[0] != ',')
10908 {
10909 if (p2[0] == '\\')
10910 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010911#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010912 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010914 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010915#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010916 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010917 }
10918 if (to == NUL)
10919 {
10920 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10921 transchar(from));
10922 return;
10923 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010924
10925#ifdef FEAT_MBYTE
10926 if (from >= 256)
10927 langmap_set_entry(from, to);
10928 else
10929#endif
10930 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931
10932 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010933 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010934 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010936 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010937 if (*p == ';')
10938 {
10939 p = p2;
10940 if (p[0] != NUL)
10941 {
10942 if (p[0] != ',')
10943 {
10944 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10945 return;
10946 }
10947 ++p;
10948 }
10949 break;
10950 }
10951 }
10952 }
10953 }
10954}
10955#endif
10956
10957/*
10958 * Return TRUE if format option 'x' is in effect.
10959 * Take care of no formatting when 'paste' is set.
10960 */
10961 int
10962has_format_option(x)
10963 int x;
10964{
10965 if (p_paste)
10966 return FALSE;
10967 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10968}
10969
10970/*
10971 * Return TRUE if "x" is present in 'shortmess' option, or
10972 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10973 */
10974 int
10975shortmess(x)
10976 int x;
10977{
10978 return ( vim_strchr(p_shm, x) != NULL
10979 || (vim_strchr(p_shm, 'a') != NULL
10980 && vim_strchr((char_u *)SHM_A, x) != NULL));
10981}
10982
10983/*
10984 * paste_option_changed() - Called after p_paste was set or reset.
10985 */
10986 static void
10987paste_option_changed()
10988{
10989 static int old_p_paste = FALSE;
10990 static int save_sm = 0;
10991#ifdef FEAT_CMDL_INFO
10992 static int save_ru = 0;
10993#endif
10994#ifdef FEAT_RIGHTLEFT
10995 static int save_ri = 0;
10996 static int save_hkmap = 0;
10997#endif
10998 buf_T *buf;
10999
11000 if (p_paste)
11001 {
11002 /*
11003 * Paste switched from off to on.
11004 * Save the current values, so they can be restored later.
11005 */
11006 if (!old_p_paste)
11007 {
11008 /* save options for each buffer */
11009 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11010 {
11011 buf->b_p_tw_nopaste = buf->b_p_tw;
11012 buf->b_p_wm_nopaste = buf->b_p_wm;
11013 buf->b_p_sts_nopaste = buf->b_p_sts;
11014 buf->b_p_ai_nopaste = buf->b_p_ai;
11015 }
11016
11017 /* save global options */
11018 save_sm = p_sm;
11019#ifdef FEAT_CMDL_INFO
11020 save_ru = p_ru;
11021#endif
11022#ifdef FEAT_RIGHTLEFT
11023 save_ri = p_ri;
11024 save_hkmap = p_hkmap;
11025#endif
11026 /* save global values for local buffer options */
11027 p_tw_nopaste = p_tw;
11028 p_wm_nopaste = p_wm;
11029 p_sts_nopaste = p_sts;
11030 p_ai_nopaste = p_ai;
11031 }
11032
11033 /*
11034 * Always set the option values, also when 'paste' is set when it is
11035 * already on.
11036 */
11037 /* set options for each buffer */
11038 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11039 {
11040 buf->b_p_tw = 0; /* textwidth is 0 */
11041 buf->b_p_wm = 0; /* wrapmargin is 0 */
11042 buf->b_p_sts = 0; /* softtabstop is 0 */
11043 buf->b_p_ai = 0; /* no auto-indent */
11044 }
11045
11046 /* set global options */
11047 p_sm = 0; /* no showmatch */
11048#ifdef FEAT_CMDL_INFO
11049# ifdef FEAT_WINDOWS
11050 if (p_ru)
11051 status_redraw_all(); /* redraw to remove the ruler */
11052# endif
11053 p_ru = 0; /* no ruler */
11054#endif
11055#ifdef FEAT_RIGHTLEFT
11056 p_ri = 0; /* no reverse insert */
11057 p_hkmap = 0; /* no Hebrew keyboard */
11058#endif
11059 /* set global values for local buffer options */
11060 p_tw = 0;
11061 p_wm = 0;
11062 p_sts = 0;
11063 p_ai = 0;
11064 }
11065
11066 /*
11067 * Paste switched from on to off: Restore saved values.
11068 */
11069 else if (old_p_paste)
11070 {
11071 /* restore options for each buffer */
11072 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11073 {
11074 buf->b_p_tw = buf->b_p_tw_nopaste;
11075 buf->b_p_wm = buf->b_p_wm_nopaste;
11076 buf->b_p_sts = buf->b_p_sts_nopaste;
11077 buf->b_p_ai = buf->b_p_ai_nopaste;
11078 }
11079
11080 /* restore global options */
11081 p_sm = save_sm;
11082#ifdef FEAT_CMDL_INFO
11083# ifdef FEAT_WINDOWS
11084 if (p_ru != save_ru)
11085 status_redraw_all(); /* redraw to draw the ruler */
11086# endif
11087 p_ru = save_ru;
11088#endif
11089#ifdef FEAT_RIGHTLEFT
11090 p_ri = save_ri;
11091 p_hkmap = save_hkmap;
11092#endif
11093 /* set global values for local buffer options */
11094 p_tw = p_tw_nopaste;
11095 p_wm = p_wm_nopaste;
11096 p_sts = p_sts_nopaste;
11097 p_ai = p_ai_nopaste;
11098 }
11099
11100 old_p_paste = p_paste;
11101}
11102
11103/*
11104 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11105 *
11106 * Reset 'compatible' and set the values for options that didn't get set yet
11107 * to the Vim defaults.
11108 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011109 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011110 */
11111 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011112vimrc_found(fname, envname)
11113 char_u *fname;
11114 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011116 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011117 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011118 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011119
11120 if (!option_was_set((char_u *)"cp"))
11121 {
11122 p_cp = FALSE;
11123 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11124 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11125 set_option_default(opt_idx, OPT_FREE, FALSE);
11126 didset_options();
11127 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011128
11129 if (fname != NULL)
11130 {
11131 p = vim_getenv(envname, &dofree);
11132 if (p == NULL)
11133 {
11134 /* Set $MYVIMRC to the first vimrc file found. */
11135 p = FullName_save(fname, FALSE);
11136 if (p != NULL)
11137 {
11138 vim_setenv(envname, p);
11139 vim_free(p);
11140 }
11141 }
11142 else if (dofree)
11143 vim_free(p);
11144 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145}
11146
11147/*
11148 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11149 */
11150 void
11151change_compatible(on)
11152 int on;
11153{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011154 int opt_idx;
11155
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156 if (p_cp != on)
11157 {
11158 p_cp = on;
11159 compatible_set();
11160 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011161 opt_idx = findoption((char_u *)"cp");
11162 if (opt_idx >= 0)
11163 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164}
11165
11166/*
11167 * Return TRUE when option "name" has been set.
11168 */
11169 int
11170option_was_set(name)
11171 char_u *name;
11172{
11173 int idx;
11174
11175 idx = findoption(name);
11176 if (idx < 0) /* unknown option */
11177 return FALSE;
11178 if (options[idx].flags & P_WAS_SET)
11179 return TRUE;
11180 return FALSE;
11181}
11182
11183/*
11184 * compatible_set() - Called when 'compatible' has been set or unset.
11185 *
11186 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11187 * flag) to a Vi compatible value.
11188 * When 'compatible' is unset: Set all options that have a different default
11189 * for Vim (without the P_VI_DEF flag) to that default.
11190 */
11191 static void
11192compatible_set()
11193{
11194 int opt_idx;
11195
11196 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11197 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11198 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11199 set_option_default(opt_idx, OPT_FREE, p_cp);
11200 didset_options();
11201}
11202
11203#ifdef FEAT_LINEBREAK
11204
11205# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11206 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011207 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208# endif
11209
11210/*
11211 * fill_breakat_flags() -- called when 'breakat' changes value.
11212 */
11213 static void
11214fill_breakat_flags()
11215{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011216 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217 int i;
11218
11219 for (i = 0; i < 256; i++)
11220 breakat_flags[i] = FALSE;
11221
11222 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011223 for (p = p_breakat; *p; p++)
11224 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225}
11226
11227# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011228 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229# endif
11230
11231#endif
11232
11233/*
11234 * Check an option that can be a range of string values.
11235 *
11236 * Return OK for correct value, FAIL otherwise.
11237 * Empty is always OK.
11238 */
11239 static int
11240check_opt_strings(val, values, list)
11241 char_u *val;
11242 char **values;
11243 int list; /* when TRUE: accept a list of values */
11244{
11245 return opt_strings_flags(val, values, NULL, list);
11246}
11247
11248/*
11249 * Handle an option that can be a range of string values.
11250 * Set a flag in "*flagp" for each string present.
11251 *
11252 * Return OK for correct value, FAIL otherwise.
11253 * Empty is always OK.
11254 */
11255 static int
11256opt_strings_flags(val, values, flagp, list)
11257 char_u *val; /* new value */
11258 char **values; /* array of valid string values */
11259 unsigned *flagp;
11260 int list; /* when TRUE: accept a list of values */
11261{
11262 int i;
11263 int len;
11264 unsigned new_flags = 0;
11265
11266 while (*val)
11267 {
11268 for (i = 0; ; ++i)
11269 {
11270 if (values[i] == NULL) /* val not found in values[] */
11271 return FAIL;
11272
11273 len = (int)STRLEN(values[i]);
11274 if (STRNCMP(values[i], val, len) == 0
11275 && ((list && val[len] == ',') || val[len] == NUL))
11276 {
11277 val += len + (val[len] == ',');
11278 new_flags |= (1 << i);
11279 break; /* check next item in val list */
11280 }
11281 }
11282 }
11283 if (flagp != NULL)
11284 *flagp = new_flags;
11285
11286 return OK;
11287}
11288
11289/*
11290 * Read the 'wildmode' option, fill wim_flags[].
11291 */
11292 static int
11293check_opt_wim()
11294{
11295 char_u new_wim_flags[4];
11296 char_u *p;
11297 int i;
11298 int idx = 0;
11299
11300 for (i = 0; i < 4; ++i)
11301 new_wim_flags[i] = 0;
11302
11303 for (p = p_wim; *p; ++p)
11304 {
11305 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11306 ;
11307 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11308 return FAIL;
11309 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11310 new_wim_flags[idx] |= WIM_LONGEST;
11311 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11312 new_wim_flags[idx] |= WIM_FULL;
11313 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11314 new_wim_flags[idx] |= WIM_LIST;
11315 else
11316 return FAIL;
11317 p += i;
11318 if (*p == NUL)
11319 break;
11320 if (*p == ',')
11321 {
11322 if (idx == 3)
11323 return FAIL;
11324 ++idx;
11325 }
11326 }
11327
11328 /* fill remaining entries with last flag */
11329 while (idx < 3)
11330 {
11331 new_wim_flags[idx + 1] = new_wim_flags[idx];
11332 ++idx;
11333 }
11334
11335 /* only when there are no errors, wim_flags[] is changed */
11336 for (i = 0; i < 4; ++i)
11337 wim_flags[i] = new_wim_flags[i];
11338 return OK;
11339}
11340
11341/*
11342 * Check if backspacing over something is allowed.
11343 */
11344 int
11345can_bs(what)
11346 int what; /* BS_INDENT, BS_EOL or BS_START */
11347{
11348 switch (*p_bs)
11349 {
11350 case '2': return TRUE;
11351 case '1': return (what != BS_START);
11352 case '0': return FALSE;
11353 }
11354 return vim_strchr(p_bs, what) != NULL;
11355}
11356
11357/*
11358 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11359 * the file must be considered changed when the value is different.
11360 */
11361 void
11362save_file_ff(buf)
11363 buf_T *buf;
11364{
11365 buf->b_start_ffc = *buf->b_p_ff;
11366 buf->b_start_eol = buf->b_p_eol;
11367#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011368 buf->b_start_bomb = buf->b_p_bomb;
11369
Bram Moolenaar071d4272004-06-13 20:20:40 +000011370 /* Only use free/alloc when necessary, they take time. */
11371 if (buf->b_start_fenc == NULL
11372 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11373 {
11374 vim_free(buf->b_start_fenc);
11375 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11376 }
11377#endif
11378}
11379
11380/*
11381 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11382 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011383 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11384 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011385 * When "ignore_empty" is true don't consider a new, empty buffer to be
11386 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387 */
11388 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011389file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011390 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011391 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011392{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011393 /* In a buffer that was never loaded the options are not valid. */
11394 if (buf->b_flags & BF_NEVERLOADED)
11395 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011396 if (ignore_empty
11397 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011398 && buf->b_ml.ml_line_count == 1
11399 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11400 return FALSE;
11401 if (buf->b_start_ffc != *buf->b_p_ff)
11402 return TRUE;
11403 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11404 return TRUE;
11405#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011406 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11407 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408 if (buf->b_start_fenc == NULL)
11409 return (*buf->b_p_fenc != NUL);
11410 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11411#else
11412 return FALSE;
11413#endif
11414}
11415
11416/*
11417 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11418 */
11419 int
11420check_ff_value(p)
11421 char_u *p;
11422{
11423 return check_opt_strings(p, p_ff_values, FALSE);
11424}