blob: 67d0bc7067fada60731bf23cc07b2afc95f63182 [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 Moolenaar06ca5132012-03-23 16:25:17 +0100463# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000464#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100465# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000466#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 Moolenaarf66b3fc2012-02-20 22:18:30 +01002276 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2277 (char_u *)&p_sxe, PV_NONE,
2278 {
2279#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2280 (char_u *)"\"&|<>()@^",
2281#else
2282 (char_u *)"",
2283#endif
2284 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2286 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2289 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2292 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002293 {(char_u *)"", (char_u *)"filnxtToO"}
2294 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 {"shortname", "sn", P_BOOL|P_VI_DEF,
2296#ifdef SHORT_FNAME
2297 (char_u *)NULL, PV_NONE,
2298#else
2299 (char_u *)&p_sn, PV_SN,
2300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2303#ifdef FEAT_LINEBREAK
2304 (char_u *)&p_sbr, PV_NONE,
2305#else
2306 (char_u *)NULL, PV_NONE,
2307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"showcmd", "sc", P_BOOL|P_VIM,
2310#ifdef FEAT_CMDL_INFO
2311 (char_u *)&p_sc, PV_NONE,
2312#else
2313 (char_u *)NULL, PV_NONE,
2314#endif
2315 {(char_u *)FALSE,
2316#ifdef UNIX
2317 (char_u *)FALSE
2318#else
2319 (char_u *)TRUE
2320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2323 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2326 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 {"showmode", "smd", P_BOOL|P_VIM,
2329 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002331 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2332#ifdef FEAT_WINDOWS
2333 (char_u *)&p_stal, PV_NONE,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2339 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2342 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2345 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2348 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2351#ifdef FEAT_SMARTINDENT
2352 (char_u *)&p_si, PV_SI,
2353#else
2354 (char_u *)NULL, PV_NONE,
2355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2358 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002359 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2361 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2364 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002366 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002367#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002368 (char_u *)VAR_WIN, PV_SPELL,
2369#else
2370 (char_u *)NULL, PV_NONE,
2371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002372 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002373 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002374#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002375 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002376 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002377#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 Moolenaar0d9c26d2005-07-02 23:19:16 +00002382 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002383#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002384 (char_u *)&p_spf, PV_SPF,
2385 {(char_u *)"", (char_u *)0L}
2386#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 Moolenaar24bbcfe2005-06-28 23:32:02 +00002391 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002392#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002393 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002394 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002395#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 Moolenaar28e4c8d2006-05-09 16:15:42 +00002400 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002401#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002402 (char_u *)&p_sps, PV_NONE,
2403 {(char_u *)"best", (char_u *)0L}
2404#else
2405 (char_u *)NULL, PV_NONE,
2406 {(char_u *)0L, (char_u *)0L}
2407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002408 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2410#ifdef FEAT_WINDOWS
2411 (char_u *)&p_sb, PV_NONE,
2412#else
2413 (char_u *)NULL, PV_NONE,
2414#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"splitright", "spr", P_BOOL|P_VI_DEF,
2417#ifdef FEAT_VERTSPLIT
2418 (char_u *)&p_spr, PV_NONE,
2419#else
2420 (char_u *)NULL, PV_NONE,
2421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2424 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2427#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002428 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429#else
2430 (char_u *)NULL, PV_NONE,
2431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2434 (char_u *)&p_su, PV_NONE,
2435 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002438#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 (char_u *)&p_sua, PV_SUA,
2440 {(char_u *)"", (char_u *)0L}
2441#else
2442 (char_u *)NULL, PV_NONE,
2443 {(char_u *)0L, (char_u *)0L}
2444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2447 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"swapsync", "sws", P_STRING|P_VI_DEF,
2450 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2453 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002455 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2456#ifdef FEAT_SYN_HL
2457 (char_u *)&p_smc, PV_SMC,
2458 {(char_u *)3000L, (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 Moolenaar293ee4d2004-12-09 21:34:53 +00002464 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465#ifdef FEAT_SYN_HL
2466 (char_u *)&p_syn, PV_SYN,
2467 {(char_u *)"", (char_u *)0L}
2468#else
2469 (char_u *)NULL, PV_NONE,
2470 {(char_u *)0L, (char_u *)0L}
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002473 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2474#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002475 (char_u *)&p_tal, PV_NONE,
2476#else
2477 (char_u *)NULL, PV_NONE,
2478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002480 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2481#ifdef FEAT_WINDOWS
2482 (char_u *)&p_tpm, PV_NONE,
2483#else
2484 (char_u *)NULL, PV_NONE,
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2488 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2491 (char_u *)&p_tbs, PV_NONE,
2492#ifdef VMS /* binary searching doesn't appear to work on VMS */
2493 {(char_u *)0L, (char_u *)0L}
2494#else
2495 {(char_u *)TRUE, (char_u *)0L}
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"taglength", "tl", P_NUM|P_VI_DEF,
2499 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"tagrelative", "tr", P_BOOL|P_VIM,
2502 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002505 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {
2507#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2508 (char_u *)"./tags,./TAGS,tags,TAGS",
2509#else
2510 (char_u *)"./tags,tags",
2511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2514 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2517 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2520#ifdef FEAT_ARABIC
2521 (char_u *)&p_tbidi, PV_NONE,
2522#else
2523 (char_u *)NULL, PV_NONE,
2524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2527#ifdef FEAT_MBYTE
2528 (char_u *)&p_tenc, PV_NONE,
2529 {(char_u *)"", (char_u *)0L}
2530#else
2531 (char_u *)NULL, PV_NONE,
2532 {(char_u *)0L, (char_u *)0L}
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"terse", NULL, P_BOOL|P_VI_DEF,
2536 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"textauto", "ta", P_BOOL|P_VIM,
2539 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2541 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2543 (char_u *)&p_tx, PV_TX,
2544 {
2545#ifdef USE_CRNL
2546 (char_u *)TRUE,
2547#else
2548 (char_u *)FALSE,
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002551 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2555#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002556 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557#else
2558 (char_u *)NULL, PV_NONE,
2559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2562 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 {"timeout", "to", P_BOOL|P_VI_DEF,
2565 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2568 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"title", NULL, P_BOOL|P_VI_DEF,
2571#ifdef FEAT_TITLE
2572 (char_u *)&p_title, PV_NONE,
2573#else
2574 (char_u *)NULL, PV_NONE,
2575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"titlelen", NULL, P_NUM|P_VI_DEF,
2578#ifdef FEAT_TITLE
2579 (char_u *)&p_titlelen, PV_NONE,
2580#else
2581 (char_u *)NULL, PV_NONE,
2582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002583 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002584 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585#ifdef FEAT_TITLE
2586 (char_u *)&p_titleold, PV_NONE,
2587 {(char_u *)N_("Thanks for flying Vim"),
2588 (char_u *)0L}
2589#else
2590 (char_u *)NULL, PV_NONE,
2591 {(char_u *)0L, (char_u *)0L}
2592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"titlestring", NULL, P_STRING|P_VI_DEF,
2595#ifdef FEAT_TITLE
2596 (char_u *)&p_titlestring, PV_NONE,
2597#else
2598 (char_u *)NULL, PV_NONE,
2599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2602 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2603 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 {(char_u *)"icons,tooltips", (char_u *)0L}
2605 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002607#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2609 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611#endif
2612 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2613 (char_u *)&p_ttimeout, 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 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2616 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2619 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2622 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2625#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2626 (char_u *)&p_ttym, PV_NONE,
2627#else
2628 (char_u *)NULL, PV_NONE,
2629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2632 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2635 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002637 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2638#ifdef FEAT_PERSISTENT_UNDO
2639 (char_u *)&p_udir, PV_NONE,
2640 {(char_u *)".", (char_u *)0L}
2641#else
2642 (char_u *)NULL, PV_NONE,
2643 {(char_u *)0L, (char_u *)0L}
2644#endif
2645 SCRIPTID_INIT},
2646 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2647#ifdef FEAT_PERSISTENT_UNDO
2648 (char_u *)&p_udf, PV_UDF,
2649#else
2650 (char_u *)NULL, PV_NONE,
2651#endif
2652 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"undolevels", "ul", P_NUM|P_VI_DEF,
2654 (char_u *)&p_ul, PV_NONE,
2655 {
2656#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2657 (char_u *)1000L,
2658#else
2659 (char_u *)100L,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002662 {"undoreload", "ur", P_NUM|P_VI_DEF,
2663 (char_u *)&p_ur, PV_NONE,
2664 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"updatecount", "uc", P_NUM|P_VI_DEF,
2666 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"updatetime", "ut", P_NUM|P_VI_DEF,
2669 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"verbose", "vbs", P_NUM|P_VI_DEF,
2672 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002674 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2675 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2678#ifdef FEAT_SESSION
2679 (char_u *)&p_vdir, PV_NONE,
2680 {(char_u *)DFLT_VDIR, (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 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2687#ifdef FEAT_SESSION
2688 (char_u *)&p_vop, PV_NONE,
2689 {(char_u *)"folds,options,cursor", (char_u *)0L}
2690#else
2691 (char_u *)NULL, PV_NONE,
2692 {(char_u *)0L, (char_u *)0L}
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2696#ifdef FEAT_VIMINFO
2697 (char_u *)&p_viminfo, PV_NONE,
2698#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002699 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700#else
2701# ifdef AMIGA
2702 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002703 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002705 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706# endif
2707#endif
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 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2714#ifdef FEAT_VIRTUALEDIT
2715 (char_u *)&p_ve, PV_NONE,
2716 {(char_u *)"", (char_u *)""}
2717#else
2718 (char_u *)NULL, PV_NONE,
2719 {(char_u *)0L, (char_u *)0L}
2720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2723 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"w300", NULL, P_NUM|P_VI_DEF,
2726 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"w1200", NULL, P_NUM|P_VI_DEF,
2729 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"w9600", NULL, P_NUM|P_VI_DEF,
2732 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002733 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {"warn", NULL, P_BOOL|P_VI_DEF,
2735 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002736 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002737 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2738 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2741 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002742 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"wildchar", "wc", P_NUM|P_VIM,
2744 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002745 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2746 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002747 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2751#ifdef FEAT_WILDIGN
2752 (char_u *)&p_wig, PV_NONE,
2753#else
2754 (char_u *)NULL, PV_NONE,
2755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002757 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2758 (char_u *)&p_wic, PV_NONE,
2759 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2761#ifdef FEAT_WILDMENU
2762 (char_u *)&p_wmnu, PV_NONE,
2763#else
2764 (char_u *)NULL, PV_NONE,
2765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2768 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002769 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002770 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2771#ifdef FEAT_CMDL_COMPL
2772 (char_u *)&p_wop, PV_NONE,
2773 {(char_u *)"", (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 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2780#ifdef FEAT_WAK
2781 (char_u *)&p_wak, PV_NONE,
2782 {(char_u *)"menu", (char_u *)0L}
2783#else
2784 (char_u *)NULL, PV_NONE,
2785 {(char_u *)NULL, (char_u *)0L}
2786#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002787 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002789 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002790 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 {"winheight", "wh", P_NUM|P_VI_DEF,
2792#ifdef FEAT_WINDOWS
2793 (char_u *)&p_wh, PV_NONE,
2794#else
2795 (char_u *)NULL, PV_NONE,
2796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002799#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 (char_u *)VAR_WIN, PV_WFH,
2801#else
2802 (char_u *)NULL, PV_NONE,
2803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002805 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2806#ifdef FEAT_VERTSPLIT
2807 (char_u *)VAR_WIN, PV_WFW,
2808#else
2809 (char_u *)NULL, PV_NONE,
2810#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2813#ifdef FEAT_WINDOWS
2814 (char_u *)&p_wmh, PV_NONE,
2815#else
2816 (char_u *)NULL, PV_NONE,
2817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2820#ifdef FEAT_VERTSPLIT
2821 (char_u *)&p_wmw, PV_NONE,
2822#else
2823 (char_u *)NULL, PV_NONE,
2824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2827#ifdef FEAT_VERTSPLIT
2828 (char_u *)&p_wiw, PV_NONE,
2829#else
2830 (char_u *)NULL, PV_NONE,
2831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2834 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2837 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2840 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 {"write", NULL, P_BOOL|P_VI_DEF,
2843 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 {"writeany", "wa", P_BOOL|P_VI_DEF,
2846 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002847 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2849 (char_u *)&p_wb, PV_NONE,
2850 {
2851#ifdef FEAT_WRITEBACKUP
2852 (char_u *)TRUE,
2853#else
2854 (char_u *)FALSE,
2855#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002856 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"writedelay", "wd", P_NUM|P_VI_DEF,
2858 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860
2861/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002862#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865
2866 p_term("t_AB", T_CAB)
2867 p_term("t_AF", T_CAF)
2868 p_term("t_AL", T_CAL)
2869 p_term("t_al", T_AL)
2870 p_term("t_bc", T_BC)
2871 p_term("t_cd", T_CD)
2872 p_term("t_ce", T_CE)
2873 p_term("t_cl", T_CL)
2874 p_term("t_cm", T_CM)
2875 p_term("t_Co", T_CCO)
2876 p_term("t_CS", T_CCS)
2877 p_term("t_cs", T_CS)
2878#ifdef FEAT_VERTSPLIT
2879 p_term("t_CV", T_CSV)
2880#endif
2881 p_term("t_ut", T_UT)
2882 p_term("t_da", T_DA)
2883 p_term("t_db", T_DB)
2884 p_term("t_DL", T_CDL)
2885 p_term("t_dl", T_DL)
2886 p_term("t_fs", T_FS)
2887 p_term("t_IE", T_CIE)
2888 p_term("t_IS", T_CIS)
2889 p_term("t_ke", T_KE)
2890 p_term("t_ks", T_KS)
2891 p_term("t_le", T_LE)
2892 p_term("t_mb", T_MB)
2893 p_term("t_md", T_MD)
2894 p_term("t_me", T_ME)
2895 p_term("t_mr", T_MR)
2896 p_term("t_ms", T_MS)
2897 p_term("t_nd", T_ND)
2898 p_term("t_op", T_OP)
2899 p_term("t_RI", T_CRI)
2900 p_term("t_RV", T_CRV)
2901 p_term("t_Sb", T_CSB)
2902 p_term("t_Sf", T_CSF)
2903 p_term("t_se", T_SE)
2904 p_term("t_so", T_SO)
2905 p_term("t_sr", T_SR)
2906 p_term("t_ts", T_TS)
2907 p_term("t_te", T_TE)
2908 p_term("t_ti", T_TI)
2909 p_term("t_ue", T_UE)
2910 p_term("t_us", T_US)
2911 p_term("t_vb", T_VB)
2912 p_term("t_ve", T_VE)
2913 p_term("t_vi", T_VI)
2914 p_term("t_vs", T_VS)
2915 p_term("t_WP", T_CWP)
2916 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002917 p_term("t_SI", T_CSI)
2918 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 p_term("t_xs", T_XS)
2920 p_term("t_ZH", T_CZH)
2921 p_term("t_ZR", T_CZR)
2922
2923/* terminal key codes are not in here */
2924
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 /* end marker */
2926 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927};
2928
2929#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2930
2931#ifdef FEAT_MBYTE
2932static char *(p_ambw_values[]) = {"single", "double", NULL};
2933#endif
2934static char *(p_bg_values[]) = {"light", "dark", NULL};
2935static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2936static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002937#ifdef FEAT_CRYPT
2938static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2939#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002940#ifdef FEAT_CMDL_COMPL
2941static char *(p_wop_values[]) = {"tagfile", NULL};
2942#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943#ifdef FEAT_WAK
2944static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2945#endif
2946static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2947#ifdef FEAT_VISUAL
2948static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2949static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2950#endif
2951#ifdef FEAT_VISUAL
2952static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2953#endif
2954#ifdef FEAT_BROWSE
2955static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2956#endif
2957#ifdef FEAT_SCROLLBIND
2958static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2959#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002960static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961#ifdef FEAT_VERTSPLIT
2962static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2963#endif
2964#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002965# ifdef FEAT_AUTOCMD
2966static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2967# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002969# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2971#endif
2972static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2973#ifdef FEAT_FOLDING
2974static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002975# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002977# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 NULL};
2979static char *(p_fcl_values[]) = {"all", NULL};
2980#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002981#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002982static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002983#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984
2985static void set_option_default __ARGS((int, int opt_flags, int compatible));
2986static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002987static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002988static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989static char_u *illegal_char __ARGS((char_u *, int));
2990static int string_to_key __ARGS((char_u *arg));
2991#ifdef FEAT_CMDWIN
2992static char_u *check_cedit __ARGS((void));
2993#endif
2994#ifdef FEAT_TITLE
2995static void did_set_title __ARGS((int icon));
2996#endif
2997static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2998static void didset_options __ARGS((void));
2999static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003000#if defined(FEAT_EVAL) || defined(PROTO)
3001static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3002#else
3003# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3004#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
3006static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
3007static 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));
3008static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003009#ifdef FEAT_SYN_HL
3010static int int_cmp __ARGS((const void *a, const void *b));
3011#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012#ifdef FEAT_CLIPBOARD
3013static char_u *check_clipboard_option __ARGS((void));
3014#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003015#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003016static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003017#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003018#ifdef FEAT_EVAL
3019static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3020#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003022static 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 +00003023static void check_redraw __ARGS((long_u flags));
3024static int findoption __ARGS((char_u *));
3025static int find_key_option __ARGS((char_u *));
3026static void showoptions __ARGS((int all, int opt_flags));
3027static int optval_default __ARGS((struct vimoption *, char_u *varp));
3028static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3029static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3030static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3031static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3032static int istermoption __ARGS((struct vimoption *));
3033static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3034static char_u *get_varp __ARGS((struct vimoption *));
3035static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3036static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3037#ifdef FEAT_LANGMAP
3038static void langmap_init __ARGS((void));
3039static void langmap_set __ARGS((void));
3040#endif
3041static void paste_option_changed __ARGS((void));
3042static void compatible_set __ARGS((void));
3043#ifdef FEAT_LINEBREAK
3044static void fill_breakat_flags __ARGS((void));
3045#endif
3046static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3047static int check_opt_strings __ARGS((char_u *val, char **values, int));
3048static int check_opt_wim __ARGS((void));
3049
3050/*
3051 * Initialize the options, first part.
3052 *
3053 * Called only once from main(), just after creating the first buffer.
3054 */
3055 void
3056set_init_1()
3057{
3058 char_u *p;
3059 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003060 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061
3062#ifdef FEAT_LANGMAP
3063 langmap_init();
3064#endif
3065
3066 /* Be Vi compatible by default */
3067 p_cp = TRUE;
3068
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003069 /* Use POSIX compatibility when $VIM_POSIX is set. */
3070 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003071 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003072 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003073 set_string_default("shm", (char_u *)"A");
3074 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003075
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 /*
3077 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003078 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003080 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3082# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003083 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003085 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003087 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088# endif
3089#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003090 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 set_string_default("sh", p);
3092
3093#ifdef FEAT_WILDIGN
3094 /*
3095 * Set the default for 'backupskip' to include environment variables for
3096 * temp files.
3097 */
3098 {
3099# ifdef UNIX
3100 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3101# else
3102 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3103# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003104 int len;
3105 garray_T ga;
3106 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107
3108 ga_init2(&ga, 1, 100);
3109 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3110 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003111 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112# ifdef UNIX
3113 if (*names[n] == NUL)
3114 p = (char_u *)"/tmp";
3115 else
3116# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003117 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 if (p != NULL && *p != NUL)
3119 {
3120 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003121 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 if (ga_grow(&ga, len) == OK)
3123 {
3124 if (ga.ga_len > 0)
3125 STRCAT(ga.ga_data, ",");
3126 STRCAT(ga.ga_data, p);
3127 add_pathsep(ga.ga_data);
3128 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 ga.ga_len += len;
3130 }
3131 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003132 if (mustfree)
3133 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 }
3135 if (ga.ga_data != NULL)
3136 {
3137 set_string_default("bsk", ga.ga_data);
3138 vim_free(ga.ga_data);
3139 }
3140 }
3141#endif
3142
3143 /*
3144 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3145 */
3146 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003147 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003149#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3150 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3151#endif
3152 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003154 /* Use amount of memory available at this moment. */
3155 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156#else
3157# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003158 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003159 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003161 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162# endif
3163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003165 opt_idx = findoption((char_u *)"maxmem");
3166 if (opt_idx >= 0)
3167 {
3168#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3169 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3170 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3171#endif
3172 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3173 }
3174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 }
3176
3177#ifdef FEAT_GUI_W32
3178 /* force 'shortname' for Win32s */
3179 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003180 {
3181 opt_idx = findoption((char_u *)"shortname");
3182 if (opt_idx >= 0)
3183 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3184 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185#endif
3186
3187#ifdef FEAT_SEARCHPATH
3188 {
3189 char_u *cdpath;
3190 char_u *buf;
3191 int i;
3192 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003193 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194
3195 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003196 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 if (cdpath != NULL)
3198 {
3199 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3200 if (buf != NULL)
3201 {
3202 buf[0] = ','; /* start with ",", current dir first */
3203 j = 1;
3204 for (i = 0; cdpath[i] != NUL; ++i)
3205 {
3206 if (vim_ispathlistsep(cdpath[i]))
3207 buf[j++] = ',';
3208 else
3209 {
3210 if (cdpath[i] == ' ' || cdpath[i] == ',')
3211 buf[j++] = '\\';
3212 buf[j++] = cdpath[i];
3213 }
3214 }
3215 buf[j] = NUL;
3216 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003217 if (opt_idx >= 0)
3218 {
3219 options[opt_idx].def_val[VI_DEFAULT] = buf;
3220 options[opt_idx].flags |= P_DEF_ALLOCED;
3221 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003222 else
3223 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003225 if (mustfree)
3226 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 }
3228 }
3229#endif
3230
3231#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3232 /* Set print encoding on platforms that don't default to latin1 */
3233 set_string_default("penc",
3234# if defined(MSWIN) || defined(OS2)
3235 (char_u *)"cp1252"
3236# else
3237# ifdef VMS
3238 (char_u *)"dec-mcs"
3239# else
3240# ifdef EBCDIC
3241 (char_u *)"ebcdic-uk"
3242# else
3243# ifdef MAC
3244 (char_u *)"mac-roman"
3245# else /* HPUX */
3246 (char_u *)"hp-roman8"
3247# endif
3248# endif
3249# endif
3250# endif
3251 );
3252#endif
3253
3254#ifdef FEAT_POSTSCRIPT
3255 /* 'printexpr' must be allocated to be able to evaluate it. */
3256 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003257# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3258 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259# else
3260# ifdef VMS
3261 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3262
3263# else
3264 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3265# endif
3266# endif
3267 );
3268#endif
3269
3270 /*
3271 * Set all the options (except the terminal options) to their default
3272 * value. Also set the global value for local options.
3273 */
3274 set_options_default(0);
3275
3276#ifdef FEAT_GUI
3277 if (found_reverse_arg)
3278 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3279#endif
3280
3281 curbuf->b_p_initialized = TRUE;
3282 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3283 check_buf_options(curbuf);
3284 check_win_options(curwin);
3285 check_options();
3286
3287 /* Must be before option_expand(), because that one needs vim_isIDc() */
3288 didset_options();
3289
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003290#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003291 /* Use the current chartab for the generic chartab. */
3292 init_spell_chartab();
3293#endif
3294
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#ifdef FEAT_LINEBREAK
3296 /*
3297 * initialize the table for 'breakat'.
3298 */
3299 fill_breakat_flags();
3300#endif
3301
3302 /*
3303 * Expand environment variables and things like "~" for the defaults.
3304 * If option_expand() returns non-NULL the variable is expanded. This can
3305 * only happen for non-indirect options.
3306 * Also set the default to the expanded value, so ":set" does not list
3307 * them.
3308 * Don't set the P_ALLOCED flag, because we don't want to free the
3309 * default.
3310 */
3311 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3312 {
3313 if ((options[opt_idx].flags & P_GETTEXT)
3314 && options[opt_idx].var != NULL)
3315 p = (char_u *)_(*(char **)options[opt_idx].var);
3316 else
3317 p = option_expand(opt_idx, NULL);
3318 if (p != NULL && (p = vim_strsave(p)) != NULL)
3319 {
3320 *(char_u **)options[opt_idx].var = p;
3321 /* VIMEXP
3322 * Defaults for all expanded options are currently the same for Vi
3323 * and Vim. When this changes, add some code here! Also need to
3324 * split P_DEF_ALLOCED in two.
3325 */
3326 if (options[opt_idx].flags & P_DEF_ALLOCED)
3327 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3328 options[opt_idx].def_val[VI_DEFAULT] = p;
3329 options[opt_idx].flags |= P_DEF_ALLOCED;
3330 }
3331 }
3332
3333 /* Initialize the highlight_attr[] table. */
3334 highlight_changed();
3335
3336 save_file_ff(curbuf); /* Buffer is unchanged */
3337
3338 /* Parse default for 'wildmode' */
3339 check_opt_wim();
3340
3341#if defined(FEAT_ARABIC)
3342 /* Detect use of mlterm.
3343 * Mlterm is a terminal emulator akin to xterm that has some special
3344 * abilities (bidi namely).
3345 * NOTE: mlterm's author is being asked to 'set' a variable
3346 * instead of an environment variable due to inheritance.
3347 */
3348 if (mch_getenv((char_u *)"MLTERM") != NULL)
3349 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3350#endif
3351
3352#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3353 /* Parse default for 'fillchars'. */
3354 (void)set_chars_option(&p_fcs);
3355#endif
3356
3357#ifdef FEAT_CLIPBOARD
3358 /* Parse default for 'clipboard' */
3359 (void)check_clipboard_option();
3360#endif
3361
3362#ifdef FEAT_MBYTE
3363# if defined(WIN3264) && defined(FEAT_GETTEXT)
3364 /*
3365 * If $LANG isn't set, try to get a good value for it. This makes the
3366 * right language be used automatically. Don't do this for English.
3367 */
3368 if (mch_getenv((char_u *)"LANG") == NULL)
3369 {
3370 char buf[20];
3371
3372 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3373 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3374 * only the first two. */
3375 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3376 (LPTSTR)buf, 20);
3377 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3378 {
3379 /* There are a few exceptions (probably more) */
3380 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3381 STRCPY(buf, "zh_TW");
3382 else if (STRNICMP(buf, "chs", 3) == 0
3383 || STRNICMP(buf, "zhc", 3) == 0)
3384 STRCPY(buf, "zh_CN");
3385 else if (STRNICMP(buf, "jp", 2) == 0)
3386 STRCPY(buf, "ja");
3387 else
3388 buf[2] = NUL; /* truncate to two-letter code */
3389 vim_setenv("LANG", buf);
3390 }
3391 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003392# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003393# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003394 /* Moved to os_mac_conv.c to avoid dependency problems. */
3395 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003396# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397# endif
3398
3399 /* enc_locale() will try to find the encoding of the current locale. */
3400 p = enc_locale();
3401 if (p != NULL)
3402 {
3403 char_u *save_enc;
3404
3405 /* Try setting 'encoding' and check if the value is valid.
3406 * If not, go back to the default "latin1". */
3407 save_enc = p_enc;
3408 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003409 if (STRCMP(p_enc, "gb18030") == 0)
3410 {
3411 /* We don't support "gb18030", but "cp936" is a good substitute
3412 * for practical purposes, thus use that. It's not an alias to
3413 * still support conversion between gb18030 and utf-8. */
3414 p_enc = vim_strsave((char_u *)"cp936");
3415 vim_free(p);
3416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 if (mb_init() == NULL)
3418 {
3419 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 if (opt_idx >= 0)
3421 {
3422 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3423 options[opt_idx].flags |= P_DEF_ALLOCED;
3424 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003426#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3427 || defined(VMS)
3428 if (STRCMP(p_enc, "latin1") == 0
3429# ifdef FEAT_MBYTE
3430 || enc_utf8
3431# endif
3432 )
3433 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003434 /* Adjust the default for 'isprint' and 'iskeyword' to match
3435 * latin1. Also set the defaults for when 'nocompatible' is
3436 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003437 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003438 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003439 set_string_option_direct((char_u *)"isk", -1,
3440 ISK_LATIN1, OPT_FREE, SID_NONE);
3441 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003442 if (opt_idx >= 0)
3443 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003444 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003445 if (opt_idx >= 0)
3446 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003447 (void)init_chartab();
3448 }
3449#endif
3450
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451# if defined(WIN3264) && !defined(FEAT_GUI)
3452 /* Win32 console: When GetACP() returns a different value from
3453 * GetConsoleCP() set 'termencoding'. */
3454 if (GetACP() != GetConsoleCP())
3455 {
3456 char buf[50];
3457
3458 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3459 p_tenc = vim_strsave((char_u *)buf);
3460 if (p_tenc != NULL)
3461 {
3462 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003463 if (opt_idx >= 0)
3464 {
3465 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3466 options[opt_idx].flags |= P_DEF_ALLOCED;
3467 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468 convert_setup(&input_conv, p_tenc, p_enc);
3469 convert_setup(&output_conv, p_enc, p_tenc);
3470 }
3471 else
3472 p_tenc = empty_option;
3473 }
3474# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003475# if defined(WIN3264) && defined(FEAT_MBYTE)
3476 /* $HOME may have characters in active code page. */
3477 init_homedir();
3478# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 }
3480 else
3481 {
3482 vim_free(p_enc);
3483 p_enc = save_enc;
3484 }
3485 }
3486#endif
3487
3488#ifdef FEAT_MULTI_LANG
3489 /* Set the default for 'helplang'. */
3490 set_helplang_default(get_mess_lang());
3491#endif
3492}
3493
3494/*
3495 * Set an option to its default value.
3496 * This does not take care of side effects!
3497 */
3498 static void
3499set_option_default(opt_idx, opt_flags, compatible)
3500 int opt_idx;
3501 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3502 int compatible; /* use Vi default value */
3503{
3504 char_u *varp; /* pointer to variable for current option */
3505 int dvi; /* index in def_val[] */
3506 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003507 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003508 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3509
3510 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3511 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003512 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 {
3514 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3515 if (flags & P_STRING)
3516 {
3517 /* Use set_string_option_direct() for local options to handle
3518 * freeing and allocating the value. */
3519 if (options[opt_idx].indir != PV_NONE)
3520 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003521 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003522 else
3523 {
3524 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3525 free_string_option(*(char_u **)(varp));
3526 *(char_u **)varp = options[opt_idx].def_val[dvi];
3527 options[opt_idx].flags &= ~P_ALLOCED;
3528 }
3529 }
3530 else if (flags & P_NUM)
3531 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003532 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533 win_comp_scroll(curwin);
3534 else
3535 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003536 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003537 /* May also set global value for local option. */
3538 if (both)
3539 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3540 *(long *)varp;
3541 }
3542 }
3543 else /* P_BOOL */
3544 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003545 /* the cast to long is required for Manx C, long_i is needed for
3546 * MSVC */
3547 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003548#ifdef UNIX
3549 /* 'modeline' defaults to off for root */
3550 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3551 *(int *)varp = FALSE;
3552#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 /* May also set global value for local option. */
3554 if (both)
3555 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3556 *(int *)varp;
3557 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003558
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003559 /* The default value is not insecure. */
3560 flagsp = insecure_flag(opt_idx, opt_flags);
3561 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003562 }
3563
3564#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003565 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003566#endif
3567}
3568
3569/*
3570 * Set all options (except terminal options) to their default value.
3571 */
3572 static void
3573set_options_default(opt_flags)
3574 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3575{
3576 int i;
3577#ifdef FEAT_WINDOWS
3578 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003579 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580#endif
3581
3582 for (i = 0; !istermoption(&options[i]); i++)
3583 if (!(options[i].flags & P_NODEFAULT))
3584 set_option_default(i, opt_flags, p_cp);
3585
3586#ifdef FEAT_WINDOWS
3587 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003588 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003589 win_comp_scroll(wp);
3590#else
3591 win_comp_scroll(curwin);
3592#endif
3593}
3594
3595/*
3596 * Set the Vi-default value of a string option.
3597 * Used for 'sh', 'backupskip' and 'term'.
3598 */
3599 void
3600set_string_default(name, val)
3601 char *name;
3602 char_u *val;
3603{
3604 char_u *p;
3605 int opt_idx;
3606
3607 p = vim_strsave(val);
3608 if (p != NULL) /* we don't want a NULL */
3609 {
3610 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003611 if (opt_idx >= 0)
3612 {
3613 if (options[opt_idx].flags & P_DEF_ALLOCED)
3614 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3615 options[opt_idx].def_val[VI_DEFAULT] = p;
3616 options[opt_idx].flags |= P_DEF_ALLOCED;
3617 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 }
3619}
3620
3621/*
3622 * Set the Vi-default value of a number option.
3623 * Used for 'lines' and 'columns'.
3624 */
3625 void
3626set_number_default(name, val)
3627 char *name;
3628 long val;
3629{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003630 int opt_idx;
3631
3632 opt_idx = findoption((char_u *)name);
3633 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003634 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635}
3636
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003637#if defined(EXITFREE) || defined(PROTO)
3638/*
3639 * Free all options.
3640 */
3641 void
3642free_all_options()
3643{
3644 int i;
3645
3646 for (i = 0; !istermoption(&options[i]); i++)
3647 {
3648 if (options[i].indir == PV_NONE)
3649 {
3650 /* global option: free value and default value. */
3651 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3652 free_string_option(*(char_u **)options[i].var);
3653 if (options[i].flags & P_DEF_ALLOCED)
3654 free_string_option(options[i].def_val[VI_DEFAULT]);
3655 }
3656 else if (options[i].var != VAR_WIN
3657 && (options[i].flags & P_STRING))
3658 /* buffer-local option: free global value */
3659 free_string_option(*(char_u **)options[i].var);
3660 }
3661}
3662#endif
3663
3664
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665/*
3666 * Initialize the options, part two: After getting Rows and Columns and
3667 * setting 'term'.
3668 */
3669 void
3670set_init_2()
3671{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003672 int idx;
3673
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674 /*
3675 * 'scroll' defaults to half the window height. Note that this default is
3676 * wrong when the window height changes.
3677 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003678 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003679 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003680 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003681 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682 comp_col();
3683
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003684 /*
3685 * 'window' is only for backwards compatibility with Vi.
3686 * Default is Rows - 1.
3687 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003688 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003689 p_window = Rows - 1;
3690 set_number_default("window", Rows - 1);
3691
Bram Moolenaarf740b292006-02-16 22:11:02 +00003692 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003694 /*
3695 * If 'background' wasn't set by the user, try guessing the value,
3696 * depending on the terminal name. Only need to check for terminals
3697 * with a dark background, that can handle color.
3698 */
3699 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3701 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003703 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003704 /* don't mark it as set, when starting the GUI it may be
3705 * changed again */
3706 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707 }
3708#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003709
3710#ifdef CURSOR_SHAPE
3711 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3712#endif
3713#ifdef FEAT_MOUSESHAPE
3714 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3715#endif
3716#ifdef FEAT_PRINTER
3717 (void)parse_printoptions(); /* parse 'printoptions' default value */
3718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003719}
3720
3721/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003722 * Return "dark" or "light" depending on the kind of terminal.
3723 * This is just guessing! Recognized are:
3724 * "linux" Linux console
3725 * "screen.linux" Linux console with screen
3726 * "cygwin" Cygwin shell
3727 * "putty" Putty program
3728 * We also check the COLORFGBG environment variable, which is set by
3729 * rxvt and derivatives. This variable contains either two or three
3730 * values separated by semicolons; we want the last value in either
3731 * case. If this value is 0-6 or 8, our background is dark.
3732 */
3733 static char_u *
3734term_bg_default()
3735{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003736#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3737 /* DOS console nearly always black */
3738 return (char_u *)"dark";
3739#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003740 char_u *p;
3741
Bram Moolenaarf740b292006-02-16 22:11:02 +00003742 if (STRCMP(T_NAME, "linux") == 0
3743 || STRCMP(T_NAME, "screen.linux") == 0
3744 || STRCMP(T_NAME, "cygwin") == 0
3745 || STRCMP(T_NAME, "putty") == 0
3746 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3747 && (p = vim_strrchr(p, ';')) != NULL
3748 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3749 && p[2] == NUL))
3750 return (char_u *)"dark";
3751 return (char_u *)"light";
3752#endif
3753}
3754
3755/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756 * Initialize the options, part three: After reading the .vimrc
3757 */
3758 void
3759set_init_3()
3760{
3761#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3762/*
3763 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3764 * This is done after other initializations, where 'shell' might have been
3765 * set, but only if they have not been set before.
3766 */
3767 char_u *p;
3768 int idx_srr;
3769 int do_srr;
3770#ifdef FEAT_QUICKFIX
3771 int idx_sp;
3772 int do_sp;
3773#endif
3774
3775 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003776 if (idx_srr < 0)
3777 do_srr = FALSE;
3778 else
3779 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780#ifdef FEAT_QUICKFIX
3781 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003782 if (idx_sp < 0)
3783 do_sp = FALSE;
3784 else
3785 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003786#endif
3787
3788 /*
3789 * Isolate the name of the shell:
3790 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3791 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003792 * But don't allow a space in the path, so that this works:
3793 * "/usr/bin/csh --rcfile ~/.cshrc"
3794 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003796#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 p = gettail(p_sh);
3798 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003799#else
3800 p = skiptowhite(p_sh);
3801 if (*p == NUL)
3802 {
3803 /* No white space, use the tail. */
3804 p = vim_strsave(gettail(p_sh));
3805 }
3806 else
3807 {
3808 char_u *p1, *p2;
3809
3810 /* Find the last path separator before the space. */
3811 p1 = p_sh;
3812 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3813 if (vim_ispathsep(*p2))
3814 p1 = p2 + 1;
3815 p = vim_strnsave(p1, (int)(p - p1));
3816 }
3817#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003818 if (p != NULL)
3819 {
3820 /*
3821 * Default for p_sp is "| tee", for p_srr is ">".
3822 * For known shells it is changed here to include stderr.
3823 */
3824 if ( fnamecmp(p, "csh") == 0
3825 || fnamecmp(p, "tcsh") == 0
3826# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3827 || fnamecmp(p, "csh.exe") == 0
3828 || fnamecmp(p, "tcsh.exe") == 0
3829# endif
3830 )
3831 {
3832#if defined(FEAT_QUICKFIX)
3833 if (do_sp)
3834 {
3835# ifdef WIN3264
3836 p_sp = (char_u *)">&";
3837# else
3838 p_sp = (char_u *)"|& tee";
3839# endif
3840 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3841 }
3842#endif
3843 if (do_srr)
3844 {
3845 p_srr = (char_u *)">&";
3846 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3847 }
3848 }
3849 else
3850# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3851 if ( fnamecmp(p, "sh") == 0
3852 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003853 || fnamecmp(p, "mksh") == 0
3854 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003856 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857 || fnamecmp(p, "bash") == 0
3858# ifdef WIN3264
3859 || fnamecmp(p, "cmd") == 0
3860 || fnamecmp(p, "sh.exe") == 0
3861 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003862 || fnamecmp(p, "mksh.exe") == 0
3863 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003865 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866 || fnamecmp(p, "bash.exe") == 0
3867 || fnamecmp(p, "cmd.exe") == 0
3868# endif
3869 )
3870# endif
3871 {
3872#if defined(FEAT_QUICKFIX)
3873 if (do_sp)
3874 {
3875# ifdef WIN3264
3876 p_sp = (char_u *)">%s 2>&1";
3877# else
3878 p_sp = (char_u *)"2>&1| tee";
3879# endif
3880 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3881 }
3882#endif
3883 if (do_srr)
3884 {
3885 p_srr = (char_u *)">%s 2>&1";
3886 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3887 }
3888 }
3889 vim_free(p);
3890 }
3891#endif
3892
3893#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3894 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003895 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3896 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 * This is done after other initializations, where 'shell' might have been
3898 * set, but only if they have not been set before. Default for p_shcf is
3899 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3900 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3901 * command.com. And for Win32 we need to set p_sxq instead.
3902 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003903 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 {
3905 int idx3;
3906
3907 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003908 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 {
3910 p_shcf = (char_u *)"-c";
3911 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3912 }
3913
3914# ifndef DJGPP
3915# ifdef WIN3264
3916 /* Somehow Win32 requires the quotes around the redirection too */
3917 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003918 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 {
3920 p_sxq = (char_u *)"\"";
3921 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3922 }
3923# else
3924 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003925 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 {
3927 p_shq = (char_u *)"\"";
3928 options[idx3].def_val[VI_DEFAULT] = p_shq;
3929 }
3930# endif
3931# endif
3932 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003933 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3934 {
3935 int idx3;
3936
3937 /*
3938 * cmd.exe on Windows will strip the first and last double quote given
3939 * on the command line, e.g. most of the time things like:
3940 * cmd /c "my path/to/echo" "my args to echo"
3941 * become:
3942 * my path/to/echo" "my args to echo
3943 * when executed.
3944 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003945 * To avoid this, set shellxquote to surround the command in
3946 * parenthesis. This appears to make most commands work, without
3947 * breaking commands that worked previously, such as
3948 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003949 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003950 idx3 = findoption((char_u *)"sxq");
3951 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3952 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003953 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003954 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3955 }
3956
Bram Moolenaara64ba222012-02-12 23:23:31 +01003957 idx3 = findoption((char_u *)"shcf");
3958 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3959 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003960 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003961 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3962 }
3963 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964#endif
3965
3966#ifdef FEAT_TITLE
3967 set_title_defaults();
3968#endif
3969}
3970
3971#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3972/*
3973 * When 'helplang' is still at its default value, set it to "lang".
3974 * Only the first two characters of "lang" are used.
3975 */
3976 void
3977set_helplang_default(lang)
3978 char_u *lang;
3979{
3980 int idx;
3981
3982 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3983 return;
3984 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003985 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 {
3987 if (options[idx].flags & P_ALLOCED)
3988 free_string_option(p_hlg);
3989 p_hlg = vim_strsave(lang);
3990 if (p_hlg == NULL)
3991 p_hlg = empty_option;
3992 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003993 {
3994 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3995 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3996 {
3997 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3998 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004001 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004002 options[idx].flags |= P_ALLOCED;
4003 }
4004}
4005#endif
4006
4007#ifdef FEAT_GUI
4008static char_u *gui_bg_default __ARGS((void));
4009
4010 static char_u *
4011gui_bg_default()
4012{
4013 if (gui_get_lightness(gui.back_pixel) < 127)
4014 return (char_u *)"dark";
4015 return (char_u *)"light";
4016}
4017
4018/*
4019 * Option initializations that can only be done after opening the GUI window.
4020 */
4021 void
4022init_gui_options()
4023{
4024 /* Set the 'background' option according to the lightness of the
4025 * background color, unless the user has set it already. */
4026 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4027 {
4028 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4029 highlight_changed();
4030 }
4031}
4032#endif
4033
4034#ifdef FEAT_TITLE
4035/*
4036 * 'title' and 'icon' only default to true if they have not been set or reset
4037 * in .vimrc and we can read the old value.
4038 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4039 * they can be reset. This reduces startup time when using X on a remote
4040 * machine.
4041 */
4042 void
4043set_title_defaults()
4044{
4045 int idx1;
4046 long val;
4047
4048 /*
4049 * If GUI is (going to be) used, we can always set the window title and
4050 * icon name. Saves a bit of time, because the X11 display server does
4051 * not need to be contacted.
4052 */
4053 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004054 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 {
4056#ifdef FEAT_GUI
4057 if (gui.starting || gui.in_use)
4058 val = TRUE;
4059 else
4060#endif
4061 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004062 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 p_title = val;
4064 }
4065 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004066 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 {
4068#ifdef FEAT_GUI
4069 if (gui.starting || gui.in_use)
4070 val = TRUE;
4071 else
4072#endif
4073 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004074 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 p_icon = val;
4076 }
4077}
4078#endif
4079
4080/*
4081 * Parse 'arg' for option settings.
4082 *
4083 * 'arg' may be IObuff, but only when no errors can be present and option
4084 * does not need to be expanded with option_expand().
4085 * "opt_flags":
4086 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004087 * OPT_GLOBAL for ":setglobal"
4088 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004090 * OPT_WINONLY to only set window-local options
4091 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 *
4093 * returns FAIL if an error is detected, OK otherwise
4094 */
4095 int
4096do_set(arg, opt_flags)
4097 char_u *arg; /* option string (may be written to!) */
4098 int opt_flags;
4099{
4100 int opt_idx;
4101 char_u *errmsg;
4102 char_u errbuf[80];
4103 char_u *startarg;
4104 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4105 int nextchar; /* next non-white char after option name */
4106 int afterchar; /* character just after option name */
4107 int len;
4108 int i;
4109 long value;
4110 int key;
4111 long_u flags; /* flags for current option */
4112 char_u *varp = NULL; /* pointer to variable for current option */
4113 int did_show = FALSE; /* already showed one value */
4114 int adding; /* "opt+=arg" */
4115 int prepending; /* "opt^=arg" */
4116 int removing; /* "opt-=arg" */
4117 int cp_val = 0;
4118 char_u key_name[2];
4119
4120 if (*arg == NUL)
4121 {
4122 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004123 did_show = TRUE;
4124 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 }
4126
4127 while (*arg != NUL) /* loop to process all options */
4128 {
4129 errmsg = NULL;
4130 startarg = arg; /* remember for error message */
4131
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004132 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4133 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 {
4135 /*
4136 * ":set all" show all options.
4137 * ":set all&" set all options to their default value.
4138 */
4139 arg += 3;
4140 if (*arg == '&')
4141 {
4142 ++arg;
4143 /* Only for :set command set global value of local options. */
4144 set_options_default(OPT_FREE | opt_flags);
4145 }
4146 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004147 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004149 did_show = TRUE;
4150 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004152 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 {
4154 showoptions(2, opt_flags);
4155 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004156 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 arg += 7;
4158 }
4159 else
4160 {
4161 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004162 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 {
4164 prefix = 0;
4165 arg += 2;
4166 }
4167 else if (STRNCMP(arg, "inv", 3) == 0)
4168 {
4169 prefix = 2;
4170 arg += 3;
4171 }
4172
4173 /* find end of name */
4174 key = 0;
4175 if (*arg == '<')
4176 {
4177 nextchar = 0;
4178 opt_idx = -1;
4179 /* look out for <t_>;> */
4180 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4181 len = 5;
4182 else
4183 {
4184 len = 1;
4185 while (arg[len] != NUL && arg[len] != '>')
4186 ++len;
4187 }
4188 if (arg[len] != '>')
4189 {
4190 errmsg = e_invarg;
4191 goto skip;
4192 }
4193 arg[len] = NUL; /* put NUL after name */
4194 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4195 opt_idx = findoption(arg + 1);
4196 arg[len++] = '>'; /* restore '>' */
4197 if (opt_idx == -1)
4198 key = find_key_option(arg + 1);
4199 }
4200 else
4201 {
4202 len = 0;
4203 /*
4204 * The two characters after "t_" may not be alphanumeric.
4205 */
4206 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4207 len = 4;
4208 else
4209 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4210 ++len;
4211 nextchar = arg[len];
4212 arg[len] = NUL; /* put NUL after name */
4213 opt_idx = findoption(arg);
4214 arg[len] = nextchar; /* restore nextchar */
4215 if (opt_idx == -1)
4216 key = find_key_option(arg);
4217 }
4218
4219 /* remember character after option name */
4220 afterchar = arg[len];
4221
4222 /* skip white space, allow ":set ai ?" */
4223 while (vim_iswhite(arg[len]))
4224 ++len;
4225
4226 adding = FALSE;
4227 prepending = FALSE;
4228 removing = FALSE;
4229 if (arg[len] != NUL && arg[len + 1] == '=')
4230 {
4231 if (arg[len] == '+')
4232 {
4233 adding = TRUE; /* "+=" */
4234 ++len;
4235 }
4236 else if (arg[len] == '^')
4237 {
4238 prepending = TRUE; /* "^=" */
4239 ++len;
4240 }
4241 else if (arg[len] == '-')
4242 {
4243 removing = TRUE; /* "-=" */
4244 ++len;
4245 }
4246 }
4247 nextchar = arg[len];
4248
4249 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4250 {
4251 errmsg = (char_u *)N_("E518: Unknown option");
4252 goto skip;
4253 }
4254
4255 if (opt_idx >= 0)
4256 {
4257 if (options[opt_idx].var == NULL) /* hidden option: skip */
4258 {
4259 /* Only give an error message when requesting the value of
4260 * a hidden option, ignore setting it. */
4261 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4262 && (!(options[opt_idx].flags & P_BOOL)
4263 || nextchar == '?'))
4264 errmsg = (char_u *)N_("E519: Option not supported");
4265 goto skip;
4266 }
4267
4268 flags = options[opt_idx].flags;
4269 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4270 }
4271 else
4272 {
4273 flags = P_STRING;
4274 if (key < 0)
4275 {
4276 key_name[0] = KEY2TERMCAP0(key);
4277 key_name[1] = KEY2TERMCAP1(key);
4278 }
4279 else
4280 {
4281 key_name[0] = KS_KEY;
4282 key_name[1] = (key & 0xff);
4283 }
4284 }
4285
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004286 /* Skip all options that are not window-local (used when showing
4287 * an already loaded buffer in a window). */
4288 if ((opt_flags & OPT_WINONLY)
4289 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4290 goto skip;
4291
Bram Moolenaara3227e22006-03-08 21:32:40 +00004292 /* Skip all options that are window-local (used for :vimgrep). */
4293 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4294 && options[opt_idx].var == VAR_WIN)
4295 goto skip;
4296
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004297 /* Disallow changing some options from modelines. */
4298 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004299 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004300 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004301 {
4302 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4303 goto skip;
4304 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004305#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004306 /* In diff mode some options are overruled. This avoids that
4307 * 'foldmethod' becomes "marker" instead of "diff" and that
4308 * "wrap" gets set. */
4309 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004310 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004311 && (options[opt_idx].indir == PV_FDM
4312 || options[opt_idx].indir == PV_WRAP))
4313 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004315 }
4316
4317#ifdef HAVE_SANDBOX
4318 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004319 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320 {
4321 errmsg = (char_u *)_(e_sandbox);
4322 goto skip;
4323 }
4324#endif
4325
4326 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4327 {
4328 arg += len;
4329 cp_val = p_cp;
4330 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4331 {
4332 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4333 {
4334 cp_val = FALSE;
4335 arg += 3;
4336 }
4337 else /* "opt&vi": set to Vi default */
4338 {
4339 cp_val = TRUE;
4340 arg += 2;
4341 }
4342 }
4343 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4344 && arg[1] != NUL && !vim_iswhite(arg[1]))
4345 {
4346 errmsg = e_trailing;
4347 goto skip;
4348 }
4349 }
4350
4351 /*
4352 * allow '=' and ':' as MSDOS command.com allows only one
4353 * '=' character per "set" command line. grrr. (jw)
4354 */
4355 if (nextchar == '?'
4356 || (prefix == 1
4357 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4358 && !(flags & P_BOOL)))
4359 {
4360 /*
4361 * print value
4362 */
4363 if (did_show)
4364 msg_putchar('\n'); /* cursor below last one */
4365 else
4366 {
4367 gotocmdline(TRUE); /* cursor at status line */
4368 did_show = TRUE; /* remember that we did a line */
4369 }
4370 if (opt_idx >= 0)
4371 {
4372 showoneopt(&options[opt_idx], opt_flags);
4373#ifdef FEAT_EVAL
4374 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004375 {
4376 /* Mention where the option was last set. */
4377 if (varp == options[opt_idx].var)
4378 last_set_msg(options[opt_idx].scriptID);
4379 else if ((int)options[opt_idx].indir & PV_WIN)
4380 last_set_msg(curwin->w_p_scriptID[
4381 (int)options[opt_idx].indir & PV_MASK]);
4382 else if ((int)options[opt_idx].indir & PV_BUF)
4383 last_set_msg(curbuf->b_p_scriptID[
4384 (int)options[opt_idx].indir & PV_MASK]);
4385 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004386#endif
4387 }
4388 else
4389 {
4390 char_u *p;
4391
4392 p = find_termcode(key_name);
4393 if (p == NULL)
4394 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004395 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396 goto skip;
4397 }
4398 else
4399 (void)show_one_termcode(key_name, p, TRUE);
4400 }
4401 if (nextchar != '?'
4402 && nextchar != NUL && !vim_iswhite(afterchar))
4403 errmsg = e_trailing;
4404 }
4405 else
4406 {
4407 if (flags & P_BOOL) /* boolean */
4408 {
4409 if (nextchar == '=' || nextchar == ':')
4410 {
4411 errmsg = e_invarg;
4412 goto skip;
4413 }
4414
4415 /*
4416 * ":set opt!": invert
4417 * ":set opt&": reset to default value
4418 * ":set opt<": reset to global value
4419 */
4420 if (nextchar == '!')
4421 value = *(int *)(varp) ^ 1;
4422 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004423 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004424 ((flags & P_VI_DEF) || cp_val)
4425 ? VI_DEFAULT : VIM_DEFAULT];
4426 else if (nextchar == '<')
4427 {
4428 /* For 'autoread' -1 means to use global value. */
4429 if ((int *)varp == &curbuf->b_p_ar
4430 && opt_flags == OPT_LOCAL)
4431 value = -1;
4432 else
4433 value = *(int *)get_varp_scope(&(options[opt_idx]),
4434 OPT_GLOBAL);
4435 }
4436 else
4437 {
4438 /*
4439 * ":set invopt": invert
4440 * ":set opt" or ":set noopt": set or reset
4441 */
4442 if (nextchar != NUL && !vim_iswhite(afterchar))
4443 {
4444 errmsg = e_trailing;
4445 goto skip;
4446 }
4447 if (prefix == 2) /* inv */
4448 value = *(int *)(varp) ^ 1;
4449 else
4450 value = prefix;
4451 }
4452
4453 errmsg = set_bool_option(opt_idx, varp, (int)value,
4454 opt_flags);
4455 }
4456 else /* numeric or string */
4457 {
4458 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4459 || prefix != 1)
4460 {
4461 errmsg = e_invarg;
4462 goto skip;
4463 }
4464
4465 if (flags & P_NUM) /* numeric */
4466 {
4467 /*
4468 * Different ways to set a number option:
4469 * & set to default value
4470 * < set to global value
4471 * <xx> accept special key codes for 'wildchar'
4472 * c accept any non-digit for 'wildchar'
4473 * [-]0-9 set number
4474 * other error
4475 */
4476 ++arg;
4477 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004478 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004479 ((flags & P_VI_DEF) || cp_val)
4480 ? VI_DEFAULT : VIM_DEFAULT];
4481 else if (nextchar == '<')
4482 value = *(long *)get_varp_scope(&(options[opt_idx]),
4483 OPT_GLOBAL);
4484 else if (((long *)varp == &p_wc
4485 || (long *)varp == &p_wcm)
4486 && (*arg == '<'
4487 || *arg == '^'
4488 || ((!arg[1] || vim_iswhite(arg[1]))
4489 && !VIM_ISDIGIT(*arg))))
4490 {
4491 value = string_to_key(arg);
4492 if (value == 0 && (long *)varp != &p_wcm)
4493 {
4494 errmsg = e_invarg;
4495 goto skip;
4496 }
4497 }
4498 /* allow negative numbers (for 'undolevels') */
4499 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4500 {
4501 i = 0;
4502 if (*arg == '-')
4503 i = 1;
4504#ifdef HAVE_STRTOL
4505 value = strtol((char *)arg, NULL, 0);
4506 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4507 i += 2;
4508#else
4509 value = atol((char *)arg);
4510#endif
4511 while (VIM_ISDIGIT(arg[i]))
4512 ++i;
4513 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4514 {
4515 errmsg = e_invarg;
4516 goto skip;
4517 }
4518 }
4519 else
4520 {
4521 errmsg = (char_u *)N_("E521: Number required after =");
4522 goto skip;
4523 }
4524
4525 if (adding)
4526 value = *(long *)varp + value;
4527 if (prepending)
4528 value = *(long *)varp * value;
4529 if (removing)
4530 value = *(long *)varp - value;
4531 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004532 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004533 }
4534 else if (opt_idx >= 0) /* string */
4535 {
4536 char_u *save_arg = NULL;
4537 char_u *s = NULL;
4538 char_u *oldval; /* previous value if *varp */
4539 char_u *newval;
4540 char_u *origval;
4541 unsigned newlen;
4542 int comma;
4543 int bs;
4544 int new_value_alloced; /* new string option
4545 was allocated */
4546
4547 /* When using ":set opt=val" for a global option
4548 * with a local value the local value will be
4549 * reset, use the global value here. */
4550 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004551 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004552 varp = options[opt_idx].var;
4553
4554 /* The old value is kept until we are sure that the
4555 * new value is valid. */
4556 oldval = *(char_u **)varp;
4557 if (nextchar == '&') /* set to default val */
4558 {
4559 newval = options[opt_idx].def_val[
4560 ((flags & P_VI_DEF) || cp_val)
4561 ? VI_DEFAULT : VIM_DEFAULT];
4562 if ((char_u **)varp == &p_bg)
4563 {
4564 /* guess the value of 'background' */
4565#ifdef FEAT_GUI
4566 if (gui.in_use)
4567 newval = gui_bg_default();
4568 else
4569#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004570 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 }
4572
4573 /* expand environment variables and ~ (since the
4574 * default value was already expanded, only
4575 * required when an environment variable was set
4576 * later */
4577 if (newval == NULL)
4578 newval = empty_option;
4579 else
4580 {
4581 s = option_expand(opt_idx, newval);
4582 if (s == NULL)
4583 s = newval;
4584 newval = vim_strsave(s);
4585 }
4586 new_value_alloced = TRUE;
4587 }
4588 else if (nextchar == '<') /* set to global val */
4589 {
4590 newval = vim_strsave(*(char_u **)get_varp_scope(
4591 &(options[opt_idx]), OPT_GLOBAL));
4592 new_value_alloced = TRUE;
4593 }
4594 else
4595 {
4596 ++arg; /* jump to after the '=' or ':' */
4597
4598 /*
4599 * Set 'keywordprg' to ":help" if an empty
4600 * value was passed to :set by the user.
4601 * Misuse errbuf[] for the resulting string.
4602 */
4603 if (varp == (char_u *)&p_kp
4604 && (*arg == NUL || *arg == ' '))
4605 {
4606 STRCPY(errbuf, ":help");
4607 save_arg = arg;
4608 arg = errbuf;
4609 }
4610 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004611 * Convert 'backspace' number to string, for
4612 * adding, prepending and removing string.
4613 */
4614 else if (varp == (char_u *)&p_bs
4615 && VIM_ISDIGIT(**(char_u **)varp))
4616 {
4617 i = getdigits((char_u **)varp);
4618 switch (i)
4619 {
4620 case 0:
4621 *(char_u **)varp = empty_option;
4622 break;
4623 case 1:
4624 *(char_u **)varp = vim_strsave(
4625 (char_u *)"indent,eol");
4626 break;
4627 case 2:
4628 *(char_u **)varp = vim_strsave(
4629 (char_u *)"indent,eol,start");
4630 break;
4631 }
4632 vim_free(oldval);
4633 oldval = *(char_u **)varp;
4634 }
4635 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004636 * Convert 'whichwrap' number to string, for
4637 * backwards compatibility with Vim 3.0.
4638 * Misuse errbuf[] for the resulting string.
4639 */
4640 else if (varp == (char_u *)&p_ww
4641 && VIM_ISDIGIT(*arg))
4642 {
4643 *errbuf = NUL;
4644 i = getdigits(&arg);
4645 if (i & 1)
4646 STRCAT(errbuf, "b,");
4647 if (i & 2)
4648 STRCAT(errbuf, "s,");
4649 if (i & 4)
4650 STRCAT(errbuf, "h,l,");
4651 if (i & 8)
4652 STRCAT(errbuf, "<,>,");
4653 if (i & 16)
4654 STRCAT(errbuf, "[,],");
4655 if (*errbuf != NUL) /* remove trailing , */
4656 errbuf[STRLEN(errbuf) - 1] = NUL;
4657 save_arg = arg;
4658 arg = errbuf;
4659 }
4660 /*
4661 * Remove '>' before 'dir' and 'bdir', for
4662 * backwards compatibility with version 3.0
4663 */
4664 else if ( *arg == '>'
4665 && (varp == (char_u *)&p_dir
4666 || varp == (char_u *)&p_bdir))
4667 {
4668 ++arg;
4669 }
4670
4671 /* When setting the local value of a global
4672 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004673 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004674 && (opt_flags & OPT_LOCAL))
4675 origval = *(char_u **)get_varp(
4676 &options[opt_idx]);
4677 else
4678 origval = oldval;
4679
4680 /*
4681 * Copy the new string into allocated memory.
4682 * Can't use set_string_option_direct(), because
4683 * we need to remove the backslashes.
4684 */
4685 /* get a bit too much */
4686 newlen = (unsigned)STRLEN(arg) + 1;
4687 if (adding || prepending || removing)
4688 newlen += (unsigned)STRLEN(origval) + 1;
4689 newval = alloc(newlen);
4690 if (newval == NULL) /* out of mem, don't change */
4691 break;
4692 s = newval;
4693
4694 /*
4695 * Copy the string, skip over escaped chars.
4696 * For MS-DOS and WIN32 backslashes before normal
4697 * file name characters are not removed, and keep
4698 * backslash at start, for "\\machine\path", but
4699 * do remove it for "\\\\machine\\path".
4700 * The reverse is found in ExpandOldSetting().
4701 */
4702 while (*arg && !vim_iswhite(*arg))
4703 {
4704 if (*arg == '\\' && arg[1] != NUL
4705#ifdef BACKSLASH_IN_FILENAME
4706 && !((flags & P_EXPAND)
4707 && vim_isfilec(arg[1])
4708 && (arg[1] != '\\'
4709 || (s == newval
4710 && arg[2] != '\\')))
4711#endif
4712 )
4713 ++arg; /* remove backslash */
4714#ifdef FEAT_MBYTE
4715 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004716 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004717 {
4718 /* copy multibyte char */
4719 mch_memmove(s, arg, (size_t)i);
4720 arg += i;
4721 s += i;
4722 }
4723 else
4724#endif
4725 *s++ = *arg++;
4726 }
4727 *s = NUL;
4728
4729 /*
4730 * Expand environment variables and ~.
4731 * Don't do it when adding without inserting a
4732 * comma.
4733 */
4734 if (!(adding || prepending || removing)
4735 || (flags & P_COMMA))
4736 {
4737 s = option_expand(opt_idx, newval);
4738 if (s != NULL)
4739 {
4740 vim_free(newval);
4741 newlen = (unsigned)STRLEN(s) + 1;
4742 if (adding || prepending || removing)
4743 newlen += (unsigned)STRLEN(origval) + 1;
4744 newval = alloc(newlen);
4745 if (newval == NULL)
4746 break;
4747 STRCPY(newval, s);
4748 }
4749 }
4750
4751 /* locate newval[] in origval[] when removing it
4752 * and when adding to avoid duplicates */
4753 i = 0; /* init for GCC */
4754 if (removing || (flags & P_NODUP))
4755 {
4756 i = (int)STRLEN(newval);
4757 bs = 0;
4758 for (s = origval; *s; ++s)
4759 {
4760 if ((!(flags & P_COMMA)
4761 || s == origval
4762 || (s[-1] == ',' && !(bs & 1)))
4763 && STRNCMP(s, newval, i) == 0
4764 && (!(flags & P_COMMA)
4765 || s[i] == ','
4766 || s[i] == NUL))
4767 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004768 /* Count backslashes. Only a comma with an
4769 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770 * recognized as a separator */
4771 if (s > origval && s[-1] == '\\')
4772 ++bs;
4773 else
4774 bs = 0;
4775 }
4776
4777 /* do not add if already there */
4778 if ((adding || prepending) && *s)
4779 {
4780 prepending = FALSE;
4781 adding = FALSE;
4782 STRCPY(newval, origval);
4783 }
4784 }
4785
4786 /* concatenate the two strings; add a ',' if
4787 * needed */
4788 if (adding || prepending)
4789 {
4790 comma = ((flags & P_COMMA) && *origval != NUL
4791 && *newval != NUL);
4792 if (adding)
4793 {
4794 i = (int)STRLEN(origval);
4795 mch_memmove(newval + i + comma, newval,
4796 STRLEN(newval) + 1);
4797 mch_memmove(newval, origval, (size_t)i);
4798 }
4799 else
4800 {
4801 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004802 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004803 }
4804 if (comma)
4805 newval[i] = ',';
4806 }
4807
4808 /* Remove newval[] from origval[]. (Note: "i" has
4809 * been set above and is used here). */
4810 if (removing)
4811 {
4812 STRCPY(newval, origval);
4813 if (*s)
4814 {
4815 /* may need to remove a comma */
4816 if (flags & P_COMMA)
4817 {
4818 if (s == origval)
4819 {
4820 /* include comma after string */
4821 if (s[i] == ',')
4822 ++i;
4823 }
4824 else
4825 {
4826 /* include comma before string */
4827 --s;
4828 ++i;
4829 }
4830 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004831 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832 }
4833 }
4834
4835 if (flags & P_FLAGLIST)
4836 {
4837 /* Remove flags that appear twice. */
4838 for (s = newval; *s; ++s)
4839 if ((!(flags & P_COMMA) || *s != ',')
4840 && vim_strchr(s + 1, *s) != NULL)
4841 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004842 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004843 --s;
4844 }
4845 }
4846
4847 if (save_arg != NULL) /* number for 'whichwrap' */
4848 arg = save_arg;
4849 new_value_alloced = TRUE;
4850 }
4851
4852 /* Set the new value. */
4853 *(char_u **)(varp) = newval;
4854
4855 /* Handle side effects, and set the global value for
4856 * ":set" on local options. */
4857 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4858 new_value_alloced, oldval, errbuf, opt_flags);
4859
4860 /* If error detected, print the error message. */
4861 if (errmsg != NULL)
4862 goto skip;
4863 }
4864 else /* key code option */
4865 {
4866 char_u *p;
4867
4868 if (nextchar == '&')
4869 {
4870 if (add_termcap_entry(key_name, TRUE) == FAIL)
4871 errmsg = (char_u *)N_("E522: Not found in termcap");
4872 }
4873 else
4874 {
4875 ++arg; /* jump to after the '=' or ':' */
4876 for (p = arg; *p && !vim_iswhite(*p); ++p)
4877 if (*p == '\\' && p[1] != NUL)
4878 ++p;
4879 nextchar = *p;
4880 *p = NUL;
4881 add_termcode(key_name, arg, FALSE);
4882 *p = nextchar;
4883 }
4884 if (full_screen)
4885 ttest(FALSE);
4886 redraw_all_later(CLEAR);
4887 }
4888 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004889
Bram Moolenaar071d4272004-06-13 20:20:40 +00004890 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004891 did_set_option(opt_idx, opt_flags,
4892 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004893 }
4894
4895skip:
4896 /*
4897 * Advance to next argument.
4898 * - skip until a blank found, taking care of backslashes
4899 * - skip blanks
4900 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4901 */
4902 for (i = 0; i < 2 ; ++i)
4903 {
4904 while (*arg != NUL && !vim_iswhite(*arg))
4905 if (*arg++ == '\\' && *arg != NUL)
4906 ++arg;
4907 arg = skipwhite(arg);
4908 if (*arg != '=')
4909 break;
4910 }
4911 }
4912
4913 if (errmsg != NULL)
4914 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004915 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004916 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004917 if (i + (arg - startarg) < IOSIZE)
4918 {
4919 /* append the argument with the error */
4920 STRCAT(IObuff, ": ");
4921 mch_memmove(IObuff + i, startarg, (arg - startarg));
4922 IObuff[i + (arg - startarg)] = NUL;
4923 }
4924 /* make sure all characters are printable */
4925 trans_characters(IObuff, IOSIZE);
4926
4927 ++no_wait_return; /* wait_return done later */
4928 emsg(IObuff); /* show error highlighted */
4929 --no_wait_return;
4930
4931 return FAIL;
4932 }
4933
4934 arg = skipwhite(arg);
4935 }
4936
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004937theend:
4938 if (silent_mode && did_show)
4939 {
4940 /* After displaying option values in silent mode. */
4941 silent_mode = FALSE;
4942 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4943 msg_putchar('\n');
4944 cursor_on(); /* msg_start() switches it off */
4945 out_flush();
4946 silent_mode = TRUE;
4947 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4948 }
4949
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 return OK;
4951}
4952
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004953/*
4954 * Call this when an option has been given a new value through a user command.
4955 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4956 */
4957 static void
4958did_set_option(opt_idx, opt_flags, new_value)
4959 int opt_idx;
4960 int opt_flags; /* possibly with OPT_MODELINE */
4961 int new_value; /* value was replaced completely */
4962{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004963 long_u *p;
4964
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004965 options[opt_idx].flags |= P_WAS_SET;
4966
4967 /* When an option is set in the sandbox, from a modeline or in secure mode
4968 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004969 * flag. */
4970 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004971 if (secure
4972#ifdef HAVE_SANDBOX
4973 || sandbox != 0
4974#endif
4975 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004976 *p = *p | P_INSECURE;
4977 else if (new_value)
4978 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004979}
4980
Bram Moolenaar071d4272004-06-13 20:20:40 +00004981 static char_u *
4982illegal_char(errbuf, c)
4983 char_u *errbuf;
4984 int c;
4985{
4986 if (errbuf == NULL)
4987 return (char_u *)"";
4988 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004989 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004990 return errbuf;
4991}
4992
4993/*
4994 * Convert a key name or string into a key value.
4995 * Used for 'wildchar' and 'cedit' options.
4996 */
4997 static int
4998string_to_key(arg)
4999 char_u *arg;
5000{
5001 if (*arg == '<')
5002 return find_key_option(arg + 1);
5003 if (*arg == '^')
5004 return Ctrl_chr(arg[1]);
5005 return *arg;
5006}
5007
5008#ifdef FEAT_CMDWIN
5009/*
5010 * Check value of 'cedit' and set cedit_key.
5011 * Returns NULL if value is OK, error message otherwise.
5012 */
5013 static char_u *
5014check_cedit()
5015{
5016 int n;
5017
5018 if (*p_cedit == NUL)
5019 cedit_key = -1;
5020 else
5021 {
5022 n = string_to_key(p_cedit);
5023 if (vim_isprintc(n))
5024 return e_invarg;
5025 cedit_key = n;
5026 }
5027 return NULL;
5028}
5029#endif
5030
5031#ifdef FEAT_TITLE
5032/*
5033 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5034 * maketitle() to create and display it.
5035 * When switching the title or icon off, call mch_restore_title() to get
5036 * the old value back.
5037 */
5038 static void
5039did_set_title(icon)
5040 int icon; /* Did set icon instead of title */
5041{
5042 if (starting != NO_SCREEN
5043#ifdef FEAT_GUI
5044 && !gui.starting
5045#endif
5046 )
5047 {
5048 maketitle();
5049 if (icon)
5050 {
5051 if (!p_icon)
5052 mch_restore_title(2);
5053 }
5054 else
5055 {
5056 if (!p_title)
5057 mch_restore_title(1);
5058 }
5059 }
5060}
5061#endif
5062
5063/*
5064 * set_options_bin - called when 'bin' changes value.
5065 */
5066 void
5067set_options_bin(oldval, newval, opt_flags)
5068 int oldval;
5069 int newval;
5070 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5071{
5072 /*
5073 * The option values that are changed when 'bin' changes are
5074 * copied when 'bin is set and restored when 'bin' is reset.
5075 */
5076 if (newval)
5077 {
5078 if (!oldval) /* switched on */
5079 {
5080 if (!(opt_flags & OPT_GLOBAL))
5081 {
5082 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5083 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5084 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5085 curbuf->b_p_et_nobin = curbuf->b_p_et;
5086 }
5087 if (!(opt_flags & OPT_LOCAL))
5088 {
5089 p_tw_nobin = p_tw;
5090 p_wm_nobin = p_wm;
5091 p_ml_nobin = p_ml;
5092 p_et_nobin = p_et;
5093 }
5094 }
5095
5096 if (!(opt_flags & OPT_GLOBAL))
5097 {
5098 curbuf->b_p_tw = 0; /* no automatic line wrap */
5099 curbuf->b_p_wm = 0; /* no automatic line wrap */
5100 curbuf->b_p_ml = 0; /* no modelines */
5101 curbuf->b_p_et = 0; /* no expandtab */
5102 }
5103 if (!(opt_flags & OPT_LOCAL))
5104 {
5105 p_tw = 0;
5106 p_wm = 0;
5107 p_ml = FALSE;
5108 p_et = FALSE;
5109 p_bin = TRUE; /* needed when called for the "-b" argument */
5110 }
5111 }
5112 else if (oldval) /* switched off */
5113 {
5114 if (!(opt_flags & OPT_GLOBAL))
5115 {
5116 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5117 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5118 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5119 curbuf->b_p_et = curbuf->b_p_et_nobin;
5120 }
5121 if (!(opt_flags & OPT_LOCAL))
5122 {
5123 p_tw = p_tw_nobin;
5124 p_wm = p_wm_nobin;
5125 p_ml = p_ml_nobin;
5126 p_et = p_et_nobin;
5127 }
5128 }
5129}
5130
5131#ifdef FEAT_VIMINFO
5132/*
5133 * Find the parameter represented by the given character (eg ', :, ", or /),
5134 * and return its associated value in the 'viminfo' string.
5135 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005136 * If the parameter is not specified in the string or there is no following
5137 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005138 */
5139 int
5140get_viminfo_parameter(type)
5141 int type;
5142{
5143 char_u *p;
5144
5145 p = find_viminfo_parameter(type);
5146 if (p != NULL && VIM_ISDIGIT(*p))
5147 return atoi((char *)p);
5148 return -1;
5149}
5150
5151/*
5152 * Find the parameter represented by the given character (eg ''', ':', '"', or
5153 * '/') in the 'viminfo' option and return a pointer to the string after it.
5154 * Return NULL if the parameter is not specified in the string.
5155 */
5156 char_u *
5157find_viminfo_parameter(type)
5158 int type;
5159{
5160 char_u *p;
5161
5162 for (p = p_viminfo; *p; ++p)
5163 {
5164 if (*p == type)
5165 return p + 1;
5166 if (*p == 'n') /* 'n' is always the last one */
5167 break;
5168 p = vim_strchr(p, ','); /* skip until next ',' */
5169 if (p == NULL) /* hit the end without finding parameter */
5170 break;
5171 }
5172 return NULL;
5173}
5174#endif
5175
5176/*
5177 * Expand environment variables for some string options.
5178 * These string options cannot be indirect!
5179 * If "val" is NULL expand the current value of the option.
5180 * Return pointer to NameBuff, or NULL when not expanded.
5181 */
5182 static char_u *
5183option_expand(opt_idx, val)
5184 int opt_idx;
5185 char_u *val;
5186{
5187 /* if option doesn't need expansion nothing to do */
5188 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5189 return NULL;
5190
5191 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5192 * expand_env() would truncate the string. */
5193 if (val != NULL && STRLEN(val) > MAXPATHL)
5194 return NULL;
5195
5196 if (val == NULL)
5197 val = *(char_u **)options[opt_idx].var;
5198
5199 /*
5200 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5201 * Escape spaces when expanding 'tags', they are used to separate file
5202 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005203 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005204 */
5205 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005206 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005207#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005208 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5209#endif
5210 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5212 return NULL;
5213
5214 return NameBuff;
5215}
5216
5217/*
5218 * After setting various option values: recompute variables that depend on
5219 * option values.
5220 */
5221 static void
5222didset_options()
5223{
5224 /* initialize the table for 'iskeyword' et.al. */
5225 (void)init_chartab();
5226
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005227#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005229#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005230 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5231#ifdef FEAT_SESSION
5232 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5233 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5234#endif
5235#ifdef FEAT_FOLDING
5236 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5237#endif
5238 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5239#ifdef FEAT_VIRTUALEDIT
5240 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5241#endif
5242#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5243 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5244#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005245#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005246 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005247 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005248 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005249#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005250#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5251 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5252#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005253#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005254 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5255#endif
5256#ifdef FEAT_CMDWIN
5257 /* set cedit_key */
5258 (void)check_cedit();
5259#endif
5260}
5261
5262/*
5263 * Check for string options that are NULL (normally only termcap options).
5264 */
5265 void
5266check_options()
5267{
5268 int opt_idx;
5269
5270 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5271 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5272 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5273}
5274
5275/*
5276 * Check string options in a buffer for NULL value.
5277 */
5278 void
5279check_buf_options(buf)
5280 buf_T *buf;
5281{
5282#if defined(FEAT_QUICKFIX)
5283 check_string_option(&buf->b_p_bh);
5284 check_string_option(&buf->b_p_bt);
5285#endif
5286#ifdef FEAT_MBYTE
5287 check_string_option(&buf->b_p_fenc);
5288#endif
5289 check_string_option(&buf->b_p_ff);
5290#ifdef FEAT_FIND_ID
5291 check_string_option(&buf->b_p_def);
5292 check_string_option(&buf->b_p_inc);
5293# ifdef FEAT_EVAL
5294 check_string_option(&buf->b_p_inex);
5295# endif
5296#endif
5297#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5298 check_string_option(&buf->b_p_inde);
5299 check_string_option(&buf->b_p_indk);
5300#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005301#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5302 check_string_option(&buf->b_p_bexpr);
5303#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005304#if defined(FEAT_CRYPT)
5305 check_string_option(&buf->b_p_cm);
5306#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005307#if defined(FEAT_EVAL)
5308 check_string_option(&buf->b_p_fex);
5309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310#ifdef FEAT_CRYPT
5311 check_string_option(&buf->b_p_key);
5312#endif
5313 check_string_option(&buf->b_p_kp);
5314 check_string_option(&buf->b_p_mps);
5315 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005316 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317 check_string_option(&buf->b_p_isk);
5318#ifdef FEAT_COMMENTS
5319 check_string_option(&buf->b_p_com);
5320#endif
5321#ifdef FEAT_FOLDING
5322 check_string_option(&buf->b_p_cms);
5323#endif
5324 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005325#ifdef FEAT_TEXTOBJ
5326 check_string_option(&buf->b_p_qe);
5327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328#ifdef FEAT_SYN_HL
5329 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005330#endif
5331#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005332 check_string_option(&buf->b_s.b_p_spc);
5333 check_string_option(&buf->b_s.b_p_spf);
5334 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335#endif
5336#ifdef FEAT_SEARCHPATH
5337 check_string_option(&buf->b_p_sua);
5338#endif
5339#ifdef FEAT_CINDENT
5340 check_string_option(&buf->b_p_cink);
5341 check_string_option(&buf->b_p_cino);
5342#endif
5343#ifdef FEAT_AUTOCMD
5344 check_string_option(&buf->b_p_ft);
5345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5347 check_string_option(&buf->b_p_cinw);
5348#endif
5349#ifdef FEAT_INS_EXPAND
5350 check_string_option(&buf->b_p_cpt);
5351#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005352#ifdef FEAT_COMPL_FUNC
5353 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005354 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356#ifdef FEAT_KEYMAP
5357 check_string_option(&buf->b_p_keymap);
5358#endif
5359#ifdef FEAT_QUICKFIX
5360 check_string_option(&buf->b_p_gp);
5361 check_string_option(&buf->b_p_mp);
5362 check_string_option(&buf->b_p_efm);
5363#endif
5364 check_string_option(&buf->b_p_ep);
5365 check_string_option(&buf->b_p_path);
5366 check_string_option(&buf->b_p_tags);
5367#ifdef FEAT_INS_EXPAND
5368 check_string_option(&buf->b_p_dict);
5369 check_string_option(&buf->b_p_tsr);
5370#endif
5371}
5372
5373/*
5374 * Free the string allocated for an option.
5375 * Checks for the string being empty_option. This may happen if we're out of
5376 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5377 * check_options().
5378 * Does NOT check for P_ALLOCED flag!
5379 */
5380 void
5381free_string_option(p)
5382 char_u *p;
5383{
5384 if (p != empty_option)
5385 vim_free(p);
5386}
5387
5388 void
5389clear_string_option(pp)
5390 char_u **pp;
5391{
5392 if (*pp != empty_option)
5393 vim_free(*pp);
5394 *pp = empty_option;
5395}
5396
5397 static void
5398check_string_option(pp)
5399 char_u **pp;
5400{
5401 if (*pp == NULL)
5402 *pp = empty_option;
5403}
5404
5405/*
5406 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5407 */
5408 void
5409set_term_option_alloced(p)
5410 char_u **p;
5411{
5412 int opt_idx;
5413
5414 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5415 if (options[opt_idx].var == (char_u *)p)
5416 {
5417 options[opt_idx].flags |= P_ALLOCED;
5418 return;
5419 }
5420 return; /* cannot happen: didn't find it! */
5421}
5422
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005423#if defined(FEAT_EVAL) || defined(PROTO)
5424/*
5425 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5426 * Return FALSE when it wasn't.
5427 * Return -1 for an unknown option.
5428 */
5429 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005430was_set_insecurely(opt, opt_flags)
5431 char_u *opt;
5432 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005433{
5434 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005435 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005436
5437 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005438 {
5439 flagp = insecure_flag(idx, opt_flags);
5440 return (*flagp & P_INSECURE) != 0;
5441 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005442 EMSG2(_(e_intern2), "was_set_insecurely()");
5443 return -1;
5444}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005445
5446/*
5447 * Get a pointer to the flags used for the P_INSECURE flag of option
5448 * "opt_idx". For some local options a local flags field is used.
5449 */
5450 static long_u *
5451insecure_flag(opt_idx, opt_flags)
5452 int opt_idx;
5453 int opt_flags;
5454{
5455 if (opt_flags & OPT_LOCAL)
5456 switch ((int)options[opt_idx].indir)
5457 {
5458#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005459 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005460#endif
5461#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005462# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005463 case PV_FDE: return &curwin->w_p_fde_flags;
5464 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005465# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005466# ifdef FEAT_BEVAL
5467 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5468# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005469# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005470 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005471# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005472 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005473# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005474 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005475# endif
5476#endif
5477 }
5478
5479 /* Nothing special, return global flags field. */
5480 return &options[opt_idx].flags;
5481}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005482#endif
5483
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005484#ifdef FEAT_TITLE
5485static void redraw_titles __ARGS((void));
5486
5487/*
5488 * Redraw the window title and/or tab page text later.
5489 */
5490static void redraw_titles()
5491{
5492 need_maketitle = TRUE;
5493# ifdef FEAT_WINDOWS
5494 redraw_tabline = TRUE;
5495# endif
5496}
5497#endif
5498
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499/*
5500 * Set a string option to a new value (without checking the effect).
5501 * The string is copied into allocated memory.
5502 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005503 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005504 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005505 */
5506 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005507set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508 char_u *name;
5509 int opt_idx;
5510 char_u *val;
5511 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005512 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513{
5514 char_u *s;
5515 char_u **varp;
5516 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005517 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518
Bram Moolenaar89d40322006-08-29 15:30:07 +00005519 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005521 idx = findoption(name);
5522 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005523 {
5524 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005526 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527 }
5528
Bram Moolenaar89d40322006-08-29 15:30:07 +00005529 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005530 return;
5531
5532 s = vim_strsave(val);
5533 if (s != NULL)
5534 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005535 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005537 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005538 free_string_option(*varp);
5539 *varp = s;
5540
5541 /* For buffer/window local option may also set the global value. */
5542 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005543 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544
Bram Moolenaar89d40322006-08-29 15:30:07 +00005545 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546
5547 /* When setting both values of a global option with a local value,
5548 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005549 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550 {
5551 free_string_option(*varp);
5552 *varp = empty_option;
5553 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005554# ifdef FEAT_EVAL
5555 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005556 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005557 set_sid == 0 ? current_SID : set_sid);
5558# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559 }
5560}
5561
5562/*
5563 * Set global value for string option when it's a local option.
5564 */
5565 static void
5566set_string_option_global(opt_idx, varp)
5567 int opt_idx; /* option index */
5568 char_u **varp; /* pointer to option variable */
5569{
5570 char_u **p, *s;
5571
5572 /* the global value is always allocated */
5573 if (options[opt_idx].var == VAR_WIN)
5574 p = (char_u **)GLOBAL_WO(varp);
5575 else
5576 p = (char_u **)options[opt_idx].var;
5577 if (options[opt_idx].indir != PV_NONE
5578 && p != varp
5579 && (s = vim_strsave(*varp)) != NULL)
5580 {
5581 free_string_option(*p);
5582 *p = s;
5583 }
5584}
5585
5586/*
5587 * Set a string option to a new value, and handle the effects.
5588 */
5589 static void
5590set_string_option(opt_idx, value, opt_flags)
5591 int opt_idx;
5592 char_u *value;
5593 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5594{
5595 char_u *s;
5596 char_u **varp;
5597 char_u *oldval;
5598
5599 if (options[opt_idx].var == NULL) /* don't set hidden option */
5600 return;
5601
5602 s = vim_strsave(value);
5603 if (s != NULL)
5604 {
5605 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5606 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005607 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005608 ? OPT_GLOBAL : OPT_LOCAL)
5609 : opt_flags);
5610 oldval = *varp;
5611 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005612 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5613 opt_flags) == NULL)
5614 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615 }
5616}
5617
5618/*
5619 * Handle string options that need some action to perform when changed.
5620 * Returns NULL for success, or an error message for an error.
5621 */
5622 static char_u *
5623did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5624 opt_flags)
5625 int opt_idx; /* index in options[] table */
5626 char_u **varp; /* pointer to the option variable */
5627 int new_value_alloced; /* new value was allocated */
5628 char_u *oldval; /* previous value of the option */
5629 char_u *errbuf; /* buffer for errors, or NULL */
5630 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5631{
5632 char_u *errmsg = NULL;
5633 char_u *s, *p;
5634 int did_chartab = FALSE;
5635 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005636 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005637#ifdef FEAT_GUI
5638 /* set when changing an option that only requires a redraw in the GUI */
5639 int redraw_gui_only = FALSE;
5640#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005641
5642 /* Get the global option to compare with, otherwise we would have to check
5643 * two values for all local options. */
5644 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5645
5646 /* Disallow changing some options from secure mode */
5647 if ((secure
5648#ifdef HAVE_SANDBOX
5649 || sandbox != 0
5650#endif
5651 ) && (options[opt_idx].flags & P_SECURE))
5652 {
5653 errmsg = e_secure;
5654 }
5655
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005656 /* Check for a "normal" file name in some options. Disallow a path
5657 * separator (slash and/or backslash), wildcards and characters that are
5658 * often illegal in a file name. */
5659 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005660 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005661 {
5662 errmsg = e_invarg;
5663 }
5664
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665 /* 'term' */
5666 else if (varp == &T_NAME)
5667 {
5668 if (T_NAME[0] == NUL)
5669 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5670#ifdef FEAT_GUI
5671 if (gui.in_use)
5672 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5673 else if (term_is_gui(T_NAME))
5674 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5675#endif
5676 else if (set_termname(T_NAME) == FAIL)
5677 errmsg = (char_u *)N_("E522: Not found in termcap");
5678 else
5679 /* Screen colors may have changed. */
5680 redraw_later_clear();
5681 }
5682
5683 /* 'backupcopy' */
5684 else if (varp == &p_bkc)
5685 {
5686 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5687 errmsg = e_invarg;
5688 if (((bkc_flags & BKC_AUTO) != 0)
5689 + ((bkc_flags & BKC_YES) != 0)
5690 + ((bkc_flags & BKC_NO) != 0) != 1)
5691 {
5692 /* Must have exactly one of "auto", "yes" and "no". */
5693 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5694 errmsg = e_invarg;
5695 }
5696 }
5697
5698 /* 'backupext' and 'patchmode' */
5699 else if (varp == &p_bex || varp == &p_pm)
5700 {
5701 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5702 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5703 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5704 }
5705
5706 /*
5707 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5708 * If the new option is invalid, use old value. 'lisp' option: refill
5709 * chartab[] for '-' char
5710 */
5711 else if ( varp == &p_isi
5712 || varp == &(curbuf->b_p_isk)
5713 || varp == &p_isp
5714 || varp == &p_isf)
5715 {
5716 if (init_chartab() == FAIL)
5717 {
5718 did_chartab = TRUE; /* need to restore it below */
5719 errmsg = e_invarg; /* error in value */
5720 }
5721 }
5722
5723 /* 'helpfile' */
5724 else if (varp == &p_hf)
5725 {
5726 /* May compute new values for $VIM and $VIMRUNTIME */
5727 if (didset_vim)
5728 {
5729 vim_setenv((char_u *)"VIM", (char_u *)"");
5730 didset_vim = FALSE;
5731 }
5732 if (didset_vimruntime)
5733 {
5734 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5735 didset_vimruntime = FALSE;
5736 }
5737 }
5738
Bram Moolenaar1a384422010-07-14 19:53:30 +02005739#ifdef FEAT_SYN_HL
5740 /* 'colorcolumn' */
5741 else if (varp == &curwin->w_p_cc)
5742 errmsg = check_colorcolumn(curwin);
5743#endif
5744
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745#ifdef FEAT_MULTI_LANG
5746 /* 'helplang' */
5747 else if (varp == &p_hlg)
5748 {
5749 /* Check for "", "ab", "ab,cd", etc. */
5750 for (s = p_hlg; *s != NUL; s += 3)
5751 {
5752 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5753 {
5754 errmsg = e_invarg;
5755 break;
5756 }
5757 if (s[2] == NUL)
5758 break;
5759 }
5760 }
5761#endif
5762
5763 /* 'highlight' */
5764 else if (varp == &p_hl)
5765 {
5766 if (highlight_changed() == FAIL)
5767 errmsg = e_invarg; /* invalid flags */
5768 }
5769
5770 /* 'nrformats' */
5771 else if (gvarp == &p_nf)
5772 {
5773 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5774 errmsg = e_invarg;
5775 }
5776
5777#ifdef FEAT_SESSION
5778 /* 'sessionoptions' */
5779 else if (varp == &p_ssop)
5780 {
5781 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5782 errmsg = e_invarg;
5783 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5784 {
5785 /* Don't allow both "sesdir" and "curdir". */
5786 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5787 errmsg = e_invarg;
5788 }
5789 }
5790 /* 'viewoptions' */
5791 else if (varp == &p_vop)
5792 {
5793 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5794 errmsg = e_invarg;
5795 }
5796#endif
5797
5798 /* 'scrollopt' */
5799#ifdef FEAT_SCROLLBIND
5800 else if (varp == &p_sbo)
5801 {
5802 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5803 errmsg = e_invarg;
5804 }
5805#endif
5806
5807 /* 'ambiwidth' */
5808#ifdef FEAT_MBYTE
5809 else if (varp == &p_ambw)
5810 {
5811 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5812 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005813 else if (set_chars_option(&p_lcs) != NULL)
5814 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5815# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5816 else if (set_chars_option(&p_fcs) != NULL)
5817 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5818# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005819 }
5820#endif
5821
5822 /* 'background' */
5823 else if (varp == &p_bg)
5824 {
5825 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5826 {
5827#ifdef FEAT_EVAL
5828 int dark = (*p_bg == 'd');
5829#endif
5830
5831 init_highlight(FALSE, FALSE);
5832
5833#ifdef FEAT_EVAL
5834 if (dark != (*p_bg == 'd')
5835 && get_var_value((char_u *)"g:colors_name") != NULL)
5836 {
5837 /* The color scheme must have set 'background' back to another
5838 * value, that's not what we want here. Disable the color
5839 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005840 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841 free_string_option(p_bg);
5842 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5843 check_string_option(&p_bg);
5844 init_highlight(FALSE, FALSE);
5845 }
5846#endif
5847 }
5848 else
5849 errmsg = e_invarg;
5850 }
5851
5852 /* 'wildmode' */
5853 else if (varp == &p_wim)
5854 {
5855 if (check_opt_wim() == FAIL)
5856 errmsg = e_invarg;
5857 }
5858
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005859#ifdef FEAT_CMDL_COMPL
5860 /* 'wildoptions' */
5861 else if (varp == &p_wop)
5862 {
5863 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5864 errmsg = e_invarg;
5865 }
5866#endif
5867
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868#ifdef FEAT_WAK
5869 /* 'winaltkeys' */
5870 else if (varp == &p_wak)
5871 {
5872 if (*p_wak == NUL
5873 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5874 errmsg = e_invarg;
5875# ifdef FEAT_MENU
5876# ifdef FEAT_GUI_MOTIF
5877 else if (gui.in_use)
5878 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5879# else
5880# ifdef FEAT_GUI_GTK
5881 else if (gui.in_use)
5882 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5883# endif
5884# endif
5885# endif
5886 }
5887#endif
5888
5889#ifdef FEAT_AUTOCMD
5890 /* 'eventignore' */
5891 else if (varp == &p_ei)
5892 {
5893 if (check_ei() == FAIL)
5894 errmsg = e_invarg;
5895 }
5896#endif
5897
5898#ifdef FEAT_MBYTE
5899 /* 'encoding' and 'fileencoding' */
5900 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5901 {
5902 if (gvarp == &p_fenc)
5903 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005904 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905 errmsg = e_modifiable;
5906 else if (vim_strchr(*varp, ',') != NULL)
5907 /* No comma allowed in 'fileencoding'; catches confusing it
5908 * with 'fileencodings'. */
5909 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005911 {
5912# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005914 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005915# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005916 /* Add 'fileencoding' to the swap file. */
5917 ml_setflags(curbuf);
5918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 }
5920 if (errmsg == NULL)
5921 {
5922 /* canonize the value, so that STRCMP() can be used on it */
5923 p = enc_canonize(*varp);
5924 if (p != NULL)
5925 {
5926 vim_free(*varp);
5927 *varp = p;
5928 }
5929 if (varp == &p_enc)
5930 {
5931 errmsg = mb_init();
5932# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005933 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934# endif
5935 }
5936 }
5937
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005938# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5940 {
5941 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5942 if (STRCMP(p_tenc, "utf-8") != 0)
5943 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5944 }
5945# endif
5946
5947 if (errmsg == NULL)
5948 {
5949# ifdef FEAT_KEYMAP
5950 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5951 * (with another encoding). */
5952 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5953 (void)keymap_init();
5954# endif
5955
5956 /* When 'termencoding' is not empty and 'encoding' changes or when
5957 * 'termencoding' changes, need to setup for keyboard input and
5958 * display output conversion. */
5959 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5960 {
5961 convert_setup(&input_conv, p_tenc, p_enc);
5962 convert_setup(&output_conv, p_enc, p_tenc);
5963 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005964
5965# if defined(WIN3264) && defined(FEAT_MBYTE)
5966 /* $HOME may have characters in active code page. */
5967 if (varp == &p_enc)
5968 init_homedir();
5969# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005970 }
5971 }
5972#endif
5973
5974#if defined(FEAT_POSTSCRIPT)
5975 else if (varp == &p_penc)
5976 {
5977 /* Canonize printencoding if VIM standard one */
5978 p = enc_canonize(p_penc);
5979 if (p != NULL)
5980 {
5981 vim_free(p_penc);
5982 p_penc = p;
5983 }
5984 else
5985 {
5986 /* Ensure lower case and '-' for '_' */
5987 for (s = p_penc; *s != NUL; s++)
5988 {
5989 if (*s == '_')
5990 *s = '-';
5991 else
5992 *s = TOLOWER_ASC(*s);
5993 }
5994 }
5995 }
5996#endif
5997
Bram Moolenaar9372a112005-12-06 19:59:18 +00005998#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999 else if (varp == &p_imak)
6000 {
6001 if (gui.in_use && !im_xim_isvalid_imactivate())
6002 errmsg = e_invarg;
6003 }
6004#endif
6005
6006#ifdef FEAT_KEYMAP
6007 else if (varp == &curbuf->b_p_keymap)
6008 {
6009 /* load or unload key mapping tables */
6010 errmsg = keymap_init();
6011
Bram Moolenaarfab06232009-03-04 03:13:35 +00006012 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006013 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006014 if (*curbuf->b_p_keymap != NUL)
6015 {
6016 /* Installed a new keymap, switch on using it. */
6017 curbuf->b_p_iminsert = B_IMODE_LMAP;
6018 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6019 curbuf->b_p_imsearch = B_IMODE_LMAP;
6020 }
6021 else
6022 {
6023 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6024 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6025 curbuf->b_p_iminsert = B_IMODE_NONE;
6026 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6027 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6028 }
6029 if ((opt_flags & OPT_LOCAL) == 0)
6030 {
6031 set_iminsert_global();
6032 set_imsearch_global();
6033 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006034# ifdef FEAT_WINDOWS
6035 status_redraw_curbuf();
6036# endif
6037 }
6038 }
6039#endif
6040
6041 /* 'fileformat' */
6042 else if (gvarp == &p_ff)
6043 {
6044 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6045 errmsg = e_modifiable;
6046 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6047 errmsg = e_invarg;
6048 else
6049 {
6050 /* may also change 'textmode' */
6051 if (get_fileformat(curbuf) == EOL_DOS)
6052 curbuf->b_p_tx = TRUE;
6053 else
6054 curbuf->b_p_tx = FALSE;
6055#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006056 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006057#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006058 /* update flag in swap file */
6059 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006060 /* Redraw needed when switching to/from "mac": a CR in the text
6061 * will be displayed differently. */
6062 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6063 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006064 }
6065 }
6066
6067 /* 'fileformats' */
6068 else if (varp == &p_ffs)
6069 {
6070 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6071 errmsg = e_invarg;
6072 else
6073 {
6074 /* also change 'textauto' */
6075 if (*p_ffs == NUL)
6076 p_ta = FALSE;
6077 else
6078 p_ta = TRUE;
6079 }
6080 }
6081
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006082#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083 /* 'cryptkey' */
6084 else if (gvarp == &p_key)
6085 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006086# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087 /* Make sure the ":set" command doesn't show the new value in the
6088 * history. */
6089 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006090# endif
6091 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6092 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006093 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6094 }
6095
6096 else if (gvarp == &p_cm)
6097 {
6098 if (opt_flags & OPT_LOCAL)
6099 p = curbuf->b_p_cm;
6100 else
6101 p = p_cm;
6102 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6103 errmsg = e_invarg;
6104 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6105 errmsg = e_invarg;
6106 else
6107 {
6108 /* When setting the global value to empty, make it "zip". */
6109 if (*p_cm == NUL)
6110 {
6111 if (new_value_alloced)
6112 free_string_option(p_cm);
6113 p_cm = vim_strsave((char_u *)"zip");
6114 new_value_alloced = TRUE;
6115 }
6116
6117 /* Need to update the swapfile when the effective method changed.
6118 * Set "s" to the effective old value, "p" to the effective new
6119 * method and compare. */
6120 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6121 s = p_cm; /* was previously using the global value */
6122 else
6123 s = oldval;
6124 if (*curbuf->b_p_cm == NUL)
6125 p = p_cm; /* is now using the global value */
6126 else
6127 p = curbuf->b_p_cm;
6128 if (STRCMP(s, p) != 0)
6129 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6130 crypt_method_from_string(s));
6131
6132 /* If the global value changes need to update the swapfile for all
6133 * buffers using that value. */
6134 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6135 {
6136 buf_T *buf;
6137
6138 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6139 if (buf != curbuf && *buf->b_p_cm == NUL)
6140 ml_set_crypt_key(buf, buf->b_p_key,
6141 crypt_method_from_string(oldval));
6142 }
6143 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144 }
6145#endif
6146
6147 /* 'matchpairs' */
6148 else if (gvarp == &p_mps)
6149 {
6150 /* Check for "x:y,x:y" */
6151 for (p = *varp; *p != NUL; p += 4)
6152 {
6153 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6154 {
6155 errmsg = e_invarg;
6156 break;
6157 }
6158 if (p[3] == NUL)
6159 break;
6160 }
6161 }
6162
6163#ifdef FEAT_COMMENTS
6164 /* 'comments' */
6165 else if (gvarp == &p_com)
6166 {
6167 for (s = *varp; *s; )
6168 {
6169 while (*s && *s != ':')
6170 {
6171 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6172 && !VIM_ISDIGIT(*s) && *s != '-')
6173 {
6174 errmsg = illegal_char(errbuf, *s);
6175 break;
6176 }
6177 ++s;
6178 }
6179 if (*s++ == NUL)
6180 errmsg = (char_u *)N_("E524: Missing colon");
6181 else if (*s == ',' || *s == NUL)
6182 errmsg = (char_u *)N_("E525: Zero length string");
6183 if (errmsg != NULL)
6184 break;
6185 while (*s && *s != ',')
6186 {
6187 if (*s == '\\' && s[1] != NUL)
6188 ++s;
6189 ++s;
6190 }
6191 s = skip_to_option_part(s);
6192 }
6193 }
6194#endif
6195
6196 /* 'listchars' */
6197 else if (varp == &p_lcs)
6198 {
6199 errmsg = set_chars_option(varp);
6200 }
6201
6202#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6203 /* 'fillchars' */
6204 else if (varp == &p_fcs)
6205 {
6206 errmsg = set_chars_option(varp);
6207 }
6208#endif
6209
6210#ifdef FEAT_CMDWIN
6211 /* 'cedit' */
6212 else if (varp == &p_cedit)
6213 {
6214 errmsg = check_cedit();
6215 }
6216#endif
6217
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006218 /* 'verbosefile' */
6219 else if (varp == &p_vfile)
6220 {
6221 verbose_stop();
6222 if (*p_vfile != NUL && verbose_open() == FAIL)
6223 errmsg = e_invarg;
6224 }
6225
Bram Moolenaar071d4272004-06-13 20:20:40 +00006226#ifdef FEAT_VIMINFO
6227 /* 'viminfo' */
6228 else if (varp == &p_viminfo)
6229 {
6230 for (s = p_viminfo; *s;)
6231 {
6232 /* Check it's a valid character */
6233 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6234 {
6235 errmsg = illegal_char(errbuf, *s);
6236 break;
6237 }
6238 if (*s == 'n') /* name is always last one */
6239 {
6240 break;
6241 }
6242 else if (*s == 'r') /* skip until next ',' */
6243 {
6244 while (*++s && *s != ',')
6245 ;
6246 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006247 else if (*s == '%')
6248 {
6249 /* optional number */
6250 while (vim_isdigit(*++s))
6251 ;
6252 }
6253 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254 ++s; /* no extra chars */
6255 else /* must have a number */
6256 {
6257 while (vim_isdigit(*++s))
6258 ;
6259
6260 if (!VIM_ISDIGIT(*(s - 1)))
6261 {
6262 if (errbuf != NULL)
6263 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006264 sprintf((char *)errbuf,
6265 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266 transchar_byte(*(s - 1)));
6267 errmsg = errbuf;
6268 }
6269 else
6270 errmsg = (char_u *)"";
6271 break;
6272 }
6273 }
6274 if (*s == ',')
6275 ++s;
6276 else if (*s)
6277 {
6278 if (errbuf != NULL)
6279 errmsg = (char_u *)N_("E527: Missing comma");
6280 else
6281 errmsg = (char_u *)"";
6282 break;
6283 }
6284 }
6285 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6286 errmsg = (char_u *)N_("E528: Must specify a ' value");
6287 }
6288#endif /* FEAT_VIMINFO */
6289
6290 /* terminal options */
6291 else if (istermoption(&options[opt_idx]) && full_screen)
6292 {
6293 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6294 if (varp == &T_CCO)
6295 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006296 int colors = atoi((char *)T_CCO);
6297
6298 /* Only reinitialize colors if t_Co value has really changed to
6299 * avoid expensive reload of colorscheme if t_Co is set to the
6300 * same value multiple times. */
6301 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006302 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006303 t_colors = colors;
6304 if (t_colors <= 1)
6305 {
6306 if (new_value_alloced)
6307 vim_free(T_CCO);
6308 T_CCO = empty_option;
6309 }
6310 /* We now have a different color setup, initialize it again. */
6311 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313 }
6314 ttest(FALSE);
6315 if (varp == &T_ME)
6316 {
6317 out_str(T_ME);
6318 redraw_later(CLEAR);
6319#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6320 /* Since t_me has been set, this probably means that the user
6321 * wants to use this as default colors. Need to reset default
6322 * background/foreground colors. */
6323 mch_set_normal_colors();
6324#endif
6325 }
6326 }
6327
6328#ifdef FEAT_LINEBREAK
6329 /* 'showbreak' */
6330 else if (varp == &p_sbr)
6331 {
6332 for (s = p_sbr; *s; )
6333 {
6334 if (ptr2cells(s) != 1)
6335 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006336 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337 }
6338 }
6339#endif
6340
6341#ifdef FEAT_GUI
6342 /* 'guifont' */
6343 else if (varp == &p_guifont)
6344 {
6345 if (gui.in_use)
6346 {
6347 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006348# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006349 /*
6350 * Put up a font dialog and let the user select a new value.
6351 * If this is cancelled go back to the old value but don't
6352 * give an error message.
6353 */
6354 if (STRCMP(p, "*") == 0)
6355 {
6356 p = gui_mch_font_dialog(oldval);
6357
6358 if (new_value_alloced)
6359 free_string_option(p_guifont);
6360
6361 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6362 new_value_alloced = TRUE;
6363 }
6364# endif
6365 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6366 {
6367# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6368 if (STRCMP(p_guifont, "*") == 0)
6369 {
6370 /* Dialog was cancelled: Keep the old value without giving
6371 * an error message. */
6372 if (new_value_alloced)
6373 free_string_option(p_guifont);
6374 p_guifont = vim_strsave(oldval);
6375 new_value_alloced = TRUE;
6376 }
6377 else
6378# endif
6379 errmsg = (char_u *)N_("E596: Invalid font(s)");
6380 }
6381 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006382 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 }
6384# ifdef FEAT_XFONTSET
6385 else if (varp == &p_guifontset)
6386 {
6387 if (STRCMP(p_guifontset, "*") == 0)
6388 errmsg = (char_u *)N_("E597: can't select fontset");
6389 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6390 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006391 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 }
6393# endif
6394# ifdef FEAT_MBYTE
6395 else if (varp == &p_guifontwide)
6396 {
6397 if (STRCMP(p_guifontwide, "*") == 0)
6398 errmsg = (char_u *)N_("E533: can't select wide font");
6399 else if (gui_get_wide_font() == FAIL)
6400 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006401 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402 }
6403# endif
6404#endif
6405
6406#ifdef CURSOR_SHAPE
6407 /* 'guicursor' */
6408 else if (varp == &p_guicursor)
6409 errmsg = parse_shape_opt(SHAPE_CURSOR);
6410#endif
6411
6412#ifdef FEAT_MOUSESHAPE
6413 /* 'mouseshape' */
6414 else if (varp == &p_mouseshape)
6415 {
6416 errmsg = parse_shape_opt(SHAPE_MOUSE);
6417 update_mouseshape(-1);
6418 }
6419#endif
6420
6421#ifdef FEAT_PRINTER
6422 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006423 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006424# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006425 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006426 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006427# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428#endif
6429
6430#ifdef FEAT_LANGMAP
6431 /* 'langmap' */
6432 else if (varp == &p_langmap)
6433 langmap_set();
6434#endif
6435
6436#ifdef FEAT_LINEBREAK
6437 /* 'breakat' */
6438 else if (varp == &p_breakat)
6439 fill_breakat_flags();
6440#endif
6441
6442#ifdef FEAT_TITLE
6443 /* 'titlestring' and 'iconstring' */
6444 else if (varp == &p_titlestring || varp == &p_iconstring)
6445 {
6446# ifdef FEAT_STL_OPT
6447 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6448
6449 /* NULL => statusline syntax */
6450 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6451 stl_syntax |= flagval;
6452 else
6453 stl_syntax &= ~flagval;
6454# endif
6455 did_set_title(varp == &p_iconstring);
6456
6457 }
6458#endif
6459
6460#ifdef FEAT_GUI
6461 /* 'guioptions' */
6462 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006463 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006464 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006465 redraw_gui_only = TRUE;
6466 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467#endif
6468
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006469#if defined(FEAT_GUI_TABLINE)
6470 /* 'guitablabel' */
6471 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006472 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006473 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006474 redraw_gui_only = TRUE;
6475 }
6476 /* 'guitabtooltip' */
6477 else if (varp == &p_gtt)
6478 {
6479 redraw_gui_only = TRUE;
6480 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006481#endif
6482
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6484 /* 'ttymouse' */
6485 else if (varp == &p_ttym)
6486 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006487 /* Switch the mouse off before changing the escape sequences used for
6488 * that. */
6489 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6491 errmsg = e_invarg;
6492 else
6493 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006494 if (termcap_active)
6495 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496 }
6497#endif
6498
6499#ifdef FEAT_VISUAL
6500 /* 'selection' */
6501 else if (varp == &p_sel)
6502 {
6503 if (*p_sel == NUL
6504 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6505 errmsg = e_invarg;
6506 }
6507
6508 /* 'selectmode' */
6509 else if (varp == &p_slm)
6510 {
6511 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6512 errmsg = e_invarg;
6513 }
6514#endif
6515
6516#ifdef FEAT_BROWSE
6517 /* 'browsedir' */
6518 else if (varp == &p_bsdir)
6519 {
6520 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6521 && !mch_isdir(p_bsdir))
6522 errmsg = e_invarg;
6523 }
6524#endif
6525
6526#ifdef FEAT_VISUAL
6527 /* 'keymodel' */
6528 else if (varp == &p_km)
6529 {
6530 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6531 errmsg = e_invarg;
6532 else
6533 {
6534 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6535 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6536 }
6537 }
6538#endif
6539
6540 /* 'mousemodel' */
6541 else if (varp == &p_mousem)
6542 {
6543 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6544 errmsg = e_invarg;
6545#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6546 else if (*p_mousem != *oldval)
6547 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6548 * to create or delete the popup menus. */
6549 gui_motif_update_mousemodel(root_menu);
6550#endif
6551 }
6552
6553 /* 'switchbuf' */
6554 else if (varp == &p_swb)
6555 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006556 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 errmsg = e_invarg;
6558 }
6559
6560 /* 'debug' */
6561 else if (varp == &p_debug)
6562 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006563 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006564 errmsg = e_invarg;
6565 }
6566
6567 /* 'display' */
6568 else if (varp == &p_dy)
6569 {
6570 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6571 errmsg = e_invarg;
6572 else
6573 (void)init_chartab();
6574
6575 }
6576
6577#ifdef FEAT_VERTSPLIT
6578 /* 'eadirection' */
6579 else if (varp == &p_ead)
6580 {
6581 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6582 errmsg = e_invarg;
6583 }
6584#endif
6585
6586#ifdef FEAT_CLIPBOARD
6587 /* 'clipboard' */
6588 else if (varp == &p_cb)
6589 errmsg = check_clipboard_option();
6590#endif
6591
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006592#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006593 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6594 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006595 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006596 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006597 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006598 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006599
Bram Moolenaar860cae12010-06-05 23:22:07 +02006600 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006601 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006602 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6603 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006604 ".add") != 0))
6605 errmsg = e_invarg;
6606 }
6607
6608 if (errmsg == NULL)
6609 {
6610 FOR_ALL_WINDOWS(wp)
6611 if (wp->w_buffer == curbuf && wp->w_p_spell)
6612 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006613 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006614# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006615 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006616# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006617 }
6618 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006619 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006620 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006621 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006622 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006623 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006624 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006625 /* 'spellsuggest' */
6626 else if (varp == &p_sps)
6627 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006628 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006629 errmsg = e_invarg;
6630 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006631 /* 'mkspellmem' */
6632 else if (varp == &p_msm)
6633 {
6634 if (spell_check_msm() != OK)
6635 errmsg = e_invarg;
6636 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006637#endif
6638
Bram Moolenaar071d4272004-06-13 20:20:40 +00006639#ifdef FEAT_QUICKFIX
6640 /* When 'bufhidden' is set, check for valid value. */
6641 else if (gvarp == &p_bh)
6642 {
6643 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6644 errmsg = e_invarg;
6645 }
6646
6647 /* When 'buftype' is set, check for valid value. */
6648 else if (gvarp == &p_bt)
6649 {
6650 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6651 errmsg = e_invarg;
6652 else
6653 {
6654# ifdef FEAT_WINDOWS
6655 if (curwin->w_status_height)
6656 {
6657 curwin->w_redr_status = TRUE;
6658 redraw_later(VALID);
6659 }
6660# endif
6661 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006662# ifdef FEAT_TITLE
6663 redraw_titles();
6664# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665 }
6666 }
6667#endif
6668
6669#ifdef FEAT_STL_OPT
6670 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006671 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006672 {
6673 int wid;
6674
6675 if (varp == &p_ruf) /* reset ru_wid first */
6676 ru_wid = 0;
6677 s = *varp;
6678 if (varp == &p_ruf && *s == '%')
6679 {
6680 /* set ru_wid if 'ruf' starts with "%99(" */
6681 if (*++s == '-') /* ignore a '-' */
6682 s++;
6683 wid = getdigits(&s);
6684 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6685 ru_wid = wid;
6686 else
6687 errmsg = check_stl_option(p_ruf);
6688 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006689 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006690 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006691 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006692 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006693 comp_col();
6694 }
6695#endif
6696
6697#ifdef FEAT_INS_EXPAND
6698 /* check if it is a valid value for 'complete' -- Acevedo */
6699 else if (gvarp == &p_cpt)
6700 {
6701 for (s = *varp; *s;)
6702 {
6703 while(*s == ',' || *s == ' ')
6704 s++;
6705 if (!*s)
6706 break;
6707 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6708 {
6709 errmsg = illegal_char(errbuf, *s);
6710 break;
6711 }
6712 if (*++s != NUL && *s != ',' && *s != ' ')
6713 {
6714 if (s[-1] == 'k' || s[-1] == 's')
6715 {
6716 /* skip optional filename after 'k' and 's' */
6717 while (*s && *s != ',' && *s != ' ')
6718 {
6719 if (*s == '\\')
6720 ++s;
6721 ++s;
6722 }
6723 }
6724 else
6725 {
6726 if (errbuf != NULL)
6727 {
6728 sprintf((char *)errbuf,
6729 _("E535: Illegal character after <%c>"),
6730 *--s);
6731 errmsg = errbuf;
6732 }
6733 else
6734 errmsg = (char_u *)"";
6735 break;
6736 }
6737 }
6738 }
6739 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006740
6741 /* 'completeopt' */
6742 else if (varp == &p_cot)
6743 {
6744 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6745 errmsg = e_invarg;
6746 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747#endif /* FEAT_INS_EXPAND */
6748
6749
6750#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6751 else if (varp == &p_toolbar)
6752 {
6753 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6754 &toolbar_flags, TRUE) != OK)
6755 errmsg = e_invarg;
6756 else
6757 {
6758 out_flush();
6759 gui_mch_show_toolbar((toolbar_flags &
6760 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6761 }
6762 }
6763#endif
6764
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006765#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766 /* 'toolbariconsize': GTK+ 2 only */
6767 else if (varp == &p_tbis)
6768 {
6769 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6770 errmsg = e_invarg;
6771 else
6772 {
6773 out_flush();
6774 gui_mch_show_toolbar((toolbar_flags &
6775 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6776 }
6777 }
6778#endif
6779
6780 /* 'pastetoggle': translate key codes like in a mapping */
6781 else if (varp == &p_pt)
6782 {
6783 if (*p_pt)
6784 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006785 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 if (p != NULL)
6787 {
6788 if (new_value_alloced)
6789 free_string_option(p_pt);
6790 p_pt = p;
6791 new_value_alloced = TRUE;
6792 }
6793 }
6794 }
6795
6796 /* 'backspace' */
6797 else if (varp == &p_bs)
6798 {
6799 if (VIM_ISDIGIT(*p_bs))
6800 {
6801 if (*p_bs >'2' || p_bs[1] != NUL)
6802 errmsg = e_invarg;
6803 }
6804 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6805 errmsg = e_invarg;
6806 }
6807
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006808#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006809 /* 'casemap' */
6810 else if (varp == &p_cmp)
6811 {
6812 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6813 errmsg = e_invarg;
6814 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006815#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816
6817#ifdef FEAT_DIFF
6818 /* 'diffopt' */
6819 else if (varp == &p_dip)
6820 {
6821 if (diffopt_changed() == FAIL)
6822 errmsg = e_invarg;
6823 }
6824#endif
6825
6826#ifdef FEAT_FOLDING
6827 /* 'foldmethod' */
6828 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6829 {
6830 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6831 || *curwin->w_p_fdm == NUL)
6832 errmsg = e_invarg;
6833 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006834 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006836 if (foldmethodIsDiff(curwin))
6837 newFoldLevel();
6838 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839 }
6840# ifdef FEAT_EVAL
6841 /* 'foldexpr' */
6842 else if (varp == &curwin->w_p_fde)
6843 {
6844 if (foldmethodIsExpr(curwin))
6845 foldUpdateAll(curwin);
6846 }
6847# endif
6848 /* 'foldmarker' */
6849 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6850 {
6851 p = vim_strchr(*varp, ',');
6852 if (p == NULL)
6853 errmsg = (char_u *)N_("E536: comma required");
6854 else if (p == *varp || p[1] == NUL)
6855 errmsg = e_invarg;
6856 else if (foldmethodIsMarker(curwin))
6857 foldUpdateAll(curwin);
6858 }
6859 /* 'commentstring' */
6860 else if (gvarp == &p_cms)
6861 {
6862 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6863 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6864 }
6865 /* 'foldopen' */
6866 else if (varp == &p_fdo)
6867 {
6868 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6869 errmsg = e_invarg;
6870 }
6871 /* 'foldclose' */
6872 else if (varp == &p_fcl)
6873 {
6874 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6875 errmsg = e_invarg;
6876 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006877 /* 'foldignore' */
6878 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6879 {
6880 if (foldmethodIsIndent(curwin))
6881 foldUpdateAll(curwin);
6882 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883#endif
6884
6885#ifdef FEAT_VIRTUALEDIT
6886 /* 'virtualedit' */
6887 else if (varp == &p_ve)
6888 {
6889 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6890 errmsg = e_invarg;
6891 else if (STRCMP(p_ve, oldval) != 0)
6892 {
6893 /* Recompute cursor position in case the new 've' setting
6894 * changes something. */
6895 validate_virtcol();
6896 coladvance(curwin->w_virtcol);
6897 }
6898 }
6899#endif
6900
6901#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6902 else if (varp == &p_csqf)
6903 {
6904 if (p_csqf != NULL)
6905 {
6906 p = p_csqf;
6907 while (*p != NUL)
6908 {
6909 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6910 || p[1] == NUL
6911 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6912 || (p[2] != NUL && p[2] != ','))
6913 {
6914 errmsg = e_invarg;
6915 break;
6916 }
6917 else if (p[2] == NUL)
6918 break;
6919 else
6920 p += 3;
6921 }
6922 }
6923 }
6924#endif
6925
6926 /* Options that are a list of flags. */
6927 else
6928 {
6929 p = NULL;
6930 if (varp == &p_ww)
6931 p = (char_u *)WW_ALL;
6932 if (varp == &p_shm)
6933 p = (char_u *)SHM_ALL;
6934 else if (varp == &(p_cpo))
6935 p = (char_u *)CPO_ALL;
6936 else if (varp == &(curbuf->b_p_fo))
6937 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02006938#ifdef FEAT_CONCEAL
6939 else if (varp == &curwin->w_p_cocu)
6940 p = (char_u *)COCU_ALL;
6941#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006942 else if (varp == &p_mouse)
6943 {
6944#ifdef FEAT_MOUSE
6945 p = (char_u *)MOUSE_ALL;
6946#else
6947 if (*p_mouse != NUL)
6948 errmsg = (char_u *)N_("E538: No mouse support");
6949#endif
6950 }
6951#if defined(FEAT_GUI)
6952 else if (varp == &p_go)
6953 p = (char_u *)GO_ALL;
6954#endif
6955 if (p != NULL)
6956 {
6957 for (s = *varp; *s; ++s)
6958 if (vim_strchr(p, *s) == NULL)
6959 {
6960 errmsg = illegal_char(errbuf, *s);
6961 break;
6962 }
6963 }
6964 }
6965
6966 /*
6967 * If error detected, restore the previous value.
6968 */
6969 if (errmsg != NULL)
6970 {
6971 if (new_value_alloced)
6972 free_string_option(*varp);
6973 *varp = oldval;
6974 /*
6975 * When resetting some values, need to act on it.
6976 */
6977 if (did_chartab)
6978 (void)init_chartab();
6979 if (varp == &p_hl)
6980 (void)highlight_changed();
6981 }
6982 else
6983 {
6984#ifdef FEAT_EVAL
6985 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006986 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987#endif
6988 /*
6989 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006990 * Use "free_oldval", because recursiveness may change the flags under
6991 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006993 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006994 free_string_option(oldval);
6995 if (new_value_alloced)
6996 options[opt_idx].flags |= P_ALLOCED;
6997 else
6998 options[opt_idx].flags &= ~P_ALLOCED;
6999
7000 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007001 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002 {
7003 /* global option with local value set to use global value; free
7004 * the local value and make it empty */
7005 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7006 free_string_option(*(char_u **)p);
7007 *(char_u **)p = empty_option;
7008 }
7009
7010 /* May set global value for local option. */
7011 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7012 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007013
7014#ifdef FEAT_AUTOCMD
7015 /*
7016 * Trigger the autocommand only after setting the flags.
7017 */
7018# ifdef FEAT_SYN_HL
7019 /* When 'syntax' is set, load the syntax of that name */
7020 if (varp == &(curbuf->b_p_syn))
7021 {
7022 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7023 curbuf->b_fname, TRUE, curbuf);
7024 }
7025# endif
7026 else if (varp == &(curbuf->b_p_ft))
7027 {
7028 /* 'filetype' is set, trigger the FileType autocommand */
7029 did_filetype = TRUE;
7030 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7031 curbuf->b_fname, TRUE, curbuf);
7032 }
7033#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007034#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007035 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007036 {
7037 char_u fname[200];
7038
7039 /*
7040 * Source the spell/LANG.vim in 'runtimepath'.
7041 * They could set 'spellcapcheck' depending on the language.
7042 * Use the first name in 'spelllang' up to '_region' or
7043 * '.encoding'.
7044 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007045 for (p = curwin->w_s->b_p_spl; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007046 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7047 break;
7048 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
Bram Moolenaar860cae12010-06-05 23:22:07 +02007049 (int)(p - curwin->w_s->b_p_spl), curwin->w_s->b_p_spl);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007050 source_runtime(fname, TRUE);
7051 }
7052#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007053 }
7054
7055#ifdef FEAT_MOUSE
7056 if (varp == &p_mouse)
7057 {
7058# ifdef FEAT_MOUSE_TTY
7059 if (*p_mouse == NUL)
7060 mch_setmouse(FALSE); /* switch mouse off */
7061 else
7062# endif
7063 setmouse(); /* in case 'mouse' changed */
7064 }
7065#endif
7066
7067 if (curwin->w_curswant != MAXCOL)
7068 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007069#ifdef FEAT_GUI
7070 /* check redraw when it's not a GUI option or the GUI is active. */
7071 if (!redraw_gui_only || gui.in_use)
7072#endif
7073 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007074
7075 return errmsg;
7076}
7077
Bram Moolenaar1a384422010-07-14 19:53:30 +02007078#ifdef FEAT_SYN_HL
7079/*
7080 * Simple int comparison function for use with qsort()
7081 */
7082 static int
7083int_cmp(a, b)
7084 const void *a;
7085 const void *b;
7086{
7087 return *(const int *)a - *(const int *)b;
7088}
7089
7090/*
7091 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7092 * Returns error message, NULL if it's OK.
7093 */
7094 char_u *
7095check_colorcolumn(wp)
7096 win_T *wp;
7097{
7098 char_u *s;
7099 int col;
7100 int count = 0;
7101 int color_cols[256];
7102 int i;
7103 int j = 0;
7104
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007105 if (wp->w_buffer == NULL)
7106 return NULL; /* buffer was closed */
7107
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007108 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007109 {
7110 if (*s == '-' || *s == '+')
7111 {
7112 /* -N and +N: add to 'textwidth' */
7113 col = (*s == '-') ? -1 : 1;
7114 ++s;
7115 if (!VIM_ISDIGIT(*s))
7116 return e_invarg;
7117 col = col * getdigits(&s);
7118 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007119 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007120 col += wp->w_buffer->b_p_tw;
7121 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007122 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007123 }
7124 else if (VIM_ISDIGIT(*s))
7125 col = getdigits(&s);
7126 else
7127 return e_invarg;
7128 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007129skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007130 if (*s == NUL)
7131 break;
7132 if (*s != ',')
7133 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007134 if (*++s == NUL)
7135 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007136 }
7137
7138 vim_free(wp->w_p_cc_cols);
7139 if (count == 0)
7140 wp->w_p_cc_cols = NULL;
7141 else
7142 {
7143 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7144 if (wp->w_p_cc_cols != NULL)
7145 {
7146 /* sort the columns for faster usage on screen redraw inside
7147 * win_line() */
7148 qsort(color_cols, count, sizeof(int), int_cmp);
7149
7150 for (i = 0; i < count; ++i)
7151 /* skip duplicates */
7152 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7153 wp->w_p_cc_cols[j++] = color_cols[i];
7154 wp->w_p_cc_cols[j] = -1; /* end marker */
7155 }
7156 }
7157
7158 return NULL; /* no error */
7159}
7160#endif
7161
Bram Moolenaar071d4272004-06-13 20:20:40 +00007162/*
7163 * Handle setting 'listchars' or 'fillchars'.
7164 * Returns error message, NULL if it's OK.
7165 */
7166 static char_u *
7167set_chars_option(varp)
7168 char_u **varp;
7169{
7170 int round, i, len, entries;
7171 char_u *p, *s;
7172 int c1, c2 = 0;
7173 struct charstab
7174 {
7175 int *cp;
7176 char *name;
7177 };
7178#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7179 static struct charstab filltab[] =
7180 {
7181 {&fill_stl, "stl"},
7182 {&fill_stlnc, "stlnc"},
7183 {&fill_vert, "vert"},
7184 {&fill_fold, "fold"},
7185 {&fill_diff, "diff"},
7186 };
7187#endif
7188 static struct charstab lcstab[] =
7189 {
7190 {&lcs_eol, "eol"},
7191 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007192 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007193 {&lcs_prec, "precedes"},
7194 {&lcs_tab2, "tab"},
7195 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007196#ifdef FEAT_CONCEAL
7197 {&lcs_conceal, "conceal"},
7198#else
7199 {NULL, "conceal"},
7200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007201 };
7202 struct charstab *tab;
7203
7204#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7205 if (varp == &p_lcs)
7206#endif
7207 {
7208 tab = lcstab;
7209 entries = sizeof(lcstab) / sizeof(struct charstab);
7210 }
7211#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7212 else
7213 {
7214 tab = filltab;
7215 entries = sizeof(filltab) / sizeof(struct charstab);
7216 }
7217#endif
7218
7219 /* first round: check for valid value, second round: assign values */
7220 for (round = 0; round <= 1; ++round)
7221 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007222 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007223 {
7224 /* After checking that the value is valid: set defaults: space for
7225 * 'fillchars', NUL for 'listchars' */
7226 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007227 if (tab[i].cp != NULL)
7228 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007229 if (varp == &p_lcs)
7230 lcs_tab1 = NUL;
7231#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7232 else
7233 fill_diff = '-';
7234#endif
7235 }
7236 p = *varp;
7237 while (*p)
7238 {
7239 for (i = 0; i < entries; ++i)
7240 {
7241 len = (int)STRLEN(tab[i].name);
7242 if (STRNCMP(p, tab[i].name, len) == 0
7243 && p[len] == ':'
7244 && p[len + 1] != NUL)
7245 {
7246 s = p + len + 1;
7247#ifdef FEAT_MBYTE
7248 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007249 if (mb_char2cells(c1) > 1)
7250 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251#else
7252 c1 = *s++;
7253#endif
7254 if (tab[i].cp == &lcs_tab2)
7255 {
7256 if (*s == NUL)
7257 continue;
7258#ifdef FEAT_MBYTE
7259 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007260 if (mb_char2cells(c2) > 1)
7261 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262#else
7263 c2 = *s++;
7264#endif
7265 }
7266 if (*s == ',' || *s == NUL)
7267 {
7268 if (round)
7269 {
7270 if (tab[i].cp == &lcs_tab2)
7271 {
7272 lcs_tab1 = c1;
7273 lcs_tab2 = c2;
7274 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007275 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007276 *(tab[i].cp) = c1;
7277
7278 }
7279 p = s;
7280 break;
7281 }
7282 }
7283 }
7284
7285 if (i == entries)
7286 return e_invarg;
7287 if (*p == ',')
7288 ++p;
7289 }
7290 }
7291
7292 return NULL; /* no error */
7293}
7294
7295#ifdef FEAT_STL_OPT
7296/*
7297 * Check validity of options with the 'statusline' format.
7298 * Return error message or NULL.
7299 */
7300 char_u *
7301check_stl_option(s)
7302 char_u *s;
7303{
7304 int itemcnt = 0;
7305 int groupdepth = 0;
7306 static char_u errbuf[80];
7307
7308 while (*s && itemcnt < STL_MAX_ITEM)
7309 {
7310 /* Check for valid keys after % sequences */
7311 while (*s && *s != '%')
7312 s++;
7313 if (!*s)
7314 break;
7315 s++;
7316 if (*s != '%' && *s != ')')
7317 ++itemcnt;
7318 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7319 {
7320 s++;
7321 continue;
7322 }
7323 if (*s == ')')
7324 {
7325 s++;
7326 if (--groupdepth < 0)
7327 break;
7328 continue;
7329 }
7330 if (*s == '-')
7331 s++;
7332 while (VIM_ISDIGIT(*s))
7333 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007334 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007335 continue;
7336 if (*s == '.')
7337 {
7338 s++;
7339 while (*s && VIM_ISDIGIT(*s))
7340 s++;
7341 }
7342 if (*s == '(')
7343 {
7344 groupdepth++;
7345 continue;
7346 }
7347 if (vim_strchr(STL_ALL, *s) == NULL)
7348 {
7349 return illegal_char(errbuf, *s);
7350 }
7351 if (*s == '{')
7352 {
7353 s++;
7354 while (*s != '}' && *s)
7355 s++;
7356 if (*s != '}')
7357 return (char_u *)N_("E540: Unclosed expression sequence");
7358 }
7359 }
7360 if (itemcnt >= STL_MAX_ITEM)
7361 return (char_u *)N_("E541: too many items");
7362 if (groupdepth != 0)
7363 return (char_u *)N_("E542: unbalanced groups");
7364 return NULL;
7365}
7366#endif
7367
7368#ifdef FEAT_CLIPBOARD
7369/*
7370 * Extract the items in the 'clipboard' option and set global values.
7371 */
7372 static char_u *
7373check_clipboard_option()
7374{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007375 int new_unnamed = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007376 int new_autoselect = FALSE;
7377 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007378 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007379 regprog_T *new_exclude_prog = NULL;
7380 char_u *errmsg = NULL;
7381 char_u *p;
7382
7383 for (p = p_cb; *p != NUL; )
7384 {
7385 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7386 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007387 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007388 p += 7;
7389 }
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007390 else if (STRNCMP(p, "unnamedplus", 11) == 0
7391 && (p[11] == ',' || p[11] == NUL))
7392 {
7393 new_unnamed |= CLIP_UNNAMED_PLUS;
7394 p += 11;
7395 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007396 else if (STRNCMP(p, "autoselect", 10) == 0
7397 && (p[10] == ',' || p[10] == NUL))
7398 {
7399 new_autoselect = TRUE;
7400 p += 10;
7401 }
7402 else if (STRNCMP(p, "autoselectml", 12) == 0
7403 && (p[12] == ',' || p[12] == NUL))
7404 {
7405 new_autoselectml = TRUE;
7406 p += 12;
7407 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007408 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7409 {
7410 new_html = TRUE;
7411 p += 4;
7412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007413 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7414 {
7415 p += 8;
7416 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7417 if (new_exclude_prog == NULL)
7418 errmsg = e_invarg;
7419 break;
7420 }
7421 else
7422 {
7423 errmsg = e_invarg;
7424 break;
7425 }
7426 if (*p == ',')
7427 ++p;
7428 }
7429 if (errmsg == NULL)
7430 {
7431 clip_unnamed = new_unnamed;
7432 clip_autoselect = new_autoselect;
7433 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007434 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007435 vim_free(clip_exclude_prog);
7436 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007437#ifdef FEAT_GUI_GTK
7438 if (gui.in_use)
7439 {
7440 gui_gtk_set_selection_targets();
7441 gui_gtk_set_dnd_targets();
7442 }
7443#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007444 }
7445 else
7446 vim_free(new_exclude_prog);
7447
7448 return errmsg;
7449}
7450#endif
7451
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007452#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007453/*
7454 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7455 * Return error message when failed, NULL when OK.
7456 */
7457 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007458compile_cap_prog(synblock)
7459 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007460{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007461 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007462 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007463
Bram Moolenaar860cae12010-06-05 23:22:07 +02007464 if (*synblock->b_p_spc == NUL)
7465 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007466 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007467 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007468 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007469 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007470 if (re != NULL)
7471 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007472 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7473 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007474 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007475 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007476 return e_invarg;
7477 }
7478 vim_free(re);
7479 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007480 }
7481
7482 vim_free(rp);
7483 return NULL;
7484}
7485#endif
7486
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007487#if defined(FEAT_EVAL) || defined(PROTO)
7488/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007489 * Set the scriptID for an option, taking care of setting the buffer- or
7490 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007491 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007492 static void
7493set_option_scriptID_idx(opt_idx, opt_flags, id)
7494 int opt_idx;
7495 int opt_flags;
7496 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007497{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007498 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7499 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007500
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007501 /* Remember where the option was set. For local options need to do that
7502 * in the buffer or window structure. */
7503 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007504 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007505 if (both || (opt_flags & OPT_LOCAL))
7506 {
7507 if (indir & PV_BUF)
7508 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7509 else if (indir & PV_WIN)
7510 curwin->w_p_scriptID[indir & PV_MASK] = id;
7511 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007512}
7513#endif
7514
Bram Moolenaar071d4272004-06-13 20:20:40 +00007515/*
7516 * Set the value of a boolean option, and take care of side effects.
7517 * Returns NULL for success, or an error message for an error.
7518 */
7519 static char_u *
7520set_bool_option(opt_idx, varp, value, opt_flags)
7521 int opt_idx; /* index in options[] table */
7522 char_u *varp; /* pointer to the option variable */
7523 int value; /* new value */
7524 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7525{
7526 int old_value = *(int *)varp;
7527
Bram Moolenaar071d4272004-06-13 20:20:40 +00007528 /* Disallow changing some options from secure mode */
7529 if ((secure
7530#ifdef HAVE_SANDBOX
7531 || sandbox != 0
7532#endif
7533 ) && (options[opt_idx].flags & P_SECURE))
7534 return e_secure;
7535
7536 *(int *)varp = value; /* set the new value */
7537#ifdef FEAT_EVAL
7538 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007539 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540#endif
7541
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007542#ifdef FEAT_GUI
7543 need_mouse_correct = TRUE;
7544#endif
7545
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546 /* May set global value for local option. */
7547 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7548 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7549
7550 /*
7551 * Handle side effects of changing a bool option.
7552 */
7553
7554 /* 'compatible' */
7555 if ((int *)varp == &p_cp)
7556 {
7557 compatible_set();
7558 }
7559
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007560#ifdef FEAT_PERSISTENT_UNDO
7561 /* 'undofile' */
7562 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7563 {
7564 char_u hash[UNDO_HASH_SIZE];
7565 buf_T *save_curbuf = curbuf;
7566
7567 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
7568 {
7569 /* When 'undofile' is set globally: for every buffer, otherwise
7570 * only for the current buffer: Try to read in the undofile, if
Bram Moolenaar3c70f332012-01-28 18:03:35 +01007571 * one exists and the buffer wasn't changed and the buffer was
7572 * loaded. */
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007573 if ((curbuf == save_curbuf
7574 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
Bram Moolenaar3c70f332012-01-28 18:03:35 +01007575 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007576 {
7577 u_compute_hash(hash);
7578 u_read_undo(NULL, hash, curbuf->b_fname);
7579 }
7580 }
7581 curbuf = save_curbuf;
7582 }
7583#endif
7584
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007585 /* 'list', 'number' */
7586 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007587 || (int *)varp == &curwin->w_p_nu
7588 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007589 {
7590 if (curwin->w_curswant != MAXCOL)
7591 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007592
7593 /* If 'number' is set, reset 'relativenumber'. */
7594 /* If 'relativenumber' is set, reset 'number'. */
7595 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7596 curwin->w_p_rnu = FALSE;
7597 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7598 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007599 }
7600
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601 else if ((int *)varp == &curbuf->b_p_ro)
7602 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007603 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007604 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7605 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007606
7607 /* when 'readonly' is set may give W10 again */
7608 if (curbuf->b_p_ro)
7609 curbuf->b_did_warn = FALSE;
7610
Bram Moolenaar071d4272004-06-13 20:20:40 +00007611#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007612 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007613#endif
7614 }
7615
Bram Moolenaar9c449722010-07-20 18:44:27 +02007616#ifdef FEAT_GUI
7617 else if ((int *)varp == &p_mh)
7618 {
7619 if (!p_mh)
7620 gui_mch_mousehide(FALSE);
7621 }
7622#endif
7623
Bram Moolenaara539df02010-08-01 14:35:05 +02007624#ifdef FEAT_TITLE
7625 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007626 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007627 {
7628 redraw_titles();
7629 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007630 /* when 'endofline' is changed, redraw the window title */
7631 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007632 {
7633 redraw_titles();
7634 }
7635# ifdef FEAT_MBYTE
7636 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007637 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007638 {
7639 redraw_titles();
7640 }
7641# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007642#endif
7643
7644 /* when 'bin' is set also set some other options */
7645 else if ((int *)varp == &curbuf->b_p_bin)
7646 {
7647 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7648#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007649 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650#endif
7651 }
7652
7653#ifdef FEAT_AUTOCMD
7654 /* when 'buflisted' changes, trigger autocommands */
7655 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7656 {
7657 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7658 NULL, NULL, TRUE, curbuf);
7659 }
7660#endif
7661
7662 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7663 else if ((int *)varp == &curbuf->b_p_swf)
7664 {
7665 if (curbuf->b_p_swf && p_uc)
7666 ml_open_file(curbuf); /* create the swap file */
7667 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007668 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7669 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670 mf_close_file(curbuf, TRUE); /* remove the swap file */
7671 }
7672
7673 /* when 'terse' is set change 'shortmess' */
7674 else if ((int *)varp == &p_terse)
7675 {
7676 char_u *p;
7677
7678 p = vim_strchr(p_shm, SHM_SEARCH);
7679
7680 /* insert 's' in p_shm */
7681 if (p_terse && p == NULL)
7682 {
7683 STRCPY(IObuff, p_shm);
7684 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007685 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686 }
7687 /* remove 's' from p_shm */
7688 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007689 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007690 }
7691
7692 /* when 'paste' is set or reset also change other options */
7693 else if ((int *)varp == &p_paste)
7694 {
7695 paste_option_changed();
7696 }
7697
7698 /* when 'insertmode' is set from an autocommand need to do work here */
7699 else if ((int *)varp == &p_im)
7700 {
7701 if (p_im)
7702 {
7703 if ((State & INSERT) == 0)
7704 need_start_insertmode = TRUE;
7705 stop_insert_mode = FALSE;
7706 }
7707 else
7708 {
7709 need_start_insertmode = FALSE;
7710 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007711 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 clear_cmdline = TRUE; /* remove "(insert)" */
7713 restart_edit = 0;
7714 }
7715 }
7716
7717 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7718 else if ((int *)varp == &p_ic && p_hls)
7719 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007720 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721 }
7722
7723#ifdef FEAT_SEARCH_EXTRA
7724 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7725 else if ((int *)varp == &p_hls)
7726 {
7727 no_hlsearch = FALSE;
7728 }
7729#endif
7730
7731#ifdef FEAT_SCROLLBIND
7732 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7733 * at the end of normal_cmd() */
7734 else if ((int *)varp == &curwin->w_p_scb)
7735 {
7736 if (curwin->w_p_scb)
7737 do_check_scrollbind(FALSE);
7738 }
7739#endif
7740
7741#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7742 /* There can be only one window with 'previewwindow' set. */
7743 else if ((int *)varp == &curwin->w_p_pvw)
7744 {
7745 if (curwin->w_p_pvw)
7746 {
7747 win_T *win;
7748
7749 for (win = firstwin; win != NULL; win = win->w_next)
7750 if (win->w_p_pvw && win != curwin)
7751 {
7752 curwin->w_p_pvw = FALSE;
7753 return (char_u *)N_("E590: A preview window already exists");
7754 }
7755 }
7756 }
7757#endif
7758
7759 /* when 'textmode' is set or reset also change 'fileformat' */
7760 else if ((int *)varp == &curbuf->b_p_tx)
7761 {
7762 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7763 }
7764
7765 /* when 'textauto' is set or reset also change 'fileformats' */
7766 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767 set_string_option_direct((char_u *)"ffs", -1,
7768 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007769 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770
7771 /*
7772 * When 'lisp' option changes include/exclude '-' in
7773 * keyword characters.
7774 */
7775#ifdef FEAT_LISP
7776 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7777 {
7778 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7779 }
7780#endif
7781
7782#ifdef FEAT_TITLE
7783 /* when 'title' changed, may need to change the title; same for 'icon' */
7784 else if ((int *)varp == &p_title)
7785 {
7786 did_set_title(FALSE);
7787 }
7788
7789 else if ((int *)varp == &p_icon)
7790 {
7791 did_set_title(TRUE);
7792 }
7793#endif
7794
7795 else if ((int *)varp == &curbuf->b_changed)
7796 {
7797 if (!value)
7798 save_file_ff(curbuf); /* Buffer is unchanged */
7799#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007800 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801#endif
7802#ifdef FEAT_AUTOCMD
7803 modified_was_set = value;
7804#endif
7805 }
7806
7807#ifdef BACKSLASH_IN_FILENAME
7808 else if ((int *)varp == &p_ssl)
7809 {
7810 if (p_ssl)
7811 {
7812 psepc = '/';
7813 psepcN = '\\';
7814 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007815 }
7816 else
7817 {
7818 psepc = '\\';
7819 psepcN = '/';
7820 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007821 }
7822
7823 /* need to adjust the file name arguments and buffer names. */
7824 buflist_slash_adjust();
7825 alist_slash_adjust();
7826# ifdef FEAT_EVAL
7827 scriptnames_slash_adjust();
7828# endif
7829 }
7830#endif
7831
7832 /* If 'wrap' is set, set w_leftcol to zero. */
7833 else if ((int *)varp == &curwin->w_p_wrap)
7834 {
7835 if (curwin->w_p_wrap)
7836 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007837 if (curwin->w_curswant != MAXCOL)
7838 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839 }
7840
7841#ifdef FEAT_WINDOWS
7842 else if ((int *)varp == &p_ea)
7843 {
7844 if (p_ea && !old_value)
7845 win_equal(curwin, FALSE, 0);
7846 }
7847#endif
7848
7849 else if ((int *)varp == &p_wiv)
7850 {
7851 /*
7852 * When 'weirdinvert' changed, set/reset 't_xs'.
7853 * Then set 'weirdinvert' according to value of 't_xs'.
7854 */
7855 if (p_wiv && !old_value)
7856 T_XS = (char_u *)"y";
7857 else if (!p_wiv && old_value)
7858 T_XS = empty_option;
7859 p_wiv = (*T_XS != NUL);
7860 }
7861
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007862#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007863 else if ((int *)varp == &p_beval)
7864 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007865 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007866 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007867 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868 gui_mch_disable_beval_area(balloonEval);
7869 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007870#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007871
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007872#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873 else if ((int *)varp == &p_acd)
7874 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007875 /* Change directories when the 'acd' option is set now. */
7876 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 }
7878#endif
7879
7880#ifdef FEAT_DIFF
7881 /* 'diff' */
7882 else if ((int *)varp == &curwin->w_p_diff)
7883 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007884 /* May add or remove the buffer from the list of diff buffers. */
7885 diff_buf_adjust(curwin);
7886# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007887 if (foldmethodIsDiff(curwin))
7888 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007889# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 }
7891#endif
7892
7893#ifdef USE_IM_CONTROL
7894 /* 'imdisable' */
7895 else if ((int *)varp == &p_imdisable)
7896 {
7897 /* Only de-activate it here, it will be enabled when changing mode. */
7898 if (p_imdisable)
7899 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007900 else if (State & INSERT)
7901 /* When the option is set from an autocommand, it may need to take
7902 * effect right away. */
7903 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 }
7905#endif
7906
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007907#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007908 /* 'spell' */
7909 else if ((int *)varp == &curwin->w_p_spell)
7910 {
7911 if (curwin->w_p_spell)
7912 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007913 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007914 if (errmsg != NULL)
7915 EMSG(_(errmsg));
7916 }
7917 }
7918#endif
7919
Bram Moolenaar071d4272004-06-13 20:20:40 +00007920#ifdef FEAT_FKMAP
7921 else if ((int *)varp == &p_altkeymap)
7922 {
7923 if (old_value != p_altkeymap)
7924 {
7925 if (!p_altkeymap)
7926 {
7927 p_hkmap = p_fkmap;
7928 p_fkmap = 0;
7929 }
7930 else
7931 {
7932 p_fkmap = p_hkmap;
7933 p_hkmap = 0;
7934 }
7935 (void)init_chartab();
7936 }
7937 }
7938
7939 /*
7940 * In case some second language keymapping options have changed, check
7941 * and correct the setting in a consistent way.
7942 */
7943
7944 /*
7945 * If hkmap or fkmap are set, reset Arabic keymapping.
7946 */
7947 if ((p_hkmap || p_fkmap) && p_altkeymap)
7948 {
7949 p_altkeymap = p_fkmap;
7950# ifdef FEAT_ARABIC
7951 curwin->w_p_arab = FALSE;
7952# endif
7953 (void)init_chartab();
7954 }
7955
7956 /*
7957 * If hkmap set, reset Farsi keymapping.
7958 */
7959 if (p_hkmap && p_altkeymap)
7960 {
7961 p_altkeymap = 0;
7962 p_fkmap = 0;
7963# ifdef FEAT_ARABIC
7964 curwin->w_p_arab = FALSE;
7965# endif
7966 (void)init_chartab();
7967 }
7968
7969 /*
7970 * If fkmap set, reset Hebrew keymapping.
7971 */
7972 if (p_fkmap && !p_altkeymap)
7973 {
7974 p_altkeymap = 1;
7975 p_hkmap = 0;
7976# ifdef FEAT_ARABIC
7977 curwin->w_p_arab = FALSE;
7978# endif
7979 (void)init_chartab();
7980 }
7981#endif
7982
7983#ifdef FEAT_ARABIC
7984 if ((int *)varp == &curwin->w_p_arab)
7985 {
7986 if (curwin->w_p_arab)
7987 {
7988 /*
7989 * 'arabic' is set, handle various sub-settings.
7990 */
7991 if (!p_tbidi)
7992 {
7993 /* set rightleft mode */
7994 if (!curwin->w_p_rl)
7995 {
7996 curwin->w_p_rl = TRUE;
7997 changed_window_setting();
7998 }
7999
8000 /* Enable Arabic shaping (major part of what Arabic requires) */
8001 if (!p_arshape)
8002 {
8003 p_arshape = TRUE;
8004 redraw_later_clear();
8005 }
8006 }
8007
8008 /* Arabic requires a utf-8 encoding, inform the user if its not
8009 * set. */
8010 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008011 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008012 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8013
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008014 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008015 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8016#ifdef FEAT_EVAL
8017 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8018#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008019 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020
8021# ifdef FEAT_MBYTE
8022 /* set 'delcombine' */
8023 p_deco = TRUE;
8024# endif
8025
8026# ifdef FEAT_KEYMAP
8027 /* Force-set the necessary keymap for arabic */
8028 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8029 OPT_LOCAL);
8030# endif
8031# ifdef FEAT_FKMAP
8032 p_altkeymap = 0;
8033 p_hkmap = 0;
8034 p_fkmap = 0;
8035 (void)init_chartab();
8036# endif
8037 }
8038 else
8039 {
8040 /*
8041 * 'arabic' is reset, handle various sub-settings.
8042 */
8043 if (!p_tbidi)
8044 {
8045 /* reset rightleft mode */
8046 if (curwin->w_p_rl)
8047 {
8048 curwin->w_p_rl = FALSE;
8049 changed_window_setting();
8050 }
8051
8052 /* 'arabicshape' isn't reset, it is a global option and
8053 * another window may still need it "on". */
8054 }
8055
8056 /* 'delcombine' isn't reset, it is a global option and another
8057 * window may still want it "on". */
8058
8059# ifdef FEAT_KEYMAP
8060 /* Revert to the default keymap */
8061 curbuf->b_p_iminsert = B_IMODE_NONE;
8062 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8063# endif
8064 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008065 if (curwin->w_curswant != MAXCOL)
8066 curwin->w_set_curswant = TRUE;
8067 }
8068
8069 else if ((int *)varp == &p_arshape)
8070 {
8071 if (curwin->w_curswant != MAXCOL)
8072 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073 }
8074#endif
8075
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008076#ifdef FEAT_LINEBREAK
8077 if ((int *)varp == &curwin->w_p_lbr)
8078 {
8079 if (curwin->w_curswant != MAXCOL)
8080 curwin->w_set_curswant = TRUE;
8081 }
8082#endif
8083
8084#ifdef FEAT_RIGHTLEFT
8085 if ((int *)varp == &curwin->w_p_rl)
8086 {
8087 if (curwin->w_curswant != MAXCOL)
8088 curwin->w_set_curswant = TRUE;
8089 }
8090#endif
8091
Bram Moolenaar071d4272004-06-13 20:20:40 +00008092 /*
8093 * End of handling side effects for bool options.
8094 */
8095
8096 options[opt_idx].flags |= P_WAS_SET;
8097
8098 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008099
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100 check_redraw(options[opt_idx].flags);
8101
8102 return NULL;
8103}
8104
8105/*
8106 * Set the value of a number option, and take care of side effects.
8107 * Returns NULL for success, or an error message for an error.
8108 */
8109 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008110set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111 int opt_idx; /* index in options[] table */
8112 char_u *varp; /* pointer to the option variable */
8113 long value; /* new value */
8114 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008115 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008116 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8117 OPT_MODELINE */
8118{
8119 char_u *errmsg = NULL;
8120 long old_value = *(long *)varp;
8121 long old_Rows = Rows; /* remember old Rows */
8122 long old_Columns = Columns; /* remember old Columns */
8123 long *pp = (long *)varp;
8124
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008125 /* Disallow changing some options from secure mode. */
8126 if ((secure
8127#ifdef HAVE_SANDBOX
8128 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008130 ) && (options[opt_idx].flags & P_SECURE))
8131 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132
8133 *pp = value;
8134#ifdef FEAT_EVAL
8135 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008136 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008138#ifdef FEAT_GUI
8139 need_mouse_correct = TRUE;
8140#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141
8142 if (curbuf->b_p_sw <= 0)
8143 {
8144 errmsg = e_positive;
8145 curbuf->b_p_sw = curbuf->b_p_ts;
8146 }
8147
8148 /*
8149 * Number options that need some action when changed
8150 */
8151#ifdef FEAT_WINDOWS
8152 if (pp == &p_wh || pp == &p_hh)
8153 {
8154 if (p_wh < 1)
8155 {
8156 errmsg = e_positive;
8157 p_wh = 1;
8158 }
8159 if (p_wmh > p_wh)
8160 {
8161 errmsg = e_winheight;
8162 p_wh = p_wmh;
8163 }
8164 if (p_hh < 0)
8165 {
8166 errmsg = e_positive;
8167 p_hh = 0;
8168 }
8169
8170 /* Change window height NOW */
8171 if (lastwin != firstwin)
8172 {
8173 if (pp == &p_wh && curwin->w_height < p_wh)
8174 win_setheight((int)p_wh);
8175 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8176 win_setheight((int)p_hh);
8177 }
8178 }
8179
8180 /* 'winminheight' */
8181 else if (pp == &p_wmh)
8182 {
8183 if (p_wmh < 0)
8184 {
8185 errmsg = e_positive;
8186 p_wmh = 0;
8187 }
8188 if (p_wmh > p_wh)
8189 {
8190 errmsg = e_winheight;
8191 p_wmh = p_wh;
8192 }
8193 win_setminheight();
8194 }
8195
8196# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008197 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 {
8199 if (p_wiw < 1)
8200 {
8201 errmsg = e_positive;
8202 p_wiw = 1;
8203 }
8204 if (p_wmw > p_wiw)
8205 {
8206 errmsg = e_winwidth;
8207 p_wiw = p_wmw;
8208 }
8209
8210 /* Change window width NOW */
8211 if (lastwin != firstwin && curwin->w_width < p_wiw)
8212 win_setwidth((int)p_wiw);
8213 }
8214
8215 /* 'winminwidth' */
8216 else if (pp == &p_wmw)
8217 {
8218 if (p_wmw < 0)
8219 {
8220 errmsg = e_positive;
8221 p_wmw = 0;
8222 }
8223 if (p_wmw > p_wiw)
8224 {
8225 errmsg = e_winwidth;
8226 p_wmw = p_wiw;
8227 }
8228 win_setminheight();
8229 }
8230# endif
8231
8232#endif
8233
8234#ifdef FEAT_WINDOWS
8235 /* (re)set last window status line */
8236 else if (pp == &p_ls)
8237 {
8238 last_status(FALSE);
8239 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008240
8241 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008242 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008243 {
8244 shell_new_rows(); /* recompute window positions and heights */
8245 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246#endif
8247
8248#ifdef FEAT_GUI
8249 else if (pp == &p_linespace)
8250 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008251 /* Recompute gui.char_height and resize the Vim window to keep the
8252 * same number of lines. */
8253 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008254 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255 }
8256#endif
8257
8258#ifdef FEAT_FOLDING
8259 /* 'foldlevel' */
8260 else if (pp == &curwin->w_p_fdl)
8261 {
8262 if (curwin->w_p_fdl < 0)
8263 curwin->w_p_fdl = 0;
8264 newFoldLevel();
8265 }
8266
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008267 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268 else if (pp == &curwin->w_p_fml)
8269 {
8270 foldUpdateAll(curwin);
8271 }
8272
8273 /* 'foldnestmax' */
8274 else if (pp == &curwin->w_p_fdn)
8275 {
8276 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8277 foldUpdateAll(curwin);
8278 }
8279
8280 /* 'foldcolumn' */
8281 else if (pp == &curwin->w_p_fdc)
8282 {
8283 if (curwin->w_p_fdc < 0)
8284 {
8285 errmsg = e_positive;
8286 curwin->w_p_fdc = 0;
8287 }
8288 else if (curwin->w_p_fdc > 12)
8289 {
8290 errmsg = e_invarg;
8291 curwin->w_p_fdc = 12;
8292 }
8293 }
8294
8295 /* 'shiftwidth' or 'tabstop' */
8296 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8297 {
8298 if (foldmethodIsIndent(curwin))
8299 foldUpdateAll(curwin);
8300 }
8301#endif /* FEAT_FOLDING */
8302
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008303#ifdef FEAT_MBYTE
8304 /* 'maxcombine' */
8305 else if (pp == &p_mco)
8306 {
8307 if (p_mco > MAX_MCO)
8308 p_mco = MAX_MCO;
8309 else if (p_mco < 0)
8310 p_mco = 0;
8311 screenclear(); /* will re-allocate the screen */
8312 }
8313#endif
8314
Bram Moolenaar071d4272004-06-13 20:20:40 +00008315 else if (pp == &curbuf->b_p_iminsert)
8316 {
8317 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8318 {
8319 errmsg = e_invarg;
8320 curbuf->b_p_iminsert = B_IMODE_NONE;
8321 }
8322 p_iminsert = curbuf->b_p_iminsert;
8323 if (termcap_active) /* don't do this in the alternate screen */
8324 showmode();
8325#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8326 /* Show/unshow value of 'keymap' in status lines. */
8327 status_redraw_curbuf();
8328#endif
8329 }
8330
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008331 else if (pp == &p_window)
8332 {
8333 if (p_window < 1)
8334 p_window = 1;
8335 else if (p_window >= Rows)
8336 p_window = Rows - 1;
8337 }
8338
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 else if (pp == &curbuf->b_p_imsearch)
8340 {
8341 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8342 {
8343 errmsg = e_invarg;
8344 curbuf->b_p_imsearch = B_IMODE_NONE;
8345 }
8346 p_imsearch = curbuf->b_p_imsearch;
8347 }
8348
8349#ifdef FEAT_TITLE
8350 /* if 'titlelen' has changed, redraw the title */
8351 else if (pp == &p_titlelen)
8352 {
8353 if (p_titlelen < 0)
8354 {
8355 errmsg = e_positive;
8356 p_titlelen = 85;
8357 }
8358 if (starting != NO_SCREEN && old_value != p_titlelen)
8359 need_maketitle = TRUE;
8360 }
8361#endif
8362
8363 /* if p_ch changed value, change the command line height */
8364 else if (pp == &p_ch)
8365 {
8366 if (p_ch < 1)
8367 {
8368 errmsg = e_positive;
8369 p_ch = 1;
8370 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008371 if (p_ch > Rows - min_rows() + 1)
8372 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008373
8374 /* Only compute the new window layout when startup has been
8375 * completed. Otherwise the frame sizes may be wrong. */
8376 if (p_ch != old_value && full_screen
8377#ifdef FEAT_GUI
8378 && !gui.starting
8379#endif
8380 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008381 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008382 }
8383
8384 /* when 'updatecount' changes from zero to non-zero, open swap files */
8385 else if (pp == &p_uc)
8386 {
8387 if (p_uc < 0)
8388 {
8389 errmsg = e_positive;
8390 p_uc = 100;
8391 }
8392 if (p_uc && !old_value)
8393 ml_open_files();
8394 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008395#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008396 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008397 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008398 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008399 {
8400 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008401 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008402 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008403 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008404 {
8405 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008406 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008407 }
8408 }
8409#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008410#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008411 else if (pp == &p_mzq)
8412 mzvim_reset_timer();
8413#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414
8415 /* sync undo before 'undolevels' changes */
8416 else if (pp == &p_ul)
8417 {
8418 /* use the old value, otherwise u_sync() may not work properly */
8419 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008420 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 p_ul = value;
8422 }
8423
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008424#ifdef FEAT_LINEBREAK
8425 /* 'numberwidth' must be positive */
8426 else if (pp == &curwin->w_p_nuw)
8427 {
8428 if (curwin->w_p_nuw < 1)
8429 {
8430 errmsg = e_positive;
8431 curwin->w_p_nuw = 1;
8432 }
8433 if (curwin->w_p_nuw > 10)
8434 {
8435 errmsg = e_invarg;
8436 curwin->w_p_nuw = 10;
8437 }
8438 curwin->w_nrwidth_line_count = 0;
8439 }
8440#endif
8441
Bram Moolenaar1a384422010-07-14 19:53:30 +02008442 else if (pp == &curbuf->b_p_tw)
8443 {
8444 if (curbuf->b_p_tw < 0)
8445 {
8446 errmsg = e_positive;
8447 curbuf->b_p_tw = 0;
8448 }
8449#ifdef FEAT_SYN_HL
8450# ifdef FEAT_WINDOWS
8451 {
8452 win_T *wp;
8453 tabpage_T *tp;
8454
8455 FOR_ALL_TAB_WINDOWS(tp, wp)
8456 check_colorcolumn(wp);
8457 }
8458# else
8459 check_colorcolumn(curwin);
8460# endif
8461#endif
8462 }
8463
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 /*
8465 * Check the bounds for numeric options here
8466 */
8467 if (Rows < min_rows() && full_screen)
8468 {
8469 if (errbuf != NULL)
8470 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008471 vim_snprintf((char *)errbuf, errbuflen,
8472 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 errmsg = errbuf;
8474 }
8475 Rows = min_rows();
8476 }
8477 if (Columns < MIN_COLUMNS && full_screen)
8478 {
8479 if (errbuf != NULL)
8480 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008481 vim_snprintf((char *)errbuf, errbuflen,
8482 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 errmsg = errbuf;
8484 }
8485 Columns = MIN_COLUMNS;
8486 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008487 /* Limit the values to avoid an overflow in Rows * Columns. */
8488 if (Columns > 10000)
8489 Columns = 10000;
8490 if (Rows > 1000)
8491 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492
8493#ifdef DJGPP
8494 /* avoid a crash by checking for a too large value of 'columns' */
8495 if (old_Columns != Columns && full_screen && term_console)
8496 mch_check_columns();
8497#endif
8498
8499 /*
8500 * If the screen (shell) height has been changed, assume it is the
8501 * physical screenheight.
8502 */
8503 if (old_Rows != Rows || old_Columns != Columns)
8504 {
8505 /* Changing the screen size is not allowed while updating the screen. */
8506 if (updating_screen)
8507 *pp = old_value;
8508 else if (full_screen
8509#ifdef FEAT_GUI
8510 && !gui.starting
8511#endif
8512 )
8513 set_shellsize((int)Columns, (int)Rows, TRUE);
8514 else
8515 {
8516 /* Postpone the resizing; check the size and cmdline position for
8517 * messages. */
8518 check_shellsize();
8519 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8520 cmdline_row = Rows - p_ch;
8521 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008522 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008523 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524 }
8525
8526 if (curbuf->b_p_sts < 0)
8527 {
8528 errmsg = e_positive;
8529 curbuf->b_p_sts = 0;
8530 }
8531 if (curbuf->b_p_ts <= 0)
8532 {
8533 errmsg = e_positive;
8534 curbuf->b_p_ts = 8;
8535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536 if (p_tm < 0)
8537 {
8538 errmsg = e_positive;
8539 p_tm = 0;
8540 }
8541 if ((curwin->w_p_scr <= 0
8542 || (curwin->w_p_scr > curwin->w_height
8543 && curwin->w_height > 0))
8544 && full_screen)
8545 {
8546 if (pp == &(curwin->w_p_scr))
8547 {
8548 if (curwin->w_p_scr != 0)
8549 errmsg = e_scroll;
8550 win_comp_scroll(curwin);
8551 }
8552 /* If 'scroll' became invalid because of a side effect silently adjust
8553 * it. */
8554 else if (curwin->w_p_scr <= 0)
8555 curwin->w_p_scr = 1;
8556 else /* curwin->w_p_scr > curwin->w_height */
8557 curwin->w_p_scr = curwin->w_height;
8558 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008559 if (p_hi < 0)
8560 {
8561 errmsg = e_positive;
8562 p_hi = 0;
8563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008564 if (p_report < 0)
8565 {
8566 errmsg = e_positive;
8567 p_report = 1;
8568 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008569 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570 {
8571 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8572 p_sj = Rows / 2;
8573 else
8574 {
8575 errmsg = e_scroll;
8576 p_sj = 1;
8577 }
8578 }
8579 if (p_so < 0 && full_screen)
8580 {
8581 errmsg = e_scroll;
8582 p_so = 0;
8583 }
8584 if (p_siso < 0 && full_screen)
8585 {
8586 errmsg = e_positive;
8587 p_siso = 0;
8588 }
8589#ifdef FEAT_CMDWIN
8590 if (p_cwh < 1)
8591 {
8592 errmsg = e_positive;
8593 p_cwh = 1;
8594 }
8595#endif
8596 if (p_ut < 0)
8597 {
8598 errmsg = e_positive;
8599 p_ut = 2000;
8600 }
8601 if (p_ss < 0)
8602 {
8603 errmsg = e_positive;
8604 p_ss = 0;
8605 }
8606
8607 /* May set global value for local option. */
8608 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8609 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8610
8611 options[opt_idx].flags |= P_WAS_SET;
8612
8613 comp_col(); /* in case 'columns' or 'ls' changed */
8614 if (curwin->w_curswant != MAXCOL)
8615 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8616 check_redraw(options[opt_idx].flags);
8617
8618 return errmsg;
8619}
8620
8621/*
8622 * Called after an option changed: check if something needs to be redrawn.
8623 */
8624 static void
8625check_redraw(flags)
8626 long_u flags;
8627{
8628 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008629 int doclear = (flags & P_RCLR) == P_RCLR;
8630 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008631
8632#ifdef FEAT_WINDOWS
8633 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8634 status_redraw_all();
8635#endif
8636
8637 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8638 changed_window_setting();
8639 if (flags & P_RBUF)
8640 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008641 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 redraw_all_later(CLEAR);
8643 else if (all)
8644 redraw_all_later(NOT_VALID);
8645}
8646
8647/*
8648 * Find index for option 'arg'.
8649 * Return -1 if not found.
8650 */
8651 static int
8652findoption(arg)
8653 char_u *arg;
8654{
8655 int opt_idx;
8656 char *s, *p;
8657 static short quick_tab[27] = {0, 0}; /* quick access table */
8658 int is_term_opt;
8659
8660 /*
8661 * For first call: Initialize the quick-access table.
8662 * It contains the index for the first option that starts with a certain
8663 * letter. There are 26 letters, plus the first "t_" option.
8664 */
8665 if (quick_tab[1] == 0)
8666 {
8667 p = options[0].fullname;
8668 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8669 {
8670 if (s[0] != p[0])
8671 {
8672 if (s[0] == 't' && s[1] == '_')
8673 quick_tab[26] = opt_idx;
8674 else
8675 quick_tab[CharOrdLow(s[0])] = opt_idx;
8676 }
8677 p = s;
8678 }
8679 }
8680
8681 /*
8682 * Check for name starting with an illegal character.
8683 */
8684#ifdef EBCDIC
8685 if (!islower(arg[0]))
8686#else
8687 if (arg[0] < 'a' || arg[0] > 'z')
8688#endif
8689 return -1;
8690
8691 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8692 if (is_term_opt)
8693 opt_idx = quick_tab[26];
8694 else
8695 opt_idx = quick_tab[CharOrdLow(arg[0])];
8696 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8697 {
8698 if (STRCMP(arg, s) == 0) /* match full name */
8699 break;
8700 }
8701 if (s == NULL && !is_term_opt)
8702 {
8703 opt_idx = quick_tab[CharOrdLow(arg[0])];
8704 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8705 {
8706 s = options[opt_idx].shortname;
8707 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8708 break;
8709 s = NULL;
8710 }
8711 }
8712 if (s == NULL)
8713 opt_idx = -1;
8714 return opt_idx;
8715}
8716
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008717#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718/*
8719 * Get the value for an option.
8720 *
8721 * Returns:
8722 * Number or Toggle option: 1, *numval gets value.
8723 * String option: 0, *stringval gets allocated string.
8724 * Hidden Number or Toggle option: -1.
8725 * hidden String option: -2.
8726 * unknown option: -3.
8727 */
8728 int
8729get_option_value(name, numval, stringval, opt_flags)
8730 char_u *name;
8731 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008732 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008733 int opt_flags;
8734{
8735 int opt_idx;
8736 char_u *varp;
8737
8738 opt_idx = findoption(name);
8739 if (opt_idx < 0) /* unknown option */
8740 return -3;
8741
8742 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8743
8744 if (options[opt_idx].flags & P_STRING)
8745 {
8746 if (varp == NULL) /* hidden option */
8747 return -2;
8748 if (stringval != NULL)
8749 {
8750#ifdef FEAT_CRYPT
8751 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008752 if ((char_u **)varp == &curbuf->b_p_key
8753 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754 *stringval = vim_strsave((char_u *)"*****");
8755 else
8756#endif
8757 *stringval = vim_strsave(*(char_u **)(varp));
8758 }
8759 return 0;
8760 }
8761
8762 if (varp == NULL) /* hidden option */
8763 return -1;
8764 if (options[opt_idx].flags & P_NUM)
8765 *numval = *(long *)varp;
8766 else
8767 {
8768 /* Special case: 'modified' is b_changed, but we also want to consider
8769 * it set when 'ff' or 'fenc' changed. */
8770 if ((int *)varp == &curbuf->b_changed)
8771 *numval = curbufIsChanged();
8772 else
8773 *numval = *(int *)varp;
8774 }
8775 return 1;
8776}
8777#endif
8778
8779/*
8780 * Set the value of option "name".
8781 * Use "string" for string options, use "number" for other options.
8782 */
8783 void
8784set_option_value(name, number, string, opt_flags)
8785 char_u *name;
8786 long number;
8787 char_u *string;
8788 int opt_flags; /* OPT_LOCAL or 0 (both) */
8789{
8790 int opt_idx;
8791 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008792 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008793
8794 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008795 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796 EMSG2(_("E355: Unknown option: %s"), name);
8797 else
8798 {
8799 flags = options[opt_idx].flags;
8800#ifdef HAVE_SANDBOX
8801 /* Disallow changing some options in the sandbox */
8802 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008803 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008805 return;
8806 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008808 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 set_string_option(opt_idx, string, opt_flags);
8810 else
8811 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008812 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813 if (varp != NULL) /* hidden option is not changed */
8814 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008815 if (number == 0 && string != NULL)
8816 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008817 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008818
8819 /* Either we are given a string or we are setting option
8820 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008821 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008822 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008823 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008824 {
8825 /* There's another character after zeros or the string
8826 * is empty. In both cases, we are trying to set a
8827 * num option using a string. */
8828 EMSG3(_("E521: Number required: &%s = '%s'"),
8829 name, string);
8830 return; /* do nothing as we hit an error */
8831
8832 }
8833 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008835 (void)set_num_option(opt_idx, varp, number,
8836 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008838 (void)set_bool_option(opt_idx, varp, (int)number,
8839 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 }
8841 }
8842 }
8843}
8844
8845/*
8846 * Get the terminal code for a terminal option.
8847 * Returns NULL when not found.
8848 */
8849 char_u *
8850get_term_code(tname)
8851 char_u *tname;
8852{
8853 int opt_idx;
8854 char_u *varp;
8855
8856 if (tname[0] != 't' || tname[1] != '_' ||
8857 tname[2] == NUL || tname[3] == NUL)
8858 return NULL;
8859 if ((opt_idx = findoption(tname)) >= 0)
8860 {
8861 varp = get_varp(&(options[opt_idx]));
8862 if (varp != NULL)
8863 varp = *(char_u **)(varp);
8864 return varp;
8865 }
8866 return find_termcode(tname + 2);
8867}
8868
8869 char_u *
8870get_highlight_default()
8871{
8872 int i;
8873
8874 i = findoption((char_u *)"hl");
8875 if (i >= 0)
8876 return options[i].def_val[VI_DEFAULT];
8877 return (char_u *)NULL;
8878}
8879
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008880#if defined(FEAT_MBYTE) || defined(PROTO)
8881 char_u *
8882get_encoding_default()
8883{
8884 int i;
8885
8886 i = findoption((char_u *)"enc");
8887 if (i >= 0)
8888 return options[i].def_val[VI_DEFAULT];
8889 return (char_u *)NULL;
8890}
8891#endif
8892
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893/*
8894 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8895 */
8896 static int
8897find_key_option(arg)
8898 char_u *arg;
8899{
8900 int key;
8901 int modifiers;
8902
8903 /*
8904 * Don't use get_special_key_code() for t_xx, we don't want it to call
8905 * add_termcap_entry().
8906 */
8907 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8908 key = TERMCAP2KEY(arg[2], arg[3]);
8909 else
8910 {
8911 --arg; /* put arg at the '<' */
8912 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008913 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008914 if (modifiers) /* can't handle modifiers here */
8915 key = 0;
8916 }
8917 return key;
8918}
8919
8920/*
8921 * if 'all' == 0: show changed options
8922 * if 'all' == 1: show all normal options
8923 * if 'all' == 2: show all terminal options
8924 */
8925 static void
8926showoptions(all, opt_flags)
8927 int all;
8928 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8929{
8930 struct vimoption *p;
8931 int col;
8932 int isterm;
8933 char_u *varp;
8934 struct vimoption **items;
8935 int item_count;
8936 int run;
8937 int row, rows;
8938 int cols;
8939 int i;
8940 int len;
8941
8942#define INC 20
8943#define GAP 3
8944
8945 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8946 PARAM_COUNT));
8947 if (items == NULL)
8948 return;
8949
8950 /* Highlight title */
8951 if (all == 2)
8952 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8953 else if (opt_flags & OPT_GLOBAL)
8954 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8955 else if (opt_flags & OPT_LOCAL)
8956 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8957 else
8958 MSG_PUTS_TITLE(_("\n--- Options ---"));
8959
8960 /*
8961 * do the loop two times:
8962 * 1. display the short items
8963 * 2. display the long items (only strings and numbers)
8964 */
8965 for (run = 1; run <= 2 && !got_int; ++run)
8966 {
8967 /*
8968 * collect the items in items[]
8969 */
8970 item_count = 0;
8971 for (p = &options[0]; p->fullname != NULL; p++)
8972 {
8973 varp = NULL;
8974 isterm = istermoption(p);
8975 if (opt_flags != 0)
8976 {
8977 if (p->indir != PV_NONE && !isterm)
8978 varp = get_varp_scope(p, opt_flags);
8979 }
8980 else
8981 varp = get_varp(p);
8982 if (varp != NULL
8983 && ((all == 2 && isterm)
8984 || (all == 1 && !isterm)
8985 || (all == 0 && !optval_default(p, varp))))
8986 {
8987 if (p->flags & P_BOOL)
8988 len = 1; /* a toggle option fits always */
8989 else
8990 {
8991 option_value2string(p, opt_flags);
8992 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8993 }
8994 if ((len <= INC - GAP && run == 1) ||
8995 (len > INC - GAP && run == 2))
8996 items[item_count++] = p;
8997 }
8998 }
8999
9000 /*
9001 * display the items
9002 */
9003 if (run == 1)
9004 {
9005 cols = (Columns + GAP - 3) / INC;
9006 if (cols == 0)
9007 cols = 1;
9008 rows = (item_count + cols - 1) / cols;
9009 }
9010 else /* run == 2 */
9011 rows = item_count;
9012 for (row = 0; row < rows && !got_int; ++row)
9013 {
9014 msg_putchar('\n'); /* go to next line */
9015 if (got_int) /* 'q' typed in more */
9016 break;
9017 col = 0;
9018 for (i = row; i < item_count; i += rows)
9019 {
9020 msg_col = col; /* make columns */
9021 showoneopt(items[i], opt_flags);
9022 col += INC;
9023 }
9024 out_flush();
9025 ui_breakcheck();
9026 }
9027 }
9028 vim_free(items);
9029}
9030
9031/*
9032 * Return TRUE if option "p" has its default value.
9033 */
9034 static int
9035optval_default(p, varp)
9036 struct vimoption *p;
9037 char_u *varp;
9038{
9039 int dvi;
9040
9041 if (varp == NULL)
9042 return TRUE; /* hidden option is always at default */
9043 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9044 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009045 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009046 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009047 /* the cast to long is required for Manx C, long_i is
9048 * needed for MSVC */
9049 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 /* P_STRING */
9051 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9052}
9053
9054/*
9055 * showoneopt: show the value of one option
9056 * must not be called with a hidden option!
9057 */
9058 static void
9059showoneopt(p, opt_flags)
9060 struct vimoption *p;
9061 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9062{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009063 char_u *varp;
9064 int save_silent = silent_mode;
9065
9066 silent_mode = FALSE;
9067 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009068
9069 varp = get_varp_scope(p, opt_flags);
9070
9071 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9072 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9073 ? !curbufIsChanged() : !*(int *)varp))
9074 MSG_PUTS("no");
9075 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9076 MSG_PUTS("--");
9077 else
9078 MSG_PUTS(" ");
9079 MSG_PUTS(p->fullname);
9080 if (!(p->flags & P_BOOL))
9081 {
9082 msg_putchar('=');
9083 /* put value string in NameBuff */
9084 option_value2string(p, opt_flags);
9085 msg_outtrans(NameBuff);
9086 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009087
9088 silent_mode = save_silent;
9089 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090}
9091
9092/*
9093 * Write modified options as ":set" commands to a file.
9094 *
9095 * There are three values for "opt_flags":
9096 * OPT_GLOBAL: Write global option values and fresh values of
9097 * buffer-local options (used for start of a session
9098 * file).
9099 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9100 * curwin (used for a vimrc file).
9101 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9102 * and local values for window-local options of
9103 * curwin. Local values are also written when at the
9104 * default value, because a modeline or autocommand
9105 * may have set them when doing ":edit file" and the
9106 * user has set them back at the default or fresh
9107 * value.
9108 * When "local_only" is TRUE, don't write fresh
9109 * values, only local values (for ":mkview").
9110 * (fresh value = value used for a new buffer or window for a local option).
9111 *
9112 * Return FAIL on error, OK otherwise.
9113 */
9114 int
9115makeset(fd, opt_flags, local_only)
9116 FILE *fd;
9117 int opt_flags;
9118 int local_only;
9119{
9120 struct vimoption *p;
9121 char_u *varp; /* currently used value */
9122 char_u *varp_fresh; /* local value */
9123 char_u *varp_local = NULL; /* fresh value */
9124 char *cmd;
9125 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009126 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009127
9128 /*
9129 * The options that don't have a default (terminal name, columns, lines)
9130 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009131 * Do the loop over "options[]" twice: once for options with the
9132 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009133 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009134 for (pri = 1; pri >= 0; --pri)
9135 {
9136 for (p = &options[0]; !istermoption(p); p++)
9137 if (!(p->flags & P_NO_MKRC)
9138 && !istermoption(p)
9139 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009140 {
9141 /* skip global option when only doing locals */
9142 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9143 continue;
9144
9145 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9146 * file, they are always buffer-specific. */
9147 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9148 continue;
9149
9150 /* Global values are only written when not at the default value. */
9151 varp = get_varp_scope(p, opt_flags);
9152 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9153 continue;
9154
9155 round = 2;
9156 if (p->indir != PV_NONE)
9157 {
9158 if (p->var == VAR_WIN)
9159 {
9160 /* skip window-local option when only doing globals */
9161 if (!(opt_flags & OPT_LOCAL))
9162 continue;
9163 /* When fresh value of window-local option is not at the
9164 * default, need to write it too. */
9165 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9166 {
9167 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9168 if (!optval_default(p, varp_fresh))
9169 {
9170 round = 1;
9171 varp_local = varp;
9172 varp = varp_fresh;
9173 }
9174 }
9175 }
9176 }
9177
9178 /* Round 1: fresh value for window-local options.
9179 * Round 2: other values */
9180 for ( ; round <= 2; varp = varp_local, ++round)
9181 {
9182 if (round == 1 || (opt_flags & OPT_GLOBAL))
9183 cmd = "set";
9184 else
9185 cmd = "setlocal";
9186
9187 if (p->flags & P_BOOL)
9188 {
9189 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9190 return FAIL;
9191 }
9192 else if (p->flags & P_NUM)
9193 {
9194 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9195 return FAIL;
9196 }
9197 else /* P_STRING */
9198 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009199#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9200 int do_endif = FALSE;
9201
Bram Moolenaar071d4272004-06-13 20:20:40 +00009202 /* Don't set 'syntax' and 'filetype' again if the value is
9203 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009204 if (
9205# if defined(FEAT_SYN_HL)
9206 p->indir == PV_SYN
9207# if defined(FEAT_AUTOCMD)
9208 ||
9209# endif
9210# endif
9211# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009212 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009213# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009214 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009215 {
9216 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9217 *(char_u **)(varp)) < 0
9218 || put_eol(fd) < 0)
9219 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009220 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009221 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009222#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009223 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9224 (p->flags & P_EXPAND) != 0) == FAIL)
9225 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009226#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9227 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009228 {
9229 if (put_line(fd, "endif") == FAIL)
9230 return FAIL;
9231 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233 }
9234 }
9235 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009236 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237 return OK;
9238}
9239
9240#if defined(FEAT_FOLDING) || defined(PROTO)
9241/*
9242 * Generate set commands for the local fold options only. Used when
9243 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9244 */
9245 int
9246makefoldset(fd)
9247 FILE *fd;
9248{
9249 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9250# ifdef FEAT_EVAL
9251 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9252 == FAIL
9253# endif
9254 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9255 == FAIL
9256 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9257 == FAIL
9258 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9259 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9260 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9261 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9262 )
9263 return FAIL;
9264
9265 return OK;
9266}
9267#endif
9268
9269 static int
9270put_setstring(fd, cmd, name, valuep, expand)
9271 FILE *fd;
9272 char *cmd;
9273 char *name;
9274 char_u **valuep;
9275 int expand;
9276{
9277 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009278 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279
9280 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9281 return FAIL;
9282 if (*valuep != NULL)
9283 {
9284 /* Output 'pastetoggle' as key names. For other
9285 * options some characters have to be escaped with
9286 * CTRL-V or backslash */
9287 if (valuep == &p_pt)
9288 {
9289 s = *valuep;
9290 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009291 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292 return FAIL;
9293 }
9294 else if (expand)
9295 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009296 buf = alloc(MAXPATHL);
9297 if (buf == NULL)
9298 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009299 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9300 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009301 {
9302 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009303 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009304 }
9305 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306 }
9307 else if (put_escstr(fd, *valuep, 2) == FAIL)
9308 return FAIL;
9309 }
9310 if (put_eol(fd) < 0)
9311 return FAIL;
9312 return OK;
9313}
9314
9315 static int
9316put_setnum(fd, cmd, name, valuep)
9317 FILE *fd;
9318 char *cmd;
9319 char *name;
9320 long *valuep;
9321{
9322 long wc;
9323
9324 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9325 return FAIL;
9326 if (wc_use_keyname((char_u *)valuep, &wc))
9327 {
9328 /* print 'wildchar' and 'wildcharm' as a key name */
9329 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9330 return FAIL;
9331 }
9332 else if (fprintf(fd, "%ld", *valuep) < 0)
9333 return FAIL;
9334 if (put_eol(fd) < 0)
9335 return FAIL;
9336 return OK;
9337}
9338
9339 static int
9340put_setbool(fd, cmd, name, value)
9341 FILE *fd;
9342 char *cmd;
9343 char *name;
9344 int value;
9345{
Bram Moolenaar893de922007-10-02 18:40:57 +00009346 if (value < 0) /* global/local option using global value */
9347 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009348 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9349 || put_eol(fd) < 0)
9350 return FAIL;
9351 return OK;
9352}
9353
9354/*
9355 * Clear all the terminal options.
9356 * If the option has been allocated, free the memory.
9357 * Terminal options are never hidden or indirect.
9358 */
9359 void
9360clear_termoptions()
9361{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362 /*
9363 * Reset a few things before clearing the old options. This may cause
9364 * outputting a few things that the terminal doesn't understand, but the
9365 * screen will be cleared later, so this is OK.
9366 */
9367#ifdef FEAT_MOUSE_TTY
9368 mch_setmouse(FALSE); /* switch mouse off */
9369#endif
9370#ifdef FEAT_TITLE
9371 mch_restore_title(3); /* restore window titles */
9372#endif
9373#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9374 /* When starting the GUI close the display opened for the clipboard.
9375 * After restoring the title, because that will need the display. */
9376 if (gui.starting)
9377 clear_xterm_clip();
9378#endif
9379#ifdef WIN3264
9380 /*
9381 * Check if this is allowed now.
9382 */
9383 if (can_end_termcap_mode(FALSE) == TRUE)
9384#endif
9385 stoptermcap(); /* stop termcap mode */
9386
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009387 free_termoptions();
9388}
9389
9390 void
9391free_termoptions()
9392{
9393 struct vimoption *p;
9394
Bram Moolenaar071d4272004-06-13 20:20:40 +00009395 for (p = &options[0]; p->fullname != NULL; p++)
9396 if (istermoption(p))
9397 {
9398 if (p->flags & P_ALLOCED)
9399 free_string_option(*(char_u **)(p->var));
9400 if (p->flags & P_DEF_ALLOCED)
9401 free_string_option(p->def_val[VI_DEFAULT]);
9402 *(char_u **)(p->var) = empty_option;
9403 p->def_val[VI_DEFAULT] = empty_option;
9404 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9405 }
9406 clear_termcodes();
9407}
9408
9409/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009410 * Free the string for one term option, if it was allocated.
9411 * Set the string to empty_option and clear allocated flag.
9412 * "var" points to the option value.
9413 */
9414 void
9415free_one_termoption(var)
9416 char_u *var;
9417{
9418 struct vimoption *p;
9419
9420 for (p = &options[0]; p->fullname != NULL; p++)
9421 if (p->var == var)
9422 {
9423 if (p->flags & P_ALLOCED)
9424 free_string_option(*(char_u **)(p->var));
9425 *(char_u **)(p->var) = empty_option;
9426 p->flags &= ~P_ALLOCED;
9427 break;
9428 }
9429}
9430
9431/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432 * Set the terminal option defaults to the current value.
9433 * Used after setting the terminal name.
9434 */
9435 void
9436set_term_defaults()
9437{
9438 struct vimoption *p;
9439
9440 for (p = &options[0]; p->fullname != NULL; p++)
9441 {
9442 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9443 {
9444 if (p->flags & P_DEF_ALLOCED)
9445 {
9446 free_string_option(p->def_val[VI_DEFAULT]);
9447 p->flags &= ~P_DEF_ALLOCED;
9448 }
9449 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9450 if (p->flags & P_ALLOCED)
9451 {
9452 p->flags |= P_DEF_ALLOCED;
9453 p->flags &= ~P_ALLOCED; /* don't free the value now */
9454 }
9455 }
9456 }
9457}
9458
9459/*
9460 * return TRUE if 'p' starts with 't_'
9461 */
9462 static int
9463istermoption(p)
9464 struct vimoption *p;
9465{
9466 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9467}
9468
9469/*
9470 * Compute columns for ruler and shown command. 'sc_col' is also used to
9471 * decide what the maximum length of a message on the status line can be.
9472 * If there is a status line for the last window, 'sc_col' is independent
9473 * of 'ru_col'.
9474 */
9475
9476#define COL_RULER 17 /* columns needed by standard ruler */
9477
9478 void
9479comp_col()
9480{
9481#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9482 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9483
9484 sc_col = 0;
9485 ru_col = 0;
9486 if (p_ru)
9487 {
9488#ifdef FEAT_STL_OPT
9489 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9490#else
9491 ru_col = COL_RULER + 1;
9492#endif
9493 /* no last status line, adjust sc_col */
9494 if (!last_has_status)
9495 sc_col = ru_col;
9496 }
9497 if (p_sc)
9498 {
9499 sc_col += SHOWCMD_COLS;
9500 if (!p_ru || last_has_status) /* no need for separating space */
9501 ++sc_col;
9502 }
9503 sc_col = Columns - sc_col;
9504 ru_col = Columns - ru_col;
9505 if (sc_col <= 0) /* screen too narrow, will become a mess */
9506 sc_col = 1;
9507 if (ru_col <= 0)
9508 ru_col = 1;
9509#else
9510 sc_col = Columns;
9511 ru_col = Columns;
9512#endif
9513}
9514
9515/*
9516 * Get pointer to option variable, depending on local or global scope.
9517 */
9518 static char_u *
9519get_varp_scope(p, opt_flags)
9520 struct vimoption *p;
9521 int opt_flags;
9522{
9523 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9524 {
9525 if (p->var == VAR_WIN)
9526 return (char_u *)GLOBAL_WO(get_varp(p));
9527 return p->var;
9528 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009529 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009530 {
9531 switch ((int)p->indir)
9532 {
9533#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009534 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9535 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9536 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009538 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9539 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9540 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009541 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009542 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009543#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009544 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9545 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009546#endif
9547#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009548 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9549 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009550#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009551#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9552 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9553#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009554#if defined(FEAT_CRYPT)
9555 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9556#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009557#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009558 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009560 }
9561 return NULL; /* "cannot happen" */
9562 }
9563 return get_varp(p);
9564}
9565
9566/*
9567 * Get pointer to option variable.
9568 */
9569 static char_u *
9570get_varp(p)
9571 struct vimoption *p;
9572{
9573 /* hidden option, always return NULL */
9574 if (p->var == NULL)
9575 return NULL;
9576
9577 switch ((int)p->indir)
9578 {
9579 case PV_NONE: return p->var;
9580
9581 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009582 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009583 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009584 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009586 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009588 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009590 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009591 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9592#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009593 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009594 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009595 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009596 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9597#endif
9598#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009599 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009600 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009601 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009602 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9603#endif
9604#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009605 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009606 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009607 case PV_GP: return *curbuf->b_p_gp != NUL
9608 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9609 case PV_MP: return *curbuf->b_p_mp != NUL
9610 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009612#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9613 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9614 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9615#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009616#if defined(FEAT_CRYPT)
9617 case PV_CM: return *curbuf->b_p_cm != NUL
9618 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9619#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009620#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009621 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009622 ? (char_u *)&(curwin->w_p_stl) : p->var;
9623#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009624
9625#ifdef FEAT_ARABIC
9626 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9627#endif
9628 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009629#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009630 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9631#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009632#ifdef FEAT_SYN_HL
9633 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9634 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009635 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009637#ifdef FEAT_DIFF
9638 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9639#endif
9640#ifdef FEAT_FOLDING
9641 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9642 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9643 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9644 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9645 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9646 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9647 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9648# ifdef FEAT_EVAL
9649 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9650 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9651# endif
9652 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9653#endif
9654 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009655 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009656#ifdef FEAT_LINEBREAK
9657 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9658#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009659#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9661#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009662#ifdef FEAT_VERTSPLIT
9663 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9664#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009665#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9666 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9667#endif
9668#ifdef FEAT_RIGHTLEFT
9669 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9670 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9671#endif
9672 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9673 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9674#ifdef FEAT_LINEBREAK
9675 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9676#endif
9677#ifdef FEAT_SCROLLBIND
9678 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9679#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +02009680#ifdef FEAT_CURSORBIND
9681 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
9682#endif
9683#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009684 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
9685 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +02009686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009687
9688 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9689 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9690#ifdef FEAT_MBYTE
9691 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9692#endif
9693#if defined(FEAT_QUICKFIX)
9694 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9695 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9696#endif
9697 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9698 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9699#ifdef FEAT_CINDENT
9700 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9701 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9702 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9703#endif
9704#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9705 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9706#endif
9707#ifdef FEAT_COMMENTS
9708 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9709#endif
9710#ifdef FEAT_FOLDING
9711 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9712#endif
9713#ifdef FEAT_INS_EXPAND
9714 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9715#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009716#ifdef FEAT_COMPL_FUNC
9717 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009718 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9721 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9722#ifdef FEAT_MBYTE
9723 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9724#endif
9725 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9726#ifdef FEAT_AUTOCMD
9727 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9728#endif
9729 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009730 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9732 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9733 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9734 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9735#ifdef FEAT_FIND_ID
9736# ifdef FEAT_EVAL
9737 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9738# endif
9739#endif
9740#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9741 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9742 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9743#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009744#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009745 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747#ifdef FEAT_CRYPT
9748 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9749#endif
9750#ifdef FEAT_LISP
9751 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9752#endif
9753 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9754 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9755 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9756 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9757 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009759#ifdef FEAT_TEXTOBJ
9760 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9763#ifdef FEAT_SMARTINDENT
9764 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9765#endif
9766#ifndef SHORT_FNAME
9767 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9768#endif
9769 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9770#ifdef FEAT_SEARCHPATH
9771 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9772#endif
9773 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9774#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009775 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009776 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9777#endif
9778#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02009779 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
9780 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
9781 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782#endif
9783 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9784 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9785 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9786 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009787#ifdef FEAT_PERSISTENT_UNDO
9788 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9789#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9791#ifdef FEAT_KEYMAP
9792 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9793#endif
9794 default: EMSG(_("E356: get_varp ERROR"));
9795 }
9796 /* always return a valid pointer to avoid a crash! */
9797 return (char_u *)&(curbuf->b_p_wm);
9798}
9799
9800/*
9801 * Get the value of 'equalprg', either the buffer-local one or the global one.
9802 */
9803 char_u *
9804get_equalprg()
9805{
9806 if (*curbuf->b_p_ep == NUL)
9807 return p_ep;
9808 return curbuf->b_p_ep;
9809}
9810
9811#if defined(FEAT_WINDOWS) || defined(PROTO)
9812/*
9813 * Copy options from one window to another.
9814 * Used when splitting a window.
9815 */
9816 void
9817win_copy_options(wp_from, wp_to)
9818 win_T *wp_from;
9819 win_T *wp_to;
9820{
9821 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9822 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9823# ifdef FEAT_RIGHTLEFT
9824# ifdef FEAT_FKMAP
9825 /* Is this right? */
9826 wp_to->w_farsi = wp_from->w_farsi;
9827# endif
9828# endif
9829}
9830#endif
9831
9832/*
9833 * Copy the options from one winopt_T to another.
9834 * Doesn't free the old option values in "to", use clear_winopt() for that.
9835 * The 'scroll' option is not copied, because it depends on the window height.
9836 * The 'previewwindow' option is reset, there can be only one preview window.
9837 */
9838 void
9839copy_winopt(from, to)
9840 winopt_T *from;
9841 winopt_T *to;
9842{
9843#ifdef FEAT_ARABIC
9844 to->wo_arab = from->wo_arab;
9845#endif
9846 to->wo_list = from->wo_list;
9847 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009848 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009849#ifdef FEAT_LINEBREAK
9850 to->wo_nuw = from->wo_nuw;
9851#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009852#ifdef FEAT_RIGHTLEFT
9853 to->wo_rl = from->wo_rl;
9854 to->wo_rlc = vim_strsave(from->wo_rlc);
9855#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009856#ifdef FEAT_STL_OPT
9857 to->wo_stl = vim_strsave(from->wo_stl);
9858#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009859 to->wo_wrap = from->wo_wrap;
9860#ifdef FEAT_LINEBREAK
9861 to->wo_lbr = from->wo_lbr;
9862#endif
9863#ifdef FEAT_SCROLLBIND
9864 to->wo_scb = from->wo_scb;
9865#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +01009866#ifdef FEAT_CURSORBIND
9867 to->wo_crb = from->wo_crb;
9868#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009869#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009870 to->wo_spell = from->wo_spell;
9871#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009872#ifdef FEAT_SYN_HL
9873 to->wo_cuc = from->wo_cuc;
9874 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +02009875 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009876#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877#ifdef FEAT_DIFF
9878 to->wo_diff = from->wo_diff;
9879#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009880#ifdef FEAT_CONCEAL
9881 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +02009882 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009884#ifdef FEAT_FOLDING
9885 to->wo_fdc = from->wo_fdc;
9886 to->wo_fen = from->wo_fen;
9887 to->wo_fdi = vim_strsave(from->wo_fdi);
9888 to->wo_fml = from->wo_fml;
9889 to->wo_fdl = from->wo_fdl;
9890 to->wo_fdm = vim_strsave(from->wo_fdm);
9891 to->wo_fdn = from->wo_fdn;
9892# ifdef FEAT_EVAL
9893 to->wo_fde = vim_strsave(from->wo_fde);
9894 to->wo_fdt = vim_strsave(from->wo_fdt);
9895# endif
9896 to->wo_fmr = vim_strsave(from->wo_fmr);
9897#endif
9898 check_winopt(to); /* don't want NULL pointers */
9899}
9900
9901/*
9902 * Check string options in a window for a NULL value.
9903 */
9904 void
9905check_win_options(win)
9906 win_T *win;
9907{
9908 check_winopt(&win->w_onebuf_opt);
9909 check_winopt(&win->w_allbuf_opt);
9910}
9911
9912/*
9913 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9914 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915 void
9916check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009917 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009918{
9919#ifdef FEAT_FOLDING
9920 check_string_option(&wop->wo_fdi);
9921 check_string_option(&wop->wo_fdm);
9922# ifdef FEAT_EVAL
9923 check_string_option(&wop->wo_fde);
9924 check_string_option(&wop->wo_fdt);
9925# endif
9926 check_string_option(&wop->wo_fmr);
9927#endif
9928#ifdef FEAT_RIGHTLEFT
9929 check_string_option(&wop->wo_rlc);
9930#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009931#ifdef FEAT_STL_OPT
9932 check_string_option(&wop->wo_stl);
9933#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009934#ifdef FEAT_SYN_HL
9935 check_string_option(&wop->wo_cc);
9936#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009937#ifdef FEAT_CONCEAL
9938 check_string_option(&wop->wo_cocu);
9939#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940}
9941
9942/*
9943 * Free the allocated memory inside a winopt_T.
9944 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009945 void
9946clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009947 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948{
9949#ifdef FEAT_FOLDING
9950 clear_string_option(&wop->wo_fdi);
9951 clear_string_option(&wop->wo_fdm);
9952# ifdef FEAT_EVAL
9953 clear_string_option(&wop->wo_fde);
9954 clear_string_option(&wop->wo_fdt);
9955# endif
9956 clear_string_option(&wop->wo_fmr);
9957#endif
9958#ifdef FEAT_RIGHTLEFT
9959 clear_string_option(&wop->wo_rlc);
9960#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009961#ifdef FEAT_STL_OPT
9962 clear_string_option(&wop->wo_stl);
9963#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +02009964#ifdef FEAT_SYN_HL
9965 clear_string_option(&wop->wo_cc);
9966#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009967#ifdef FEAT_CONCEAL
9968 clear_string_option(&wop->wo_cocu);
9969#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009970}
9971
9972/*
9973 * Copy global option values to local options for one buffer.
9974 * Used when creating a new buffer and sometimes when entering a buffer.
9975 * flags:
9976 * BCO_ENTER We will enter the buf buffer.
9977 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9978 * appropriate.
9979 * BCO_NOHELP Don't copy the values to a help buffer.
9980 */
9981 void
9982buf_copy_options(buf, flags)
9983 buf_T *buf;
9984 int flags;
9985{
9986 int should_copy = TRUE;
9987 char_u *save_p_isk = NULL; /* init for GCC */
9988 int dont_do_help;
9989 int did_isk = FALSE;
9990
9991 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +02009992 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993 */
9994 if (buf == NULL || !buf_valid(buf))
9995 return;
9996
9997 /*
9998 * Skip this when the option defaults have not been set yet. Happens when
9999 * main() allocates the first buffer.
10000 */
10001 if (p_cpo != NULL)
10002 {
10003 /*
10004 * Always copy when entering and 'cpo' contains 'S'.
10005 * Don't copy when already initialized.
10006 * Don't copy when 'cpo' contains 's' and not entering.
10007 * 'S' BCO_ENTER initialized 's' should_copy
10008 * yes yes X X TRUE
10009 * yes no yes X FALSE
10010 * no X yes X FALSE
10011 * X no no yes FALSE
10012 * X no no no TRUE
10013 * no yes no X TRUE
10014 */
10015 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10016 && (buf->b_p_initialized
10017 || (!(flags & BCO_ENTER)
10018 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10019 should_copy = FALSE;
10020
10021 if (should_copy || (flags & BCO_ALWAYS))
10022 {
10023 /* Don't copy the options specific to a help buffer when
10024 * BCO_NOHELP is given or the options were initialized already
10025 * (jumping back to a help file with CTRL-T or CTRL-O) */
10026 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10027 || buf->b_p_initialized;
10028 if (dont_do_help) /* don't free b_p_isk */
10029 {
10030 save_p_isk = buf->b_p_isk;
10031 buf->b_p_isk = NULL;
10032 }
10033 /*
10034 * Always free the allocated strings.
10035 * If not already initialized, set 'readonly' and copy 'fileformat'.
10036 */
10037 if (!buf->b_p_initialized)
10038 {
10039 free_buf_options(buf, TRUE);
10040 buf->b_p_ro = FALSE; /* don't copy readonly */
10041 buf->b_p_tx = p_tx;
10042#ifdef FEAT_MBYTE
10043 buf->b_p_fenc = vim_strsave(p_fenc);
10044#endif
10045 buf->b_p_ff = vim_strsave(p_ff);
10046#if defined(FEAT_QUICKFIX)
10047 buf->b_p_bh = empty_option;
10048 buf->b_p_bt = empty_option;
10049#endif
10050 }
10051 else
10052 free_buf_options(buf, FALSE);
10053
10054 buf->b_p_ai = p_ai;
10055 buf->b_p_ai_nopaste = p_ai_nopaste;
10056 buf->b_p_sw = p_sw;
10057 buf->b_p_tw = p_tw;
10058 buf->b_p_tw_nopaste = p_tw_nopaste;
10059 buf->b_p_tw_nobin = p_tw_nobin;
10060 buf->b_p_wm = p_wm;
10061 buf->b_p_wm_nopaste = p_wm_nopaste;
10062 buf->b_p_wm_nobin = p_wm_nobin;
10063 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010064#ifdef FEAT_MBYTE
10065 buf->b_p_bomb = p_bomb;
10066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010067 buf->b_p_et = p_et;
10068 buf->b_p_et_nobin = p_et_nobin;
10069 buf->b_p_ml = p_ml;
10070 buf->b_p_ml_nobin = p_ml_nobin;
10071 buf->b_p_inf = p_inf;
10072 buf->b_p_swf = p_swf;
10073#ifdef FEAT_INS_EXPAND
10074 buf->b_p_cpt = vim_strsave(p_cpt);
10075#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010076#ifdef FEAT_COMPL_FUNC
10077 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010078 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010080 buf->b_p_sts = p_sts;
10081 buf->b_p_sts_nopaste = p_sts_nopaste;
10082#ifndef SHORT_FNAME
10083 buf->b_p_sn = p_sn;
10084#endif
10085#ifdef FEAT_COMMENTS
10086 buf->b_p_com = vim_strsave(p_com);
10087#endif
10088#ifdef FEAT_FOLDING
10089 buf->b_p_cms = vim_strsave(p_cms);
10090#endif
10091 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010092 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010093 buf->b_p_nf = vim_strsave(p_nf);
10094 buf->b_p_mps = vim_strsave(p_mps);
10095#ifdef FEAT_SMARTINDENT
10096 buf->b_p_si = p_si;
10097#endif
10098 buf->b_p_ci = p_ci;
10099#ifdef FEAT_CINDENT
10100 buf->b_p_cin = p_cin;
10101 buf->b_p_cink = vim_strsave(p_cink);
10102 buf->b_p_cino = vim_strsave(p_cino);
10103#endif
10104#ifdef FEAT_AUTOCMD
10105 /* Don't copy 'filetype', it must be detected */
10106 buf->b_p_ft = empty_option;
10107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010108 buf->b_p_pi = p_pi;
10109#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10110 buf->b_p_cinw = vim_strsave(p_cinw);
10111#endif
10112#ifdef FEAT_LISP
10113 buf->b_p_lisp = p_lisp;
10114#endif
10115#ifdef FEAT_SYN_HL
10116 /* Don't copy 'syntax', it must be set */
10117 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010118 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010119#endif
10120#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010121 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010122 (void)compile_cap_prog(&buf->b_s);
10123 buf->b_s.b_p_spf = vim_strsave(p_spf);
10124 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125#endif
10126#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10127 buf->b_p_inde = vim_strsave(p_inde);
10128 buf->b_p_indk = vim_strsave(p_indk);
10129#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010130#if defined(FEAT_EVAL)
10131 buf->b_p_fex = vim_strsave(p_fex);
10132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133#ifdef FEAT_CRYPT
10134 buf->b_p_key = vim_strsave(p_key);
10135#endif
10136#ifdef FEAT_SEARCHPATH
10137 buf->b_p_sua = vim_strsave(p_sua);
10138#endif
10139#ifdef FEAT_KEYMAP
10140 buf->b_p_keymap = vim_strsave(p_keymap);
10141 buf->b_kmap_state |= KEYMAP_INIT;
10142#endif
10143 /* This isn't really an option, but copying the langmap and IME
10144 * state from the current buffer is better than resetting it. */
10145 buf->b_p_iminsert = p_iminsert;
10146 buf->b_p_imsearch = p_imsearch;
10147
10148 /* options that are normally global but also have a local value
10149 * are not copied, start using the global value */
10150 buf->b_p_ar = -1;
10151#ifdef FEAT_QUICKFIX
10152 buf->b_p_gp = empty_option;
10153 buf->b_p_mp = empty_option;
10154 buf->b_p_efm = empty_option;
10155#endif
10156 buf->b_p_ep = empty_option;
10157 buf->b_p_kp = empty_option;
10158 buf->b_p_path = empty_option;
10159 buf->b_p_tags = empty_option;
10160#ifdef FEAT_FIND_ID
10161 buf->b_p_def = empty_option;
10162 buf->b_p_inc = empty_option;
10163# ifdef FEAT_EVAL
10164 buf->b_p_inex = vim_strsave(p_inex);
10165# endif
10166#endif
10167#ifdef FEAT_INS_EXPAND
10168 buf->b_p_dict = empty_option;
10169 buf->b_p_tsr = empty_option;
10170#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010171#ifdef FEAT_TEXTOBJ
10172 buf->b_p_qe = vim_strsave(p_qe);
10173#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010174#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10175 buf->b_p_bexpr = empty_option;
10176#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010177#if defined(FEAT_CRYPT)
10178 buf->b_p_cm = empty_option;
10179#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010180#ifdef FEAT_PERSISTENT_UNDO
10181 buf->b_p_udf = p_udf;
10182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010183
10184 /*
10185 * Don't copy the options set by ex_help(), use the saved values,
10186 * when going from a help buffer to a non-help buffer.
10187 * Don't touch these at all when BCO_NOHELP is used and going from
10188 * or to a help buffer.
10189 */
10190 if (dont_do_help)
10191 buf->b_p_isk = save_p_isk;
10192 else
10193 {
10194 buf->b_p_isk = vim_strsave(p_isk);
10195 did_isk = TRUE;
10196 buf->b_p_ts = p_ts;
10197 buf->b_help = FALSE;
10198#ifdef FEAT_QUICKFIX
10199 if (buf->b_p_bt[0] == 'h')
10200 clear_string_option(&buf->b_p_bt);
10201#endif
10202 buf->b_p_ma = p_ma;
10203 }
10204 }
10205
10206 /*
10207 * When the options should be copied (ignoring BCO_ALWAYS), set the
10208 * flag that indicates that the options have been initialized.
10209 */
10210 if (should_copy)
10211 buf->b_p_initialized = TRUE;
10212 }
10213
10214 check_buf_options(buf); /* make sure we don't have NULLs */
10215 if (did_isk)
10216 (void)buf_init_chartab(buf, FALSE);
10217}
10218
10219/*
10220 * Reset the 'modifiable' option and its default value.
10221 */
10222 void
10223reset_modifiable()
10224{
10225 int opt_idx;
10226
10227 curbuf->b_p_ma = FALSE;
10228 p_ma = FALSE;
10229 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010230 if (opt_idx >= 0)
10231 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232}
10233
10234/*
10235 * Set the global value for 'iminsert' to the local value.
10236 */
10237 void
10238set_iminsert_global()
10239{
10240 p_iminsert = curbuf->b_p_iminsert;
10241}
10242
10243/*
10244 * Set the global value for 'imsearch' to the local value.
10245 */
10246 void
10247set_imsearch_global()
10248{
10249 p_imsearch = curbuf->b_p_imsearch;
10250}
10251
10252#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10253static int expand_option_idx = -1;
10254static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10255static int expand_option_flags = 0;
10256
10257 void
10258set_context_in_set_cmd(xp, arg, opt_flags)
10259 expand_T *xp;
10260 char_u *arg;
10261 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10262{
10263 int nextchar;
10264 long_u flags = 0; /* init for GCC */
10265 int opt_idx = 0; /* init for GCC */
10266 char_u *p;
10267 char_u *s;
10268 int is_term_option = FALSE;
10269 int key;
10270
10271 expand_option_flags = opt_flags;
10272
10273 xp->xp_context = EXPAND_SETTINGS;
10274 if (*arg == NUL)
10275 {
10276 xp->xp_pattern = arg;
10277 return;
10278 }
10279 p = arg + STRLEN(arg) - 1;
10280 if (*p == ' ' && *(p - 1) != '\\')
10281 {
10282 xp->xp_pattern = p + 1;
10283 return;
10284 }
10285 while (p > arg)
10286 {
10287 s = p;
10288 /* count number of backslashes before ' ' or ',' */
10289 if (*p == ' ' || *p == ',')
10290 {
10291 while (s > arg && *(s - 1) == '\\')
10292 --s;
10293 }
10294 /* break at a space with an even number of backslashes */
10295 if (*p == ' ' && ((p - s) & 1) == 0)
10296 {
10297 ++p;
10298 break;
10299 }
10300 --p;
10301 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010302 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303 {
10304 xp->xp_context = EXPAND_BOOL_SETTINGS;
10305 p += 2;
10306 }
10307 if (STRNCMP(p, "inv", 3) == 0)
10308 {
10309 xp->xp_context = EXPAND_BOOL_SETTINGS;
10310 p += 3;
10311 }
10312 xp->xp_pattern = arg = p;
10313 if (*arg == '<')
10314 {
10315 while (*p != '>')
10316 if (*p++ == NUL) /* expand terminal option name */
10317 return;
10318 key = get_special_key_code(arg + 1);
10319 if (key == 0) /* unknown name */
10320 {
10321 xp->xp_context = EXPAND_NOTHING;
10322 return;
10323 }
10324 nextchar = *++p;
10325 is_term_option = TRUE;
10326 expand_option_name[2] = KEY2TERMCAP0(key);
10327 expand_option_name[3] = KEY2TERMCAP1(key);
10328 }
10329 else
10330 {
10331 if (p[0] == 't' && p[1] == '_')
10332 {
10333 p += 2;
10334 if (*p != NUL)
10335 ++p;
10336 if (*p == NUL)
10337 return; /* expand option name */
10338 nextchar = *++p;
10339 is_term_option = TRUE;
10340 expand_option_name[2] = p[-2];
10341 expand_option_name[3] = p[-1];
10342 }
10343 else
10344 {
10345 /* Allow * wildcard */
10346 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10347 p++;
10348 if (*p == NUL)
10349 return;
10350 nextchar = *p;
10351 *p = NUL;
10352 opt_idx = findoption(arg);
10353 *p = nextchar;
10354 if (opt_idx == -1 || options[opt_idx].var == NULL)
10355 {
10356 xp->xp_context = EXPAND_NOTHING;
10357 return;
10358 }
10359 flags = options[opt_idx].flags;
10360 if (flags & P_BOOL)
10361 {
10362 xp->xp_context = EXPAND_NOTHING;
10363 return;
10364 }
10365 }
10366 }
10367 /* handle "-=" and "+=" */
10368 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10369 {
10370 ++p;
10371 nextchar = '=';
10372 }
10373 if ((nextchar != '=' && nextchar != ':')
10374 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10375 {
10376 xp->xp_context = EXPAND_UNSUCCESSFUL;
10377 return;
10378 }
10379 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10380 {
10381 xp->xp_context = EXPAND_OLD_SETTING;
10382 if (is_term_option)
10383 expand_option_idx = -1;
10384 else
10385 expand_option_idx = opt_idx;
10386 xp->xp_pattern = p + 1;
10387 return;
10388 }
10389 xp->xp_context = EXPAND_NOTHING;
10390 if (is_term_option || (flags & P_NUM))
10391 return;
10392
10393 xp->xp_pattern = p + 1;
10394
10395 if (flags & P_EXPAND)
10396 {
10397 p = options[opt_idx].var;
10398 if (p == (char_u *)&p_bdir
10399 || p == (char_u *)&p_dir
10400 || p == (char_u *)&p_path
10401 || p == (char_u *)&p_rtp
10402#ifdef FEAT_SEARCHPATH
10403 || p == (char_u *)&p_cdpath
10404#endif
10405#ifdef FEAT_SESSION
10406 || p == (char_u *)&p_vdir
10407#endif
10408 )
10409 {
10410 xp->xp_context = EXPAND_DIRECTORIES;
10411 if (p == (char_u *)&p_path
10412#ifdef FEAT_SEARCHPATH
10413 || p == (char_u *)&p_cdpath
10414#endif
10415 )
10416 xp->xp_backslash = XP_BS_THREE;
10417 else
10418 xp->xp_backslash = XP_BS_ONE;
10419 }
10420 else
10421 {
10422 xp->xp_context = EXPAND_FILES;
10423 /* for 'tags' need three backslashes for a space */
10424 if (p == (char_u *)&p_tags)
10425 xp->xp_backslash = XP_BS_THREE;
10426 else
10427 xp->xp_backslash = XP_BS_ONE;
10428 }
10429 }
10430
10431 /* For an option that is a list of file names, find the start of the
10432 * last file name. */
10433 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10434 {
10435 /* count number of backslashes before ' ' or ',' */
10436 if (*p == ' ' || *p == ',')
10437 {
10438 s = p;
10439 while (s > xp->xp_pattern && *(s - 1) == '\\')
10440 --s;
10441 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10442 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10443 {
10444 xp->xp_pattern = p + 1;
10445 break;
10446 }
10447 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010448
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010449#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010450 /* for 'spellsuggest' start at "file:" */
10451 if (options[opt_idx].var == (char_u *)&p_sps
10452 && STRNCMP(p, "file:", 5) == 0)
10453 {
10454 xp->xp_pattern = p + 5;
10455 break;
10456 }
10457#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010458 }
10459
10460 return;
10461}
10462
10463 int
10464ExpandSettings(xp, regmatch, num_file, file)
10465 expand_T *xp;
10466 regmatch_T *regmatch;
10467 int *num_file;
10468 char_u ***file;
10469{
10470 int num_normal = 0; /* Nr of matching non-term-code settings */
10471 int num_term = 0; /* Nr of matching terminal code settings */
10472 int opt_idx;
10473 int match;
10474 int count = 0;
10475 char_u *str;
10476 int loop;
10477 int is_term_opt;
10478 char_u name_buf[MAX_KEY_NAME_LEN];
10479 static char *(names[]) = {"all", "termcap"};
10480 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10481
10482 /* do this loop twice:
10483 * loop == 0: count the number of matching options
10484 * loop == 1: copy the matching options into allocated memory
10485 */
10486 for (loop = 0; loop <= 1; ++loop)
10487 {
10488 regmatch->rm_ic = ic;
10489 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10490 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010491 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10492 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10494 {
10495 if (loop == 0)
10496 num_normal++;
10497 else
10498 (*file)[count++] = vim_strsave((char_u *)names[match]);
10499 }
10500 }
10501 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10502 opt_idx++)
10503 {
10504 if (options[opt_idx].var == NULL)
10505 continue;
10506 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10507 && !(options[opt_idx].flags & P_BOOL))
10508 continue;
10509 is_term_opt = istermoption(&options[opt_idx]);
10510 if (is_term_opt && num_normal > 0)
10511 continue;
10512 match = FALSE;
10513 if (vim_regexec(regmatch, str, (colnr_T)0)
10514 || (options[opt_idx].shortname != NULL
10515 && vim_regexec(regmatch,
10516 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10517 match = TRUE;
10518 else if (is_term_opt)
10519 {
10520 name_buf[0] = '<';
10521 name_buf[1] = 't';
10522 name_buf[2] = '_';
10523 name_buf[3] = str[2];
10524 name_buf[4] = str[3];
10525 name_buf[5] = '>';
10526 name_buf[6] = NUL;
10527 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10528 {
10529 match = TRUE;
10530 str = name_buf;
10531 }
10532 }
10533 if (match)
10534 {
10535 if (loop == 0)
10536 {
10537 if (is_term_opt)
10538 num_term++;
10539 else
10540 num_normal++;
10541 }
10542 else
10543 (*file)[count++] = vim_strsave(str);
10544 }
10545 }
10546 /*
10547 * Check terminal key codes, these are not in the option table
10548 */
10549 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10550 {
10551 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10552 {
10553 if (!isprint(str[0]) || !isprint(str[1]))
10554 continue;
10555
10556 name_buf[0] = 't';
10557 name_buf[1] = '_';
10558 name_buf[2] = str[0];
10559 name_buf[3] = str[1];
10560 name_buf[4] = NUL;
10561
10562 match = FALSE;
10563 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10564 match = TRUE;
10565 else
10566 {
10567 name_buf[0] = '<';
10568 name_buf[1] = 't';
10569 name_buf[2] = '_';
10570 name_buf[3] = str[0];
10571 name_buf[4] = str[1];
10572 name_buf[5] = '>';
10573 name_buf[6] = NUL;
10574
10575 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10576 match = TRUE;
10577 }
10578 if (match)
10579 {
10580 if (loop == 0)
10581 num_term++;
10582 else
10583 (*file)[count++] = vim_strsave(name_buf);
10584 }
10585 }
10586
10587 /*
10588 * Check special key names.
10589 */
10590 regmatch->rm_ic = TRUE; /* ignore case here */
10591 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10592 {
10593 name_buf[0] = '<';
10594 STRCPY(name_buf + 1, str);
10595 STRCAT(name_buf, ">");
10596
10597 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10598 {
10599 if (loop == 0)
10600 num_term++;
10601 else
10602 (*file)[count++] = vim_strsave(name_buf);
10603 }
10604 }
10605 }
10606 if (loop == 0)
10607 {
10608 if (num_normal > 0)
10609 *num_file = num_normal;
10610 else if (num_term > 0)
10611 *num_file = num_term;
10612 else
10613 return OK;
10614 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10615 if (*file == NULL)
10616 {
10617 *file = (char_u **)"";
10618 return FAIL;
10619 }
10620 }
10621 }
10622 return OK;
10623}
10624
10625 int
10626ExpandOldSetting(num_file, file)
10627 int *num_file;
10628 char_u ***file;
10629{
10630 char_u *var = NULL; /* init for GCC */
10631 char_u *buf;
10632
10633 *num_file = 0;
10634 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10635 if (*file == NULL)
10636 return FAIL;
10637
10638 /*
10639 * For a terminal key code expand_option_idx is < 0.
10640 */
10641 if (expand_option_idx < 0)
10642 {
10643 var = find_termcode(expand_option_name + 2);
10644 if (var == NULL)
10645 expand_option_idx = findoption(expand_option_name);
10646 }
10647
10648 if (expand_option_idx >= 0)
10649 {
10650 /* put string of option value in NameBuff */
10651 option_value2string(&options[expand_option_idx], expand_option_flags);
10652 var = NameBuff;
10653 }
10654 else if (var == NULL)
10655 var = (char_u *)"";
10656
10657 /* A backslash is required before some characters. This is the reverse of
10658 * what happens in do_set(). */
10659 buf = vim_strsave_escaped(var, escape_chars);
10660
10661 if (buf == NULL)
10662 {
10663 vim_free(*file);
10664 *file = NULL;
10665 return FAIL;
10666 }
10667
10668#ifdef BACKSLASH_IN_FILENAME
10669 /* For MS-Windows et al. we don't double backslashes at the start and
10670 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010671 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010672 if (var[0] == '\\' && var[1] == '\\'
10673 && expand_option_idx >= 0
10674 && (options[expand_option_idx].flags & P_EXPAND)
10675 && vim_isfilec(var[2])
10676 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010677 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678#endif
10679
10680 *file[0] = buf;
10681 *num_file = 1;
10682 return OK;
10683}
10684#endif
10685
10686/*
10687 * Get the value for the numeric or string option *opp in a nice format into
10688 * NameBuff[]. Must not be called with a hidden option!
10689 */
10690 static void
10691option_value2string(opp, opt_flags)
10692 struct vimoption *opp;
10693 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10694{
10695 char_u *varp;
10696
10697 varp = get_varp_scope(opp, opt_flags);
10698
10699 if (opp->flags & P_NUM)
10700 {
10701 long wc = 0;
10702
10703 if (wc_use_keyname(varp, &wc))
10704 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10705 else if (wc != 0)
10706 STRCPY(NameBuff, transchar((int)wc));
10707 else
10708 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10709 }
10710 else /* P_STRING */
10711 {
10712 varp = *(char_u **)(varp);
10713 if (varp == NULL) /* just in case */
10714 NameBuff[0] = NUL;
10715#ifdef FEAT_CRYPT
10716 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010717 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 STRCPY(NameBuff, "*****");
10719#endif
10720 else if (opp->flags & P_EXPAND)
10721 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10722 /* Translate 'pastetoggle' into special key names */
10723 else if ((char_u **)opp->var == &p_pt)
10724 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10725 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010726 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 }
10728}
10729
10730/*
10731 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10732 * printed as a keyname.
10733 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10734 */
10735 static int
10736wc_use_keyname(varp, wcp)
10737 char_u *varp;
10738 long *wcp;
10739{
10740 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10741 {
10742 *wcp = *(long *)varp;
10743 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10744 return TRUE;
10745 }
10746 return FALSE;
10747}
10748
10749#ifdef FEAT_LANGMAP
10750/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010751 * Any character has an equivalent 'langmap' character. This is used for
10752 * keyboards that have a special language mode that sends characters above
10753 * 128 (although other characters can be translated too). The "to" field is a
10754 * Vim command character. This avoids having to switch the keyboard back to
10755 * ASCII mode when leaving Insert mode.
10756 *
10757 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10758 * commands.
10759 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10760 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10761 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010763# ifdef FEAT_MBYTE
10764/*
10765 * With multi-byte support use growarray for 'langmap' chars >= 256
10766 */
10767typedef struct
10768{
10769 int from;
10770 int to;
10771} langmap_entry_T;
10772
10773static garray_T langmap_mapga;
10774static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775
10776/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010777 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10778 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010780 static void
10781langmap_set_entry(from, to)
10782 int from;
10783 int to;
10784{
10785 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020010786 int a = 0;
10787 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010788
10789 /* Do a binary search for an existing entry. */
10790 while (a != b)
10791 {
10792 int i = (a + b) / 2;
10793 int d = entries[i].from - from;
10794
10795 if (d == 0)
10796 {
10797 entries[i].to = to;
10798 return;
10799 }
10800 if (d < 0)
10801 a = i + 1;
10802 else
10803 b = i;
10804 }
10805
10806 if (ga_grow(&langmap_mapga, 1) != OK)
10807 return; /* out of memory */
10808
10809 /* insert new entry at position "a" */
10810 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10811 mch_memmove(entries + 1, entries,
10812 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10813 ++langmap_mapga.ga_len;
10814 entries[0].from = from;
10815 entries[0].to = to;
10816}
10817
10818/*
10819 * Apply 'langmap' to multi-byte character "c" and return the result.
10820 */
10821 int
10822langmap_adjust_mb(c)
10823 int c;
10824{
10825 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10826 int a = 0;
10827 int b = langmap_mapga.ga_len;
10828
10829 while (a != b)
10830 {
10831 int i = (a + b) / 2;
10832 int d = entries[i].from - c;
10833
10834 if (d == 0)
10835 return entries[i].to; /* found matching entry */
10836 if (d < 0)
10837 a = i + 1;
10838 else
10839 b = i;
10840 }
10841 return c; /* no entry found, return "c" unmodified */
10842}
10843# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010844
10845 static void
10846langmap_init()
10847{
10848 int i;
10849
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010850 for (i = 0; i < 256; i++)
10851 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10852# ifdef FEAT_MBYTE
10853 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10854# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855}
10856
10857/*
10858 * Called when langmap option is set; the language map can be
10859 * changed at any time!
10860 */
10861 static void
10862langmap_set()
10863{
10864 char_u *p;
10865 char_u *p2;
10866 int from, to;
10867
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010868#ifdef FEAT_MBYTE
10869 ga_clear(&langmap_mapga); /* clear the previous map first */
10870#endif
10871 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872
10873 for (p = p_langmap; p[0] != NUL; )
10874 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010875 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10876 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010877 {
10878 if (p2[0] == '\\' && p2[1] != NUL)
10879 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880 }
10881 if (p2[0] == ';')
10882 ++p2; /* abcd;ABCD form, p2 points to A */
10883 else
10884 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10885 while (p[0])
10886 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010887 if (p[0] == ',')
10888 {
10889 ++p;
10890 break;
10891 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892 if (p[0] == '\\' && p[1] != NUL)
10893 ++p;
10894#ifdef FEAT_MBYTE
10895 from = (*mb_ptr2char)(p);
10896#else
10897 from = p[0];
10898#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010899 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900 if (p2 == NULL)
10901 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010902 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010903 if (p[0] != ',')
10904 {
10905 if (p[0] == '\\')
10906 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010908 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010910 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010911#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010912 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913 }
10914 else
10915 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010916 if (p2[0] != ',')
10917 {
10918 if (p2[0] == '\\')
10919 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010921 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010923 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010925 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010926 }
10927 if (to == NUL)
10928 {
10929 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10930 transchar(from));
10931 return;
10932 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010933
10934#ifdef FEAT_MBYTE
10935 if (from >= 256)
10936 langmap_set_entry(from, to);
10937 else
10938#endif
10939 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940
10941 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010942 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010943 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010945 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946 if (*p == ';')
10947 {
10948 p = p2;
10949 if (p[0] != NUL)
10950 {
10951 if (p[0] != ',')
10952 {
10953 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10954 return;
10955 }
10956 ++p;
10957 }
10958 break;
10959 }
10960 }
10961 }
10962 }
10963}
10964#endif
10965
10966/*
10967 * Return TRUE if format option 'x' is in effect.
10968 * Take care of no formatting when 'paste' is set.
10969 */
10970 int
10971has_format_option(x)
10972 int x;
10973{
10974 if (p_paste)
10975 return FALSE;
10976 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10977}
10978
10979/*
10980 * Return TRUE if "x" is present in 'shortmess' option, or
10981 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10982 */
10983 int
10984shortmess(x)
10985 int x;
10986{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010010987 return p_shm != NULL &&
10988 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989 || (vim_strchr(p_shm, 'a') != NULL
10990 && vim_strchr((char_u *)SHM_A, x) != NULL));
10991}
10992
10993/*
10994 * paste_option_changed() - Called after p_paste was set or reset.
10995 */
10996 static void
10997paste_option_changed()
10998{
10999 static int old_p_paste = FALSE;
11000 static int save_sm = 0;
11001#ifdef FEAT_CMDL_INFO
11002 static int save_ru = 0;
11003#endif
11004#ifdef FEAT_RIGHTLEFT
11005 static int save_ri = 0;
11006 static int save_hkmap = 0;
11007#endif
11008 buf_T *buf;
11009
11010 if (p_paste)
11011 {
11012 /*
11013 * Paste switched from off to on.
11014 * Save the current values, so they can be restored later.
11015 */
11016 if (!old_p_paste)
11017 {
11018 /* save options for each buffer */
11019 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11020 {
11021 buf->b_p_tw_nopaste = buf->b_p_tw;
11022 buf->b_p_wm_nopaste = buf->b_p_wm;
11023 buf->b_p_sts_nopaste = buf->b_p_sts;
11024 buf->b_p_ai_nopaste = buf->b_p_ai;
11025 }
11026
11027 /* save global options */
11028 save_sm = p_sm;
11029#ifdef FEAT_CMDL_INFO
11030 save_ru = p_ru;
11031#endif
11032#ifdef FEAT_RIGHTLEFT
11033 save_ri = p_ri;
11034 save_hkmap = p_hkmap;
11035#endif
11036 /* save global values for local buffer options */
11037 p_tw_nopaste = p_tw;
11038 p_wm_nopaste = p_wm;
11039 p_sts_nopaste = p_sts;
11040 p_ai_nopaste = p_ai;
11041 }
11042
11043 /*
11044 * Always set the option values, also when 'paste' is set when it is
11045 * already on.
11046 */
11047 /* set options for each buffer */
11048 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11049 {
11050 buf->b_p_tw = 0; /* textwidth is 0 */
11051 buf->b_p_wm = 0; /* wrapmargin is 0 */
11052 buf->b_p_sts = 0; /* softtabstop is 0 */
11053 buf->b_p_ai = 0; /* no auto-indent */
11054 }
11055
11056 /* set global options */
11057 p_sm = 0; /* no showmatch */
11058#ifdef FEAT_CMDL_INFO
11059# ifdef FEAT_WINDOWS
11060 if (p_ru)
11061 status_redraw_all(); /* redraw to remove the ruler */
11062# endif
11063 p_ru = 0; /* no ruler */
11064#endif
11065#ifdef FEAT_RIGHTLEFT
11066 p_ri = 0; /* no reverse insert */
11067 p_hkmap = 0; /* no Hebrew keyboard */
11068#endif
11069 /* set global values for local buffer options */
11070 p_tw = 0;
11071 p_wm = 0;
11072 p_sts = 0;
11073 p_ai = 0;
11074 }
11075
11076 /*
11077 * Paste switched from on to off: Restore saved values.
11078 */
11079 else if (old_p_paste)
11080 {
11081 /* restore options for each buffer */
11082 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11083 {
11084 buf->b_p_tw = buf->b_p_tw_nopaste;
11085 buf->b_p_wm = buf->b_p_wm_nopaste;
11086 buf->b_p_sts = buf->b_p_sts_nopaste;
11087 buf->b_p_ai = buf->b_p_ai_nopaste;
11088 }
11089
11090 /* restore global options */
11091 p_sm = save_sm;
11092#ifdef FEAT_CMDL_INFO
11093# ifdef FEAT_WINDOWS
11094 if (p_ru != save_ru)
11095 status_redraw_all(); /* redraw to draw the ruler */
11096# endif
11097 p_ru = save_ru;
11098#endif
11099#ifdef FEAT_RIGHTLEFT
11100 p_ri = save_ri;
11101 p_hkmap = save_hkmap;
11102#endif
11103 /* set global values for local buffer options */
11104 p_tw = p_tw_nopaste;
11105 p_wm = p_wm_nopaste;
11106 p_sts = p_sts_nopaste;
11107 p_ai = p_ai_nopaste;
11108 }
11109
11110 old_p_paste = p_paste;
11111}
11112
11113/*
11114 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11115 *
11116 * Reset 'compatible' and set the values for options that didn't get set yet
11117 * to the Vim defaults.
11118 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011119 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120 */
11121 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011122vimrc_found(fname, envname)
11123 char_u *fname;
11124 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011125{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011126 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011127 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011128 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129
11130 if (!option_was_set((char_u *)"cp"))
11131 {
11132 p_cp = FALSE;
11133 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11134 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11135 set_option_default(opt_idx, OPT_FREE, FALSE);
11136 didset_options();
11137 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011138
11139 if (fname != NULL)
11140 {
11141 p = vim_getenv(envname, &dofree);
11142 if (p == NULL)
11143 {
11144 /* Set $MYVIMRC to the first vimrc file found. */
11145 p = FullName_save(fname, FALSE);
11146 if (p != NULL)
11147 {
11148 vim_setenv(envname, p);
11149 vim_free(p);
11150 }
11151 }
11152 else if (dofree)
11153 vim_free(p);
11154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155}
11156
11157/*
11158 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11159 */
11160 void
11161change_compatible(on)
11162 int on;
11163{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011164 int opt_idx;
11165
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166 if (p_cp != on)
11167 {
11168 p_cp = on;
11169 compatible_set();
11170 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011171 opt_idx = findoption((char_u *)"cp");
11172 if (opt_idx >= 0)
11173 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011174}
11175
11176/*
11177 * Return TRUE when option "name" has been set.
11178 */
11179 int
11180option_was_set(name)
11181 char_u *name;
11182{
11183 int idx;
11184
11185 idx = findoption(name);
11186 if (idx < 0) /* unknown option */
11187 return FALSE;
11188 if (options[idx].flags & P_WAS_SET)
11189 return TRUE;
11190 return FALSE;
11191}
11192
11193/*
11194 * compatible_set() - Called when 'compatible' has been set or unset.
11195 *
11196 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11197 * flag) to a Vi compatible value.
11198 * When 'compatible' is unset: Set all options that have a different default
11199 * for Vim (without the P_VI_DEF flag) to that default.
11200 */
11201 static void
11202compatible_set()
11203{
11204 int opt_idx;
11205
11206 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11207 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11208 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11209 set_option_default(opt_idx, OPT_FREE, p_cp);
11210 didset_options();
11211}
11212
11213#ifdef FEAT_LINEBREAK
11214
11215# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11216 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011217 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011218# endif
11219
11220/*
11221 * fill_breakat_flags() -- called when 'breakat' changes value.
11222 */
11223 static void
11224fill_breakat_flags()
11225{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011226 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011227 int i;
11228
11229 for (i = 0; i < 256; i++)
11230 breakat_flags[i] = FALSE;
11231
11232 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011233 for (p = p_breakat; *p; p++)
11234 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235}
11236
11237# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011238 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239# endif
11240
11241#endif
11242
11243/*
11244 * Check an option that can be a range of string values.
11245 *
11246 * Return OK for correct value, FAIL otherwise.
11247 * Empty is always OK.
11248 */
11249 static int
11250check_opt_strings(val, values, list)
11251 char_u *val;
11252 char **values;
11253 int list; /* when TRUE: accept a list of values */
11254{
11255 return opt_strings_flags(val, values, NULL, list);
11256}
11257
11258/*
11259 * Handle an option that can be a range of string values.
11260 * Set a flag in "*flagp" for each string present.
11261 *
11262 * Return OK for correct value, FAIL otherwise.
11263 * Empty is always OK.
11264 */
11265 static int
11266opt_strings_flags(val, values, flagp, list)
11267 char_u *val; /* new value */
11268 char **values; /* array of valid string values */
11269 unsigned *flagp;
11270 int list; /* when TRUE: accept a list of values */
11271{
11272 int i;
11273 int len;
11274 unsigned new_flags = 0;
11275
11276 while (*val)
11277 {
11278 for (i = 0; ; ++i)
11279 {
11280 if (values[i] == NULL) /* val not found in values[] */
11281 return FAIL;
11282
11283 len = (int)STRLEN(values[i]);
11284 if (STRNCMP(values[i], val, len) == 0
11285 && ((list && val[len] == ',') || val[len] == NUL))
11286 {
11287 val += len + (val[len] == ',');
11288 new_flags |= (1 << i);
11289 break; /* check next item in val list */
11290 }
11291 }
11292 }
11293 if (flagp != NULL)
11294 *flagp = new_flags;
11295
11296 return OK;
11297}
11298
11299/*
11300 * Read the 'wildmode' option, fill wim_flags[].
11301 */
11302 static int
11303check_opt_wim()
11304{
11305 char_u new_wim_flags[4];
11306 char_u *p;
11307 int i;
11308 int idx = 0;
11309
11310 for (i = 0; i < 4; ++i)
11311 new_wim_flags[i] = 0;
11312
11313 for (p = p_wim; *p; ++p)
11314 {
11315 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11316 ;
11317 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11318 return FAIL;
11319 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11320 new_wim_flags[idx] |= WIM_LONGEST;
11321 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11322 new_wim_flags[idx] |= WIM_FULL;
11323 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11324 new_wim_flags[idx] |= WIM_LIST;
11325 else
11326 return FAIL;
11327 p += i;
11328 if (*p == NUL)
11329 break;
11330 if (*p == ',')
11331 {
11332 if (idx == 3)
11333 return FAIL;
11334 ++idx;
11335 }
11336 }
11337
11338 /* fill remaining entries with last flag */
11339 while (idx < 3)
11340 {
11341 new_wim_flags[idx + 1] = new_wim_flags[idx];
11342 ++idx;
11343 }
11344
11345 /* only when there are no errors, wim_flags[] is changed */
11346 for (i = 0; i < 4; ++i)
11347 wim_flags[i] = new_wim_flags[i];
11348 return OK;
11349}
11350
11351/*
11352 * Check if backspacing over something is allowed.
11353 */
11354 int
11355can_bs(what)
11356 int what; /* BS_INDENT, BS_EOL or BS_START */
11357{
11358 switch (*p_bs)
11359 {
11360 case '2': return TRUE;
11361 case '1': return (what != BS_START);
11362 case '0': return FALSE;
11363 }
11364 return vim_strchr(p_bs, what) != NULL;
11365}
11366
11367/*
11368 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11369 * the file must be considered changed when the value is different.
11370 */
11371 void
11372save_file_ff(buf)
11373 buf_T *buf;
11374{
11375 buf->b_start_ffc = *buf->b_p_ff;
11376 buf->b_start_eol = buf->b_p_eol;
11377#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011378 buf->b_start_bomb = buf->b_p_bomb;
11379
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380 /* Only use free/alloc when necessary, they take time. */
11381 if (buf->b_start_fenc == NULL
11382 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11383 {
11384 vim_free(buf->b_start_fenc);
11385 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11386 }
11387#endif
11388}
11389
11390/*
11391 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11392 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011393 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11394 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011395 * When "ignore_empty" is true don't consider a new, empty buffer to be
11396 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011397 */
11398 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011399file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011401 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011402{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011403 /* In a buffer that was never loaded the options are not valid. */
11404 if (buf->b_flags & BF_NEVERLOADED)
11405 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011406 if (ignore_empty
11407 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408 && buf->b_ml.ml_line_count == 1
11409 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11410 return FALSE;
11411 if (buf->b_start_ffc != *buf->b_p_ff)
11412 return TRUE;
11413 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11414 return TRUE;
11415#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011416 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11417 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011418 if (buf->b_start_fenc == NULL)
11419 return (*buf->b_p_fenc != NUL);
11420 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11421#else
11422 return FALSE;
11423#endif
11424}
11425
11426/*
11427 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11428 */
11429 int
11430check_ff_value(p)
11431 char_u *p;
11432{
11433 return check_opt_strings(p, p_ff_values, FALSE);
11434}