blob: 4b669be7236f122c2593927da6f482e09ea1881f [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
80#ifdef FEAT_FOLDING
81# define PV_CMS OPT_BUF(BV_CMS)
82#endif
83#ifdef FEAT_COMMENTS
84# define PV_COM OPT_BUF(BV_COM)
85#endif
86#ifdef FEAT_INS_EXPAND
87# define PV_CPT OPT_BUF(BV_CPT)
88# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
89# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
90#endif
91#ifdef FEAT_COMPL_FUNC
92# define PV_CFU OPT_BUF(BV_CFU)
93#endif
94#ifdef FEAT_FIND_ID
95# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
96# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
97#endif
98#define PV_EOL OPT_BUF(BV_EOL)
99#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
100#define PV_ET OPT_BUF(BV_ET)
101#ifdef FEAT_MBYTE
102# define PV_FENC OPT_BUF(BV_FENC)
103#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000104#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
105# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
106#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000107#ifdef FEAT_EVAL
108# define PV_FEX OPT_BUF(BV_FEX)
109#endif
110#define PV_FF OPT_BUF(BV_FF)
111#define PV_FLP OPT_BUF(BV_FLP)
112#define PV_FO OPT_BUF(BV_FO)
113#ifdef FEAT_AUTOCMD
114# define PV_FT OPT_BUF(BV_FT)
115#endif
116#define PV_IMI OPT_BUF(BV_IMI)
117#define PV_IMS OPT_BUF(BV_IMS)
118#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
119# define PV_INDE OPT_BUF(BV_INDE)
120# define PV_INDK OPT_BUF(BV_INDK)
121#endif
122#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
123# define PV_INEX OPT_BUF(BV_INEX)
124#endif
125#define PV_INF OPT_BUF(BV_INF)
126#define PV_ISK OPT_BUF(BV_ISK)
127#ifdef FEAT_CRYPT
128# define PV_KEY OPT_BUF(BV_KEY)
129#endif
130#ifdef FEAT_KEYMAP
131# define PV_KMAP OPT_BUF(BV_KMAP)
132#endif
133#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
134#ifdef FEAT_LISP
135# define PV_LISP OPT_BUF(BV_LISP)
136#endif
137#define PV_MA OPT_BUF(BV_MA)
138#define PV_ML OPT_BUF(BV_ML)
139#define PV_MOD OPT_BUF(BV_MOD)
140#define PV_MPS OPT_BUF(BV_MPS)
141#define PV_NF OPT_BUF(BV_NF)
142#ifdef FEAT_OSFILETYPE
143# define PV_OFT OPT_BUF(BV_OFT)
144#endif
145#ifdef FEAT_COMPL_FUNC
146# define PV_OFU OPT_BUF(BV_OFU)
147#endif
148#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
149#define PV_PI OPT_BUF(BV_PI)
150#ifdef FEAT_TEXTOBJ
151# define PV_QE OPT_BUF(BV_QE)
152#endif
153#define PV_RO OPT_BUF(BV_RO)
154#ifdef FEAT_SMARTINDENT
155# define PV_SI OPT_BUF(BV_SI)
156#endif
157#ifndef SHORT_FNAME
158# define PV_SN OPT_BUF(BV_SN)
159#endif
160#ifdef FEAT_SYN_HL
161# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000162# define PV_SYN OPT_BUF(BV_SYN)
163#endif
164#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000165# define PV_SPC OPT_BUF(BV_SPC)
166# define PV_SPF OPT_BUF(BV_SPF)
167# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168#endif
169#define PV_STS OPT_BUF(BV_STS)
170#ifdef FEAT_SEARCHPATH
171# define PV_SUA OPT_BUF(BV_SUA)
172#endif
173#define PV_SW OPT_BUF(BV_SW)
174#define PV_SWF OPT_BUF(BV_SWF)
175#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
179#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000180
181/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182 * Definition of the PV_ values for window-local options.
183 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185#define PV_LIST OPT_WIN(WV_LIST)
186#ifdef FEAT_ARABIC
187# define PV_ARAB OPT_WIN(WV_ARAB)
188#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189#ifdef FEAT_DIFF
190# define PV_DIFF OPT_WIN(WV_DIFF)
191#endif
192#ifdef FEAT_FOLDING
193# define PV_FDC OPT_WIN(WV_FDC)
194# define PV_FEN OPT_WIN(WV_FEN)
195# define PV_FDI OPT_WIN(WV_FDI)
196# define PV_FDL OPT_WIN(WV_FDL)
197# define PV_FDM OPT_WIN(WV_FDM)
198# define PV_FML OPT_WIN(WV_FML)
199# define PV_FDN OPT_WIN(WV_FDN)
200# ifdef FEAT_EVAL
201# define PV_FDE OPT_WIN(WV_FDE)
202# define PV_FDT OPT_WIN(WV_FDT)
203# endif
204# define PV_FMR OPT_WIN(WV_FMR)
205#endif
206#ifdef FEAT_LINEBREAK
207# define PV_LBR OPT_WIN(WV_LBR)
208#endif
209#define PV_NU OPT_WIN(WV_NU)
210#ifdef FEAT_LINEBREAK
211# define PV_NUW OPT_WIN(WV_NUW)
212#endif
213#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
214# define PV_PVW OPT_WIN(WV_PVW)
215#endif
216#ifdef FEAT_RIGHTLEFT
217# define PV_RL OPT_WIN(WV_RL)
218# define PV_RLC OPT_WIN(WV_RLC)
219#endif
220#ifdef FEAT_SCROLLBIND
221# define PV_SCBIND OPT_WIN(WV_SCBIND)
222#endif
223#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000224#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000225# define PV_SPELL OPT_WIN(WV_SPELL)
226#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000227#ifdef FEAT_SYN_HL
228# define PV_CUC OPT_WIN(WV_CUC)
229# define PV_CUL OPT_WIN(WV_CUL)
230#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000231#ifdef FEAT_STL_OPT
232# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
233#endif
234#ifdef FEAT_WINDOWS
235# define PV_WFH OPT_WIN(WV_WFH)
236#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000237#ifdef FEAT_VERTSPLIT
238# define PV_WFW OPT_WIN(WV_WFW)
239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000241
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242
243/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244typedef enum
245{
246 PV_NONE = 0
Bram Moolenaar071d4272004-06-13 20:20:40 +0000247} idopt_T;
248
249/*
250 * Options local to a window have a value local to a buffer and global to all
251 * buffers. Indicate this by setting "var" to VAR_WIN.
252 */
253#define VAR_WIN ((char_u *)-1)
254
255/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000256 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257 * Only to be used in option.c!
258 */
259static int p_ai;
260static int p_bin;
261#ifdef FEAT_MBYTE
262static int p_bomb;
263#endif
264#if defined(FEAT_QUICKFIX)
265static char_u *p_bh;
266static char_u *p_bt;
267#endif
268static int p_bl;
269static int p_ci;
270#ifdef FEAT_CINDENT
271static int p_cin;
272static char_u *p_cink;
273static char_u *p_cino;
274#endif
275#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
276static char_u *p_cinw;
277#endif
278#ifdef FEAT_COMMENTS
279static char_u *p_com;
280#endif
281#ifdef FEAT_FOLDING
282static char_u *p_cms;
283#endif
284#ifdef FEAT_INS_EXPAND
285static char_u *p_cpt;
286#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000287#ifdef FEAT_COMPL_FUNC
288static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000289static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000290#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000291static int p_eol;
292static int p_et;
293#ifdef FEAT_MBYTE
294static char_u *p_fenc;
295#endif
296static char_u *p_ff;
297static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000298static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000299#ifdef FEAT_AUTOCMD
300static char_u *p_ft;
301#endif
302static long p_iminsert;
303static long p_imsearch;
304#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
305static char_u *p_inex;
306#endif
307#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
308static char_u *p_inde;
309static char_u *p_indk;
310#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000311#if defined(FEAT_EVAL)
312static char_u *p_fex;
313#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static int p_inf;
315static char_u *p_isk;
316#ifdef FEAT_CRYPT
317static char_u *p_key;
318#endif
319#ifdef FEAT_LISP
320static int p_lisp;
321#endif
322static int p_ml;
323static int p_ma;
324static int p_mod;
325static char_u *p_mps;
326static char_u *p_nf;
327#ifdef FEAT_OSFILETYPE
328static char_u *p_oft;
329#endif
330static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000331#ifdef FEAT_TEXTOBJ
332static char_u *p_qe;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_ro;
335#ifdef FEAT_SMARTINDENT
336static int p_si;
337#endif
338#ifndef SHORT_FNAME
339static int p_sn;
340#endif
341static long p_sts;
342#if defined(FEAT_SEARCHPATH)
343static char_u *p_sua;
344#endif
345static long p_sw;
346static int p_swf;
347#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000348static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000349static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000350#endif
351#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000352static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000353static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000354static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355#endif
356static long p_ts;
357static long p_tw;
358static int p_tx;
359static long p_wm;
360#ifdef FEAT_KEYMAP
361static char_u *p_keymap;
362#endif
363
364/* Saved values for when 'bin' is set. */
365static int p_et_nobin;
366static int p_ml_nobin;
367static long p_tw_nobin;
368static long p_wm_nobin;
369
370/* Saved values for when 'paste' is set */
371static long p_tw_nopaste;
372static long p_wm_nopaste;
373static long p_sts_nopaste;
374static int p_ai_nopaste;
375
376struct vimoption
377{
378 char *fullname; /* full option name */
379 char *shortname; /* permissible abbreviation */
380 long_u flags; /* see below */
381 char_u *var; /* global option: pointer to variable;
382 * window-local option: VAR_WIN;
383 * buffer-local option: global value */
384 idopt_T indir; /* global option: PV_NONE;
385 * local option: indirect option index */
386 char_u *def_val[2]; /* default values for variable (vi and vim) */
387#ifdef FEAT_EVAL
388 scid_T scriptID; /* script in which the option was last set */
389#endif
390};
391
392#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
393#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
394
395/*
396 * Flags
397 */
398#define P_BOOL 0x01 /* the option is boolean */
399#define P_NUM 0x02 /* the option is numeric */
400#define P_STRING 0x04 /* the option is a string */
401#define P_ALLOCED 0x08 /* the string option is in allocated memory,
402 must use vim_free() when assigning new
403 value. Not set if default is the same. */
404#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
405 never be used for local or hidden options! */
406#define P_NODEFAULT 0x40 /* don't set to default value */
407#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
408 use vim_free() when assigning new value */
409#define P_WAS_SET 0x100 /* option has been set/reset */
410#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
411#define P_VI_DEF 0x400 /* Use Vi default for Vim */
412#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
413
414 /* when option changed, what to display: */
415#define P_RSTAT 0x1000 /* redraw status lines */
416#define P_RWIN 0x2000 /* redraw current window */
417#define P_RBUF 0x4000 /* redraw current buffer */
418#define P_RALL 0x6000 /* redraw all windows */
419#define P_RCLR 0x7000 /* clear and redraw all */
420
421#define P_COMMA 0x8000 /* comma separated list */
422#define P_NODUP 0x10000L/* don't allow duplicate strings */
423#define P_FLAGLIST 0x20000L/* list of single-char flags */
424
425#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
426#define P_GETTEXT 0x80000L/* expand default value with _() */
427#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000428#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000429#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000431#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
432
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000433/* 'isprint' for latin1 is also used for MS-Windows, where 0x80 is used for
434 * the currency sign. Thus this isn't really latin1... */
435#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
436# define ISP_LATIN1 (char_u *)"@,128,161-255"
437#else
438# define ISP_LATIN1 (char_u *)"@,161-255"
439#endif
440
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441/*
442 * options[] is initialized here.
443 * The order of the options MUST be alphabetic for ":set all" and findoption().
444 * All option names MUST start with a lowercase letter (for findoption()).
445 * Exception: "t_" options are at the end.
446 * The options with a NULL variable are 'hidden': a set command for them is
447 * ignored and they are not printed.
448 */
449static struct vimoption
450#ifdef FEAT_GUI_W16
451 _far
452#endif
453 options[] =
454{
455 {"aleph", "al", P_NUM|P_VI_DEF,
456#ifdef FEAT_RIGHTLEFT
457 (char_u *)&p_aleph, PV_NONE,
458#else
459 (char_u *)NULL, PV_NONE,
460#endif
461 {
462#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
463 (char_u *)128L,
464#else
465 (char_u *)224L,
466#endif
467 (char_u *)0L}},
468 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
469#if defined(FEAT_GUI) && defined(MACOS_X)
470 (char_u *)&p_antialias, PV_NONE,
471 {(char_u *)FALSE, (char_u *)FALSE}
472#else
473 (char_u *)NULL, PV_NONE,
474 {(char_u *)FALSE, (char_u *)FALSE}
475#endif
476 },
477 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
478#ifdef FEAT_ARABIC
479 (char_u *)VAR_WIN, PV_ARAB,
480#else
481 (char_u *)NULL, PV_NONE,
482#endif
483 {(char_u *)FALSE, (char_u *)0L}},
484 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
485#ifdef FEAT_ARABIC
486 (char_u *)&p_arshape, PV_NONE,
487#else
488 (char_u *)NULL, PV_NONE,
489#endif
490 {(char_u *)TRUE, (char_u *)0L}},
491 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
492#ifdef FEAT_RIGHTLEFT
493 (char_u *)&p_ari, PV_NONE,
494#else
495 (char_u *)NULL, PV_NONE,
496#endif
497 {(char_u *)FALSE, (char_u *)0L}},
498 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
499#ifdef FEAT_FKMAP
500 (char_u *)&p_altkeymap, PV_NONE,
501#else
502 (char_u *)NULL, PV_NONE,
503#endif
504 {(char_u *)FALSE, (char_u *)0L}},
505 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
506#if defined(FEAT_MBYTE)
507 (char_u *)&p_ambw, PV_NONE,
508 {(char_u *)"single", (char_u *)0L}
509#else
510 (char_u *)NULL, PV_NONE,
511 {(char_u *)0L, (char_u *)0L}
512#endif
513 },
514#if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
515 {"autochdir", "acd", P_BOOL|P_VI_DEF,
516 (char_u *)&p_acd, PV_NONE,
517 {(char_u *)FALSE, (char_u *)0L}},
518#endif
519 {"autoindent", "ai", P_BOOL|P_VI_DEF,
520 (char_u *)&p_ai, PV_AI,
521 {(char_u *)FALSE, (char_u *)0L}},
522 {"autoprint", "ap", P_BOOL|P_VI_DEF,
523 (char_u *)NULL, PV_NONE,
524 {(char_u *)FALSE, (char_u *)0L}},
525 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000526 (char_u *)&p_ar, PV_AR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527 {(char_u *)FALSE, (char_u *)0L}},
528 {"autowrite", "aw", P_BOOL|P_VI_DEF,
529 (char_u *)&p_aw, PV_NONE,
530 {(char_u *)FALSE, (char_u *)0L}},
531 {"autowriteall","awa", P_BOOL|P_VI_DEF,
532 (char_u *)&p_awa, PV_NONE,
533 {(char_u *)FALSE, (char_u *)0L}},
534 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
535 (char_u *)&p_bg, PV_NONE,
536 {
537#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
538 (char_u *)"dark",
539#else
540 (char_u *)"light",
541#endif
542 (char_u *)0L}},
543 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
544 (char_u *)&p_bs, PV_NONE,
545 {(char_u *)"", (char_u *)0L}},
546 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
547 (char_u *)&p_bk, PV_NONE,
548 {(char_u *)FALSE, (char_u *)0L}},
549 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
550 (char_u *)&p_bkc, PV_NONE,
551#ifdef UNIX
552 {(char_u *)"yes", (char_u *)"auto"}
553#else
554 {(char_u *)"auto", (char_u *)"auto"}
555#endif
556 },
557 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
558 (char_u *)&p_bdir, PV_NONE,
559 {(char_u *)DFLT_BDIR, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000560 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 (char_u *)&p_bex, PV_NONE,
562 {
563#ifdef VMS
564 (char_u *)"_",
565#else
566 (char_u *)"~",
567#endif
568 (char_u *)0L}},
569 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
570#ifdef FEAT_WILDIGN
571 (char_u *)&p_bsk, PV_NONE,
572 {(char_u *)"", (char_u *)0L}
573#else
574 (char_u *)NULL, PV_NONE,
575 {(char_u *)0L, (char_u *)0L}
576#endif
577 },
578#ifdef FEAT_BEVAL
579 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
580 (char_u *)&p_bdlay, PV_NONE,
581 {(char_u *)600L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
583 (char_u *)&p_beval, PV_NONE,
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000584 {(char_u *)FALSE, (char_u *)0L}},
585# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000586 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000587 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000588 {(char_u *)"", (char_u *)0L}},
589# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590#endif
591 {"beautify", "bf", P_BOOL|P_VI_DEF,
592 (char_u *)NULL, PV_NONE,
593 {(char_u *)FALSE, (char_u *)0L}},
594 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
595 (char_u *)&p_bin, PV_BIN,
596 {(char_u *)FALSE, (char_u *)0L}},
597 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
598#ifdef MSDOS
599 (char_u *)&p_biosk, PV_NONE,
600#else
601 (char_u *)NULL, PV_NONE,
602#endif
603 {(char_u *)TRUE, (char_u *)0L}},
604 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
605#ifdef FEAT_MBYTE
606 (char_u *)&p_bomb, PV_BOMB,
607#else
608 (char_u *)NULL, PV_NONE,
609#endif
610 {(char_u *)FALSE, (char_u *)0L}},
611 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
612#ifdef FEAT_LINEBREAK
613 (char_u *)&p_breakat, PV_NONE,
614 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
615#else
616 (char_u *)NULL, PV_NONE,
617 {(char_u *)0L, (char_u *)0L}
618#endif
619 },
620 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
621#ifdef FEAT_BROWSE
622 (char_u *)&p_bsdir, PV_NONE,
623 {(char_u *)"last", (char_u *)0L}
624#else
625 (char_u *)NULL, PV_NONE,
626 {(char_u *)0L, (char_u *)0L}
627#endif
628 },
629 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
630#if defined(FEAT_QUICKFIX)
631 (char_u *)&p_bh, PV_BH,
632 {(char_u *)"", (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
636#endif
637 },
638 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
639 (char_u *)&p_bl, PV_BL,
640 {(char_u *)1L, (char_u *)0L}
641 },
642 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
643#if defined(FEAT_QUICKFIX)
644 (char_u *)&p_bt, PV_BT,
645 {(char_u *)"", (char_u *)0L}
646#else
647 (char_u *)NULL, PV_NONE,
648 {(char_u *)0L, (char_u *)0L}
649#endif
650 },
651 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000652#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000653 (char_u *)&p_cmp, PV_NONE,
654 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000655#else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659 },
660 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
661#ifdef FEAT_SEARCHPATH
662 (char_u *)&p_cdpath, PV_NONE,
663 {(char_u *)",,", (char_u *)0L}
664#else
665 (char_u *)NULL, PV_NONE,
666 {(char_u *)0L, (char_u *)0L}
667#endif
668 },
669 {"cedit", NULL, P_STRING,
670#ifdef FEAT_CMDWIN
671 (char_u *)&p_cedit, PV_NONE,
672 {(char_u *)"", (char_u *)CTRL_F_STR}
673#else
674 (char_u *)NULL, PV_NONE,
675 {(char_u *)0L, (char_u *)0L}
676#endif
677 },
678 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
679#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
680 (char_u *)&p_ccv, PV_NONE,
681 {(char_u *)"", (char_u *)0L}
682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)0L, (char_u *)0L}
685#endif
686 },
687 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
688#ifdef FEAT_CINDENT
689 (char_u *)&p_cin, PV_CIN,
690#else
691 (char_u *)NULL, PV_NONE,
692#endif
693 {(char_u *)FALSE, (char_u *)0L}},
694 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
695#ifdef FEAT_CINDENT
696 (char_u *)&p_cink, PV_CINK,
697 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
698#else
699 (char_u *)NULL, PV_NONE,
700 {(char_u *)0L, (char_u *)0L}
701#endif
702 },
703 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
704#ifdef FEAT_CINDENT
705 (char_u *)&p_cino, PV_CINO,
706#else
707 (char_u *)NULL, PV_NONE,
708#endif
709 {(char_u *)"", (char_u *)0L}},
710 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
711#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
712 (char_u *)&p_cinw, PV_CINW,
713 {(char_u *)"if,else,while,do,for,switch",
714 (char_u *)0L}
715#else
716 (char_u *)NULL, PV_NONE,
717 {(char_u *)0L, (char_u *)0L}
718#endif
719 },
720 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
721#ifdef FEAT_CLIPBOARD
722 (char_u *)&p_cb, PV_NONE,
723# ifdef FEAT_XCLIPBOARD
724 {(char_u *)"autoselect,exclude:cons\\|linux",
725 (char_u *)0L}
726# else
727 {(char_u *)"", (char_u *)0L}
728# endif
729#else
730 (char_u *)NULL, PV_NONE,
731 {(char_u *)"", (char_u *)0L}
732#endif
733 },
734 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
735 (char_u *)&p_ch, PV_NONE,
736 {(char_u *)1L, (char_u *)0L}},
737 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
738#ifdef FEAT_CMDWIN
739 (char_u *)&p_cwh, PV_NONE,
740#else
741 (char_u *)NULL, PV_NONE,
742#endif
743 {(char_u *)7L, (char_u *)0L}},
744 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
745 (char_u *)&Columns, PV_NONE,
746 {(char_u *)80L, (char_u *)0L}},
747 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
748#ifdef FEAT_COMMENTS
749 (char_u *)&p_com, PV_COM,
750 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
751 (char_u *)0L}
752#else
753 (char_u *)NULL, PV_NONE,
754 {(char_u *)0L, (char_u *)0L}
755#endif
756 },
757 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
758#ifdef FEAT_FOLDING
759 (char_u *)&p_cms, PV_CMS,
760 {(char_u *)"/*%s*/", (char_u *)0L}
761#else
762 (char_u *)NULL, PV_NONE,
763 {(char_u *)0L, (char_u *)0L}
764#endif
765 },
766 {"compatible", "cp", P_BOOL|P_RALL,
767 (char_u *)&p_cp, PV_NONE,
768 {(char_u *)TRUE, (char_u *)FALSE}},
769 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
770#ifdef FEAT_INS_EXPAND
771 (char_u *)&p_cpt, PV_CPT,
772 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
773#else
774 (char_u *)NULL, PV_NONE,
775 {(char_u *)0L, (char_u *)0L}
776#endif
777 },
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000778 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
779#ifdef FEAT_COMPL_FUNC
780 (char_u *)&p_cfu, PV_CFU,
781 {(char_u *)"", (char_u *)0L}
782#else
783 (char_u *)NULL, PV_NONE,
784 {(char_u *)0L, (char_u *)0L}
785#endif
786 },
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000787 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
788#ifdef FEAT_INS_EXPAND
789 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000790 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000791#else
792 (char_u *)NULL, PV_NONE,
793 {(char_u *)0L, (char_u *)0L}
794#endif
795 },
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796 {"confirm", "cf", P_BOOL|P_VI_DEF,
797#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
798 (char_u *)&p_confirm, PV_NONE,
799#else
800 (char_u *)NULL, PV_NONE,
801#endif
802 {(char_u *)FALSE, (char_u *)0L}},
803 {"conskey", "consk",P_BOOL|P_VI_DEF,
804#ifdef MSDOS
805 (char_u *)&p_consk, PV_NONE,
806#else
807 (char_u *)NULL, PV_NONE,
808#endif
809 {(char_u *)FALSE, (char_u *)0L}},
810 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
811 (char_u *)&p_ci, PV_CI,
812 {(char_u *)FALSE, (char_u *)0L}},
813 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
814 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar4399ef42005-02-12 14:29:27 +0000815 {(char_u *)CPO_VI, (char_u *)CPO_VIM}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
817#ifdef FEAT_CSCOPE
818 (char_u *)&p_cspc, PV_NONE,
819#else
820 (char_u *)NULL, PV_NONE,
821#endif
822 {(char_u *)0L, (char_u *)0L}},
823 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
824#ifdef FEAT_CSCOPE
825 (char_u *)&p_csprg, PV_NONE,
826 {(char_u *)"cscope", (char_u *)0L}
827#else
828 (char_u *)NULL, PV_NONE,
829 {(char_u *)0L, (char_u *)0L}
830#endif
831 },
832 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
833#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
834 (char_u *)&p_csqf, PV_NONE,
835 {(char_u *)"", (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
840 },
841 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
842#ifdef FEAT_CSCOPE
843 (char_u *)&p_cst, PV_NONE,
844#else
845 (char_u *)NULL, PV_NONE,
846#endif
847 {(char_u *)0L, (char_u *)0L}},
848 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
849#ifdef FEAT_CSCOPE
850 (char_u *)&p_csto, PV_NONE,
851#else
852 (char_u *)NULL, PV_NONE,
853#endif
854 {(char_u *)0L, (char_u *)0L}},
855 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
856#ifdef FEAT_CSCOPE
857 (char_u *)&p_csverbose, PV_NONE,
858#else
859 (char_u *)NULL, PV_NONE,
860#endif
861 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000862 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
863#ifdef FEAT_SYN_HL
864 (char_u *)VAR_WIN, PV_CUC,
865#else
866 (char_u *)NULL, PV_NONE,
867#endif
868 {(char_u *)FALSE, (char_u *)0L}},
869 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
870#ifdef FEAT_SYN_HL
871 (char_u *)VAR_WIN, PV_CUL,
872#else
873 (char_u *)NULL, PV_NONE,
874#endif
875 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876 {"debug", NULL, P_STRING|P_VI_DEF,
877 (char_u *)&p_debug, PV_NONE,
878 {(char_u *)"", (char_u *)0L}},
879 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
880#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000881 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000882 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883#else
884 (char_u *)NULL, PV_NONE,
885 {(char_u *)NULL, (char_u *)0L}
886#endif
887 },
888 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
889#ifdef FEAT_MBYTE
890 (char_u *)&p_deco, PV_NONE,
891#else
892 (char_u *)NULL, PV_NONE,
893#endif
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000894 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
896#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000897 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898#else
899 (char_u *)NULL, PV_NONE,
900#endif
901 {(char_u *)"", (char_u *)0L}},
902 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
903#ifdef FEAT_DIFF
904 (char_u *)VAR_WIN, PV_DIFF,
905#else
906 (char_u *)NULL, PV_NONE,
907#endif
908 {(char_u *)FALSE, (char_u *)0L}},
909 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
910#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
911 (char_u *)&p_dex, PV_NONE,
912 {(char_u *)"", (char_u *)0L}
913#else
914 (char_u *)NULL, PV_NONE,
915 {(char_u *)0L, (char_u *)0L}
916#endif
917 },
918 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
919#ifdef FEAT_DIFF
920 (char_u *)&p_dip, PV_NONE,
921 {(char_u *)"filler", (char_u *)NULL}
922#else
923 (char_u *)NULL, PV_NONE,
924 {(char_u *)"", (char_u *)NULL}
925#endif
926 },
927 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
928#ifdef FEAT_DIGRAPHS
929 (char_u *)&p_dg, PV_NONE,
930#else
931 (char_u *)NULL, PV_NONE,
932#endif
933 {(char_u *)FALSE, (char_u *)0L}},
934 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
935 (char_u *)&p_dir, PV_NONE,
936 {(char_u *)DFLT_DIR, (char_u *)0L}},
937 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
938 (char_u *)&p_dy, PV_NONE,
939 {(char_u *)"", (char_u *)0L}},
940 {"eadirection", "ead", P_STRING|P_VI_DEF,
941#ifdef FEAT_VERTSPLIT
942 (char_u *)&p_ead, PV_NONE,
943 {(char_u *)"both", (char_u *)0L}
944#else
945 (char_u *)NULL, PV_NONE,
946 {(char_u *)NULL, (char_u *)0L}
947#endif
948 },
949 {"edcompatible","ed", P_BOOL|P_VI_DEF,
950 (char_u *)&p_ed, PV_NONE,
951 {(char_u *)FALSE, (char_u *)0L}},
952 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
953#ifdef FEAT_MBYTE
954 (char_u *)&p_enc, PV_NONE,
955 {(char_u *)ENC_DFLT, (char_u *)0L}
956#else
957 (char_u *)NULL, PV_NONE,
958 {(char_u *)0L, (char_u *)0L}
959#endif
960 },
961 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
962 (char_u *)&p_eol, PV_EOL,
963 {(char_u *)TRUE, (char_u *)0L}},
964 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
965 (char_u *)&p_ea, PV_NONE,
966 {(char_u *)TRUE, (char_u *)0L}},
967 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000968 (char_u *)&p_ep, PV_EP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {(char_u *)"", (char_u *)0L}},
970 {"errorbells", "eb", P_BOOL|P_VI_DEF,
971 (char_u *)&p_eb, PV_NONE,
972 {(char_u *)FALSE, (char_u *)0L}},
973 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
974#ifdef FEAT_QUICKFIX
975 (char_u *)&p_ef, PV_NONE,
976 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
977#else
978 (char_u *)NULL, PV_NONE,
979 {(char_u *)NULL, (char_u *)0L}
980#endif
981 },
982 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
983#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000984 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {(char_u *)DFLT_EFM, (char_u *)0L},
986#else
987 (char_u *)NULL, PV_NONE,
988 {(char_u *)NULL, (char_u *)0L}
989#endif
990 },
991 {"esckeys", "ek", P_BOOL|P_VIM,
992 (char_u *)&p_ek, PV_NONE,
993 {(char_u *)FALSE, (char_u *)TRUE}},
994 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
995#ifdef FEAT_AUTOCMD
996 (char_u *)&p_ei, PV_NONE,
997#else
998 (char_u *)NULL, PV_NONE,
999#endif
1000 {(char_u *)"", (char_u *)0L}},
1001 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1002 (char_u *)&p_et, PV_ET,
1003 {(char_u *)FALSE, (char_u *)0L}},
1004 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1005 (char_u *)&p_exrc, PV_NONE,
1006 {(char_u *)FALSE, (char_u *)0L}},
1007 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1008#ifdef FEAT_MBYTE
1009 (char_u *)&p_fenc, PV_FENC,
1010 {(char_u *)"", (char_u *)0L}
1011#else
1012 (char_u *)NULL, PV_NONE,
1013 {(char_u *)0L, (char_u *)0L}
1014#endif
1015 },
1016 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1017#ifdef FEAT_MBYTE
1018 (char_u *)&p_fencs, PV_NONE,
1019 {(char_u *)"ucs-bom", (char_u *)0L}
1020#else
1021 (char_u *)NULL, PV_NONE,
1022 {(char_u *)0L, (char_u *)0L}
1023#endif
1024 },
1025 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1026 (char_u *)&p_ff, PV_FF,
1027 {(char_u *)DFLT_FF, (char_u *)0L}},
1028 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1029 (char_u *)&p_ffs, PV_NONE,
1030 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001031 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032#ifdef FEAT_AUTOCMD
1033 (char_u *)&p_ft, PV_FT,
1034 {(char_u *)"", (char_u *)0L}
1035#else
1036 (char_u *)NULL, PV_NONE,
1037 {(char_u *)0L, (char_u *)0L}
1038#endif
1039 },
1040 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1041#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1042 (char_u *)&p_fcs, PV_NONE,
1043 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1044#else
1045 (char_u *)NULL, PV_NONE,
1046 {(char_u *)"", (char_u *)0L}
1047#endif
1048 },
1049 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1050#ifdef FEAT_FKMAP
1051 (char_u *)&p_fkmap, PV_NONE,
1052#else
1053 (char_u *)NULL, PV_NONE,
1054#endif
1055 {(char_u *)FALSE, (char_u *)0L}},
1056 {"flash", "fl", P_BOOL|P_VI_DEF,
1057 (char_u *)NULL, PV_NONE,
1058 {(char_u *)FALSE, (char_u *)0L}},
1059#ifdef FEAT_FOLDING
1060 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1061 (char_u *)&p_fcl, PV_NONE,
1062 {(char_u *)"", (char_u *)0L}},
1063 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1064 (char_u *)VAR_WIN, PV_FDC,
1065 {(char_u *)FALSE, (char_u *)0L}},
1066 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1067 (char_u *)VAR_WIN, PV_FEN,
1068 {(char_u *)TRUE, (char_u *)0L}},
1069 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1070# ifdef FEAT_EVAL
1071 (char_u *)VAR_WIN, PV_FDE,
1072 {(char_u *)"0", (char_u *)NULL}
1073# else
1074 (char_u *)NULL, PV_NONE,
1075 {(char_u *)NULL, (char_u *)0L}
1076# endif
1077 },
1078 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1079 (char_u *)VAR_WIN, PV_FDI,
1080 {(char_u *)"#", (char_u *)NULL}},
1081 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1082 (char_u *)VAR_WIN, PV_FDL,
1083 {(char_u *)0L, (char_u *)0L}},
1084 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1085 (char_u *)&p_fdls, PV_NONE,
1086 {(char_u *)-1L, (char_u *)0L}},
1087 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1088 P_RWIN|P_COMMA|P_NODUP,
1089 (char_u *)VAR_WIN, PV_FMR,
1090 {(char_u *)"{{{,}}}", (char_u *)NULL}},
1091 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1092 (char_u *)VAR_WIN, PV_FDM,
1093 {(char_u *)"manual", (char_u *)NULL}},
1094 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1095 (char_u *)VAR_WIN, PV_FML,
1096 {(char_u *)1L, (char_u *)0L}},
1097 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1098 (char_u *)VAR_WIN, PV_FDN,
1099 {(char_u *)20L, (char_u *)0L}},
1100 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1101 (char_u *)&p_fdo, PV_NONE,
1102 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1103 (char_u *)0L}},
1104 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1105# ifdef FEAT_EVAL
1106 (char_u *)VAR_WIN, PV_FDT,
1107 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001108# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 (char_u *)NULL, PV_NONE,
1110 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001111# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 },
1113#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001114 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001115#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001116 (char_u *)&p_fex, PV_FEX,
1117 {(char_u *)"", (char_u *)0L}
1118#else
1119 (char_u *)NULL, PV_NONE,
1120 {(char_u *)0L, (char_u *)0L}
1121#endif
1122 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1124 (char_u *)&p_fo, PV_FO,
1125 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001126 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1127 (char_u *)&p_flp, PV_FLP,
1128 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1130 (char_u *)&p_fp, PV_NONE,
1131 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001132 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1133#ifdef HAVE_FSYNC
1134 (char_u *)&p_fs, PV_NONE,
1135 {(char_u *)TRUE, (char_u *)0L}
1136#else
1137 (char_u *)NULL, PV_NONE,
1138 {(char_u *)FALSE, (char_u *)0L}
1139#endif
1140 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1142 (char_u *)&p_gd, PV_NONE,
1143 {(char_u *)FALSE, (char_u *)0L}},
1144 {"graphic", "gr", P_BOOL|P_VI_DEF,
1145 (char_u *)NULL, PV_NONE,
1146 {(char_u *)FALSE, (char_u *)0L}},
1147 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1148#ifdef FEAT_QUICKFIX
1149 (char_u *)&p_gefm, PV_NONE,
1150 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L},
1151#else
1152 (char_u *)NULL, PV_NONE,
1153 {(char_u *)NULL, (char_u *)0L}
1154#endif
1155 },
1156 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1157#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001158 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 {
1160# ifdef WIN3264
1161 /* may be changed to "grep -n" in os_win32.c */
1162 (char_u *)"findstr /n",
1163# else
1164# ifdef UNIX
1165 /* Add an extra file name so that grep will always
1166 * insert a file name in the match line. */
1167 (char_u *)"grep -n $* /dev/null",
1168# else
1169# ifdef VMS
1170 (char_u *)"SEARCH/NUMBERS ",
1171# else
1172 (char_u *)"grep -n ",
1173#endif
1174#endif
1175# endif
1176 (char_u *)0L},
1177#else
1178 (char_u *)NULL, PV_NONE,
1179 {(char_u *)NULL, (char_u *)0L}
1180#endif
1181 },
1182 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1183#ifdef CURSOR_SHAPE
1184 (char_u *)&p_guicursor, PV_NONE,
1185 {
1186# ifdef FEAT_GUI
1187 (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",
1188# else /* MSDOS or Win32 console */
1189 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1190# endif
1191 (char_u *)0L}
1192#else
1193 (char_u *)NULL, PV_NONE,
1194 {(char_u *)NULL, (char_u *)0L}
1195#endif
1196 },
1197 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1198#ifdef FEAT_GUI
1199 (char_u *)&p_guifont, PV_NONE,
1200 {(char_u *)"", (char_u *)0L}
1201#else
1202 (char_u *)NULL, PV_NONE,
1203 {(char_u *)NULL, (char_u *)0L}
1204#endif
1205 },
1206 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1207#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1208 (char_u *)&p_guifontset, PV_NONE,
1209 {(char_u *)"", (char_u *)0L}
1210#else
1211 (char_u *)NULL, PV_NONE,
1212 {(char_u *)NULL, (char_u *)0L}
1213#endif
1214 },
1215 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1216#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1217 (char_u *)&p_guifontwide, PV_NONE,
1218 {(char_u *)"", (char_u *)0L}
1219#else
1220 (char_u *)NULL, PV_NONE,
1221 {(char_u *)NULL, (char_u *)0L}
1222#endif
1223 },
1224 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001225#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 (char_u *)&p_ghr, PV_NONE,
1227#else
1228 (char_u *)NULL, PV_NONE,
1229#endif
1230 {(char_u *)50L, (char_u *)0L}},
1231 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001232#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 (char_u *)&p_go, PV_NONE,
1234# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001235 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001237 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238# endif
1239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)NULL, (char_u *)0L}
1242#endif
1243 },
1244 {"guipty", NULL, P_BOOL|P_VI_DEF,
1245#if defined(FEAT_GUI)
1246 (char_u *)&p_guipty, PV_NONE,
1247#else
1248 (char_u *)NULL, PV_NONE,
1249#endif
1250 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001251 {"guitablabel", "gtl", P_STRING|P_VI_DEF,
1252#if defined(FEAT_GUI_TABLINE)
1253 (char_u *)&p_gtl, PV_NONE,
1254 {(char_u *)"", (char_u *)0L}
1255#else
1256 (char_u *)NULL, PV_NONE,
1257 {(char_u *)NULL, (char_u *)0L}
1258#endif
1259 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)0L, (char_u *)0L}},
1263 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1264 (char_u *)&p_hf, PV_NONE,
1265 {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
1266 {"helpheight", "hh", P_NUM|P_VI_DEF,
1267#ifdef FEAT_WINDOWS
1268 (char_u *)&p_hh, PV_NONE,
1269#else
1270 (char_u *)NULL, PV_NONE,
1271#endif
1272 {(char_u *)20L, (char_u *)0L}},
1273 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1274#ifdef FEAT_MULTI_LANG
1275 (char_u *)&p_hlg, PV_NONE,
1276 {(char_u *)"", (char_u *)0L}
1277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)0L, (char_u *)0L}
1280#endif
1281 },
1282 {"hidden", "hid", P_BOOL|P_VI_DEF,
1283 (char_u *)&p_hid, PV_NONE,
1284 {(char_u *)FALSE, (char_u *)0L}},
1285 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1286 (char_u *)&p_hl, PV_NONE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001287 {(char_u *)"8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine",
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 (char_u *)0L}},
1289 {"history", "hi", P_NUM|P_VIM,
1290 (char_u *)&p_hi, PV_NONE,
1291 {(char_u *)0L, (char_u *)20L}},
1292 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1293#ifdef FEAT_RIGHTLEFT
1294 (char_u *)&p_hkmap, PV_NONE,
1295#else
1296 (char_u *)NULL, PV_NONE,
1297#endif
1298 {(char_u *)FALSE, (char_u *)0L}},
1299 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1300#ifdef FEAT_RIGHTLEFT
1301 (char_u *)&p_hkmapp, PV_NONE,
1302#else
1303 (char_u *)NULL, PV_NONE,
1304#endif
1305 {(char_u *)FALSE, (char_u *)0L}},
1306 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1307 (char_u *)&p_hls, PV_NONE,
1308 {(char_u *)FALSE, (char_u *)0L}},
1309 {"icon", NULL, P_BOOL|P_VI_DEF,
1310#ifdef FEAT_TITLE
1311 (char_u *)&p_icon, PV_NONE,
1312#else
1313 (char_u *)NULL, PV_NONE,
1314#endif
1315 {(char_u *)FALSE, (char_u *)0L}},
1316 {"iconstring", NULL, P_STRING|P_VI_DEF,
1317#ifdef FEAT_TITLE
1318 (char_u *)&p_iconstring, PV_NONE,
1319#else
1320 (char_u *)NULL, PV_NONE,
1321#endif
1322 {(char_u *)"", (char_u *)0L}},
1323 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1324 (char_u *)&p_ic, PV_NONE,
1325 {(char_u *)FALSE, (char_u *)0L}},
1326 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001327#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001328 (char_u *)&p_imak, PV_NONE,
1329#else
1330 (char_u *)NULL, PV_NONE,
1331#endif
1332 {(char_u *)"", (char_u *)0L}},
1333 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1334#ifdef USE_IM_CONTROL
1335 (char_u *)&p_imcmdline, PV_NONE,
1336#else
1337 (char_u *)NULL, PV_NONE,
1338#endif
1339 {(char_u *)FALSE, (char_u *)0L}},
1340 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1341#ifdef USE_IM_CONTROL
1342 (char_u *)&p_imdisable, PV_NONE,
1343#else
1344 (char_u *)NULL, PV_NONE,
1345#endif
1346#ifdef __sgi
1347 {(char_u *)TRUE, (char_u *)0L}
1348#else
1349 {(char_u *)FALSE, (char_u *)0L}
1350#endif
1351 },
1352 {"iminsert", "imi", P_NUM|P_VI_DEF,
1353 (char_u *)&p_iminsert, PV_IMI,
1354#ifdef B_IMODE_IM
1355 {(char_u *)B_IMODE_IM, (char_u *)0L}
1356#else
1357 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1358#endif
1359 },
1360 {"imsearch", "ims", P_NUM|P_VI_DEF,
1361 (char_u *)&p_imsearch, PV_IMS,
1362#ifdef B_IMODE_IM
1363 {(char_u *)B_IMODE_IM, (char_u *)0L}
1364#else
1365 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1366#endif
1367 },
1368 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1369#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001370 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1372#else
1373 (char_u *)NULL, PV_NONE,
1374 {(char_u *)0L, (char_u *)0L}
1375#endif
1376 },
1377 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1378#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1379 (char_u *)&p_inex, PV_INEX,
1380 {(char_u *)"", (char_u *)0L}
1381#else
1382 (char_u *)NULL, PV_NONE,
1383 {(char_u *)0L, (char_u *)0L}
1384#endif
1385 },
1386 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1387 (char_u *)&p_is, PV_NONE,
1388 {(char_u *)FALSE, (char_u *)0L}},
1389 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1390#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1391 (char_u *)&p_inde, PV_INDE,
1392 {(char_u *)"", (char_u *)0L}
1393#else
1394 (char_u *)NULL, PV_NONE,
1395 {(char_u *)0L, (char_u *)0L}
1396#endif
1397 },
1398 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1399#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1400 (char_u *)&p_indk, PV_INDK,
1401 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1402#else
1403 (char_u *)NULL, PV_NONE,
1404 {(char_u *)0L, (char_u *)0L}
1405#endif
1406 },
1407 {"infercase", "inf", P_BOOL|P_VI_DEF,
1408 (char_u *)&p_inf, PV_INF,
1409 {(char_u *)FALSE, (char_u *)0L}},
1410 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1411 (char_u *)&p_im, PV_NONE,
1412 {(char_u *)FALSE, (char_u *)0L}},
1413 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1414 (char_u *)&p_isf, PV_NONE,
1415 {
1416#ifdef BACKSLASH_IN_FILENAME
1417 /* Excluded are: & and ^ are special in cmd.exe
1418 * ( and ) are used in text separating fnames */
1419 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1420#else
1421# ifdef AMIGA
1422 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1423# else
1424# ifdef VMS
1425 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1426# else /* UNIX et al. */
1427# ifdef EBCDIC
1428 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1429# else
1430 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1431# endif
1432# endif
1433# endif
1434#endif
1435 (char_u *)0L}},
1436 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1437 (char_u *)&p_isi, PV_NONE,
1438 {
1439#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1440 (char_u *)"@,48-57,_,128-167,224-235",
1441#else
1442# ifdef EBCDIC
1443 /* TODO: EBCDIC Check this! @ == isalpha()*/
1444 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1445 "112-120,128,140-142,156,158,172,"
1446 "174,186,191,203-207,219-225,235-239,"
1447 "251-254",
1448# else
1449 (char_u *)"@,48-57,_,192-255",
1450# endif
1451#endif
1452 (char_u *)0L}},
1453 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1454 (char_u *)&p_isk, PV_ISK,
1455 {
1456#ifdef EBCDIC
1457 (char_u *)"@,240-249,_",
1458 /* TODO: EBCDIC Check this! @ == isalpha()*/
1459 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1460 "112-120,128,140-142,156,158,172,"
1461 "174,186,191,203-207,219-225,235-239,"
1462 "251-254",
1463#else
1464 (char_u *)"@,48-57,_",
1465# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1466 (char_u *)"@,48-57,_,128-167,224-235"
1467# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001468 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469# endif
1470#endif
1471 }},
1472 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1473 (char_u *)&p_isp, PV_NONE,
1474 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001475#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1476 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 || defined(VMS)
1478 (char_u *)"@,~-255",
1479#else
1480# ifdef EBCDIC
1481 /* all chars above 63 are printable */
1482 (char_u *)"63-255",
1483# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001484 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485# endif
1486#endif
1487 (char_u *)0L}},
1488 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1489 (char_u *)&p_js, PV_NONE,
1490 {(char_u *)TRUE, (char_u *)0L}},
1491 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1492#ifdef FEAT_CRYPT
1493 (char_u *)&p_key, PV_KEY,
1494 {(char_u *)"", (char_u *)0L}
1495#else
1496 (char_u *)NULL, PV_NONE,
1497 {(char_u *)0L, (char_u *)0L}
1498#endif
1499 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001500 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501#ifdef FEAT_KEYMAP
1502 (char_u *)&p_keymap, PV_KMAP,
1503 {(char_u *)"", (char_u *)0L}
1504#else
1505 (char_u *)NULL, PV_NONE,
1506 {(char_u *)"", (char_u *)0L}
1507#endif
1508 },
1509 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1510#ifdef FEAT_VISUAL
1511 (char_u *)&p_km, PV_NONE,
1512#else
1513 (char_u *)NULL, PV_NONE,
1514#endif
1515 {(char_u *)"", (char_u *)0L}},
1516 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001517 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 {
1519#if defined(MSDOS) || defined(MSWIN)
1520 (char_u *)":help",
1521#else
1522#ifdef VMS
1523 (char_u *)"help",
1524#else
1525# if defined(OS2)
1526 (char_u *)"view /",
1527# else
1528# ifdef USEMAN_S
1529 (char_u *)"man -s",
1530# else
1531 (char_u *)"man",
1532# endif
1533# endif
1534#endif
1535#endif
1536 (char_u *)0L}},
1537 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1538#ifdef FEAT_LANGMAP
1539 (char_u *)&p_langmap, PV_NONE,
1540 {(char_u *)"", /* unmatched } */
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)NULL,
1544#endif
1545 (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001546 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1548 (char_u *)&p_lm, PV_NONE,
1549#else
1550 (char_u *)NULL, PV_NONE,
1551#endif
1552 {(char_u *)"", (char_u *)0L}},
1553 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1554#ifdef FEAT_WINDOWS
1555 (char_u *)&p_ls, PV_NONE,
1556#else
1557 (char_u *)NULL, PV_NONE,
1558#endif
1559 {(char_u *)1L, (char_u *)0L}},
1560 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1561 (char_u *)&p_lz, PV_NONE,
1562 {(char_u *)FALSE, (char_u *)0L}},
1563 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1564#ifdef FEAT_LINEBREAK
1565 (char_u *)VAR_WIN, PV_LBR,
1566#else
1567 (char_u *)NULL, PV_NONE,
1568#endif
1569 {(char_u *)FALSE, (char_u *)0L}},
1570 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1571 (char_u *)&Rows, PV_NONE,
1572 {
1573#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1574 (char_u *)25L,
1575#else
1576 (char_u *)24L,
1577#endif
1578 (char_u *)0L}},
1579 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1580#ifdef FEAT_GUI
1581 (char_u *)&p_linespace, PV_NONE,
1582#else
1583 (char_u *)NULL, PV_NONE,
1584#endif
1585#ifdef FEAT_GUI_W32
1586 {(char_u *)1L, (char_u *)0L}
1587#else
1588 {(char_u *)0L, (char_u *)0L}
1589#endif
1590 },
1591 {"lisp", NULL, P_BOOL|P_VI_DEF,
1592#ifdef FEAT_LISP
1593 (char_u *)&p_lisp, PV_LISP,
1594#else
1595 (char_u *)NULL, PV_NONE,
1596#endif
1597 {(char_u *)FALSE, (char_u *)0L}},
1598 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1599#ifdef FEAT_LISP
1600 (char_u *)&p_lispwords, PV_NONE,
1601 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1602#else
1603 (char_u *)NULL, PV_NONE,
1604 {(char_u *)"", (char_u *)0L}
1605#endif
1606 },
1607 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1608 (char_u *)VAR_WIN, PV_LIST,
1609 {(char_u *)FALSE, (char_u *)0L}},
1610 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1611 (char_u *)&p_lcs, PV_NONE,
1612 {(char_u *)"eol:$", (char_u *)0L}},
1613 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1614 (char_u *)&p_lpl, PV_NONE,
1615 {(char_u *)TRUE, (char_u *)0L}},
1616 {"magic", NULL, P_BOOL|P_VI_DEF,
1617 (char_u *)&p_magic, PV_NONE,
1618 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001619 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620#ifdef FEAT_QUICKFIX
1621 (char_u *)&p_mef, PV_NONE,
1622 {(char_u *)"", (char_u *)0L}
1623#else
1624 (char_u *)NULL, PV_NONE,
1625 {(char_u *)NULL, (char_u *)0L}
1626#endif
1627 },
1628 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1629#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001630 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631# ifdef VMS
1632 {(char_u *)"MMS", (char_u *)0L}
1633# else
1634 {(char_u *)"make", (char_u *)0L}
1635# endif
1636#else
1637 (char_u *)NULL, PV_NONE,
1638 {(char_u *)NULL, (char_u *)0L}
1639#endif
1640 },
1641 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1642 (char_u *)&p_mps, PV_MPS,
1643 {(char_u *)"(:),{:},[:]", (char_u *)0L}},
1644 {"matchtime", "mat", P_NUM|P_VI_DEF,
1645 (char_u *)&p_mat, PV_NONE,
1646 {(char_u *)5L, (char_u *)0L}},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001647 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1648#ifdef FEAT_MBYTE
1649 (char_u *)&p_mco, PV_NONE,
1650#else
1651 (char_u *)NULL, PV_NONE,
1652#endif
1653 {(char_u *)2, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1655#ifdef FEAT_EVAL
1656 (char_u *)&p_mfd, PV_NONE,
1657#else
1658 (char_u *)NULL, PV_NONE,
1659#endif
1660 {(char_u *)100L, (char_u *)0L}},
1661 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1662 (char_u *)&p_mmd, PV_NONE,
1663 {(char_u *)1000L, (char_u *)0L}},
1664 {"maxmem", "mm", P_NUM|P_VI_DEF,
1665 (char_u *)&p_mm, PV_NONE,
1666 {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001667 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1668 (char_u *)&p_mmp, PV_NONE,
1669 {(char_u *)1000L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1671 (char_u *)&p_mmt, PV_NONE,
1672 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
1673 {"menuitems", "mis", P_NUM|P_VI_DEF,
1674#ifdef FEAT_MENU
1675 (char_u *)&p_mis, PV_NONE,
1676#else
1677 (char_u *)NULL, PV_NONE,
1678#endif
1679 {(char_u *)25L, (char_u *)0L}},
1680 {"mesg", NULL, P_BOOL|P_VI_DEF,
1681 (char_u *)NULL, PV_NONE,
1682 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001683 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001684#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001685 (char_u *)&p_msm, PV_NONE,
1686 {(char_u *)"460000,2000,500", (char_u *)0L}
1687#else
1688 (char_u *)NULL, PV_NONE,
1689 {(char_u *)0L, (char_u *)0L}
1690#endif
1691 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 {"modeline", "ml", P_BOOL|P_VIM,
1693 (char_u *)&p_ml, PV_ML,
1694 {(char_u *)FALSE, (char_u *)TRUE}},
1695 {"modelines", "mls", P_NUM|P_VI_DEF,
1696 (char_u *)&p_mls, PV_NONE,
1697 {(char_u *)5L, (char_u *)0L}},
1698 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1699 (char_u *)&p_ma, PV_MA,
1700 {(char_u *)TRUE, (char_u *)0L}},
1701 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1702 (char_u *)&p_mod, PV_MOD,
1703 {(char_u *)FALSE, (char_u *)0L}},
1704 {"more", NULL, P_BOOL|P_VIM,
1705 (char_u *)&p_more, PV_NONE,
1706 {(char_u *)FALSE, (char_u *)TRUE}},
1707 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1708 (char_u *)&p_mouse, PV_NONE,
1709 {
1710#if defined(MSDOS) || defined(WIN3264)
1711 (char_u *)"a",
1712#else
1713 (char_u *)"",
1714#endif
1715 (char_u *)0L}},
1716 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1717#ifdef FEAT_GUI
1718 (char_u *)&p_mousef, PV_NONE,
1719#else
1720 (char_u *)NULL, PV_NONE,
1721#endif
1722 {(char_u *)FALSE, (char_u *)0L}},
1723 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1724#ifdef FEAT_GUI
1725 (char_u *)&p_mh, PV_NONE,
1726#else
1727 (char_u *)NULL, PV_NONE,
1728#endif
1729 {(char_u *)TRUE, (char_u *)0L}},
1730 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1731 (char_u *)&p_mousem, PV_NONE,
1732 {
1733#if defined(MSDOS) || defined(MSWIN)
1734 (char_u *)"popup",
1735#else
1736# if defined(MACOS)
1737 (char_u *)"popup_setpos",
1738# else
1739 (char_u *)"extend",
1740# endif
1741#endif
1742 (char_u *)0L}},
1743 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1744#ifdef FEAT_MOUSESHAPE
1745 (char_u *)&p_mouseshape, PV_NONE,
1746 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1747#else
1748 (char_u *)NULL, PV_NONE,
1749 {(char_u *)NULL, (char_u *)0L}
1750#endif
1751 },
1752 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1753 (char_u *)&p_mouset, PV_NONE,
1754 {(char_u *)500L, (char_u *)0L}},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001755 {"mzquantum", "mzq", P_NUM,
1756#ifdef FEAT_MZSCHEME
1757 (char_u *)&p_mzq, PV_NONE,
1758#else
1759 (char_u *)NULL, PV_NONE,
1760#endif
1761 {(char_u *)100L, (char_u *)100L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 {"novice", NULL, P_BOOL|P_VI_DEF,
1763 (char_u *)NULL, PV_NONE,
1764 {(char_u *)FALSE, (char_u *)0L}},
1765 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1766 (char_u *)&p_nf, PV_NF,
1767 {(char_u *)"octal,hex", (char_u *)0L}},
1768 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1769 (char_u *)VAR_WIN, PV_NU,
1770 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001771 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1772#ifdef FEAT_LINEBREAK
1773 (char_u *)VAR_WIN, PV_NUW,
1774#else
1775 (char_u *)NULL, PV_NONE,
1776#endif
1777 {(char_u *)8L, (char_u *)4L}},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001778 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001779#ifdef FEAT_COMPL_FUNC
1780 (char_u *)&p_ofu, PV_OFU,
1781 {(char_u *)"", (char_u *)0L}
1782#else
1783 (char_u *)NULL, PV_NONE,
1784 {(char_u *)0L, (char_u *)0L}
1785#endif
1786 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"open", NULL, P_BOOL|P_VI_DEF,
1788 (char_u *)NULL, PV_NONE,
1789 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001790 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1791 (char_u *)&p_opfunc, PV_NONE,
1792 {(char_u *)"", (char_u *)0L} },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793 {"optimize", "opt", P_BOOL|P_VI_DEF,
1794 (char_u *)NULL, PV_NONE,
1795 {(char_u *)FALSE, (char_u *)0L}},
1796 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1797#ifdef FEAT_OSFILETYPE
1798 (char_u *)&p_oft, PV_OFT,
1799 {(char_u *)DFLT_OFT, (char_u *)0L}
1800#else
1801 (char_u *)NULL, PV_NONE,
1802 {(char_u *)0L, (char_u *)0L}
1803#endif
1804 },
1805 {"paragraphs", "para", P_STRING|P_VI_DEF,
1806 (char_u *)&p_para, PV_NONE,
1807 {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}},
1808 {"paste", NULL, P_BOOL|P_VI_DEF,
1809 (char_u *)&p_paste, PV_NONE,
1810 {(char_u *)FALSE, (char_u *)0L}},
1811 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1812 (char_u *)&p_pt, PV_NONE,
1813 {(char_u *)"", (char_u *)0L}},
1814 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1815#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1816 (char_u *)&p_pex, PV_NONE,
1817 {(char_u *)"", (char_u *)0L}
1818#else
1819 (char_u *)NULL, PV_NONE,
1820 {(char_u *)0L, (char_u *)0L}
1821#endif
1822 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001823 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 (char_u *)&p_pm, PV_NONE,
1825 {(char_u *)"", (char_u *)0L}},
1826 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001827 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {
1829#if defined AMIGA || defined MSDOS || defined MSWIN
1830 (char_u *)".,,",
1831#else
1832# if defined(__EMX__)
1833 (char_u *)".,/emx/include,,",
1834# else /* Unix, probably */
1835 (char_u *)".,/usr/include,,",
1836# endif
1837#endif
1838 (char_u *)0L}},
1839 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1840 (char_u *)&p_pi, PV_PI,
1841 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001842 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1844 (char_u *)&p_pvh, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
1848 {(char_u *)12L, (char_u *)0L}},
1849 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1850#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1851 (char_u *)VAR_WIN, PV_PVW,
1852#else
1853 (char_u *)NULL, PV_NONE,
1854#endif
1855 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001856 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857#ifdef FEAT_PRINTER
1858 (char_u *)&p_pdev, PV_NONE,
1859 {(char_u *)"", (char_u *)0L}
1860#else
1861 (char_u *)NULL, PV_NONE,
1862 {(char_u *)NULL, (char_u *)0L}
1863#endif
1864 },
1865 {"printencoding", "penc", P_STRING|P_VI_DEF,
1866#ifdef FEAT_POSTSCRIPT
1867 (char_u *)&p_penc, PV_NONE,
1868 {(char_u *)"", (char_u *)0L}
1869#else
1870 (char_u *)NULL, PV_NONE,
1871 {(char_u *)NULL, (char_u *)0L}
1872#endif
1873 },
1874 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1875#ifdef FEAT_POSTSCRIPT
1876 (char_u *)&p_pexpr, PV_NONE,
1877 {(char_u *)"", (char_u *)0L}
1878#else
1879 (char_u *)NULL, PV_NONE,
1880 {(char_u *)NULL, (char_u *)0L}
1881#endif
1882 },
1883 {"printfont", "pfn", P_STRING|P_VI_DEF,
1884#ifdef FEAT_PRINTER
1885 (char_u *)&p_pfn, PV_NONE,
1886 {
1887# ifdef MSWIN
1888 (char_u *)"Courier_New:h10",
1889# else
1890 (char_u *)"courier",
1891# endif
1892 (char_u *)0L}
1893#else
1894 (char_u *)NULL, PV_NONE,
1895 {(char_u *)NULL, (char_u *)0L}
1896#endif
1897 },
1898 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1899#ifdef FEAT_PRINTER
1900 (char_u *)&p_header, PV_NONE,
1901 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1902#else
1903 (char_u *)NULL, PV_NONE,
1904 {(char_u *)NULL, (char_u *)0L}
1905#endif
1906 },
Bram Moolenaar8299df92004-07-10 09:47:34 +00001907 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1908#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1909 (char_u *)&p_pmcs, PV_NONE,
1910 {(char_u *)"", (char_u *)0L}
1911#else
1912 (char_u *)NULL, PV_NONE,
1913 {(char_u *)NULL, (char_u *)0L}
1914#endif
1915 },
1916 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1917#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1918 (char_u *)&p_pmfn, PV_NONE,
1919 {(char_u *)"", (char_u *)0L}
1920#else
1921 (char_u *)NULL, PV_NONE,
1922 {(char_u *)NULL, (char_u *)0L}
1923#endif
1924 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1926#ifdef FEAT_PRINTER
1927 (char_u *)&p_popt, PV_NONE,
1928 {(char_u *)"", (char_u *)0L}
1929#else
1930 (char_u *)NULL, PV_NONE,
1931 {(char_u *)NULL, (char_u *)0L}
1932#endif
1933 },
1934 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001935 (char_u *)&p_prompt, PV_NONE,
1936 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00001937 {"pumheight", "ph", P_NUM|P_VI_DEF,
1938#ifdef FEAT_INS_EXPAND
1939 (char_u *)&p_ph, PV_NONE,
1940#else
1941 (char_u *)NULL, PV_NONE,
1942#endif
1943 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001944 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
1945#ifdef FEAT_TEXTOBJ
1946 (char_u *)&p_qe, PV_QE,
1947 {(char_u *)"\\", (char_u *)0L}
1948#else
1949 (char_u *)NULL, PV_NONE,
1950 {(char_u *)NULL, (char_u *)0L}
1951#endif
1952 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1954 (char_u *)&p_ro, PV_RO,
1955 {(char_u *)FALSE, (char_u *)0L}},
1956 {"redraw", NULL, P_BOOL|P_VI_DEF,
1957 (char_u *)NULL, PV_NONE,
1958 {(char_u *)FALSE, (char_u *)0L}},
1959 {"remap", NULL, P_BOOL|P_VI_DEF,
1960 (char_u *)&p_remap, PV_NONE,
1961 {(char_u *)TRUE, (char_u *)0L}},
1962 {"report", NULL, P_NUM|P_VI_DEF,
1963 (char_u *)&p_report, PV_NONE,
1964 {(char_u *)2L, (char_u *)0L}},
1965 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
1966#ifdef WIN3264
1967 (char_u *)&p_rs, PV_NONE,
1968#else
1969 (char_u *)NULL, PV_NONE,
1970#endif
1971 {(char_u *)TRUE, (char_u *)0L}},
1972 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
1973#ifdef FEAT_RIGHTLEFT
1974 (char_u *)&p_ri, PV_NONE,
1975#else
1976 (char_u *)NULL, PV_NONE,
1977#endif
1978 {(char_u *)FALSE, (char_u *)0L}},
1979 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
1980#ifdef FEAT_RIGHTLEFT
1981 (char_u *)VAR_WIN, PV_RL,
1982#else
1983 (char_u *)NULL, PV_NONE,
1984#endif
1985 {(char_u *)FALSE, (char_u *)0L}},
1986 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
1987#ifdef FEAT_RIGHTLEFT
1988 (char_u *)VAR_WIN, PV_RLC,
1989 {(char_u *)"search", (char_u *)NULL}
1990#else
1991 (char_u *)NULL, PV_NONE,
1992 {(char_u *)NULL, (char_u *)0L}
1993#endif
1994 },
1995 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
1996#ifdef FEAT_CMDL_INFO
1997 (char_u *)&p_ru, PV_NONE,
1998#else
1999 (char_u *)NULL, PV_NONE,
2000#endif
2001 {(char_u *)FALSE, (char_u *)0L}},
2002 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2003#ifdef FEAT_STL_OPT
2004 (char_u *)&p_ruf, PV_NONE,
2005#else
2006 (char_u *)NULL, PV_NONE,
2007#endif
2008 {(char_u *)"", (char_u *)0L}},
2009 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2010 (char_u *)&p_rtp, PV_NONE,
2011 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
2012 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2013 (char_u *)VAR_WIN, PV_SCROLL,
2014 {(char_u *)12L, (char_u *)0L}},
2015 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2016#ifdef FEAT_SCROLLBIND
2017 (char_u *)VAR_WIN, PV_SCBIND,
2018#else
2019 (char_u *)NULL, PV_NONE,
2020#endif
2021 {(char_u *)FALSE, (char_u *)0L}},
2022 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2023 (char_u *)&p_sj, PV_NONE,
2024 {(char_u *)1L, (char_u *)0L}},
2025 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2026 (char_u *)&p_so, PV_NONE,
2027 {(char_u *)0L, (char_u *)0L}},
2028 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2029#ifdef FEAT_SCROLLBIND
2030 (char_u *)&p_sbo, PV_NONE,
2031 {(char_u *)"ver,jump", (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)0L, (char_u *)0L}
2035#endif
2036 },
2037 {"sections", "sect", P_STRING|P_VI_DEF,
2038 (char_u *)&p_sections, PV_NONE,
2039 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
2040 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2041 (char_u *)&p_secure, PV_NONE,
2042 {(char_u *)FALSE, (char_u *)0L}},
2043 {"selection", "sel", P_STRING|P_VI_DEF,
2044#ifdef FEAT_VISUAL
2045 (char_u *)&p_sel, PV_NONE,
2046#else
2047 (char_u *)NULL, PV_NONE,
2048#endif
2049 {(char_u *)"inclusive", (char_u *)0L}},
2050 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2051#ifdef FEAT_VISUAL
2052 (char_u *)&p_slm, PV_NONE,
2053#else
2054 (char_u *)NULL, PV_NONE,
2055#endif
2056 {(char_u *)"", (char_u *)0L}},
2057 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2058#ifdef FEAT_SESSION
2059 (char_u *)&p_ssop, PV_NONE,
2060 {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
2061 (char_u *)0L}
2062#else
2063 (char_u *)NULL, PV_NONE,
2064 {(char_u *)0L, (char_u *)0L}
2065#endif
2066 },
2067 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2068 (char_u *)&p_sh, PV_NONE,
2069 {
2070#ifdef VMS
2071 (char_u *)"-",
2072#else
2073# if defined(MSDOS)
2074 (char_u *)"command",
2075# else
2076# if defined(WIN16)
2077 (char_u *)"command.com",
2078# else
2079# if defined(WIN3264)
2080 (char_u *)"", /* set in set_init_1() */
2081# else
2082# if defined(OS2)
2083 (char_u *)"cmd.exe",
2084# else
2085# if defined(ARCHIE)
2086 (char_u *)"gos",
2087# else
2088 (char_u *)"sh",
2089# endif
2090# endif
2091# endif
2092# endif
2093# endif
2094#endif /* VMS */
2095 (char_u *)0L}},
2096 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2097 (char_u *)&p_shcf, PV_NONE,
2098 {
2099#if defined(MSDOS) || defined(MSWIN)
2100 (char_u *)"/c",
2101#else
2102# if defined(OS2)
2103 (char_u *)"/c",
2104# else
2105 (char_u *)"-c",
2106# endif
2107#endif
2108 (char_u *)0L}},
2109 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2110#ifdef FEAT_QUICKFIX
2111 (char_u *)&p_sp, PV_NONE,
2112 {
2113#if defined(UNIX) || defined(OS2)
2114# ifdef ARCHIE
2115 (char_u *)"2>",
2116# else
2117 (char_u *)"| tee",
2118# endif
2119#else
2120 (char_u *)">",
2121#endif
2122 (char_u *)0L}
2123#else
2124 (char_u *)NULL, PV_NONE,
2125 {(char_u *)0L, (char_u *)0L}
2126#endif
2127 },
2128 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2129 (char_u *)&p_shq, PV_NONE,
2130 {(char_u *)"", (char_u *)0L}},
2131 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2132 (char_u *)&p_srr, PV_NONE,
2133 {(char_u *)">", (char_u *)0L}},
2134 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2135#ifdef BACKSLASH_IN_FILENAME
2136 (char_u *)&p_ssl, PV_NONE,
2137#else
2138 (char_u *)NULL, PV_NONE,
2139#endif
2140 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002141 {"shelltemp", "stmp", P_BOOL,
2142 (char_u *)&p_stmp, PV_NONE,
2143 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"shelltype", "st", P_NUM|P_VI_DEF,
2145#ifdef AMIGA
2146 (char_u *)&p_st, PV_NONE,
2147#else
2148 (char_u *)NULL, PV_NONE,
2149#endif
2150 {(char_u *)0L, (char_u *)0L}},
2151 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2152 (char_u *)&p_sxq, PV_NONE,
2153 {
2154#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2155 (char_u *)"\"",
2156#else
2157 (char_u *)"",
2158#endif
2159 (char_u *)0L}},
2160 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2161 (char_u *)&p_sr, PV_NONE,
2162 {(char_u *)FALSE, (char_u *)0L}},
2163 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2164 (char_u *)&p_sw, PV_SW,
2165 {(char_u *)8L, (char_u *)0L}},
2166 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2167 (char_u *)&p_shm, PV_NONE,
2168 {(char_u *)"", (char_u *)"filnxtToO"}},
2169 {"shortname", "sn", P_BOOL|P_VI_DEF,
2170#ifdef SHORT_FNAME
2171 (char_u *)NULL, PV_NONE,
2172#else
2173 (char_u *)&p_sn, PV_SN,
2174#endif
2175 {(char_u *)FALSE, (char_u *)0L}},
2176 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2177#ifdef FEAT_LINEBREAK
2178 (char_u *)&p_sbr, PV_NONE,
2179#else
2180 (char_u *)NULL, PV_NONE,
2181#endif
2182 {(char_u *)"", (char_u *)0L}},
2183 {"showcmd", "sc", P_BOOL|P_VIM,
2184#ifdef FEAT_CMDL_INFO
2185 (char_u *)&p_sc, PV_NONE,
2186#else
2187 (char_u *)NULL, PV_NONE,
2188#endif
2189 {(char_u *)FALSE,
2190#ifdef UNIX
2191 (char_u *)FALSE
2192#else
2193 (char_u *)TRUE
2194#endif
2195 }},
2196 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2197 (char_u *)&p_sft, PV_NONE,
2198 {(char_u *)FALSE, (char_u *)0L}},
2199 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2200 (char_u *)&p_sm, PV_NONE,
2201 {(char_u *)FALSE, (char_u *)0L}},
2202 {"showmode", "smd", P_BOOL|P_VIM,
2203 (char_u *)&p_smd, PV_NONE,
2204 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002205 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2206#ifdef FEAT_WINDOWS
2207 (char_u *)&p_stal, PV_NONE,
2208#else
2209 (char_u *)NULL, PV_NONE,
2210#endif
2211 {(char_u *)1L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2213 (char_u *)&p_ss, PV_NONE,
2214 {(char_u *)0L, (char_u *)0L}},
2215 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2216 (char_u *)&p_siso, PV_NONE,
2217 {(char_u *)0L, (char_u *)0L}},
2218 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)FALSE, (char_u *)0L}},
2221 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2222 (char_u *)&p_scs, PV_NONE,
2223 {(char_u *)FALSE, (char_u *)0L}},
2224 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2225#ifdef FEAT_SMARTINDENT
2226 (char_u *)&p_si, PV_SI,
2227#else
2228 (char_u *)NULL, PV_NONE,
2229#endif
2230 {(char_u *)FALSE, (char_u *)0L}},
2231 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2232 (char_u *)&p_sta, PV_NONE,
2233 {(char_u *)FALSE, (char_u *)0L}},
2234 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2235 (char_u *)&p_sts, PV_STS,
2236 {(char_u *)0L, (char_u *)0L}},
2237 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2238 (char_u *)NULL, PV_NONE,
2239 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002240 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002241#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002242 (char_u *)VAR_WIN, PV_SPELL,
2243#else
2244 (char_u *)NULL, PV_NONE,
2245#endif
2246 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002247 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002248#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002249 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002250 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002251#else
2252 (char_u *)NULL, PV_NONE,
2253 {(char_u *)0L, (char_u *)0L}
2254#endif
2255 },
2256 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002257#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002258 (char_u *)&p_spf, PV_SPF,
2259 {(char_u *)"", (char_u *)0L}
2260#else
2261 (char_u *)NULL, PV_NONE,
2262 {(char_u *)0L, (char_u *)0L}
2263#endif
2264 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002265 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002266#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002267 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002268 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002269#else
2270 (char_u *)NULL, PV_NONE,
2271 {(char_u *)0L, (char_u *)0L}
2272#endif
2273 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002274 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002275#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002276 (char_u *)&p_sps, PV_NONE,
2277 {(char_u *)"best", (char_u *)0L}
2278#else
2279 (char_u *)NULL, PV_NONE,
2280 {(char_u *)0L, (char_u *)0L}
2281#endif
2282 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2284#ifdef FEAT_WINDOWS
2285 (char_u *)&p_sb, PV_NONE,
2286#else
2287 (char_u *)NULL, PV_NONE,
2288#endif
2289 {(char_u *)FALSE, (char_u *)0L}},
2290 {"splitright", "spr", P_BOOL|P_VI_DEF,
2291#ifdef FEAT_VERTSPLIT
2292 (char_u *)&p_spr, PV_NONE,
2293#else
2294 (char_u *)NULL, PV_NONE,
2295#endif
2296 {(char_u *)FALSE, (char_u *)0L}},
2297 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2298 (char_u *)&p_sol, PV_NONE,
2299 {(char_u *)TRUE, (char_u *)0L}},
2300 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2301#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002302 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303#else
2304 (char_u *)NULL, PV_NONE,
2305#endif
2306 {(char_u *)"", (char_u *)0L}},
2307 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2308 (char_u *)&p_su, PV_NONE,
2309 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2310 (char_u *)0L}},
2311 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002312#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 (char_u *)&p_sua, PV_SUA,
2314 {(char_u *)"", (char_u *)0L}
2315#else
2316 (char_u *)NULL, PV_NONE,
2317 {(char_u *)0L, (char_u *)0L}
2318#endif
2319 },
2320 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2321 (char_u *)&p_swf, PV_SWF,
2322 {(char_u *)TRUE, (char_u *)0L}},
2323 {"swapsync", "sws", P_STRING|P_VI_DEF,
2324 (char_u *)&p_sws, PV_NONE,
2325 {(char_u *)"fsync", (char_u *)0L}},
2326 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2327 (char_u *)&p_swb, PV_NONE,
2328 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002329 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2330#ifdef FEAT_SYN_HL
2331 (char_u *)&p_smc, PV_SMC,
2332 {(char_u *)3000L, (char_u *)0L}
2333#else
2334 (char_u *)NULL, PV_NONE,
2335 {(char_u *)0L, (char_u *)0L}
2336#endif
2337 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002338 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339#ifdef FEAT_SYN_HL
2340 (char_u *)&p_syn, PV_SYN,
2341 {(char_u *)"", (char_u *)0L}
2342#else
2343 (char_u *)NULL, PV_NONE,
2344 {(char_u *)0L, (char_u *)0L}
2345#endif
2346 },
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002347 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2348#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002349 (char_u *)&p_tal, PV_NONE,
2350#else
2351 (char_u *)NULL, PV_NONE,
2352#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002353 {(char_u *)"", (char_u *)0L}},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002354 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2355#ifdef FEAT_WINDOWS
2356 (char_u *)&p_tpm, PV_NONE,
2357#else
2358 (char_u *)NULL, PV_NONE,
2359#endif
2360 {(char_u *)10L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2362 (char_u *)&p_ts, PV_TS,
2363 {(char_u *)8L, (char_u *)0L}},
2364 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2365 (char_u *)&p_tbs, PV_NONE,
2366#ifdef VMS /* binary searching doesn't appear to work on VMS */
2367 {(char_u *)0L, (char_u *)0L}
2368#else
2369 {(char_u *)TRUE, (char_u *)0L}
2370#endif
2371 },
2372 {"taglength", "tl", P_NUM|P_VI_DEF,
2373 (char_u *)&p_tl, PV_NONE,
2374 {(char_u *)0L, (char_u *)0L}},
2375 {"tagrelative", "tr", P_BOOL|P_VIM,
2376 (char_u *)&p_tr, PV_NONE,
2377 {(char_u *)FALSE, (char_u *)TRUE}},
2378 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002379 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 {
2381#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2382 (char_u *)"./tags,./TAGS,tags,TAGS",
2383#else
2384 (char_u *)"./tags,tags",
2385#endif
2386 (char_u *)0L}},
2387 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2388 (char_u *)&p_tgst, PV_NONE,
2389 {(char_u *)TRUE, (char_u *)0L}},
2390 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2391 (char_u *)&T_NAME, PV_NONE,
2392 {(char_u *)"", (char_u *)0L}},
2393 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2394#ifdef FEAT_ARABIC
2395 (char_u *)&p_tbidi, PV_NONE,
2396#else
2397 (char_u *)NULL, PV_NONE,
2398#endif
2399 {(char_u *)FALSE, (char_u *)0L}},
2400 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2401#ifdef FEAT_MBYTE
2402 (char_u *)&p_tenc, PV_NONE,
2403 {(char_u *)"", (char_u *)0L}
2404#else
2405 (char_u *)NULL, PV_NONE,
2406 {(char_u *)0L, (char_u *)0L}
2407#endif
2408 },
2409 {"terse", NULL, P_BOOL|P_VI_DEF,
2410 (char_u *)&p_terse, PV_NONE,
2411 {(char_u *)FALSE, (char_u *)0L}},
2412 {"textauto", "ta", P_BOOL|P_VIM,
2413 (char_u *)&p_ta, PV_NONE,
2414 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2415 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2416 (char_u *)&p_tx, PV_TX,
2417 {
2418#ifdef USE_CRNL
2419 (char_u *)TRUE,
2420#else
2421 (char_u *)FALSE,
2422#endif
2423 (char_u *)0L}},
2424 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2425 (char_u *)&p_tw, PV_TW,
2426 {(char_u *)0L, (char_u *)0L}},
2427 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2428#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002429 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430#else
2431 (char_u *)NULL, PV_NONE,
2432#endif
2433 {(char_u *)"", (char_u *)0L}},
2434 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2435 (char_u *)&p_to, PV_NONE,
2436 {(char_u *)FALSE, (char_u *)0L}},
2437 {"timeout", "to", P_BOOL|P_VI_DEF,
2438 (char_u *)&p_timeout, PV_NONE,
2439 {(char_u *)TRUE, (char_u *)0L}},
2440 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2441 (char_u *)&p_tm, PV_NONE,
2442 {(char_u *)1000L, (char_u *)0L}},
2443 {"title", NULL, P_BOOL|P_VI_DEF,
2444#ifdef FEAT_TITLE
2445 (char_u *)&p_title, PV_NONE,
2446#else
2447 (char_u *)NULL, PV_NONE,
2448#endif
2449 {(char_u *)FALSE, (char_u *)0L}},
2450 {"titlelen", NULL, P_NUM|P_VI_DEF,
2451#ifdef FEAT_TITLE
2452 (char_u *)&p_titlelen, PV_NONE,
2453#else
2454 (char_u *)NULL, PV_NONE,
2455#endif
2456 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002457 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458#ifdef FEAT_TITLE
2459 (char_u *)&p_titleold, PV_NONE,
2460 {(char_u *)N_("Thanks for flying Vim"),
2461 (char_u *)0L}
2462#else
2463 (char_u *)NULL, PV_NONE,
2464 {(char_u *)0L, (char_u *)0L}
2465#endif
2466 },
2467 {"titlestring", NULL, P_STRING|P_VI_DEF,
2468#ifdef FEAT_TITLE
2469 (char_u *)&p_titlestring, PV_NONE,
2470#else
2471 (char_u *)NULL, PV_NONE,
2472#endif
2473 {(char_u *)"", (char_u *)0L}},
2474#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2475 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2476 (char_u *)&p_toolbar, PV_NONE,
2477 {(char_u *)"icons,tooltips", (char_u *)0L}},
2478#endif
2479#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2480 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2481 (char_u *)&p_tbis, PV_NONE,
2482 {(char_u *)"small", (char_u *)0L}},
2483#endif
2484 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2485 (char_u *)&p_ttimeout, PV_NONE,
2486 {(char_u *)FALSE, (char_u *)0L}},
2487 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2488 (char_u *)&p_ttm, PV_NONE,
2489 {(char_u *)-1L, (char_u *)0L}},
2490 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2491 (char_u *)&p_tbi, PV_NONE,
2492 {(char_u *)TRUE, (char_u *)0L}},
2493 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2494 (char_u *)&p_tf, PV_NONE,
2495 {(char_u *)FALSE, (char_u *)0L}},
2496 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2497#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2498 (char_u *)&p_ttym, PV_NONE,
2499#else
2500 (char_u *)NULL, PV_NONE,
2501#endif
2502 {(char_u *)"", (char_u *)0L}},
2503 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2504 (char_u *)&p_ttyscroll, PV_NONE,
2505 {(char_u *)999L, (char_u *)0L}},
2506 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2507 (char_u *)&T_NAME, PV_NONE,
2508 {(char_u *)"", (char_u *)0L}},
2509 {"undolevels", "ul", P_NUM|P_VI_DEF,
2510 (char_u *)&p_ul, PV_NONE,
2511 {
2512#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2513 (char_u *)1000L,
2514#else
2515 (char_u *)100L,
2516#endif
2517 (char_u *)0L}},
2518 {"updatecount", "uc", P_NUM|P_VI_DEF,
2519 (char_u *)&p_uc, PV_NONE,
2520 {(char_u *)200L, (char_u *)0L}},
2521 {"updatetime", "ut", P_NUM|P_VI_DEF,
2522 (char_u *)&p_ut, PV_NONE,
2523 {(char_u *)4000L, (char_u *)0L}},
2524 {"verbose", "vbs", P_NUM|P_VI_DEF,
2525 (char_u *)&p_verbose, PV_NONE,
2526 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002527 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2528 (char_u *)&p_vfile, PV_NONE,
2529 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2531#ifdef FEAT_SESSION
2532 (char_u *)&p_vdir, PV_NONE,
2533 {(char_u *)DFLT_VDIR, (char_u *)0L}
2534#else
2535 (char_u *)NULL, PV_NONE,
2536 {(char_u *)0L, (char_u *)0L}
2537#endif
2538 },
2539 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2540#ifdef FEAT_SESSION
2541 (char_u *)&p_vop, PV_NONE,
2542 {(char_u *)"folds,options,cursor", (char_u *)0L}
2543#else
2544 (char_u *)NULL, PV_NONE,
2545 {(char_u *)0L, (char_u *)0L}
2546#endif
2547 },
2548 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2549#ifdef FEAT_VIMINFO
2550 (char_u *)&p_viminfo, PV_NONE,
2551#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2552 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2553#else
2554# ifdef AMIGA
2555 {(char_u *)"",
2556 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2557# else
2558 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2559# endif
2560#endif
2561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)0L, (char_u *)0L}
2564#endif
2565 },
2566 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2567#ifdef FEAT_VIRTUALEDIT
2568 (char_u *)&p_ve, PV_NONE,
2569 {(char_u *)"", (char_u *)""}
2570#else
2571 (char_u *)NULL, PV_NONE,
2572 {(char_u *)0L, (char_u *)0L}
2573#endif
2574 },
2575 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2576 (char_u *)&p_vb, PV_NONE,
2577 {(char_u *)FALSE, (char_u *)0L}},
2578 {"w300", NULL, P_NUM|P_VI_DEF,
2579 (char_u *)NULL, PV_NONE,
2580 {(char_u *)0L, (char_u *)0L}},
2581 {"w1200", NULL, P_NUM|P_VI_DEF,
2582 (char_u *)NULL, PV_NONE,
2583 {(char_u *)0L, (char_u *)0L}},
2584 {"w9600", NULL, P_NUM|P_VI_DEF,
2585 (char_u *)NULL, PV_NONE,
2586 {(char_u *)0L, (char_u *)0L}},
2587 {"warn", NULL, P_BOOL|P_VI_DEF,
2588 (char_u *)&p_warn, PV_NONE,
2589 {(char_u *)TRUE, (char_u *)0L}},
2590 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2591 (char_u *)&p_wiv, PV_NONE,
2592 {(char_u *)FALSE, (char_u *)0L}},
2593 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2594 (char_u *)&p_ww, PV_NONE,
2595 {(char_u *)"", (char_u *)"b,s"}},
2596 {"wildchar", "wc", P_NUM|P_VIM,
2597 (char_u *)&p_wc, PV_NONE,
2598 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2599 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2600 (char_u *)&p_wcm, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}},
2602 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2603#ifdef FEAT_WILDIGN
2604 (char_u *)&p_wig, PV_NONE,
2605#else
2606 (char_u *)NULL, PV_NONE,
2607#endif
2608 {(char_u *)"", (char_u *)0L}},
2609 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2610#ifdef FEAT_WILDMENU
2611 (char_u *)&p_wmnu, PV_NONE,
2612#else
2613 (char_u *)NULL, PV_NONE,
2614#endif
2615 {(char_u *)FALSE, (char_u *)0L}},
2616 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2617 (char_u *)&p_wim, PV_NONE,
2618 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002619 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2620#ifdef FEAT_CMDL_COMPL
2621 (char_u *)&p_wop, PV_NONE,
2622 {(char_u *)"", (char_u *)0L}
2623#else
2624 (char_u *)NULL, PV_NONE,
2625 {(char_u *)NULL, (char_u *)0L}
2626#endif
2627 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2629#ifdef FEAT_WAK
2630 (char_u *)&p_wak, PV_NONE,
2631 {(char_u *)"menu", (char_u *)0L}
2632#else
2633 (char_u *)NULL, PV_NONE,
2634 {(char_u *)NULL, (char_u *)0L}
2635#endif
2636 },
2637 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002638 (char_u *)&p_window, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 {(char_u *)0L, (char_u *)0L}},
2640 {"winheight", "wh", P_NUM|P_VI_DEF,
2641#ifdef FEAT_WINDOWS
2642 (char_u *)&p_wh, PV_NONE,
2643#else
2644 (char_u *)NULL, PV_NONE,
2645#endif
2646 {(char_u *)1L, (char_u *)0L}},
2647 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002648#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 (char_u *)VAR_WIN, PV_WFH,
2650#else
2651 (char_u *)NULL, PV_NONE,
2652#endif
2653 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002654 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2655#ifdef FEAT_VERTSPLIT
2656 (char_u *)VAR_WIN, PV_WFW,
2657#else
2658 (char_u *)NULL, PV_NONE,
2659#endif
2660 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2662#ifdef FEAT_WINDOWS
2663 (char_u *)&p_wmh, PV_NONE,
2664#else
2665 (char_u *)NULL, PV_NONE,
2666#endif
2667 {(char_u *)1L, (char_u *)0L}},
2668 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2669#ifdef FEAT_VERTSPLIT
2670 (char_u *)&p_wmw, PV_NONE,
2671#else
2672 (char_u *)NULL, PV_NONE,
2673#endif
2674 {(char_u *)1L, (char_u *)0L}},
2675 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2676#ifdef FEAT_VERTSPLIT
2677 (char_u *)&p_wiw, PV_NONE,
2678#else
2679 (char_u *)NULL, PV_NONE,
2680#endif
2681 {(char_u *)20L, (char_u *)0L}},
2682 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2683 (char_u *)VAR_WIN, PV_WRAP,
2684 {(char_u *)TRUE, (char_u *)0L}},
2685 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2686 (char_u *)&p_wm, PV_WM,
2687 {(char_u *)0L, (char_u *)0L}},
2688 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2689 (char_u *)&p_ws, PV_NONE,
2690 {(char_u *)TRUE, (char_u *)0L}},
2691 {"write", NULL, P_BOOL|P_VI_DEF,
2692 (char_u *)&p_write, PV_NONE,
2693 {(char_u *)TRUE, (char_u *)0L}},
2694 {"writeany", "wa", P_BOOL|P_VI_DEF,
2695 (char_u *)&p_wa, PV_NONE,
2696 {(char_u *)FALSE, (char_u *)0L}},
2697 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2698 (char_u *)&p_wb, PV_NONE,
2699 {
2700#ifdef FEAT_WRITEBACKUP
2701 (char_u *)TRUE,
2702#else
2703 (char_u *)FALSE,
2704#endif
2705 (char_u *)0L}},
2706 {"writedelay", "wd", P_NUM|P_VI_DEF,
2707 (char_u *)&p_wd, PV_NONE,
2708 {(char_u *)0L, (char_u *)0L}},
2709
2710/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002711#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 (char_u *)&vvv, PV_NONE, \
2713 {(char_u *)"", (char_u *)0L}},
2714
2715 p_term("t_AB", T_CAB)
2716 p_term("t_AF", T_CAF)
2717 p_term("t_AL", T_CAL)
2718 p_term("t_al", T_AL)
2719 p_term("t_bc", T_BC)
2720 p_term("t_cd", T_CD)
2721 p_term("t_ce", T_CE)
2722 p_term("t_cl", T_CL)
2723 p_term("t_cm", T_CM)
2724 p_term("t_Co", T_CCO)
2725 p_term("t_CS", T_CCS)
2726 p_term("t_cs", T_CS)
2727#ifdef FEAT_VERTSPLIT
2728 p_term("t_CV", T_CSV)
2729#endif
2730 p_term("t_ut", T_UT)
2731 p_term("t_da", T_DA)
2732 p_term("t_db", T_DB)
2733 p_term("t_DL", T_CDL)
2734 p_term("t_dl", T_DL)
2735 p_term("t_fs", T_FS)
2736 p_term("t_IE", T_CIE)
2737 p_term("t_IS", T_CIS)
2738 p_term("t_ke", T_KE)
2739 p_term("t_ks", T_KS)
2740 p_term("t_le", T_LE)
2741 p_term("t_mb", T_MB)
2742 p_term("t_md", T_MD)
2743 p_term("t_me", T_ME)
2744 p_term("t_mr", T_MR)
2745 p_term("t_ms", T_MS)
2746 p_term("t_nd", T_ND)
2747 p_term("t_op", T_OP)
2748 p_term("t_RI", T_CRI)
2749 p_term("t_RV", T_CRV)
2750 p_term("t_Sb", T_CSB)
2751 p_term("t_Sf", T_CSF)
2752 p_term("t_se", T_SE)
2753 p_term("t_so", T_SO)
2754 p_term("t_sr", T_SR)
2755 p_term("t_ts", T_TS)
2756 p_term("t_te", T_TE)
2757 p_term("t_ti", T_TI)
2758 p_term("t_ue", T_UE)
2759 p_term("t_us", T_US)
2760 p_term("t_vb", T_VB)
2761 p_term("t_ve", T_VE)
2762 p_term("t_vi", T_VI)
2763 p_term("t_vs", T_VS)
2764 p_term("t_WP", T_CWP)
2765 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002766 p_term("t_SI", T_CSI)
2767 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 p_term("t_xs", T_XS)
2769 p_term("t_ZH", T_CZH)
2770 p_term("t_ZR", T_CZR)
2771
2772/* terminal key codes are not in here */
2773
2774 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2775};
2776
2777#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2778
2779#ifdef FEAT_MBYTE
2780static char *(p_ambw_values[]) = {"single", "double", NULL};
2781#endif
2782static char *(p_bg_values[]) = {"light", "dark", NULL};
2783static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2784static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002785#ifdef FEAT_CMDL_COMPL
2786static char *(p_wop_values[]) = {"tagfile", NULL};
2787#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788#ifdef FEAT_WAK
2789static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2790#endif
2791static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2792#ifdef FEAT_VISUAL
2793static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2794static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2795#endif
2796#ifdef FEAT_VISUAL
2797static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2798#endif
2799#ifdef FEAT_BROWSE
2800static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2801#endif
2802#ifdef FEAT_SCROLLBIND
2803static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2804#endif
2805static char *(p_swb_values[]) = {"useopen", "split", NULL};
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002806static char *(p_debug_values[]) = {"msg", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807#ifdef FEAT_VERTSPLIT
2808static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2809#endif
2810#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002811# ifdef FEAT_AUTOCMD
2812static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2813# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002815# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2817#endif
2818static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2819#ifdef FEAT_FOLDING
2820static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002821# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002823# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 NULL};
2825static char *(p_fcl_values[]) = {"all", NULL};
2826#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002827#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002828static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002829#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830
2831static void set_option_default __ARGS((int, int opt_flags, int compatible));
2832static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002833static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002834static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835static char_u *illegal_char __ARGS((char_u *, int));
2836static int string_to_key __ARGS((char_u *arg));
2837#ifdef FEAT_CMDWIN
2838static char_u *check_cedit __ARGS((void));
2839#endif
2840#ifdef FEAT_TITLE
2841static void did_set_title __ARGS((int icon));
2842#endif
2843static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2844static void didset_options __ARGS((void));
2845static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002846#if defined(FEAT_EVAL) || defined(PROTO)
2847static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2848#else
2849# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2852static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2853static 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));
2854static char_u *set_chars_option __ARGS((char_u **varp));
2855#ifdef FEAT_CLIPBOARD
2856static char_u *check_clipboard_option __ARGS((void));
2857#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002858#ifdef FEAT_SPELL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002859static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002860#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002861#ifdef FEAT_EVAL
2862static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002865static 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 +00002866static void check_redraw __ARGS((long_u flags));
2867static int findoption __ARGS((char_u *));
2868static int find_key_option __ARGS((char_u *));
2869static void showoptions __ARGS((int all, int opt_flags));
2870static int optval_default __ARGS((struct vimoption *, char_u *varp));
2871static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2872static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2873static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2874static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2875static int istermoption __ARGS((struct vimoption *));
2876static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2877static char_u *get_varp __ARGS((struct vimoption *));
2878static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2879static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2880#ifdef FEAT_LANGMAP
2881static void langmap_init __ARGS((void));
2882static void langmap_set __ARGS((void));
2883#endif
2884static void paste_option_changed __ARGS((void));
2885static void compatible_set __ARGS((void));
2886#ifdef FEAT_LINEBREAK
2887static void fill_breakat_flags __ARGS((void));
2888#endif
2889static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2890static int check_opt_strings __ARGS((char_u *val, char **values, int));
2891static int check_opt_wim __ARGS((void));
2892
2893/*
2894 * Initialize the options, first part.
2895 *
2896 * Called only once from main(), just after creating the first buffer.
2897 */
2898 void
2899set_init_1()
2900{
2901 char_u *p;
2902 int opt_idx;
2903 long n;
2904
2905#ifdef FEAT_LANGMAP
2906 langmap_init();
2907#endif
2908
2909 /* Be Vi compatible by default */
2910 p_cp = TRUE;
2911
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002912 /* Use POSIX compatibility when $VIM_POSIX is set. */
2913 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002914 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002915 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002916 set_string_default("shm", (char_u *)"A");
2917 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002918
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 /*
2920 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002921 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002923 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2925# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002926 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002928 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002930 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931# endif
2932#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002933 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 set_string_default("sh", p);
2935
2936#ifdef FEAT_WILDIGN
2937 /*
2938 * Set the default for 'backupskip' to include environment variables for
2939 * temp files.
2940 */
2941 {
2942# ifdef UNIX
2943 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2944# else
2945 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2946# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002947 int len;
2948 garray_T ga;
2949 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950
2951 ga_init2(&ga, 1, 100);
2952 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2953 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002954 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955# ifdef UNIX
2956 if (*names[n] == NUL)
2957 p = (char_u *)"/tmp";
2958 else
2959# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002960 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 if (p != NULL && *p != NUL)
2962 {
2963 /* First time count the NUL, otherwise count the ','. */
2964 len = STRLEN(p) + 3;
2965 if (ga_grow(&ga, len) == OK)
2966 {
2967 if (ga.ga_len > 0)
2968 STRCAT(ga.ga_data, ",");
2969 STRCAT(ga.ga_data, p);
2970 add_pathsep(ga.ga_data);
2971 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 ga.ga_len += len;
2973 }
2974 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002975 if (mustfree)
2976 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 }
2978 if (ga.ga_data != NULL)
2979 {
2980 set_string_default("bsk", ga.ga_data);
2981 vim_free(ga.ga_data);
2982 }
2983 }
2984#endif
2985
2986 /*
2987 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2988 */
2989 opt_idx = findoption((char_u *)"maxmemtot");
2990#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2991 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2992#endif
2993 {
2994#ifdef HAVE_AVAIL_MEM
2995 /* Use amount of memory available at this moment. */
2996 n = (mch_avail_mem(FALSE) >> 11);
2997#else
2998# ifdef HAVE_TOTAL_MEM
2999 /* Use amount of memory available to Vim. */
3000 n = (mch_total_mem(FALSE) >> 11);
3001# else
3002 n = (0x7fffffff >> 11);
3003# endif
3004#endif
3005 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3006 opt_idx = findoption((char_u *)"maxmem");
3007#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3008 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3009 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3010#endif
3011 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3012 }
3013
3014#ifdef FEAT_GUI_W32
3015 /* force 'shortname' for Win32s */
3016 if (gui_is_win32s())
3017 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
3018 (char_u *)TRUE;
3019#endif
3020
3021#ifdef FEAT_SEARCHPATH
3022 {
3023 char_u *cdpath;
3024 char_u *buf;
3025 int i;
3026 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003027 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028
3029 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003030 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 if (cdpath != NULL)
3032 {
3033 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3034 if (buf != NULL)
3035 {
3036 buf[0] = ','; /* start with ",", current dir first */
3037 j = 1;
3038 for (i = 0; cdpath[i] != NUL; ++i)
3039 {
3040 if (vim_ispathlistsep(cdpath[i]))
3041 buf[j++] = ',';
3042 else
3043 {
3044 if (cdpath[i] == ' ' || cdpath[i] == ',')
3045 buf[j++] = '\\';
3046 buf[j++] = cdpath[i];
3047 }
3048 }
3049 buf[j] = NUL;
3050 opt_idx = findoption((char_u *)"cdpath");
3051 options[opt_idx].def_val[VI_DEFAULT] = buf;
3052 options[opt_idx].flags |= P_DEF_ALLOCED;
3053 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003054 if (mustfree)
3055 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 }
3057 }
3058#endif
3059
3060#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3061 /* Set print encoding on platforms that don't default to latin1 */
3062 set_string_default("penc",
3063# if defined(MSWIN) || defined(OS2)
3064 (char_u *)"cp1252"
3065# else
3066# ifdef VMS
3067 (char_u *)"dec-mcs"
3068# else
3069# ifdef EBCDIC
3070 (char_u *)"ebcdic-uk"
3071# else
3072# ifdef MAC
3073 (char_u *)"mac-roman"
3074# else /* HPUX */
3075 (char_u *)"hp-roman8"
3076# endif
3077# endif
3078# endif
3079# endif
3080 );
3081#endif
3082
3083#ifdef FEAT_POSTSCRIPT
3084 /* 'printexpr' must be allocated to be able to evaluate it. */
3085 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003086# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3087 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088# else
3089# ifdef VMS
3090 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3091
3092# else
3093 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3094# endif
3095# endif
3096 );
3097#endif
3098
3099 /*
3100 * Set all the options (except the terminal options) to their default
3101 * value. Also set the global value for local options.
3102 */
3103 set_options_default(0);
3104
3105#ifdef FEAT_GUI
3106 if (found_reverse_arg)
3107 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3108#endif
3109
3110 curbuf->b_p_initialized = TRUE;
3111 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3112 check_buf_options(curbuf);
3113 check_win_options(curwin);
3114 check_options();
3115
3116 /* Must be before option_expand(), because that one needs vim_isIDc() */
3117 didset_options();
3118
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003119#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003120 /* Use the current chartab for the generic chartab. */
3121 init_spell_chartab();
3122#endif
3123
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124#ifdef FEAT_LINEBREAK
3125 /*
3126 * initialize the table for 'breakat'.
3127 */
3128 fill_breakat_flags();
3129#endif
3130
3131 /*
3132 * Expand environment variables and things like "~" for the defaults.
3133 * If option_expand() returns non-NULL the variable is expanded. This can
3134 * only happen for non-indirect options.
3135 * Also set the default to the expanded value, so ":set" does not list
3136 * them.
3137 * Don't set the P_ALLOCED flag, because we don't want to free the
3138 * default.
3139 */
3140 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3141 {
3142 if ((options[opt_idx].flags & P_GETTEXT)
3143 && options[opt_idx].var != NULL)
3144 p = (char_u *)_(*(char **)options[opt_idx].var);
3145 else
3146 p = option_expand(opt_idx, NULL);
3147 if (p != NULL && (p = vim_strsave(p)) != NULL)
3148 {
3149 *(char_u **)options[opt_idx].var = p;
3150 /* VIMEXP
3151 * Defaults for all expanded options are currently the same for Vi
3152 * and Vim. When this changes, add some code here! Also need to
3153 * split P_DEF_ALLOCED in two.
3154 */
3155 if (options[opt_idx].flags & P_DEF_ALLOCED)
3156 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3157 options[opt_idx].def_val[VI_DEFAULT] = p;
3158 options[opt_idx].flags |= P_DEF_ALLOCED;
3159 }
3160 }
3161
3162 /* Initialize the highlight_attr[] table. */
3163 highlight_changed();
3164
3165 save_file_ff(curbuf); /* Buffer is unchanged */
3166
3167 /* Parse default for 'wildmode' */
3168 check_opt_wim();
3169
3170#if defined(FEAT_ARABIC)
3171 /* Detect use of mlterm.
3172 * Mlterm is a terminal emulator akin to xterm that has some special
3173 * abilities (bidi namely).
3174 * NOTE: mlterm's author is being asked to 'set' a variable
3175 * instead of an environment variable due to inheritance.
3176 */
3177 if (mch_getenv((char_u *)"MLTERM") != NULL)
3178 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3179#endif
3180
3181#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3182 /* Parse default for 'fillchars'. */
3183 (void)set_chars_option(&p_fcs);
3184#endif
3185
3186#ifdef FEAT_CLIPBOARD
3187 /* Parse default for 'clipboard' */
3188 (void)check_clipboard_option();
3189#endif
3190
3191#ifdef FEAT_MBYTE
3192# if defined(WIN3264) && defined(FEAT_GETTEXT)
3193 /*
3194 * If $LANG isn't set, try to get a good value for it. This makes the
3195 * right language be used automatically. Don't do this for English.
3196 */
3197 if (mch_getenv((char_u *)"LANG") == NULL)
3198 {
3199 char buf[20];
3200
3201 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3202 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3203 * only the first two. */
3204 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3205 (LPTSTR)buf, 20);
3206 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3207 {
3208 /* There are a few exceptions (probably more) */
3209 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3210 STRCPY(buf, "zh_TW");
3211 else if (STRNICMP(buf, "chs", 3) == 0
3212 || STRNICMP(buf, "zhc", 3) == 0)
3213 STRCPY(buf, "zh_CN");
3214 else if (STRNICMP(buf, "jp", 2) == 0)
3215 STRCPY(buf, "ja");
3216 else
3217 buf[2] = NUL; /* truncate to two-letter code */
3218 vim_setenv("LANG", buf);
3219 }
3220 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003221# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003222# ifdef MACOS_CONVERT
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003223 if (mch_getenv((char_u *)"LANG") == NULL)
3224 {
3225 char buf[20];
3226 if (LocaleRefGetPartString(NULL,
3227 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3228 kLocaleRegionMask | kLocaleRegionVariantMask,
3229 sizeof buf, buf) == noErr && *buf)
3230 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003231 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003232# ifdef HAVE_LOCALE_H
3233 setlocale(LC_ALL, "");
3234# endif
3235 }
3236 }
3237# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238# endif
3239
3240 /* enc_locale() will try to find the encoding of the current locale. */
3241 p = enc_locale();
3242 if (p != NULL)
3243 {
3244 char_u *save_enc;
3245
3246 /* Try setting 'encoding' and check if the value is valid.
3247 * If not, go back to the default "latin1". */
3248 save_enc = p_enc;
3249 p_enc = p;
3250 if (mb_init() == NULL)
3251 {
3252 opt_idx = findoption((char_u *)"encoding");
3253 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3254 options[opt_idx].flags |= P_DEF_ALLOCED;
3255
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003256#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3257 || defined(VMS)
3258 if (STRCMP(p_enc, "latin1") == 0
3259# ifdef FEAT_MBYTE
3260 || enc_utf8
3261# endif
3262 )
3263 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003264 /* Adjust the default for 'isprint' and 'iskeyword' to match
3265 * latin1. Also set the defaults for when 'nocompatible' is
3266 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003267 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003268 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003269 set_string_option_direct((char_u *)"isk", -1,
3270 ISK_LATIN1, OPT_FREE, SID_NONE);
3271 opt_idx = findoption((char_u *)"isp");
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003272 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003273 opt_idx = findoption((char_u *)"isk");
3274 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003275 (void)init_chartab();
3276 }
3277#endif
3278
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279# if defined(WIN3264) && !defined(FEAT_GUI)
3280 /* Win32 console: When GetACP() returns a different value from
3281 * GetConsoleCP() set 'termencoding'. */
3282 if (GetACP() != GetConsoleCP())
3283 {
3284 char buf[50];
3285
3286 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3287 p_tenc = vim_strsave((char_u *)buf);
3288 if (p_tenc != NULL)
3289 {
3290 opt_idx = findoption((char_u *)"termencoding");
3291 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3292 options[opt_idx].flags |= P_DEF_ALLOCED;
3293 convert_setup(&input_conv, p_tenc, p_enc);
3294 convert_setup(&output_conv, p_enc, p_tenc);
3295 }
3296 else
3297 p_tenc = empty_option;
3298 }
3299# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003300# if defined(WIN3264) && defined(FEAT_MBYTE)
3301 /* $HOME may have characters in active code page. */
3302 init_homedir();
3303# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304 }
3305 else
3306 {
3307 vim_free(p_enc);
3308 p_enc = save_enc;
3309 }
3310 }
3311#endif
3312
3313#ifdef FEAT_MULTI_LANG
3314 /* Set the default for 'helplang'. */
3315 set_helplang_default(get_mess_lang());
3316#endif
3317}
3318
3319/*
3320 * Set an option to its default value.
3321 * This does not take care of side effects!
3322 */
3323 static void
3324set_option_default(opt_idx, opt_flags, compatible)
3325 int opt_idx;
3326 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3327 int compatible; /* use Vi default value */
3328{
3329 char_u *varp; /* pointer to variable for current option */
3330 int dvi; /* index in def_val[] */
3331 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003332 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3334
3335 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3336 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003337 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 {
3339 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3340 if (flags & P_STRING)
3341 {
3342 /* Use set_string_option_direct() for local options to handle
3343 * freeing and allocating the value. */
3344 if (options[opt_idx].indir != PV_NONE)
3345 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003346 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 else
3348 {
3349 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3350 free_string_option(*(char_u **)(varp));
3351 *(char_u **)varp = options[opt_idx].def_val[dvi];
3352 options[opt_idx].flags &= ~P_ALLOCED;
3353 }
3354 }
3355 else if (flags & P_NUM)
3356 {
3357 if (varp == (char_u *)PV_SCROLL)
3358 win_comp_scroll(curwin);
3359 else
3360 {
3361 *(long *)varp = (long)options[opt_idx].def_val[dvi];
3362 /* May also set global value for local option. */
3363 if (both)
3364 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3365 *(long *)varp;
3366 }
3367 }
3368 else /* P_BOOL */
3369 {
3370 /* the cast to long is required for Manx C */
3371 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3372 /* May also set global value for local option. */
3373 if (both)
3374 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3375 *(int *)varp;
3376 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003377
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003378 /* The default value is not insecure. */
3379 flagsp = insecure_flag(opt_idx, opt_flags);
3380 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381 }
3382
3383#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003384 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385#endif
3386}
3387
3388/*
3389 * Set all options (except terminal options) to their default value.
3390 */
3391 static void
3392set_options_default(opt_flags)
3393 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3394{
3395 int i;
3396#ifdef FEAT_WINDOWS
3397 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003398 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399#endif
3400
3401 for (i = 0; !istermoption(&options[i]); i++)
3402 if (!(options[i].flags & P_NODEFAULT))
3403 set_option_default(i, opt_flags, p_cp);
3404
3405#ifdef FEAT_WINDOWS
3406 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003407 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408 win_comp_scroll(wp);
3409#else
3410 win_comp_scroll(curwin);
3411#endif
3412}
3413
3414/*
3415 * Set the Vi-default value of a string option.
3416 * Used for 'sh', 'backupskip' and 'term'.
3417 */
3418 void
3419set_string_default(name, val)
3420 char *name;
3421 char_u *val;
3422{
3423 char_u *p;
3424 int opt_idx;
3425
3426 p = vim_strsave(val);
3427 if (p != NULL) /* we don't want a NULL */
3428 {
3429 opt_idx = findoption((char_u *)name);
3430 if (options[opt_idx].flags & P_DEF_ALLOCED)
3431 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3432 options[opt_idx].def_val[VI_DEFAULT] = p;
3433 options[opt_idx].flags |= P_DEF_ALLOCED;
3434 }
3435}
3436
3437/*
3438 * Set the Vi-default value of a number option.
3439 * Used for 'lines' and 'columns'.
3440 */
3441 void
3442set_number_default(name, val)
3443 char *name;
3444 long val;
3445{
3446 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3447}
3448
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003449#if defined(EXITFREE) || defined(PROTO)
3450/*
3451 * Free all options.
3452 */
3453 void
3454free_all_options()
3455{
3456 int i;
3457
3458 for (i = 0; !istermoption(&options[i]); i++)
3459 {
3460 if (options[i].indir == PV_NONE)
3461 {
3462 /* global option: free value and default value. */
3463 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3464 free_string_option(*(char_u **)options[i].var);
3465 if (options[i].flags & P_DEF_ALLOCED)
3466 free_string_option(options[i].def_val[VI_DEFAULT]);
3467 }
3468 else if (options[i].var != VAR_WIN
3469 && (options[i].flags & P_STRING))
3470 /* buffer-local option: free global value */
3471 free_string_option(*(char_u **)options[i].var);
3472 }
3473}
3474#endif
3475
3476
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477/*
3478 * Initialize the options, part two: After getting Rows and Columns and
3479 * setting 'term'.
3480 */
3481 void
3482set_init_2()
3483{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003484 int idx;
3485
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 /*
3487 * 'scroll' defaults to half the window height. Note that this default is
3488 * wrong when the window height changes.
3489 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003490 set_number_default("scroll", (long_u)Rows >> 1);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003491 idx = findoption((char_u *)"scroll");
3492 if (!(options[idx].flags & P_WAS_SET))
3493 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494 comp_col();
3495
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003496 /*
3497 * 'window' is only for backwards compatibility with Vi.
3498 * Default is Rows - 1.
3499 */
3500 idx = findoption((char_u *)"wi");
3501 if (!(options[idx].flags & P_WAS_SET))
3502 p_window = Rows - 1;
3503 set_number_default("window", Rows - 1);
3504
Bram Moolenaarf740b292006-02-16 22:11:02 +00003505 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003507 /*
3508 * If 'background' wasn't set by the user, try guessing the value,
3509 * depending on the terminal name. Only need to check for terminals
3510 * with a dark background, that can handle color.
3511 */
3512 idx = findoption((char_u *)"bg");
3513 if (!(options[idx].flags & P_WAS_SET) && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003515 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003516 /* don't mark it as set, when starting the GUI it may be
3517 * changed again */
3518 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519 }
3520#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003521
3522#ifdef CURSOR_SHAPE
3523 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3524#endif
3525#ifdef FEAT_MOUSESHAPE
3526 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3527#endif
3528#ifdef FEAT_PRINTER
3529 (void)parse_printoptions(); /* parse 'printoptions' default value */
3530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531}
3532
3533/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003534 * Return "dark" or "light" depending on the kind of terminal.
3535 * This is just guessing! Recognized are:
3536 * "linux" Linux console
3537 * "screen.linux" Linux console with screen
3538 * "cygwin" Cygwin shell
3539 * "putty" Putty program
3540 * We also check the COLORFGBG environment variable, which is set by
3541 * rxvt and derivatives. This variable contains either two or three
3542 * values separated by semicolons; we want the last value in either
3543 * case. If this value is 0-6 or 8, our background is dark.
3544 */
3545 static char_u *
3546term_bg_default()
3547{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003548#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3549 /* DOS console nearly always black */
3550 return (char_u *)"dark";
3551#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003552 char_u *p;
3553
Bram Moolenaarf740b292006-02-16 22:11:02 +00003554 if (STRCMP(T_NAME, "linux") == 0
3555 || STRCMP(T_NAME, "screen.linux") == 0
3556 || STRCMP(T_NAME, "cygwin") == 0
3557 || STRCMP(T_NAME, "putty") == 0
3558 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3559 && (p = vim_strrchr(p, ';')) != NULL
3560 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3561 && p[2] == NUL))
3562 return (char_u *)"dark";
3563 return (char_u *)"light";
3564#endif
3565}
3566
3567/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003568 * Initialize the options, part three: After reading the .vimrc
3569 */
3570 void
3571set_init_3()
3572{
3573#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3574/*
3575 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3576 * This is done after other initializations, where 'shell' might have been
3577 * set, but only if they have not been set before.
3578 */
3579 char_u *p;
3580 int idx_srr;
3581 int do_srr;
3582#ifdef FEAT_QUICKFIX
3583 int idx_sp;
3584 int do_sp;
3585#endif
3586
3587 idx_srr = findoption((char_u *)"srr");
3588 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3589#ifdef FEAT_QUICKFIX
3590 idx_sp = findoption((char_u *)"sp");
3591 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3592#endif
3593
3594 /*
3595 * Isolate the name of the shell:
3596 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3597 * - Remove any argument. E.g., "csh -f" -> "csh".
3598 */
3599 p = gettail(p_sh);
3600 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3601 if (p != NULL)
3602 {
3603 /*
3604 * Default for p_sp is "| tee", for p_srr is ">".
3605 * For known shells it is changed here to include stderr.
3606 */
3607 if ( fnamecmp(p, "csh") == 0
3608 || fnamecmp(p, "tcsh") == 0
3609# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3610 || fnamecmp(p, "csh.exe") == 0
3611 || fnamecmp(p, "tcsh.exe") == 0
3612# endif
3613 )
3614 {
3615#if defined(FEAT_QUICKFIX)
3616 if (do_sp)
3617 {
3618# ifdef WIN3264
3619 p_sp = (char_u *)">&";
3620# else
3621 p_sp = (char_u *)"|& tee";
3622# endif
3623 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3624 }
3625#endif
3626 if (do_srr)
3627 {
3628 p_srr = (char_u *)">&";
3629 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3630 }
3631 }
3632 else
3633# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3634 if ( fnamecmp(p, "sh") == 0
3635 || fnamecmp(p, "ksh") == 0
3636 || fnamecmp(p, "zsh") == 0
3637 || fnamecmp(p, "bash") == 0
3638# ifdef WIN3264
3639 || fnamecmp(p, "cmd") == 0
3640 || fnamecmp(p, "sh.exe") == 0
3641 || fnamecmp(p, "ksh.exe") == 0
3642 || fnamecmp(p, "zsh.exe") == 0
3643 || fnamecmp(p, "bash.exe") == 0
3644 || fnamecmp(p, "cmd.exe") == 0
3645# endif
3646 )
3647# endif
3648 {
3649#if defined(FEAT_QUICKFIX)
3650 if (do_sp)
3651 {
3652# ifdef WIN3264
3653 p_sp = (char_u *)">%s 2>&1";
3654# else
3655 p_sp = (char_u *)"2>&1| tee";
3656# endif
3657 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3658 }
3659#endif
3660 if (do_srr)
3661 {
3662 p_srr = (char_u *)">%s 2>&1";
3663 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3664 }
3665 }
3666 vim_free(p);
3667 }
3668#endif
3669
3670#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3671 /*
3672 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3673 * This is done after other initializations, where 'shell' might have been
3674 * set, but only if they have not been set before. Default for p_shcf is
3675 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3676 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3677 * command.com. And for Win32 we need to set p_sxq instead.
3678 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003679 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680 {
3681 int idx3;
3682
3683 idx3 = findoption((char_u *)"shcf");
3684 if (!(options[idx3].flags & P_WAS_SET))
3685 {
3686 p_shcf = (char_u *)"-c";
3687 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3688 }
3689
3690# ifndef DJGPP
3691# ifdef WIN3264
3692 /* Somehow Win32 requires the quotes around the redirection too */
3693 idx3 = findoption((char_u *)"sxq");
3694 if (!(options[idx3].flags & P_WAS_SET))
3695 {
3696 p_sxq = (char_u *)"\"";
3697 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3698 }
3699# else
3700 idx3 = findoption((char_u *)"shq");
3701 if (!(options[idx3].flags & P_WAS_SET))
3702 {
3703 p_shq = (char_u *)"\"";
3704 options[idx3].def_val[VI_DEFAULT] = p_shq;
3705 }
3706# endif
3707# endif
3708 }
3709#endif
3710
3711#ifdef FEAT_TITLE
3712 set_title_defaults();
3713#endif
3714}
3715
3716#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3717/*
3718 * When 'helplang' is still at its default value, set it to "lang".
3719 * Only the first two characters of "lang" are used.
3720 */
3721 void
3722set_helplang_default(lang)
3723 char_u *lang;
3724{
3725 int idx;
3726
3727 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3728 return;
3729 idx = findoption((char_u *)"hlg");
3730 if (!(options[idx].flags & P_WAS_SET))
3731 {
3732 if (options[idx].flags & P_ALLOCED)
3733 free_string_option(p_hlg);
3734 p_hlg = vim_strsave(lang);
3735 if (p_hlg == NULL)
3736 p_hlg = empty_option;
3737 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003738 {
3739 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3740 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3741 {
3742 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3743 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3744 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003745 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003746 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747 options[idx].flags |= P_ALLOCED;
3748 }
3749}
3750#endif
3751
3752#ifdef FEAT_GUI
3753static char_u *gui_bg_default __ARGS((void));
3754
3755 static char_u *
3756gui_bg_default()
3757{
3758 if (gui_get_lightness(gui.back_pixel) < 127)
3759 return (char_u *)"dark";
3760 return (char_u *)"light";
3761}
3762
3763/*
3764 * Option initializations that can only be done after opening the GUI window.
3765 */
3766 void
3767init_gui_options()
3768{
3769 /* Set the 'background' option according to the lightness of the
3770 * background color, unless the user has set it already. */
3771 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3772 {
3773 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3774 highlight_changed();
3775 }
3776}
3777#endif
3778
3779#ifdef FEAT_TITLE
3780/*
3781 * 'title' and 'icon' only default to true if they have not been set or reset
3782 * in .vimrc and we can read the old value.
3783 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3784 * they can be reset. This reduces startup time when using X on a remote
3785 * machine.
3786 */
3787 void
3788set_title_defaults()
3789{
3790 int idx1;
3791 long val;
3792
3793 /*
3794 * If GUI is (going to be) used, we can always set the window title and
3795 * icon name. Saves a bit of time, because the X11 display server does
3796 * not need to be contacted.
3797 */
3798 idx1 = findoption((char_u *)"title");
3799 if (!(options[idx1].flags & P_WAS_SET))
3800 {
3801#ifdef FEAT_GUI
3802 if (gui.starting || gui.in_use)
3803 val = TRUE;
3804 else
3805#endif
3806 val = mch_can_restore_title();
3807 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3808 p_title = val;
3809 }
3810 idx1 = findoption((char_u *)"icon");
3811 if (!(options[idx1].flags & P_WAS_SET))
3812 {
3813#ifdef FEAT_GUI
3814 if (gui.starting || gui.in_use)
3815 val = TRUE;
3816 else
3817#endif
3818 val = mch_can_restore_icon();
3819 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3820 p_icon = val;
3821 }
3822}
3823#endif
3824
3825/*
3826 * Parse 'arg' for option settings.
3827 *
3828 * 'arg' may be IObuff, but only when no errors can be present and option
3829 * does not need to be expanded with option_expand().
3830 * "opt_flags":
3831 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00003832 * OPT_GLOBAL for ":setglobal"
3833 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00003835 * OPT_WINONLY to only set window-local options
3836 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837 *
3838 * returns FAIL if an error is detected, OK otherwise
3839 */
3840 int
3841do_set(arg, opt_flags)
3842 char_u *arg; /* option string (may be written to!) */
3843 int opt_flags;
3844{
3845 int opt_idx;
3846 char_u *errmsg;
3847 char_u errbuf[80];
3848 char_u *startarg;
3849 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3850 int nextchar; /* next non-white char after option name */
3851 int afterchar; /* character just after option name */
3852 int len;
3853 int i;
3854 long value;
3855 int key;
3856 long_u flags; /* flags for current option */
3857 char_u *varp = NULL; /* pointer to variable for current option */
3858 int did_show = FALSE; /* already showed one value */
3859 int adding; /* "opt+=arg" */
3860 int prepending; /* "opt^=arg" */
3861 int removing; /* "opt-=arg" */
3862 int cp_val = 0;
3863 char_u key_name[2];
3864
3865 if (*arg == NUL)
3866 {
3867 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003868 did_show = TRUE;
3869 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870 }
3871
3872 while (*arg != NUL) /* loop to process all options */
3873 {
3874 errmsg = NULL;
3875 startarg = arg; /* remember for error message */
3876
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003877 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3878 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 {
3880 /*
3881 * ":set all" show all options.
3882 * ":set all&" set all options to their default value.
3883 */
3884 arg += 3;
3885 if (*arg == '&')
3886 {
3887 ++arg;
3888 /* Only for :set command set global value of local options. */
3889 set_options_default(OPT_FREE | opt_flags);
3890 }
3891 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003892 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003894 did_show = TRUE;
3895 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003897 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898 {
3899 showoptions(2, opt_flags);
3900 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003901 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 arg += 7;
3903 }
3904 else
3905 {
3906 prefix = 1;
3907 if (STRNCMP(arg, "no", 2) == 0)
3908 {
3909 prefix = 0;
3910 arg += 2;
3911 }
3912 else if (STRNCMP(arg, "inv", 3) == 0)
3913 {
3914 prefix = 2;
3915 arg += 3;
3916 }
3917
3918 /* find end of name */
3919 key = 0;
3920 if (*arg == '<')
3921 {
3922 nextchar = 0;
3923 opt_idx = -1;
3924 /* look out for <t_>;> */
3925 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3926 len = 5;
3927 else
3928 {
3929 len = 1;
3930 while (arg[len] != NUL && arg[len] != '>')
3931 ++len;
3932 }
3933 if (arg[len] != '>')
3934 {
3935 errmsg = e_invarg;
3936 goto skip;
3937 }
3938 arg[len] = NUL; /* put NUL after name */
3939 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3940 opt_idx = findoption(arg + 1);
3941 arg[len++] = '>'; /* restore '>' */
3942 if (opt_idx == -1)
3943 key = find_key_option(arg + 1);
3944 }
3945 else
3946 {
3947 len = 0;
3948 /*
3949 * The two characters after "t_" may not be alphanumeric.
3950 */
3951 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3952 len = 4;
3953 else
3954 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3955 ++len;
3956 nextchar = arg[len];
3957 arg[len] = NUL; /* put NUL after name */
3958 opt_idx = findoption(arg);
3959 arg[len] = nextchar; /* restore nextchar */
3960 if (opt_idx == -1)
3961 key = find_key_option(arg);
3962 }
3963
3964 /* remember character after option name */
3965 afterchar = arg[len];
3966
3967 /* skip white space, allow ":set ai ?" */
3968 while (vim_iswhite(arg[len]))
3969 ++len;
3970
3971 adding = FALSE;
3972 prepending = FALSE;
3973 removing = FALSE;
3974 if (arg[len] != NUL && arg[len + 1] == '=')
3975 {
3976 if (arg[len] == '+')
3977 {
3978 adding = TRUE; /* "+=" */
3979 ++len;
3980 }
3981 else if (arg[len] == '^')
3982 {
3983 prepending = TRUE; /* "^=" */
3984 ++len;
3985 }
3986 else if (arg[len] == '-')
3987 {
3988 removing = TRUE; /* "-=" */
3989 ++len;
3990 }
3991 }
3992 nextchar = arg[len];
3993
3994 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3995 {
3996 errmsg = (char_u *)N_("E518: Unknown option");
3997 goto skip;
3998 }
3999
4000 if (opt_idx >= 0)
4001 {
4002 if (options[opt_idx].var == NULL) /* hidden option: skip */
4003 {
4004 /* Only give an error message when requesting the value of
4005 * a hidden option, ignore setting it. */
4006 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4007 && (!(options[opt_idx].flags & P_BOOL)
4008 || nextchar == '?'))
4009 errmsg = (char_u *)N_("E519: Option not supported");
4010 goto skip;
4011 }
4012
4013 flags = options[opt_idx].flags;
4014 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4015 }
4016 else
4017 {
4018 flags = P_STRING;
4019 if (key < 0)
4020 {
4021 key_name[0] = KEY2TERMCAP0(key);
4022 key_name[1] = KEY2TERMCAP1(key);
4023 }
4024 else
4025 {
4026 key_name[0] = KS_KEY;
4027 key_name[1] = (key & 0xff);
4028 }
4029 }
4030
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004031 /* Skip all options that are not window-local (used when showing
4032 * an already loaded buffer in a window). */
4033 if ((opt_flags & OPT_WINONLY)
4034 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4035 goto skip;
4036
Bram Moolenaara3227e22006-03-08 21:32:40 +00004037 /* Skip all options that are window-local (used for :vimgrep). */
4038 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4039 && options[opt_idx].var == VAR_WIN)
4040 goto skip;
4041
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042 /* Disallow changing some options from modelines */
4043 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
4044 {
4045 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4046 goto skip;
4047 }
4048
4049#ifdef HAVE_SANDBOX
4050 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004051 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 {
4053 errmsg = (char_u *)_(e_sandbox);
4054 goto skip;
4055 }
4056#endif
4057
4058 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4059 {
4060 arg += len;
4061 cp_val = p_cp;
4062 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4063 {
4064 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4065 {
4066 cp_val = FALSE;
4067 arg += 3;
4068 }
4069 else /* "opt&vi": set to Vi default */
4070 {
4071 cp_val = TRUE;
4072 arg += 2;
4073 }
4074 }
4075 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4076 && arg[1] != NUL && !vim_iswhite(arg[1]))
4077 {
4078 errmsg = e_trailing;
4079 goto skip;
4080 }
4081 }
4082
4083 /*
4084 * allow '=' and ':' as MSDOS command.com allows only one
4085 * '=' character per "set" command line. grrr. (jw)
4086 */
4087 if (nextchar == '?'
4088 || (prefix == 1
4089 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4090 && !(flags & P_BOOL)))
4091 {
4092 /*
4093 * print value
4094 */
4095 if (did_show)
4096 msg_putchar('\n'); /* cursor below last one */
4097 else
4098 {
4099 gotocmdline(TRUE); /* cursor at status line */
4100 did_show = TRUE; /* remember that we did a line */
4101 }
4102 if (opt_idx >= 0)
4103 {
4104 showoneopt(&options[opt_idx], opt_flags);
4105#ifdef FEAT_EVAL
4106 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004107 {
4108 /* Mention where the option was last set. */
4109 if (varp == options[opt_idx].var)
4110 last_set_msg(options[opt_idx].scriptID);
4111 else if ((int)options[opt_idx].indir & PV_WIN)
4112 last_set_msg(curwin->w_p_scriptID[
4113 (int)options[opt_idx].indir & PV_MASK]);
4114 else if ((int)options[opt_idx].indir & PV_BUF)
4115 last_set_msg(curbuf->b_p_scriptID[
4116 (int)options[opt_idx].indir & PV_MASK]);
4117 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118#endif
4119 }
4120 else
4121 {
4122 char_u *p;
4123
4124 p = find_termcode(key_name);
4125 if (p == NULL)
4126 {
4127 errmsg = (char_u *)N_("E518: Unknown option");
4128 goto skip;
4129 }
4130 else
4131 (void)show_one_termcode(key_name, p, TRUE);
4132 }
4133 if (nextchar != '?'
4134 && nextchar != NUL && !vim_iswhite(afterchar))
4135 errmsg = e_trailing;
4136 }
4137 else
4138 {
4139 if (flags & P_BOOL) /* boolean */
4140 {
4141 if (nextchar == '=' || nextchar == ':')
4142 {
4143 errmsg = e_invarg;
4144 goto skip;
4145 }
4146
4147 /*
4148 * ":set opt!": invert
4149 * ":set opt&": reset to default value
4150 * ":set opt<": reset to global value
4151 */
4152 if (nextchar == '!')
4153 value = *(int *)(varp) ^ 1;
4154 else if (nextchar == '&')
4155 value = (int)(long)options[opt_idx].def_val[
4156 ((flags & P_VI_DEF) || cp_val)
4157 ? VI_DEFAULT : VIM_DEFAULT];
4158 else if (nextchar == '<')
4159 {
4160 /* For 'autoread' -1 means to use global value. */
4161 if ((int *)varp == &curbuf->b_p_ar
4162 && opt_flags == OPT_LOCAL)
4163 value = -1;
4164 else
4165 value = *(int *)get_varp_scope(&(options[opt_idx]),
4166 OPT_GLOBAL);
4167 }
4168 else
4169 {
4170 /*
4171 * ":set invopt": invert
4172 * ":set opt" or ":set noopt": set or reset
4173 */
4174 if (nextchar != NUL && !vim_iswhite(afterchar))
4175 {
4176 errmsg = e_trailing;
4177 goto skip;
4178 }
4179 if (prefix == 2) /* inv */
4180 value = *(int *)(varp) ^ 1;
4181 else
4182 value = prefix;
4183 }
4184
4185 errmsg = set_bool_option(opt_idx, varp, (int)value,
4186 opt_flags);
4187 }
4188 else /* numeric or string */
4189 {
4190 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4191 || prefix != 1)
4192 {
4193 errmsg = e_invarg;
4194 goto skip;
4195 }
4196
4197 if (flags & P_NUM) /* numeric */
4198 {
4199 /*
4200 * Different ways to set a number option:
4201 * & set to default value
4202 * < set to global value
4203 * <xx> accept special key codes for 'wildchar'
4204 * c accept any non-digit for 'wildchar'
4205 * [-]0-9 set number
4206 * other error
4207 */
4208 ++arg;
4209 if (nextchar == '&')
4210 value = (long)options[opt_idx].def_val[
4211 ((flags & P_VI_DEF) || cp_val)
4212 ? VI_DEFAULT : VIM_DEFAULT];
4213 else if (nextchar == '<')
4214 value = *(long *)get_varp_scope(&(options[opt_idx]),
4215 OPT_GLOBAL);
4216 else if (((long *)varp == &p_wc
4217 || (long *)varp == &p_wcm)
4218 && (*arg == '<'
4219 || *arg == '^'
4220 || ((!arg[1] || vim_iswhite(arg[1]))
4221 && !VIM_ISDIGIT(*arg))))
4222 {
4223 value = string_to_key(arg);
4224 if (value == 0 && (long *)varp != &p_wcm)
4225 {
4226 errmsg = e_invarg;
4227 goto skip;
4228 }
4229 }
4230 /* allow negative numbers (for 'undolevels') */
4231 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4232 {
4233 i = 0;
4234 if (*arg == '-')
4235 i = 1;
4236#ifdef HAVE_STRTOL
4237 value = strtol((char *)arg, NULL, 0);
4238 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4239 i += 2;
4240#else
4241 value = atol((char *)arg);
4242#endif
4243 while (VIM_ISDIGIT(arg[i]))
4244 ++i;
4245 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4246 {
4247 errmsg = e_invarg;
4248 goto skip;
4249 }
4250 }
4251 else
4252 {
4253 errmsg = (char_u *)N_("E521: Number required after =");
4254 goto skip;
4255 }
4256
4257 if (adding)
4258 value = *(long *)varp + value;
4259 if (prepending)
4260 value = *(long *)varp * value;
4261 if (removing)
4262 value = *(long *)varp - value;
4263 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004264 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004265 }
4266 else if (opt_idx >= 0) /* string */
4267 {
4268 char_u *save_arg = NULL;
4269 char_u *s = NULL;
4270 char_u *oldval; /* previous value if *varp */
4271 char_u *newval;
4272 char_u *origval;
4273 unsigned newlen;
4274 int comma;
4275 int bs;
4276 int new_value_alloced; /* new string option
4277 was allocated */
4278
4279 /* When using ":set opt=val" for a global option
4280 * with a local value the local value will be
4281 * reset, use the global value here. */
4282 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004283 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004284 varp = options[opt_idx].var;
4285
4286 /* The old value is kept until we are sure that the
4287 * new value is valid. */
4288 oldval = *(char_u **)varp;
4289 if (nextchar == '&') /* set to default val */
4290 {
4291 newval = options[opt_idx].def_val[
4292 ((flags & P_VI_DEF) || cp_val)
4293 ? VI_DEFAULT : VIM_DEFAULT];
4294 if ((char_u **)varp == &p_bg)
4295 {
4296 /* guess the value of 'background' */
4297#ifdef FEAT_GUI
4298 if (gui.in_use)
4299 newval = gui_bg_default();
4300 else
4301#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004302 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 }
4304
4305 /* expand environment variables and ~ (since the
4306 * default value was already expanded, only
4307 * required when an environment variable was set
4308 * later */
4309 if (newval == NULL)
4310 newval = empty_option;
4311 else
4312 {
4313 s = option_expand(opt_idx, newval);
4314 if (s == NULL)
4315 s = newval;
4316 newval = vim_strsave(s);
4317 }
4318 new_value_alloced = TRUE;
4319 }
4320 else if (nextchar == '<') /* set to global val */
4321 {
4322 newval = vim_strsave(*(char_u **)get_varp_scope(
4323 &(options[opt_idx]), OPT_GLOBAL));
4324 new_value_alloced = TRUE;
4325 }
4326 else
4327 {
4328 ++arg; /* jump to after the '=' or ':' */
4329
4330 /*
4331 * Set 'keywordprg' to ":help" if an empty
4332 * value was passed to :set by the user.
4333 * Misuse errbuf[] for the resulting string.
4334 */
4335 if (varp == (char_u *)&p_kp
4336 && (*arg == NUL || *arg == ' '))
4337 {
4338 STRCPY(errbuf, ":help");
4339 save_arg = arg;
4340 arg = errbuf;
4341 }
4342 /*
4343 * Convert 'whichwrap' number to string, for
4344 * backwards compatibility with Vim 3.0.
4345 * Misuse errbuf[] for the resulting string.
4346 */
4347 else if (varp == (char_u *)&p_ww
4348 && VIM_ISDIGIT(*arg))
4349 {
4350 *errbuf = NUL;
4351 i = getdigits(&arg);
4352 if (i & 1)
4353 STRCAT(errbuf, "b,");
4354 if (i & 2)
4355 STRCAT(errbuf, "s,");
4356 if (i & 4)
4357 STRCAT(errbuf, "h,l,");
4358 if (i & 8)
4359 STRCAT(errbuf, "<,>,");
4360 if (i & 16)
4361 STRCAT(errbuf, "[,],");
4362 if (*errbuf != NUL) /* remove trailing , */
4363 errbuf[STRLEN(errbuf) - 1] = NUL;
4364 save_arg = arg;
4365 arg = errbuf;
4366 }
4367 /*
4368 * Remove '>' before 'dir' and 'bdir', for
4369 * backwards compatibility with version 3.0
4370 */
4371 else if ( *arg == '>'
4372 && (varp == (char_u *)&p_dir
4373 || varp == (char_u *)&p_bdir))
4374 {
4375 ++arg;
4376 }
4377
4378 /* When setting the local value of a global
4379 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004380 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004381 && (opt_flags & OPT_LOCAL))
4382 origval = *(char_u **)get_varp(
4383 &options[opt_idx]);
4384 else
4385 origval = oldval;
4386
4387 /*
4388 * Copy the new string into allocated memory.
4389 * Can't use set_string_option_direct(), because
4390 * we need to remove the backslashes.
4391 */
4392 /* get a bit too much */
4393 newlen = (unsigned)STRLEN(arg) + 1;
4394 if (adding || prepending || removing)
4395 newlen += (unsigned)STRLEN(origval) + 1;
4396 newval = alloc(newlen);
4397 if (newval == NULL) /* out of mem, don't change */
4398 break;
4399 s = newval;
4400
4401 /*
4402 * Copy the string, skip over escaped chars.
4403 * For MS-DOS and WIN32 backslashes before normal
4404 * file name characters are not removed, and keep
4405 * backslash at start, for "\\machine\path", but
4406 * do remove it for "\\\\machine\\path".
4407 * The reverse is found in ExpandOldSetting().
4408 */
4409 while (*arg && !vim_iswhite(*arg))
4410 {
4411 if (*arg == '\\' && arg[1] != NUL
4412#ifdef BACKSLASH_IN_FILENAME
4413 && !((flags & P_EXPAND)
4414 && vim_isfilec(arg[1])
4415 && (arg[1] != '\\'
4416 || (s == newval
4417 && arg[2] != '\\')))
4418#endif
4419 )
4420 ++arg; /* remove backslash */
4421#ifdef FEAT_MBYTE
4422 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004423 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004424 {
4425 /* copy multibyte char */
4426 mch_memmove(s, arg, (size_t)i);
4427 arg += i;
4428 s += i;
4429 }
4430 else
4431#endif
4432 *s++ = *arg++;
4433 }
4434 *s = NUL;
4435
4436 /*
4437 * Expand environment variables and ~.
4438 * Don't do it when adding without inserting a
4439 * comma.
4440 */
4441 if (!(adding || prepending || removing)
4442 || (flags & P_COMMA))
4443 {
4444 s = option_expand(opt_idx, newval);
4445 if (s != NULL)
4446 {
4447 vim_free(newval);
4448 newlen = (unsigned)STRLEN(s) + 1;
4449 if (adding || prepending || removing)
4450 newlen += (unsigned)STRLEN(origval) + 1;
4451 newval = alloc(newlen);
4452 if (newval == NULL)
4453 break;
4454 STRCPY(newval, s);
4455 }
4456 }
4457
4458 /* locate newval[] in origval[] when removing it
4459 * and when adding to avoid duplicates */
4460 i = 0; /* init for GCC */
4461 if (removing || (flags & P_NODUP))
4462 {
4463 i = (int)STRLEN(newval);
4464 bs = 0;
4465 for (s = origval; *s; ++s)
4466 {
4467 if ((!(flags & P_COMMA)
4468 || s == origval
4469 || (s[-1] == ',' && !(bs & 1)))
4470 && STRNCMP(s, newval, i) == 0
4471 && (!(flags & P_COMMA)
4472 || s[i] == ','
4473 || s[i] == NUL))
4474 break;
4475 /* Count backspaces. Only a comma with an
4476 * even number of backspaces before it is
4477 * recognized as a separator */
4478 if (s > origval && s[-1] == '\\')
4479 ++bs;
4480 else
4481 bs = 0;
4482 }
4483
4484 /* do not add if already there */
4485 if ((adding || prepending) && *s)
4486 {
4487 prepending = FALSE;
4488 adding = FALSE;
4489 STRCPY(newval, origval);
4490 }
4491 }
4492
4493 /* concatenate the two strings; add a ',' if
4494 * needed */
4495 if (adding || prepending)
4496 {
4497 comma = ((flags & P_COMMA) && *origval != NUL
4498 && *newval != NUL);
4499 if (adding)
4500 {
4501 i = (int)STRLEN(origval);
4502 mch_memmove(newval + i + comma, newval,
4503 STRLEN(newval) + 1);
4504 mch_memmove(newval, origval, (size_t)i);
4505 }
4506 else
4507 {
4508 i = (int)STRLEN(newval);
4509 mch_memmove(newval + i + comma, origval,
4510 STRLEN(origval) + 1);
4511 }
4512 if (comma)
4513 newval[i] = ',';
4514 }
4515
4516 /* Remove newval[] from origval[]. (Note: "i" has
4517 * been set above and is used here). */
4518 if (removing)
4519 {
4520 STRCPY(newval, origval);
4521 if (*s)
4522 {
4523 /* may need to remove a comma */
4524 if (flags & P_COMMA)
4525 {
4526 if (s == origval)
4527 {
4528 /* include comma after string */
4529 if (s[i] == ',')
4530 ++i;
4531 }
4532 else
4533 {
4534 /* include comma before string */
4535 --s;
4536 ++i;
4537 }
4538 }
4539 mch_memmove(newval + (s - origval), s + i,
4540 STRLEN(s + i) + 1);
4541 }
4542 }
4543
4544 if (flags & P_FLAGLIST)
4545 {
4546 /* Remove flags that appear twice. */
4547 for (s = newval; *s; ++s)
4548 if ((!(flags & P_COMMA) || *s != ',')
4549 && vim_strchr(s + 1, *s) != NULL)
4550 {
4551 STRCPY(s, s + 1);
4552 --s;
4553 }
4554 }
4555
4556 if (save_arg != NULL) /* number for 'whichwrap' */
4557 arg = save_arg;
4558 new_value_alloced = TRUE;
4559 }
4560
4561 /* Set the new value. */
4562 *(char_u **)(varp) = newval;
4563
4564 /* Handle side effects, and set the global value for
4565 * ":set" on local options. */
4566 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4567 new_value_alloced, oldval, errbuf, opt_flags);
4568
4569 /* If error detected, print the error message. */
4570 if (errmsg != NULL)
4571 goto skip;
4572 }
4573 else /* key code option */
4574 {
4575 char_u *p;
4576
4577 if (nextchar == '&')
4578 {
4579 if (add_termcap_entry(key_name, TRUE) == FAIL)
4580 errmsg = (char_u *)N_("E522: Not found in termcap");
4581 }
4582 else
4583 {
4584 ++arg; /* jump to after the '=' or ':' */
4585 for (p = arg; *p && !vim_iswhite(*p); ++p)
4586 if (*p == '\\' && p[1] != NUL)
4587 ++p;
4588 nextchar = *p;
4589 *p = NUL;
4590 add_termcode(key_name, arg, FALSE);
4591 *p = nextchar;
4592 }
4593 if (full_screen)
4594 ttest(FALSE);
4595 redraw_all_later(CLEAR);
4596 }
4597 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004598
Bram Moolenaar071d4272004-06-13 20:20:40 +00004599 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004600 did_set_option(opt_idx, opt_flags,
4601 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004602 }
4603
4604skip:
4605 /*
4606 * Advance to next argument.
4607 * - skip until a blank found, taking care of backslashes
4608 * - skip blanks
4609 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4610 */
4611 for (i = 0; i < 2 ; ++i)
4612 {
4613 while (*arg != NUL && !vim_iswhite(*arg))
4614 if (*arg++ == '\\' && *arg != NUL)
4615 ++arg;
4616 arg = skipwhite(arg);
4617 if (*arg != '=')
4618 break;
4619 }
4620 }
4621
4622 if (errmsg != NULL)
4623 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004624 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004625 i = STRLEN(IObuff) + 2;
4626 if (i + (arg - startarg) < IOSIZE)
4627 {
4628 /* append the argument with the error */
4629 STRCAT(IObuff, ": ");
4630 mch_memmove(IObuff + i, startarg, (arg - startarg));
4631 IObuff[i + (arg - startarg)] = NUL;
4632 }
4633 /* make sure all characters are printable */
4634 trans_characters(IObuff, IOSIZE);
4635
4636 ++no_wait_return; /* wait_return done later */
4637 emsg(IObuff); /* show error highlighted */
4638 --no_wait_return;
4639
4640 return FAIL;
4641 }
4642
4643 arg = skipwhite(arg);
4644 }
4645
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004646theend:
4647 if (silent_mode && did_show)
4648 {
4649 /* After displaying option values in silent mode. */
4650 silent_mode = FALSE;
4651 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4652 msg_putchar('\n');
4653 cursor_on(); /* msg_start() switches it off */
4654 out_flush();
4655 silent_mode = TRUE;
4656 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4657 }
4658
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659 return OK;
4660}
4661
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004662/*
4663 * Call this when an option has been given a new value through a user command.
4664 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4665 */
4666 static void
4667did_set_option(opt_idx, opt_flags, new_value)
4668 int opt_idx;
4669 int opt_flags; /* possibly with OPT_MODELINE */
4670 int new_value; /* value was replaced completely */
4671{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004672 long_u *p;
4673
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004674 options[opt_idx].flags |= P_WAS_SET;
4675
4676 /* When an option is set in the sandbox, from a modeline or in secure mode
4677 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004678 * flag. */
4679 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004680 if (secure
4681#ifdef HAVE_SANDBOX
4682 || sandbox != 0
4683#endif
4684 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004685 *p = *p | P_INSECURE;
4686 else if (new_value)
4687 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004688}
4689
Bram Moolenaar071d4272004-06-13 20:20:40 +00004690 static char_u *
4691illegal_char(errbuf, c)
4692 char_u *errbuf;
4693 int c;
4694{
4695 if (errbuf == NULL)
4696 return (char_u *)"";
4697 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004698 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004699 return errbuf;
4700}
4701
4702/*
4703 * Convert a key name or string into a key value.
4704 * Used for 'wildchar' and 'cedit' options.
4705 */
4706 static int
4707string_to_key(arg)
4708 char_u *arg;
4709{
4710 if (*arg == '<')
4711 return find_key_option(arg + 1);
4712 if (*arg == '^')
4713 return Ctrl_chr(arg[1]);
4714 return *arg;
4715}
4716
4717#ifdef FEAT_CMDWIN
4718/*
4719 * Check value of 'cedit' and set cedit_key.
4720 * Returns NULL if value is OK, error message otherwise.
4721 */
4722 static char_u *
4723check_cedit()
4724{
4725 int n;
4726
4727 if (*p_cedit == NUL)
4728 cedit_key = -1;
4729 else
4730 {
4731 n = string_to_key(p_cedit);
4732 if (vim_isprintc(n))
4733 return e_invarg;
4734 cedit_key = n;
4735 }
4736 return NULL;
4737}
4738#endif
4739
4740#ifdef FEAT_TITLE
4741/*
4742 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4743 * maketitle() to create and display it.
4744 * When switching the title or icon off, call mch_restore_title() to get
4745 * the old value back.
4746 */
4747 static void
4748did_set_title(icon)
4749 int icon; /* Did set icon instead of title */
4750{
4751 if (starting != NO_SCREEN
4752#ifdef FEAT_GUI
4753 && !gui.starting
4754#endif
4755 )
4756 {
4757 maketitle();
4758 if (icon)
4759 {
4760 if (!p_icon)
4761 mch_restore_title(2);
4762 }
4763 else
4764 {
4765 if (!p_title)
4766 mch_restore_title(1);
4767 }
4768 }
4769}
4770#endif
4771
4772/*
4773 * set_options_bin - called when 'bin' changes value.
4774 */
4775 void
4776set_options_bin(oldval, newval, opt_flags)
4777 int oldval;
4778 int newval;
4779 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4780{
4781 /*
4782 * The option values that are changed when 'bin' changes are
4783 * copied when 'bin is set and restored when 'bin' is reset.
4784 */
4785 if (newval)
4786 {
4787 if (!oldval) /* switched on */
4788 {
4789 if (!(opt_flags & OPT_GLOBAL))
4790 {
4791 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4792 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4793 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4794 curbuf->b_p_et_nobin = curbuf->b_p_et;
4795 }
4796 if (!(opt_flags & OPT_LOCAL))
4797 {
4798 p_tw_nobin = p_tw;
4799 p_wm_nobin = p_wm;
4800 p_ml_nobin = p_ml;
4801 p_et_nobin = p_et;
4802 }
4803 }
4804
4805 if (!(opt_flags & OPT_GLOBAL))
4806 {
4807 curbuf->b_p_tw = 0; /* no automatic line wrap */
4808 curbuf->b_p_wm = 0; /* no automatic line wrap */
4809 curbuf->b_p_ml = 0; /* no modelines */
4810 curbuf->b_p_et = 0; /* no expandtab */
4811 }
4812 if (!(opt_flags & OPT_LOCAL))
4813 {
4814 p_tw = 0;
4815 p_wm = 0;
4816 p_ml = FALSE;
4817 p_et = FALSE;
4818 p_bin = TRUE; /* needed when called for the "-b" argument */
4819 }
4820 }
4821 else if (oldval) /* switched off */
4822 {
4823 if (!(opt_flags & OPT_GLOBAL))
4824 {
4825 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4826 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4827 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4828 curbuf->b_p_et = curbuf->b_p_et_nobin;
4829 }
4830 if (!(opt_flags & OPT_LOCAL))
4831 {
4832 p_tw = p_tw_nobin;
4833 p_wm = p_wm_nobin;
4834 p_ml = p_ml_nobin;
4835 p_et = p_et_nobin;
4836 }
4837 }
4838}
4839
4840#ifdef FEAT_VIMINFO
4841/*
4842 * Find the parameter represented by the given character (eg ', :, ", or /),
4843 * and return its associated value in the 'viminfo' string.
4844 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004845 * If the parameter is not specified in the string or there is no following
4846 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004847 */
4848 int
4849get_viminfo_parameter(type)
4850 int type;
4851{
4852 char_u *p;
4853
4854 p = find_viminfo_parameter(type);
4855 if (p != NULL && VIM_ISDIGIT(*p))
4856 return atoi((char *)p);
4857 return -1;
4858}
4859
4860/*
4861 * Find the parameter represented by the given character (eg ''', ':', '"', or
4862 * '/') in the 'viminfo' option and return a pointer to the string after it.
4863 * Return NULL if the parameter is not specified in the string.
4864 */
4865 char_u *
4866find_viminfo_parameter(type)
4867 int type;
4868{
4869 char_u *p;
4870
4871 for (p = p_viminfo; *p; ++p)
4872 {
4873 if (*p == type)
4874 return p + 1;
4875 if (*p == 'n') /* 'n' is always the last one */
4876 break;
4877 p = vim_strchr(p, ','); /* skip until next ',' */
4878 if (p == NULL) /* hit the end without finding parameter */
4879 break;
4880 }
4881 return NULL;
4882}
4883#endif
4884
4885/*
4886 * Expand environment variables for some string options.
4887 * These string options cannot be indirect!
4888 * If "val" is NULL expand the current value of the option.
4889 * Return pointer to NameBuff, or NULL when not expanded.
4890 */
4891 static char_u *
4892option_expand(opt_idx, val)
4893 int opt_idx;
4894 char_u *val;
4895{
4896 /* if option doesn't need expansion nothing to do */
4897 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4898 return NULL;
4899
4900 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4901 * expand_env() would truncate the string. */
4902 if (val != NULL && STRLEN(val) > MAXPATHL)
4903 return NULL;
4904
4905 if (val == NULL)
4906 val = *(char_u **)options[opt_idx].var;
4907
4908 /*
4909 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4910 * Escape spaces when expanding 'tags', they are used to separate file
4911 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004912 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004913 */
4914 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004915 (char_u **)options[opt_idx].var == &p_tags,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00004916#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004917 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4918#endif
4919 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004920 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4921 return NULL;
4922
4923 return NameBuff;
4924}
4925
4926/*
4927 * After setting various option values: recompute variables that depend on
4928 * option values.
4929 */
4930 static void
4931didset_options()
4932{
4933 /* initialize the table for 'iskeyword' et.al. */
4934 (void)init_chartab();
4935
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00004936#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00004937 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00004938#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4940#ifdef FEAT_SESSION
4941 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4942 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4943#endif
4944#ifdef FEAT_FOLDING
4945 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4946#endif
4947 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4948#ifdef FEAT_VIRTUALEDIT
4949 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4950#endif
4951#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4952 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4953#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00004954#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004955 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004956 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004957 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004958#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004959#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4960 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4961#endif
4962#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4963 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4964#endif
4965#ifdef FEAT_CMDWIN
4966 /* set cedit_key */
4967 (void)check_cedit();
4968#endif
4969}
4970
4971/*
4972 * Check for string options that are NULL (normally only termcap options).
4973 */
4974 void
4975check_options()
4976{
4977 int opt_idx;
4978
4979 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4980 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4981 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4982}
4983
4984/*
4985 * Check string options in a buffer for NULL value.
4986 */
4987 void
4988check_buf_options(buf)
4989 buf_T *buf;
4990{
4991#if defined(FEAT_QUICKFIX)
4992 check_string_option(&buf->b_p_bh);
4993 check_string_option(&buf->b_p_bt);
4994#endif
4995#ifdef FEAT_MBYTE
4996 check_string_option(&buf->b_p_fenc);
4997#endif
4998 check_string_option(&buf->b_p_ff);
4999#ifdef FEAT_FIND_ID
5000 check_string_option(&buf->b_p_def);
5001 check_string_option(&buf->b_p_inc);
5002# ifdef FEAT_EVAL
5003 check_string_option(&buf->b_p_inex);
5004# endif
5005#endif
5006#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5007 check_string_option(&buf->b_p_inde);
5008 check_string_option(&buf->b_p_indk);
5009#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005010#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5011 check_string_option(&buf->b_p_bexpr);
5012#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005013#if defined(FEAT_EVAL)
5014 check_string_option(&buf->b_p_fex);
5015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016#ifdef FEAT_CRYPT
5017 check_string_option(&buf->b_p_key);
5018#endif
5019 check_string_option(&buf->b_p_kp);
5020 check_string_option(&buf->b_p_mps);
5021 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005022 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005023 check_string_option(&buf->b_p_isk);
5024#ifdef FEAT_COMMENTS
5025 check_string_option(&buf->b_p_com);
5026#endif
5027#ifdef FEAT_FOLDING
5028 check_string_option(&buf->b_p_cms);
5029#endif
5030 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005031#ifdef FEAT_TEXTOBJ
5032 check_string_option(&buf->b_p_qe);
5033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005034#ifdef FEAT_SYN_HL
5035 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005036#endif
5037#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005038 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00005039 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00005040 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005041#endif
5042#ifdef FEAT_SEARCHPATH
5043 check_string_option(&buf->b_p_sua);
5044#endif
5045#ifdef FEAT_CINDENT
5046 check_string_option(&buf->b_p_cink);
5047 check_string_option(&buf->b_p_cino);
5048#endif
5049#ifdef FEAT_AUTOCMD
5050 check_string_option(&buf->b_p_ft);
5051#endif
5052#ifdef FEAT_OSFILETYPE
5053 check_string_option(&buf->b_p_oft);
5054#endif
5055#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5056 check_string_option(&buf->b_p_cinw);
5057#endif
5058#ifdef FEAT_INS_EXPAND
5059 check_string_option(&buf->b_p_cpt);
5060#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005061#ifdef FEAT_COMPL_FUNC
5062 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005063 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005064#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065#ifdef FEAT_KEYMAP
5066 check_string_option(&buf->b_p_keymap);
5067#endif
5068#ifdef FEAT_QUICKFIX
5069 check_string_option(&buf->b_p_gp);
5070 check_string_option(&buf->b_p_mp);
5071 check_string_option(&buf->b_p_efm);
5072#endif
5073 check_string_option(&buf->b_p_ep);
5074 check_string_option(&buf->b_p_path);
5075 check_string_option(&buf->b_p_tags);
5076#ifdef FEAT_INS_EXPAND
5077 check_string_option(&buf->b_p_dict);
5078 check_string_option(&buf->b_p_tsr);
5079#endif
5080}
5081
5082/*
5083 * Free the string allocated for an option.
5084 * Checks for the string being empty_option. This may happen if we're out of
5085 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5086 * check_options().
5087 * Does NOT check for P_ALLOCED flag!
5088 */
5089 void
5090free_string_option(p)
5091 char_u *p;
5092{
5093 if (p != empty_option)
5094 vim_free(p);
5095}
5096
5097 void
5098clear_string_option(pp)
5099 char_u **pp;
5100{
5101 if (*pp != empty_option)
5102 vim_free(*pp);
5103 *pp = empty_option;
5104}
5105
5106 static void
5107check_string_option(pp)
5108 char_u **pp;
5109{
5110 if (*pp == NULL)
5111 *pp = empty_option;
5112}
5113
5114/*
5115 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5116 */
5117 void
5118set_term_option_alloced(p)
5119 char_u **p;
5120{
5121 int opt_idx;
5122
5123 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5124 if (options[opt_idx].var == (char_u *)p)
5125 {
5126 options[opt_idx].flags |= P_ALLOCED;
5127 return;
5128 }
5129 return; /* cannot happen: didn't find it! */
5130}
5131
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005132#if defined(FEAT_EVAL) || defined(PROTO)
5133/*
5134 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5135 * Return FALSE when it wasn't.
5136 * Return -1 for an unknown option.
5137 */
5138 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005139was_set_insecurely(opt, opt_flags)
5140 char_u *opt;
5141 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005142{
5143 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005144 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005145
5146 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005147 {
5148 flagp = insecure_flag(idx, opt_flags);
5149 return (*flagp & P_INSECURE) != 0;
5150 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005151 EMSG2(_(e_intern2), "was_set_insecurely()");
5152 return -1;
5153}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005154
5155/*
5156 * Get a pointer to the flags used for the P_INSECURE flag of option
5157 * "opt_idx". For some local options a local flags field is used.
5158 */
5159 static long_u *
5160insecure_flag(opt_idx, opt_flags)
5161 int opt_idx;
5162 int opt_flags;
5163{
5164 if (opt_flags & OPT_LOCAL)
5165 switch ((int)options[opt_idx].indir)
5166 {
5167#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005168 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005169#endif
5170#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005171 case PV_FDE: return &curwin->w_p_fde_flags;
5172 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005173# ifdef FEAT_BEVAL
5174 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5175# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005176#endif
5177#if defined(FEAT_EVAL)
5178# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005179 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005180# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005181 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005182# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005183 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005184# endif
5185#endif
5186 }
5187
5188 /* Nothing special, return global flags field. */
5189 return &options[opt_idx].flags;
5190}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005191#endif
5192
Bram Moolenaar071d4272004-06-13 20:20:40 +00005193/*
5194 * Set a string option to a new value (without checking the effect).
5195 * The string is copied into allocated memory.
5196 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005197 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
5198 * SID_NONE don't set the scriptID. Otherwose set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005199 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005200/*ARGSUSED*/
Bram Moolenaar071d4272004-06-13 20:20:40 +00005201 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005202set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005203 char_u *name;
5204 int opt_idx;
5205 char_u *val;
5206 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005207 int set_sid;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005208{
5209 char_u *s;
5210 char_u **varp;
5211 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5212
5213 if (opt_idx == -1) /* use name */
5214 {
5215 opt_idx = findoption(name);
5216 if (opt_idx == -1) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005217 {
5218 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005220 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221 }
5222
5223 if (options[opt_idx].var == NULL) /* can't set hidden option */
5224 return;
5225
5226 s = vim_strsave(val);
5227 if (s != NULL)
5228 {
5229 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5230 both ? OPT_LOCAL : opt_flags);
5231 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
5232 free_string_option(*varp);
5233 *varp = s;
5234
5235 /* For buffer/window local option may also set the global value. */
5236 if (both)
5237 set_string_option_global(opt_idx, varp);
5238
5239 options[opt_idx].flags |= P_ALLOCED;
5240
5241 /* When setting both values of a global option with a local value,
5242 * make the local value empty, so that the global value is used. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005243 if (((int)options[opt_idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005244 {
5245 free_string_option(*varp);
5246 *varp = empty_option;
5247 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005248# ifdef FEAT_EVAL
5249 if (set_sid != SID_NONE)
5250 set_option_scriptID_idx(opt_idx, opt_flags,
5251 set_sid == 0 ? current_SID : set_sid);
5252# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005253 }
5254}
5255
5256/*
5257 * Set global value for string option when it's a local option.
5258 */
5259 static void
5260set_string_option_global(opt_idx, varp)
5261 int opt_idx; /* option index */
5262 char_u **varp; /* pointer to option variable */
5263{
5264 char_u **p, *s;
5265
5266 /* the global value is always allocated */
5267 if (options[opt_idx].var == VAR_WIN)
5268 p = (char_u **)GLOBAL_WO(varp);
5269 else
5270 p = (char_u **)options[opt_idx].var;
5271 if (options[opt_idx].indir != PV_NONE
5272 && p != varp
5273 && (s = vim_strsave(*varp)) != NULL)
5274 {
5275 free_string_option(*p);
5276 *p = s;
5277 }
5278}
5279
5280/*
5281 * Set a string option to a new value, and handle the effects.
5282 */
5283 static void
5284set_string_option(opt_idx, value, opt_flags)
5285 int opt_idx;
5286 char_u *value;
5287 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5288{
5289 char_u *s;
5290 char_u **varp;
5291 char_u *oldval;
5292
5293 if (options[opt_idx].var == NULL) /* don't set hidden option */
5294 return;
5295
5296 s = vim_strsave(value);
5297 if (s != NULL)
5298 {
5299 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5300 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005301 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005302 ? OPT_GLOBAL : OPT_LOCAL)
5303 : opt_flags);
5304 oldval = *varp;
5305 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005306 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5307 opt_flags) == NULL)
5308 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309 }
5310}
5311
5312/*
5313 * Handle string options that need some action to perform when changed.
5314 * Returns NULL for success, or an error message for an error.
5315 */
5316 static char_u *
5317did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5318 opt_flags)
5319 int opt_idx; /* index in options[] table */
5320 char_u **varp; /* pointer to the option variable */
5321 int new_value_alloced; /* new value was allocated */
5322 char_u *oldval; /* previous value of the option */
5323 char_u *errbuf; /* buffer for errors, or NULL */
5324 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5325{
5326 char_u *errmsg = NULL;
5327 char_u *s, *p;
5328 int did_chartab = FALSE;
5329 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005330 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005331
5332 /* Get the global option to compare with, otherwise we would have to check
5333 * two values for all local options. */
5334 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5335
5336 /* Disallow changing some options from secure mode */
5337 if ((secure
5338#ifdef HAVE_SANDBOX
5339 || sandbox != 0
5340#endif
5341 ) && (options[opt_idx].flags & P_SECURE))
5342 {
5343 errmsg = e_secure;
5344 }
5345
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005346 /* Check for a "normal" file name in some options. Disallow a path
5347 * separator (slash and/or backslash), wildcards and characters that are
5348 * often illegal in a file name. */
5349 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005350 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005351 {
5352 errmsg = e_invarg;
5353 }
5354
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 /* 'term' */
5356 else if (varp == &T_NAME)
5357 {
5358 if (T_NAME[0] == NUL)
5359 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5360#ifdef FEAT_GUI
5361 if (gui.in_use)
5362 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5363 else if (term_is_gui(T_NAME))
5364 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5365#endif
5366 else if (set_termname(T_NAME) == FAIL)
5367 errmsg = (char_u *)N_("E522: Not found in termcap");
5368 else
5369 /* Screen colors may have changed. */
5370 redraw_later_clear();
5371 }
5372
5373 /* 'backupcopy' */
5374 else if (varp == &p_bkc)
5375 {
5376 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5377 errmsg = e_invarg;
5378 if (((bkc_flags & BKC_AUTO) != 0)
5379 + ((bkc_flags & BKC_YES) != 0)
5380 + ((bkc_flags & BKC_NO) != 0) != 1)
5381 {
5382 /* Must have exactly one of "auto", "yes" and "no". */
5383 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5384 errmsg = e_invarg;
5385 }
5386 }
5387
5388 /* 'backupext' and 'patchmode' */
5389 else if (varp == &p_bex || varp == &p_pm)
5390 {
5391 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5392 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5393 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5394 }
5395
5396 /*
5397 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5398 * If the new option is invalid, use old value. 'lisp' option: refill
5399 * chartab[] for '-' char
5400 */
5401 else if ( varp == &p_isi
5402 || varp == &(curbuf->b_p_isk)
5403 || varp == &p_isp
5404 || varp == &p_isf)
5405 {
5406 if (init_chartab() == FAIL)
5407 {
5408 did_chartab = TRUE; /* need to restore it below */
5409 errmsg = e_invarg; /* error in value */
5410 }
5411 }
5412
5413 /* 'helpfile' */
5414 else if (varp == &p_hf)
5415 {
5416 /* May compute new values for $VIM and $VIMRUNTIME */
5417 if (didset_vim)
5418 {
5419 vim_setenv((char_u *)"VIM", (char_u *)"");
5420 didset_vim = FALSE;
5421 }
5422 if (didset_vimruntime)
5423 {
5424 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5425 didset_vimruntime = FALSE;
5426 }
5427 }
5428
5429#ifdef FEAT_MULTI_LANG
5430 /* 'helplang' */
5431 else if (varp == &p_hlg)
5432 {
5433 /* Check for "", "ab", "ab,cd", etc. */
5434 for (s = p_hlg; *s != NUL; s += 3)
5435 {
5436 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5437 {
5438 errmsg = e_invarg;
5439 break;
5440 }
5441 if (s[2] == NUL)
5442 break;
5443 }
5444 }
5445#endif
5446
5447 /* 'highlight' */
5448 else if (varp == &p_hl)
5449 {
5450 if (highlight_changed() == FAIL)
5451 errmsg = e_invarg; /* invalid flags */
5452 }
5453
5454 /* 'nrformats' */
5455 else if (gvarp == &p_nf)
5456 {
5457 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5458 errmsg = e_invarg;
5459 }
5460
5461#ifdef FEAT_SESSION
5462 /* 'sessionoptions' */
5463 else if (varp == &p_ssop)
5464 {
5465 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5466 errmsg = e_invarg;
5467 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5468 {
5469 /* Don't allow both "sesdir" and "curdir". */
5470 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5471 errmsg = e_invarg;
5472 }
5473 }
5474 /* 'viewoptions' */
5475 else if (varp == &p_vop)
5476 {
5477 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5478 errmsg = e_invarg;
5479 }
5480#endif
5481
5482 /* 'scrollopt' */
5483#ifdef FEAT_SCROLLBIND
5484 else if (varp == &p_sbo)
5485 {
5486 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5487 errmsg = e_invarg;
5488 }
5489#endif
5490
5491 /* 'ambiwidth' */
5492#ifdef FEAT_MBYTE
5493 else if (varp == &p_ambw)
5494 {
5495 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5496 errmsg = e_invarg;
5497 }
5498#endif
5499
5500 /* 'background' */
5501 else if (varp == &p_bg)
5502 {
5503 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5504 {
5505#ifdef FEAT_EVAL
5506 int dark = (*p_bg == 'd');
5507#endif
5508
5509 init_highlight(FALSE, FALSE);
5510
5511#ifdef FEAT_EVAL
5512 if (dark != (*p_bg == 'd')
5513 && get_var_value((char_u *)"g:colors_name") != NULL)
5514 {
5515 /* The color scheme must have set 'background' back to another
5516 * value, that's not what we want here. Disable the color
5517 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005518 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005519 free_string_option(p_bg);
5520 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5521 check_string_option(&p_bg);
5522 init_highlight(FALSE, FALSE);
5523 }
5524#endif
5525 }
5526 else
5527 errmsg = e_invarg;
5528 }
5529
5530 /* 'wildmode' */
5531 else if (varp == &p_wim)
5532 {
5533 if (check_opt_wim() == FAIL)
5534 errmsg = e_invarg;
5535 }
5536
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005537#ifdef FEAT_CMDL_COMPL
5538 /* 'wildoptions' */
5539 else if (varp == &p_wop)
5540 {
5541 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5542 errmsg = e_invarg;
5543 }
5544#endif
5545
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546#ifdef FEAT_WAK
5547 /* 'winaltkeys' */
5548 else if (varp == &p_wak)
5549 {
5550 if (*p_wak == NUL
5551 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5552 errmsg = e_invarg;
5553# ifdef FEAT_MENU
5554# ifdef FEAT_GUI_MOTIF
5555 else if (gui.in_use)
5556 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5557# else
5558# ifdef FEAT_GUI_GTK
5559 else if (gui.in_use)
5560 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5561# endif
5562# endif
5563# endif
5564 }
5565#endif
5566
5567#ifdef FEAT_AUTOCMD
5568 /* 'eventignore' */
5569 else if (varp == &p_ei)
5570 {
5571 if (check_ei() == FAIL)
5572 errmsg = e_invarg;
5573 }
5574#endif
5575
5576#ifdef FEAT_MBYTE
5577 /* 'encoding' and 'fileencoding' */
5578 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5579 {
5580 if (gvarp == &p_fenc)
5581 {
5582 if (!curbuf->b_p_ma)
5583 errmsg = e_modifiable;
5584 else if (vim_strchr(*varp, ',') != NULL)
5585 /* No comma allowed in 'fileencoding'; catches confusing it
5586 * with 'fileencodings'. */
5587 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005589 {
5590# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591 /* May show a "+" in the title now. */
5592 need_maketitle = TRUE;
5593# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005594 /* Add 'fileencoding' to the swap file. */
5595 ml_setflags(curbuf);
5596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597 }
5598 if (errmsg == NULL)
5599 {
5600 /* canonize the value, so that STRCMP() can be used on it */
5601 p = enc_canonize(*varp);
5602 if (p != NULL)
5603 {
5604 vim_free(*varp);
5605 *varp = p;
5606 }
5607 if (varp == &p_enc)
5608 {
5609 errmsg = mb_init();
5610# ifdef FEAT_TITLE
5611 need_maketitle = TRUE;
5612# endif
5613 }
5614 }
5615
5616# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5617 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5618 {
5619 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5620 if (STRCMP(p_tenc, "utf-8") != 0)
5621 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5622 }
5623# endif
5624
5625 if (errmsg == NULL)
5626 {
5627# ifdef FEAT_KEYMAP
5628 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5629 * (with another encoding). */
5630 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5631 (void)keymap_init();
5632# endif
5633
5634 /* When 'termencoding' is not empty and 'encoding' changes or when
5635 * 'termencoding' changes, need to setup for keyboard input and
5636 * display output conversion. */
5637 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5638 {
5639 convert_setup(&input_conv, p_tenc, p_enc);
5640 convert_setup(&output_conv, p_enc, p_tenc);
5641 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005642
5643# if defined(WIN3264) && defined(FEAT_MBYTE)
5644 /* $HOME may have characters in active code page. */
5645 if (varp == &p_enc)
5646 init_homedir();
5647# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648 }
5649 }
5650#endif
5651
5652#if defined(FEAT_POSTSCRIPT)
5653 else if (varp == &p_penc)
5654 {
5655 /* Canonize printencoding if VIM standard one */
5656 p = enc_canonize(p_penc);
5657 if (p != NULL)
5658 {
5659 vim_free(p_penc);
5660 p_penc = p;
5661 }
5662 else
5663 {
5664 /* Ensure lower case and '-' for '_' */
5665 for (s = p_penc; *s != NUL; s++)
5666 {
5667 if (*s == '_')
5668 *s = '-';
5669 else
5670 *s = TOLOWER_ASC(*s);
5671 }
5672 }
5673 }
5674#endif
5675
Bram Moolenaar9372a112005-12-06 19:59:18 +00005676#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677 else if (varp == &p_imak)
5678 {
5679 if (gui.in_use && !im_xim_isvalid_imactivate())
5680 errmsg = e_invarg;
5681 }
5682#endif
5683
5684#ifdef FEAT_KEYMAP
5685 else if (varp == &curbuf->b_p_keymap)
5686 {
5687 /* load or unload key mapping tables */
5688 errmsg = keymap_init();
5689
5690 /* When successfully installed a new keymap switch on using it. */
5691 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5692 {
5693 curbuf->b_p_iminsert = B_IMODE_LMAP;
5694 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5695 curbuf->b_p_imsearch = B_IMODE_LMAP;
5696 set_iminsert_global();
5697 set_imsearch_global();
5698# ifdef FEAT_WINDOWS
5699 status_redraw_curbuf();
5700# endif
5701 }
5702 }
5703#endif
5704
5705 /* 'fileformat' */
5706 else if (gvarp == &p_ff)
5707 {
5708 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5709 errmsg = e_modifiable;
5710 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5711 errmsg = e_invarg;
5712 else
5713 {
5714 /* may also change 'textmode' */
5715 if (get_fileformat(curbuf) == EOL_DOS)
5716 curbuf->b_p_tx = TRUE;
5717 else
5718 curbuf->b_p_tx = FALSE;
5719#ifdef FEAT_TITLE
5720 need_maketitle = TRUE;
5721#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005722 /* update flag in swap file */
5723 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005724 }
5725 }
5726
5727 /* 'fileformats' */
5728 else if (varp == &p_ffs)
5729 {
5730 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5731 errmsg = e_invarg;
5732 else
5733 {
5734 /* also change 'textauto' */
5735 if (*p_ffs == NUL)
5736 p_ta = FALSE;
5737 else
5738 p_ta = TRUE;
5739 }
5740 }
5741
5742#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5743 /* 'cryptkey' */
5744 else if (gvarp == &p_key)
5745 {
5746 /* Make sure the ":set" command doesn't show the new value in the
5747 * history. */
5748 remove_key_from_history();
5749 }
5750#endif
5751
5752 /* 'matchpairs' */
5753 else if (gvarp == &p_mps)
5754 {
5755 /* Check for "x:y,x:y" */
5756 for (p = *varp; *p != NUL; p += 4)
5757 {
5758 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5759 {
5760 errmsg = e_invarg;
5761 break;
5762 }
5763 if (p[3] == NUL)
5764 break;
5765 }
5766 }
5767
5768#ifdef FEAT_COMMENTS
5769 /* 'comments' */
5770 else if (gvarp == &p_com)
5771 {
5772 for (s = *varp; *s; )
5773 {
5774 while (*s && *s != ':')
5775 {
5776 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5777 && !VIM_ISDIGIT(*s) && *s != '-')
5778 {
5779 errmsg = illegal_char(errbuf, *s);
5780 break;
5781 }
5782 ++s;
5783 }
5784 if (*s++ == NUL)
5785 errmsg = (char_u *)N_("E524: Missing colon");
5786 else if (*s == ',' || *s == NUL)
5787 errmsg = (char_u *)N_("E525: Zero length string");
5788 if (errmsg != NULL)
5789 break;
5790 while (*s && *s != ',')
5791 {
5792 if (*s == '\\' && s[1] != NUL)
5793 ++s;
5794 ++s;
5795 }
5796 s = skip_to_option_part(s);
5797 }
5798 }
5799#endif
5800
5801 /* 'listchars' */
5802 else if (varp == &p_lcs)
5803 {
5804 errmsg = set_chars_option(varp);
5805 }
5806
5807#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5808 /* 'fillchars' */
5809 else if (varp == &p_fcs)
5810 {
5811 errmsg = set_chars_option(varp);
5812 }
5813#endif
5814
5815#ifdef FEAT_CMDWIN
5816 /* 'cedit' */
5817 else if (varp == &p_cedit)
5818 {
5819 errmsg = check_cedit();
5820 }
5821#endif
5822
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005823 /* 'verbosefile' */
5824 else if (varp == &p_vfile)
5825 {
5826 verbose_stop();
5827 if (*p_vfile != NUL && verbose_open() == FAIL)
5828 errmsg = e_invarg;
5829 }
5830
Bram Moolenaar071d4272004-06-13 20:20:40 +00005831#ifdef FEAT_VIMINFO
5832 /* 'viminfo' */
5833 else if (varp == &p_viminfo)
5834 {
5835 for (s = p_viminfo; *s;)
5836 {
5837 /* Check it's a valid character */
5838 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5839 {
5840 errmsg = illegal_char(errbuf, *s);
5841 break;
5842 }
5843 if (*s == 'n') /* name is always last one */
5844 {
5845 break;
5846 }
5847 else if (*s == 'r') /* skip until next ',' */
5848 {
5849 while (*++s && *s != ',')
5850 ;
5851 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005852 else if (*s == '%')
5853 {
5854 /* optional number */
5855 while (vim_isdigit(*++s))
5856 ;
5857 }
5858 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859 ++s; /* no extra chars */
5860 else /* must have a number */
5861 {
5862 while (vim_isdigit(*++s))
5863 ;
5864
5865 if (!VIM_ISDIGIT(*(s - 1)))
5866 {
5867 if (errbuf != NULL)
5868 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005869 sprintf((char *)errbuf,
5870 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871 transchar_byte(*(s - 1)));
5872 errmsg = errbuf;
5873 }
5874 else
5875 errmsg = (char_u *)"";
5876 break;
5877 }
5878 }
5879 if (*s == ',')
5880 ++s;
5881 else if (*s)
5882 {
5883 if (errbuf != NULL)
5884 errmsg = (char_u *)N_("E527: Missing comma");
5885 else
5886 errmsg = (char_u *)"";
5887 break;
5888 }
5889 }
5890 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5891 errmsg = (char_u *)N_("E528: Must specify a ' value");
5892 }
5893#endif /* FEAT_VIMINFO */
5894
5895 /* terminal options */
5896 else if (istermoption(&options[opt_idx]) && full_screen)
5897 {
5898 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5899 if (varp == &T_CCO)
5900 {
5901 t_colors = atoi((char *)T_CCO);
5902 if (t_colors <= 1)
5903 {
5904 if (new_value_alloced)
5905 vim_free(T_CCO);
5906 T_CCO = empty_option;
5907 }
5908 /* We now have a different color setup, initialize it again. */
5909 init_highlight(TRUE, FALSE);
5910 }
5911 ttest(FALSE);
5912 if (varp == &T_ME)
5913 {
5914 out_str(T_ME);
5915 redraw_later(CLEAR);
5916#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5917 /* Since t_me has been set, this probably means that the user
5918 * wants to use this as default colors. Need to reset default
5919 * background/foreground colors. */
5920 mch_set_normal_colors();
5921#endif
5922 }
5923 }
5924
5925#ifdef FEAT_LINEBREAK
5926 /* 'showbreak' */
5927 else if (varp == &p_sbr)
5928 {
5929 for (s = p_sbr; *s; )
5930 {
5931 if (ptr2cells(s) != 1)
5932 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005933 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934 }
5935 }
5936#endif
5937
5938#ifdef FEAT_GUI
5939 /* 'guifont' */
5940 else if (varp == &p_guifont)
5941 {
5942 if (gui.in_use)
5943 {
5944 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00005945# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946 /*
5947 * Put up a font dialog and let the user select a new value.
5948 * If this is cancelled go back to the old value but don't
5949 * give an error message.
5950 */
5951 if (STRCMP(p, "*") == 0)
5952 {
5953 p = gui_mch_font_dialog(oldval);
5954
5955 if (new_value_alloced)
5956 free_string_option(p_guifont);
5957
5958 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5959 new_value_alloced = TRUE;
5960 }
5961# endif
5962 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5963 {
5964# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5965 if (STRCMP(p_guifont, "*") == 0)
5966 {
5967 /* Dialog was cancelled: Keep the old value without giving
5968 * an error message. */
5969 if (new_value_alloced)
5970 free_string_option(p_guifont);
5971 p_guifont = vim_strsave(oldval);
5972 new_value_alloced = TRUE;
5973 }
5974 else
5975# endif
5976 errmsg = (char_u *)N_("E596: Invalid font(s)");
5977 }
5978 }
5979 }
5980# ifdef FEAT_XFONTSET
5981 else if (varp == &p_guifontset)
5982 {
5983 if (STRCMP(p_guifontset, "*") == 0)
5984 errmsg = (char_u *)N_("E597: can't select fontset");
5985 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5986 errmsg = (char_u *)N_("E598: Invalid fontset");
5987 }
5988# endif
5989# ifdef FEAT_MBYTE
5990 else if (varp == &p_guifontwide)
5991 {
5992 if (STRCMP(p_guifontwide, "*") == 0)
5993 errmsg = (char_u *)N_("E533: can't select wide font");
5994 else if (gui_get_wide_font() == FAIL)
5995 errmsg = (char_u *)N_("E534: Invalid wide font");
5996 }
5997# endif
5998#endif
5999
6000#ifdef CURSOR_SHAPE
6001 /* 'guicursor' */
6002 else if (varp == &p_guicursor)
6003 errmsg = parse_shape_opt(SHAPE_CURSOR);
6004#endif
6005
6006#ifdef FEAT_MOUSESHAPE
6007 /* 'mouseshape' */
6008 else if (varp == &p_mouseshape)
6009 {
6010 errmsg = parse_shape_opt(SHAPE_MOUSE);
6011 update_mouseshape(-1);
6012 }
6013#endif
6014
6015#ifdef FEAT_PRINTER
6016 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006017 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006018# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006019 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006020 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006021# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006022#endif
6023
6024#ifdef FEAT_LANGMAP
6025 /* 'langmap' */
6026 else if (varp == &p_langmap)
6027 langmap_set();
6028#endif
6029
6030#ifdef FEAT_LINEBREAK
6031 /* 'breakat' */
6032 else if (varp == &p_breakat)
6033 fill_breakat_flags();
6034#endif
6035
6036#ifdef FEAT_TITLE
6037 /* 'titlestring' and 'iconstring' */
6038 else if (varp == &p_titlestring || varp == &p_iconstring)
6039 {
6040# ifdef FEAT_STL_OPT
6041 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6042
6043 /* NULL => statusline syntax */
6044 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6045 stl_syntax |= flagval;
6046 else
6047 stl_syntax &= ~flagval;
6048# endif
6049 did_set_title(varp == &p_iconstring);
6050
6051 }
6052#endif
6053
6054#ifdef FEAT_GUI
6055 /* 'guioptions' */
6056 else if (varp == &p_go)
6057 gui_init_which_components(oldval);
6058#endif
6059
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006060#if defined(FEAT_GUI_TABLINE)
6061 /* 'guitablabel' */
6062 else if (varp == &p_gtl)
Bram Moolenaardb552d602006-03-23 22:59:57 +00006063 gui_init_which_components(NULL);
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006064#endif
6065
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6067 /* 'ttymouse' */
6068 else if (varp == &p_ttym)
6069 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006070 /* Switch the mouse off before changing the escape sequences used for
6071 * that. */
6072 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6074 errmsg = e_invarg;
6075 else
6076 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006077 if (termcap_active)
6078 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 }
6080#endif
6081
6082#ifdef FEAT_VISUAL
6083 /* 'selection' */
6084 else if (varp == &p_sel)
6085 {
6086 if (*p_sel == NUL
6087 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6088 errmsg = e_invarg;
6089 }
6090
6091 /* 'selectmode' */
6092 else if (varp == &p_slm)
6093 {
6094 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6095 errmsg = e_invarg;
6096 }
6097#endif
6098
6099#ifdef FEAT_BROWSE
6100 /* 'browsedir' */
6101 else if (varp == &p_bsdir)
6102 {
6103 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6104 && !mch_isdir(p_bsdir))
6105 errmsg = e_invarg;
6106 }
6107#endif
6108
6109#ifdef FEAT_VISUAL
6110 /* 'keymodel' */
6111 else if (varp == &p_km)
6112 {
6113 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6114 errmsg = e_invarg;
6115 else
6116 {
6117 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6118 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6119 }
6120 }
6121#endif
6122
6123 /* 'mousemodel' */
6124 else if (varp == &p_mousem)
6125 {
6126 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6127 errmsg = e_invarg;
6128#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6129 else if (*p_mousem != *oldval)
6130 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6131 * to create or delete the popup menus. */
6132 gui_motif_update_mousemodel(root_menu);
6133#endif
6134 }
6135
6136 /* 'switchbuf' */
6137 else if (varp == &p_swb)
6138 {
6139 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
6140 errmsg = e_invarg;
6141 }
6142
6143 /* 'debug' */
6144 else if (varp == &p_debug)
6145 {
6146 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
6147 errmsg = e_invarg;
6148 }
6149
6150 /* 'display' */
6151 else if (varp == &p_dy)
6152 {
6153 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6154 errmsg = e_invarg;
6155 else
6156 (void)init_chartab();
6157
6158 }
6159
6160#ifdef FEAT_VERTSPLIT
6161 /* 'eadirection' */
6162 else if (varp == &p_ead)
6163 {
6164 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6165 errmsg = e_invarg;
6166 }
6167#endif
6168
6169#ifdef FEAT_CLIPBOARD
6170 /* 'clipboard' */
6171 else if (varp == &p_cb)
6172 errmsg = check_clipboard_option();
6173#endif
6174
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006175#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006176 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6177 * buffer in which 'spell' is set load the wordlists. */
6178 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006179 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006180 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006181 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006182
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006183 if (varp == &(curbuf->b_p_spf))
6184 {
6185 l = STRLEN(curbuf->b_p_spf);
6186 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6187 ".add") != 0))
6188 errmsg = e_invarg;
6189 }
6190
6191 if (errmsg == NULL)
6192 {
6193 FOR_ALL_WINDOWS(wp)
6194 if (wp->w_buffer == curbuf && wp->w_p_spell)
6195 {
6196 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006197# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006198 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006199# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006200 }
6201 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006202 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006203 /* When 'spellcapcheck' is set compile the regexp program. */
6204 else if (varp == &(curbuf->b_p_spc))
6205 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006206 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006207 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006208 /* 'spellsuggest' */
6209 else if (varp == &p_sps)
6210 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006211 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006212 errmsg = e_invarg;
6213 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006214 /* 'mkspellmem' */
6215 else if (varp == &p_msm)
6216 {
6217 if (spell_check_msm() != OK)
6218 errmsg = e_invarg;
6219 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006220#endif
6221
Bram Moolenaar071d4272004-06-13 20:20:40 +00006222#ifdef FEAT_QUICKFIX
6223 /* When 'bufhidden' is set, check for valid value. */
6224 else if (gvarp == &p_bh)
6225 {
6226 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6227 errmsg = e_invarg;
6228 }
6229
6230 /* When 'buftype' is set, check for valid value. */
6231 else if (gvarp == &p_bt)
6232 {
6233 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6234 errmsg = e_invarg;
6235 else
6236 {
6237# ifdef FEAT_WINDOWS
6238 if (curwin->w_status_height)
6239 {
6240 curwin->w_redr_status = TRUE;
6241 redraw_later(VALID);
6242 }
6243# endif
6244 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6245 }
6246 }
6247#endif
6248
6249#ifdef FEAT_STL_OPT
6250 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006251 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252 {
6253 int wid;
6254
6255 if (varp == &p_ruf) /* reset ru_wid first */
6256 ru_wid = 0;
6257 s = *varp;
6258 if (varp == &p_ruf && *s == '%')
6259 {
6260 /* set ru_wid if 'ruf' starts with "%99(" */
6261 if (*++s == '-') /* ignore a '-' */
6262 s++;
6263 wid = getdigits(&s);
6264 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6265 ru_wid = wid;
6266 else
6267 errmsg = check_stl_option(p_ruf);
6268 }
6269 else
6270 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006271 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006272 comp_col();
6273 }
6274#endif
6275
6276#ifdef FEAT_INS_EXPAND
6277 /* check if it is a valid value for 'complete' -- Acevedo */
6278 else if (gvarp == &p_cpt)
6279 {
6280 for (s = *varp; *s;)
6281 {
6282 while(*s == ',' || *s == ' ')
6283 s++;
6284 if (!*s)
6285 break;
6286 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6287 {
6288 errmsg = illegal_char(errbuf, *s);
6289 break;
6290 }
6291 if (*++s != NUL && *s != ',' && *s != ' ')
6292 {
6293 if (s[-1] == 'k' || s[-1] == 's')
6294 {
6295 /* skip optional filename after 'k' and 's' */
6296 while (*s && *s != ',' && *s != ' ')
6297 {
6298 if (*s == '\\')
6299 ++s;
6300 ++s;
6301 }
6302 }
6303 else
6304 {
6305 if (errbuf != NULL)
6306 {
6307 sprintf((char *)errbuf,
6308 _("E535: Illegal character after <%c>"),
6309 *--s);
6310 errmsg = errbuf;
6311 }
6312 else
6313 errmsg = (char_u *)"";
6314 break;
6315 }
6316 }
6317 }
6318 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006319
6320 /* 'completeopt' */
6321 else if (varp == &p_cot)
6322 {
6323 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6324 errmsg = e_invarg;
6325 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006326#endif /* FEAT_INS_EXPAND */
6327
6328
6329#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6330 else if (varp == &p_toolbar)
6331 {
6332 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6333 &toolbar_flags, TRUE) != OK)
6334 errmsg = e_invarg;
6335 else
6336 {
6337 out_flush();
6338 gui_mch_show_toolbar((toolbar_flags &
6339 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6340 }
6341 }
6342#endif
6343
6344#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6345 /* 'toolbariconsize': GTK+ 2 only */
6346 else if (varp == &p_tbis)
6347 {
6348 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6349 errmsg = e_invarg;
6350 else
6351 {
6352 out_flush();
6353 gui_mch_show_toolbar((toolbar_flags &
6354 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6355 }
6356 }
6357#endif
6358
6359 /* 'pastetoggle': translate key codes like in a mapping */
6360 else if (varp == &p_pt)
6361 {
6362 if (*p_pt)
6363 {
6364 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
6365 if (p != NULL)
6366 {
6367 if (new_value_alloced)
6368 free_string_option(p_pt);
6369 p_pt = p;
6370 new_value_alloced = TRUE;
6371 }
6372 }
6373 }
6374
6375 /* 'backspace' */
6376 else if (varp == &p_bs)
6377 {
6378 if (VIM_ISDIGIT(*p_bs))
6379 {
6380 if (*p_bs >'2' || p_bs[1] != NUL)
6381 errmsg = e_invarg;
6382 }
6383 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6384 errmsg = e_invarg;
6385 }
6386
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006387#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388 /* 'casemap' */
6389 else if (varp == &p_cmp)
6390 {
6391 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6392 errmsg = e_invarg;
6393 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006394#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006395
6396#ifdef FEAT_DIFF
6397 /* 'diffopt' */
6398 else if (varp == &p_dip)
6399 {
6400 if (diffopt_changed() == FAIL)
6401 errmsg = e_invarg;
6402 }
6403#endif
6404
6405#ifdef FEAT_FOLDING
6406 /* 'foldmethod' */
6407 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6408 {
6409 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6410 || *curwin->w_p_fdm == NUL)
6411 errmsg = e_invarg;
6412 else
6413 foldUpdateAll(curwin);
6414 }
6415# ifdef FEAT_EVAL
6416 /* 'foldexpr' */
6417 else if (varp == &curwin->w_p_fde)
6418 {
6419 if (foldmethodIsExpr(curwin))
6420 foldUpdateAll(curwin);
6421 }
6422# endif
6423 /* 'foldmarker' */
6424 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6425 {
6426 p = vim_strchr(*varp, ',');
6427 if (p == NULL)
6428 errmsg = (char_u *)N_("E536: comma required");
6429 else if (p == *varp || p[1] == NUL)
6430 errmsg = e_invarg;
6431 else if (foldmethodIsMarker(curwin))
6432 foldUpdateAll(curwin);
6433 }
6434 /* 'commentstring' */
6435 else if (gvarp == &p_cms)
6436 {
6437 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6438 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6439 }
6440 /* 'foldopen' */
6441 else if (varp == &p_fdo)
6442 {
6443 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6444 errmsg = e_invarg;
6445 }
6446 /* 'foldclose' */
6447 else if (varp == &p_fcl)
6448 {
6449 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6450 errmsg = e_invarg;
6451 }
6452#endif
6453
6454#ifdef FEAT_VIRTUALEDIT
6455 /* 'virtualedit' */
6456 else if (varp == &p_ve)
6457 {
6458 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6459 errmsg = e_invarg;
6460 else if (STRCMP(p_ve, oldval) != 0)
6461 {
6462 /* Recompute cursor position in case the new 've' setting
6463 * changes something. */
6464 validate_virtcol();
6465 coladvance(curwin->w_virtcol);
6466 }
6467 }
6468#endif
6469
6470#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6471 else if (varp == &p_csqf)
6472 {
6473 if (p_csqf != NULL)
6474 {
6475 p = p_csqf;
6476 while (*p != NUL)
6477 {
6478 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6479 || p[1] == NUL
6480 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6481 || (p[2] != NUL && p[2] != ','))
6482 {
6483 errmsg = e_invarg;
6484 break;
6485 }
6486 else if (p[2] == NUL)
6487 break;
6488 else
6489 p += 3;
6490 }
6491 }
6492 }
6493#endif
6494
6495 /* Options that are a list of flags. */
6496 else
6497 {
6498 p = NULL;
6499 if (varp == &p_ww)
6500 p = (char_u *)WW_ALL;
6501 if (varp == &p_shm)
6502 p = (char_u *)SHM_ALL;
6503 else if (varp == &(p_cpo))
6504 p = (char_u *)CPO_ALL;
6505 else if (varp == &(curbuf->b_p_fo))
6506 p = (char_u *)FO_ALL;
6507 else if (varp == &p_mouse)
6508 {
6509#ifdef FEAT_MOUSE
6510 p = (char_u *)MOUSE_ALL;
6511#else
6512 if (*p_mouse != NUL)
6513 errmsg = (char_u *)N_("E538: No mouse support");
6514#endif
6515 }
6516#if defined(FEAT_GUI)
6517 else if (varp == &p_go)
6518 p = (char_u *)GO_ALL;
6519#endif
6520 if (p != NULL)
6521 {
6522 for (s = *varp; *s; ++s)
6523 if (vim_strchr(p, *s) == NULL)
6524 {
6525 errmsg = illegal_char(errbuf, *s);
6526 break;
6527 }
6528 }
6529 }
6530
6531 /*
6532 * If error detected, restore the previous value.
6533 */
6534 if (errmsg != NULL)
6535 {
6536 if (new_value_alloced)
6537 free_string_option(*varp);
6538 *varp = oldval;
6539 /*
6540 * When resetting some values, need to act on it.
6541 */
6542 if (did_chartab)
6543 (void)init_chartab();
6544 if (varp == &p_hl)
6545 (void)highlight_changed();
6546 }
6547 else
6548 {
6549#ifdef FEAT_EVAL
6550 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006551 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006552#endif
6553 /*
6554 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006555 * Use "free_oldval", because recursiveness may change the flags under
6556 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006558 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006559 free_string_option(oldval);
6560 if (new_value_alloced)
6561 options[opt_idx].flags |= P_ALLOCED;
6562 else
6563 options[opt_idx].flags &= ~P_ALLOCED;
6564
6565 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006566 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 {
6568 /* global option with local value set to use global value; free
6569 * the local value and make it empty */
6570 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6571 free_string_option(*(char_u **)p);
6572 *(char_u **)p = empty_option;
6573 }
6574
6575 /* May set global value for local option. */
6576 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6577 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006578
6579#ifdef FEAT_AUTOCMD
6580 /*
6581 * Trigger the autocommand only after setting the flags.
6582 */
6583# ifdef FEAT_SYN_HL
6584 /* When 'syntax' is set, load the syntax of that name */
6585 if (varp == &(curbuf->b_p_syn))
6586 {
6587 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6588 curbuf->b_fname, TRUE, curbuf);
6589 }
6590# endif
6591 else if (varp == &(curbuf->b_p_ft))
6592 {
6593 /* 'filetype' is set, trigger the FileType autocommand */
6594 did_filetype = TRUE;
6595 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6596 curbuf->b_fname, TRUE, curbuf);
6597 }
6598#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006599#ifdef FEAT_SPELL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006600 if (varp == &(curbuf->b_p_spl))
6601 {
6602 char_u fname[200];
6603
6604 /*
6605 * Source the spell/LANG.vim in 'runtimepath'.
6606 * They could set 'spellcapcheck' depending on the language.
6607 * Use the first name in 'spelllang' up to '_region' or
6608 * '.encoding'.
6609 */
6610 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6611 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6612 break;
6613 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6614 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6615 source_runtime(fname, TRUE);
6616 }
6617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 }
6619
6620#ifdef FEAT_MOUSE
6621 if (varp == &p_mouse)
6622 {
6623# ifdef FEAT_MOUSE_TTY
6624 if (*p_mouse == NUL)
6625 mch_setmouse(FALSE); /* switch mouse off */
6626 else
6627# endif
6628 setmouse(); /* in case 'mouse' changed */
6629 }
6630#endif
6631
6632 if (curwin->w_curswant != MAXCOL)
6633 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6634 check_redraw(options[opt_idx].flags);
6635
6636 return errmsg;
6637}
6638
6639/*
6640 * Handle setting 'listchars' or 'fillchars'.
6641 * Returns error message, NULL if it's OK.
6642 */
6643 static char_u *
6644set_chars_option(varp)
6645 char_u **varp;
6646{
6647 int round, i, len, entries;
6648 char_u *p, *s;
6649 int c1, c2 = 0;
6650 struct charstab
6651 {
6652 int *cp;
6653 char *name;
6654 };
6655#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6656 static struct charstab filltab[] =
6657 {
6658 {&fill_stl, "stl"},
6659 {&fill_stlnc, "stlnc"},
6660 {&fill_vert, "vert"},
6661 {&fill_fold, "fold"},
6662 {&fill_diff, "diff"},
6663 };
6664#endif
6665 static struct charstab lcstab[] =
6666 {
6667 {&lcs_eol, "eol"},
6668 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006669 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670 {&lcs_prec, "precedes"},
6671 {&lcs_tab2, "tab"},
6672 {&lcs_trail, "trail"},
6673 };
6674 struct charstab *tab;
6675
6676#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6677 if (varp == &p_lcs)
6678#endif
6679 {
6680 tab = lcstab;
6681 entries = sizeof(lcstab) / sizeof(struct charstab);
6682 }
6683#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6684 else
6685 {
6686 tab = filltab;
6687 entries = sizeof(filltab) / sizeof(struct charstab);
6688 }
6689#endif
6690
6691 /* first round: check for valid value, second round: assign values */
6692 for (round = 0; round <= 1; ++round)
6693 {
6694 if (round)
6695 {
6696 /* After checking that the value is valid: set defaults: space for
6697 * 'fillchars', NUL for 'listchars' */
6698 for (i = 0; i < entries; ++i)
6699 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6700 if (varp == &p_lcs)
6701 lcs_tab1 = NUL;
6702#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6703 else
6704 fill_diff = '-';
6705#endif
6706 }
6707 p = *varp;
6708 while (*p)
6709 {
6710 for (i = 0; i < entries; ++i)
6711 {
6712 len = (int)STRLEN(tab[i].name);
6713 if (STRNCMP(p, tab[i].name, len) == 0
6714 && p[len] == ':'
6715 && p[len + 1] != NUL)
6716 {
6717 s = p + len + 1;
6718#ifdef FEAT_MBYTE
6719 c1 = mb_ptr2char_adv(&s);
6720#else
6721 c1 = *s++;
6722#endif
6723 if (tab[i].cp == &lcs_tab2)
6724 {
6725 if (*s == NUL)
6726 continue;
6727#ifdef FEAT_MBYTE
6728 c2 = mb_ptr2char_adv(&s);
6729#else
6730 c2 = *s++;
6731#endif
6732 }
6733 if (*s == ',' || *s == NUL)
6734 {
6735 if (round)
6736 {
6737 if (tab[i].cp == &lcs_tab2)
6738 {
6739 lcs_tab1 = c1;
6740 lcs_tab2 = c2;
6741 }
6742 else
6743 *(tab[i].cp) = c1;
6744
6745 }
6746 p = s;
6747 break;
6748 }
6749 }
6750 }
6751
6752 if (i == entries)
6753 return e_invarg;
6754 if (*p == ',')
6755 ++p;
6756 }
6757 }
6758
6759 return NULL; /* no error */
6760}
6761
6762#ifdef FEAT_STL_OPT
6763/*
6764 * Check validity of options with the 'statusline' format.
6765 * Return error message or NULL.
6766 */
6767 char_u *
6768check_stl_option(s)
6769 char_u *s;
6770{
6771 int itemcnt = 0;
6772 int groupdepth = 0;
6773 static char_u errbuf[80];
6774
6775 while (*s && itemcnt < STL_MAX_ITEM)
6776 {
6777 /* Check for valid keys after % sequences */
6778 while (*s && *s != '%')
6779 s++;
6780 if (!*s)
6781 break;
6782 s++;
6783 if (*s != '%' && *s != ')')
6784 ++itemcnt;
6785 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6786 {
6787 s++;
6788 continue;
6789 }
6790 if (*s == ')')
6791 {
6792 s++;
6793 if (--groupdepth < 0)
6794 break;
6795 continue;
6796 }
6797 if (*s == '-')
6798 s++;
6799 while (VIM_ISDIGIT(*s))
6800 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006801 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006802 continue;
6803 if (*s == '.')
6804 {
6805 s++;
6806 while (*s && VIM_ISDIGIT(*s))
6807 s++;
6808 }
6809 if (*s == '(')
6810 {
6811 groupdepth++;
6812 continue;
6813 }
6814 if (vim_strchr(STL_ALL, *s) == NULL)
6815 {
6816 return illegal_char(errbuf, *s);
6817 }
6818 if (*s == '{')
6819 {
6820 s++;
6821 while (*s != '}' && *s)
6822 s++;
6823 if (*s != '}')
6824 return (char_u *)N_("E540: Unclosed expression sequence");
6825 }
6826 }
6827 if (itemcnt >= STL_MAX_ITEM)
6828 return (char_u *)N_("E541: too many items");
6829 if (groupdepth != 0)
6830 return (char_u *)N_("E542: unbalanced groups");
6831 return NULL;
6832}
6833#endif
6834
6835#ifdef FEAT_CLIPBOARD
6836/*
6837 * Extract the items in the 'clipboard' option and set global values.
6838 */
6839 static char_u *
6840check_clipboard_option()
6841{
6842 int new_unnamed = FALSE;
6843 int new_autoselect = FALSE;
6844 int new_autoselectml = FALSE;
6845 regprog_T *new_exclude_prog = NULL;
6846 char_u *errmsg = NULL;
6847 char_u *p;
6848
6849 for (p = p_cb; *p != NUL; )
6850 {
6851 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6852 {
6853 new_unnamed = TRUE;
6854 p += 7;
6855 }
6856 else if (STRNCMP(p, "autoselect", 10) == 0
6857 && (p[10] == ',' || p[10] == NUL))
6858 {
6859 new_autoselect = TRUE;
6860 p += 10;
6861 }
6862 else if (STRNCMP(p, "autoselectml", 12) == 0
6863 && (p[12] == ',' || p[12] == NUL))
6864 {
6865 new_autoselectml = TRUE;
6866 p += 12;
6867 }
6868 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6869 {
6870 p += 8;
6871 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6872 if (new_exclude_prog == NULL)
6873 errmsg = e_invarg;
6874 break;
6875 }
6876 else
6877 {
6878 errmsg = e_invarg;
6879 break;
6880 }
6881 if (*p == ',')
6882 ++p;
6883 }
6884 if (errmsg == NULL)
6885 {
6886 clip_unnamed = new_unnamed;
6887 clip_autoselect = new_autoselect;
6888 clip_autoselectml = new_autoselectml;
6889 vim_free(clip_exclude_prog);
6890 clip_exclude_prog = new_exclude_prog;
6891 }
6892 else
6893 vim_free(new_exclude_prog);
6894
6895 return errmsg;
6896}
6897#endif
6898
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006899#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006900/*
6901 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6902 * Return error message when failed, NULL when OK.
6903 */
6904 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006905compile_cap_prog(buf)
6906 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006907{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006908 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006909 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006910
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006911 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006912 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006913 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006914 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006915 /* Prepend a ^ so that we only match at one column */
6916 re = concat_str((char_u *)"^", buf->b_p_spc);
6917 if (re != NULL)
6918 {
6919 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
6920 if (buf->b_cap_prog == NULL)
6921 {
6922 buf->b_cap_prog = rp; /* restore the previous program */
6923 return e_invarg;
6924 }
6925 vim_free(re);
6926 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006927 }
6928
6929 vim_free(rp);
6930 return NULL;
6931}
6932#endif
6933
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006934#if defined(FEAT_EVAL) || defined(PROTO)
6935/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006936 * Set the scriptID for an option, taking care of setting the buffer- or
6937 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006938 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006939 static void
6940set_option_scriptID_idx(opt_idx, opt_flags, id)
6941 int opt_idx;
6942 int opt_flags;
6943 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006944{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006945 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
6946 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006947
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006948 /* Remember where the option was set. For local options need to do that
6949 * in the buffer or window structure. */
6950 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006951 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006952 if (both || (opt_flags & OPT_LOCAL))
6953 {
6954 if (indir & PV_BUF)
6955 curbuf->b_p_scriptID[indir & PV_MASK] = id;
6956 else if (indir & PV_WIN)
6957 curwin->w_p_scriptID[indir & PV_MASK] = id;
6958 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006959}
6960#endif
6961
Bram Moolenaar071d4272004-06-13 20:20:40 +00006962/*
6963 * Set the value of a boolean option, and take care of side effects.
6964 * Returns NULL for success, or an error message for an error.
6965 */
6966 static char_u *
6967set_bool_option(opt_idx, varp, value, opt_flags)
6968 int opt_idx; /* index in options[] table */
6969 char_u *varp; /* pointer to the option variable */
6970 int value; /* new value */
6971 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6972{
6973 int old_value = *(int *)varp;
6974
Bram Moolenaar071d4272004-06-13 20:20:40 +00006975 /* Disallow changing some options from secure mode */
6976 if ((secure
6977#ifdef HAVE_SANDBOX
6978 || sandbox != 0
6979#endif
6980 ) && (options[opt_idx].flags & P_SECURE))
6981 return e_secure;
6982
6983 *(int *)varp = value; /* set the new value */
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
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006989#ifdef FEAT_GUI
6990 need_mouse_correct = TRUE;
6991#endif
6992
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 /* May set global value for local option. */
6994 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6995 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6996
6997 /*
6998 * Handle side effects of changing a bool option.
6999 */
7000
7001 /* 'compatible' */
7002 if ((int *)varp == &p_cp)
7003 {
7004 compatible_set();
7005 }
7006
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007 else if ((int *)varp == &curbuf->b_p_ro)
7008 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007009 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007010 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7011 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007012
7013 /* when 'readonly' is set may give W10 again */
7014 if (curbuf->b_p_ro)
7015 curbuf->b_did_warn = FALSE;
7016
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017#ifdef FEAT_TITLE
7018 need_maketitle = TRUE;
7019#endif
7020 }
7021
7022#ifdef FEAT_TITLE
7023 /* when 'modifiable' is changed, redraw the window title */
7024 else if ((int *)varp == &curbuf->b_p_ma)
7025 need_maketitle = TRUE;
7026 /* when 'endofline' is changed, redraw the window title */
7027 else if ((int *)varp == &curbuf->b_p_eol)
7028 need_maketitle = TRUE;
7029#endif
7030
7031 /* when 'bin' is set also set some other options */
7032 else if ((int *)varp == &curbuf->b_p_bin)
7033 {
7034 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7035#ifdef FEAT_TITLE
7036 need_maketitle = TRUE;
7037#endif
7038 }
7039
7040#ifdef FEAT_AUTOCMD
7041 /* when 'buflisted' changes, trigger autocommands */
7042 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7043 {
7044 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7045 NULL, NULL, TRUE, curbuf);
7046 }
7047#endif
7048
7049 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7050 else if ((int *)varp == &curbuf->b_p_swf)
7051 {
7052 if (curbuf->b_p_swf && p_uc)
7053 ml_open_file(curbuf); /* create the swap file */
7054 else
7055 mf_close_file(curbuf, TRUE); /* remove the swap file */
7056 }
7057
7058 /* when 'terse' is set change 'shortmess' */
7059 else if ((int *)varp == &p_terse)
7060 {
7061 char_u *p;
7062
7063 p = vim_strchr(p_shm, SHM_SEARCH);
7064
7065 /* insert 's' in p_shm */
7066 if (p_terse && p == NULL)
7067 {
7068 STRCPY(IObuff, p_shm);
7069 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007070 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 }
7072 /* remove 's' from p_shm */
7073 else if (!p_terse && p != NULL)
7074 mch_memmove(p, p + 1, STRLEN(p));
7075 }
7076
7077 /* when 'paste' is set or reset also change other options */
7078 else if ((int *)varp == &p_paste)
7079 {
7080 paste_option_changed();
7081 }
7082
7083 /* when 'insertmode' is set from an autocommand need to do work here */
7084 else if ((int *)varp == &p_im)
7085 {
7086 if (p_im)
7087 {
7088 if ((State & INSERT) == 0)
7089 need_start_insertmode = TRUE;
7090 stop_insert_mode = FALSE;
7091 }
7092 else
7093 {
7094 need_start_insertmode = FALSE;
7095 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007096 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007097 clear_cmdline = TRUE; /* remove "(insert)" */
7098 restart_edit = 0;
7099 }
7100 }
7101
7102 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7103 else if ((int *)varp == &p_ic && p_hls)
7104 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007105 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 }
7107
7108#ifdef FEAT_SEARCH_EXTRA
7109 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7110 else if ((int *)varp == &p_hls)
7111 {
7112 no_hlsearch = FALSE;
7113 }
7114#endif
7115
7116#ifdef FEAT_SCROLLBIND
7117 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7118 * at the end of normal_cmd() */
7119 else if ((int *)varp == &curwin->w_p_scb)
7120 {
7121 if (curwin->w_p_scb)
7122 do_check_scrollbind(FALSE);
7123 }
7124#endif
7125
7126#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7127 /* There can be only one window with 'previewwindow' set. */
7128 else if ((int *)varp == &curwin->w_p_pvw)
7129 {
7130 if (curwin->w_p_pvw)
7131 {
7132 win_T *win;
7133
7134 for (win = firstwin; win != NULL; win = win->w_next)
7135 if (win->w_p_pvw && win != curwin)
7136 {
7137 curwin->w_p_pvw = FALSE;
7138 return (char_u *)N_("E590: A preview window already exists");
7139 }
7140 }
7141 }
7142#endif
7143
7144 /* when 'textmode' is set or reset also change 'fileformat' */
7145 else if ((int *)varp == &curbuf->b_p_tx)
7146 {
7147 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7148 }
7149
7150 /* when 'textauto' is set or reset also change 'fileformats' */
7151 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007152 set_string_option_direct((char_u *)"ffs", -1,
7153 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007154 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007155
7156 /*
7157 * When 'lisp' option changes include/exclude '-' in
7158 * keyword characters.
7159 */
7160#ifdef FEAT_LISP
7161 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7162 {
7163 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7164 }
7165#endif
7166
7167#ifdef FEAT_TITLE
7168 /* when 'title' changed, may need to change the title; same for 'icon' */
7169 else if ((int *)varp == &p_title)
7170 {
7171 did_set_title(FALSE);
7172 }
7173
7174 else if ((int *)varp == &p_icon)
7175 {
7176 did_set_title(TRUE);
7177 }
7178#endif
7179
7180 else if ((int *)varp == &curbuf->b_changed)
7181 {
7182 if (!value)
7183 save_file_ff(curbuf); /* Buffer is unchanged */
7184#ifdef FEAT_TITLE
7185 need_maketitle = TRUE;
7186#endif
7187#ifdef FEAT_AUTOCMD
7188 modified_was_set = value;
7189#endif
7190 }
7191
7192#ifdef BACKSLASH_IN_FILENAME
7193 else if ((int *)varp == &p_ssl)
7194 {
7195 if (p_ssl)
7196 {
7197 psepc = '/';
7198 psepcN = '\\';
7199 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007200 }
7201 else
7202 {
7203 psepc = '\\';
7204 psepcN = '/';
7205 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206 }
7207
7208 /* need to adjust the file name arguments and buffer names. */
7209 buflist_slash_adjust();
7210 alist_slash_adjust();
7211# ifdef FEAT_EVAL
7212 scriptnames_slash_adjust();
7213# endif
7214 }
7215#endif
7216
7217 /* If 'wrap' is set, set w_leftcol to zero. */
7218 else if ((int *)varp == &curwin->w_p_wrap)
7219 {
7220 if (curwin->w_p_wrap)
7221 curwin->w_leftcol = 0;
7222 }
7223
7224#ifdef FEAT_WINDOWS
7225 else if ((int *)varp == &p_ea)
7226 {
7227 if (p_ea && !old_value)
7228 win_equal(curwin, FALSE, 0);
7229 }
7230#endif
7231
7232 else if ((int *)varp == &p_wiv)
7233 {
7234 /*
7235 * When 'weirdinvert' changed, set/reset 't_xs'.
7236 * Then set 'weirdinvert' according to value of 't_xs'.
7237 */
7238 if (p_wiv && !old_value)
7239 T_XS = (char_u *)"y";
7240 else if (!p_wiv && old_value)
7241 T_XS = empty_option;
7242 p_wiv = (*T_XS != NUL);
7243 }
7244
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007245#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007246 else if ((int *)varp == &p_beval)
7247 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007248 if (p_beval == TRUE)
7249 gui_mch_enable_beval_area(balloonEval);
7250 else
7251 gui_mch_disable_beval_area(balloonEval);
7252 }
7253
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007254# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255 else if ((int *)varp == &p_acd)
7256 {
7257 if (p_acd && curbuf->b_ffname != NULL
7258 && vim_chdirfile(curbuf->b_ffname) == OK)
7259 shorten_fnames(TRUE);
7260 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007261# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262#endif
7263
7264#ifdef FEAT_DIFF
7265 /* 'diff' */
7266 else if ((int *)varp == &curwin->w_p_diff)
7267 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007268 /* May add or remove the buffer from the list of diff buffers. */
7269 diff_buf_adjust(curwin);
7270# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007271 if (foldmethodIsDiff(curwin))
7272 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007273# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274 }
7275#endif
7276
7277#ifdef USE_IM_CONTROL
7278 /* 'imdisable' */
7279 else if ((int *)varp == &p_imdisable)
7280 {
7281 /* Only de-activate it here, it will be enabled when changing mode. */
7282 if (p_imdisable)
7283 im_set_active(FALSE);
7284 }
7285#endif
7286
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007287#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007288 /* 'spell' */
7289 else if ((int *)varp == &curwin->w_p_spell)
7290 {
7291 if (curwin->w_p_spell)
7292 {
7293 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007294
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007295 if (errmsg != NULL)
7296 EMSG(_(errmsg));
7297 }
7298 }
7299#endif
7300
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301#ifdef FEAT_FKMAP
7302 else if ((int *)varp == &p_altkeymap)
7303 {
7304 if (old_value != p_altkeymap)
7305 {
7306 if (!p_altkeymap)
7307 {
7308 p_hkmap = p_fkmap;
7309 p_fkmap = 0;
7310 }
7311 else
7312 {
7313 p_fkmap = p_hkmap;
7314 p_hkmap = 0;
7315 }
7316 (void)init_chartab();
7317 }
7318 }
7319
7320 /*
7321 * In case some second language keymapping options have changed, check
7322 * and correct the setting in a consistent way.
7323 */
7324
7325 /*
7326 * If hkmap or fkmap are set, reset Arabic keymapping.
7327 */
7328 if ((p_hkmap || p_fkmap) && p_altkeymap)
7329 {
7330 p_altkeymap = p_fkmap;
7331# ifdef FEAT_ARABIC
7332 curwin->w_p_arab = FALSE;
7333# endif
7334 (void)init_chartab();
7335 }
7336
7337 /*
7338 * If hkmap set, reset Farsi keymapping.
7339 */
7340 if (p_hkmap && p_altkeymap)
7341 {
7342 p_altkeymap = 0;
7343 p_fkmap = 0;
7344# ifdef FEAT_ARABIC
7345 curwin->w_p_arab = FALSE;
7346# endif
7347 (void)init_chartab();
7348 }
7349
7350 /*
7351 * If fkmap set, reset Hebrew keymapping.
7352 */
7353 if (p_fkmap && !p_altkeymap)
7354 {
7355 p_altkeymap = 1;
7356 p_hkmap = 0;
7357# ifdef FEAT_ARABIC
7358 curwin->w_p_arab = FALSE;
7359# endif
7360 (void)init_chartab();
7361 }
7362#endif
7363
7364#ifdef FEAT_ARABIC
7365 if ((int *)varp == &curwin->w_p_arab)
7366 {
7367 if (curwin->w_p_arab)
7368 {
7369 /*
7370 * 'arabic' is set, handle various sub-settings.
7371 */
7372 if (!p_tbidi)
7373 {
7374 /* set rightleft mode */
7375 if (!curwin->w_p_rl)
7376 {
7377 curwin->w_p_rl = TRUE;
7378 changed_window_setting();
7379 }
7380
7381 /* Enable Arabic shaping (major part of what Arabic requires) */
7382 if (!p_arshape)
7383 {
7384 p_arshape = TRUE;
7385 redraw_later_clear();
7386 }
7387 }
7388
7389 /* Arabic requires a utf-8 encoding, inform the user if its not
7390 * set. */
7391 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007392 {
7393 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007394 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
7395 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007396 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007397
7398# ifdef FEAT_MBYTE
7399 /* set 'delcombine' */
7400 p_deco = TRUE;
7401# endif
7402
7403# ifdef FEAT_KEYMAP
7404 /* Force-set the necessary keymap for arabic */
7405 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7406 OPT_LOCAL);
7407# endif
7408# ifdef FEAT_FKMAP
7409 p_altkeymap = 0;
7410 p_hkmap = 0;
7411 p_fkmap = 0;
7412 (void)init_chartab();
7413# endif
7414 }
7415 else
7416 {
7417 /*
7418 * 'arabic' is reset, handle various sub-settings.
7419 */
7420 if (!p_tbidi)
7421 {
7422 /* reset rightleft mode */
7423 if (curwin->w_p_rl)
7424 {
7425 curwin->w_p_rl = FALSE;
7426 changed_window_setting();
7427 }
7428
7429 /* 'arabicshape' isn't reset, it is a global option and
7430 * another window may still need it "on". */
7431 }
7432
7433 /* 'delcombine' isn't reset, it is a global option and another
7434 * window may still want it "on". */
7435
7436# ifdef FEAT_KEYMAP
7437 /* Revert to the default keymap */
7438 curbuf->b_p_iminsert = B_IMODE_NONE;
7439 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7440# endif
7441 }
7442 }
7443#endif
7444
7445 /*
7446 * End of handling side effects for bool options.
7447 */
7448
7449 options[opt_idx].flags |= P_WAS_SET;
7450
7451 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7452 if (curwin->w_curswant != MAXCOL)
7453 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7454 check_redraw(options[opt_idx].flags);
7455
7456 return NULL;
7457}
7458
7459/*
7460 * Set the value of a number option, and take care of side effects.
7461 * Returns NULL for success, or an error message for an error.
7462 */
7463 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007464set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007465 int opt_idx; /* index in options[] table */
7466 char_u *varp; /* pointer to the option variable */
7467 long value; /* new value */
7468 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007469 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007470 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7471 OPT_MODELINE */
7472{
7473 char_u *errmsg = NULL;
7474 long old_value = *(long *)varp;
7475 long old_Rows = Rows; /* remember old Rows */
7476 long old_Columns = Columns; /* remember old Columns */
7477 long *pp = (long *)varp;
7478
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007479 /* Disallow changing some options from secure mode. */
7480 if ((secure
7481#ifdef HAVE_SANDBOX
7482 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007483#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007484 ) && (options[opt_idx].flags & P_SECURE))
7485 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486
7487 *pp = value;
7488#ifdef FEAT_EVAL
7489 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007490 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007492#ifdef FEAT_GUI
7493 need_mouse_correct = TRUE;
7494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007495
7496 if (curbuf->b_p_sw <= 0)
7497 {
7498 errmsg = e_positive;
7499 curbuf->b_p_sw = curbuf->b_p_ts;
7500 }
7501
7502 /*
7503 * Number options that need some action when changed
7504 */
7505#ifdef FEAT_WINDOWS
7506 if (pp == &p_wh || pp == &p_hh)
7507 {
7508 if (p_wh < 1)
7509 {
7510 errmsg = e_positive;
7511 p_wh = 1;
7512 }
7513 if (p_wmh > p_wh)
7514 {
7515 errmsg = e_winheight;
7516 p_wh = p_wmh;
7517 }
7518 if (p_hh < 0)
7519 {
7520 errmsg = e_positive;
7521 p_hh = 0;
7522 }
7523
7524 /* Change window height NOW */
7525 if (lastwin != firstwin)
7526 {
7527 if (pp == &p_wh && curwin->w_height < p_wh)
7528 win_setheight((int)p_wh);
7529 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7530 win_setheight((int)p_hh);
7531 }
7532 }
7533
7534 /* 'winminheight' */
7535 else if (pp == &p_wmh)
7536 {
7537 if (p_wmh < 0)
7538 {
7539 errmsg = e_positive;
7540 p_wmh = 0;
7541 }
7542 if (p_wmh > p_wh)
7543 {
7544 errmsg = e_winheight;
7545 p_wmh = p_wh;
7546 }
7547 win_setminheight();
7548 }
7549
7550# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007551 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007552 {
7553 if (p_wiw < 1)
7554 {
7555 errmsg = e_positive;
7556 p_wiw = 1;
7557 }
7558 if (p_wmw > p_wiw)
7559 {
7560 errmsg = e_winwidth;
7561 p_wiw = p_wmw;
7562 }
7563
7564 /* Change window width NOW */
7565 if (lastwin != firstwin && curwin->w_width < p_wiw)
7566 win_setwidth((int)p_wiw);
7567 }
7568
7569 /* 'winminwidth' */
7570 else if (pp == &p_wmw)
7571 {
7572 if (p_wmw < 0)
7573 {
7574 errmsg = e_positive;
7575 p_wmw = 0;
7576 }
7577 if (p_wmw > p_wiw)
7578 {
7579 errmsg = e_winwidth;
7580 p_wmw = p_wiw;
7581 }
7582 win_setminheight();
7583 }
7584# endif
7585
7586#endif
7587
7588#ifdef FEAT_WINDOWS
7589 /* (re)set last window status line */
7590 else if (pp == &p_ls)
7591 {
7592 last_status(FALSE);
7593 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007594
7595 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007596 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007597 {
7598 shell_new_rows(); /* recompute window positions and heights */
7599 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007600#endif
7601
7602#ifdef FEAT_GUI
7603 else if (pp == &p_linespace)
7604 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007605 /* Recompute gui.char_height and resize the Vim window to keep the
7606 * same number of lines. */
7607 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007608 gui_set_shellsize(FALSE, FALSE);
7609 }
7610#endif
7611
7612#ifdef FEAT_FOLDING
7613 /* 'foldlevel' */
7614 else if (pp == &curwin->w_p_fdl)
7615 {
7616 if (curwin->w_p_fdl < 0)
7617 curwin->w_p_fdl = 0;
7618 newFoldLevel();
7619 }
7620
7621 /* 'foldminlevel' */
7622 else if (pp == &curwin->w_p_fml)
7623 {
7624 foldUpdateAll(curwin);
7625 }
7626
7627 /* 'foldnestmax' */
7628 else if (pp == &curwin->w_p_fdn)
7629 {
7630 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7631 foldUpdateAll(curwin);
7632 }
7633
7634 /* 'foldcolumn' */
7635 else if (pp == &curwin->w_p_fdc)
7636 {
7637 if (curwin->w_p_fdc < 0)
7638 {
7639 errmsg = e_positive;
7640 curwin->w_p_fdc = 0;
7641 }
7642 else if (curwin->w_p_fdc > 12)
7643 {
7644 errmsg = e_invarg;
7645 curwin->w_p_fdc = 12;
7646 }
7647 }
7648
7649 /* 'shiftwidth' or 'tabstop' */
7650 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7651 {
7652 if (foldmethodIsIndent(curwin))
7653 foldUpdateAll(curwin);
7654 }
7655#endif /* FEAT_FOLDING */
7656
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007657#ifdef FEAT_MBYTE
7658 /* 'maxcombine' */
7659 else if (pp == &p_mco)
7660 {
7661 if (p_mco > MAX_MCO)
7662 p_mco = MAX_MCO;
7663 else if (p_mco < 0)
7664 p_mco = 0;
7665 screenclear(); /* will re-allocate the screen */
7666 }
7667#endif
7668
Bram Moolenaar071d4272004-06-13 20:20:40 +00007669 else if (pp == &curbuf->b_p_iminsert)
7670 {
7671 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7672 {
7673 errmsg = e_invarg;
7674 curbuf->b_p_iminsert = B_IMODE_NONE;
7675 }
7676 p_iminsert = curbuf->b_p_iminsert;
7677 if (termcap_active) /* don't do this in the alternate screen */
7678 showmode();
7679#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7680 /* Show/unshow value of 'keymap' in status lines. */
7681 status_redraw_curbuf();
7682#endif
7683 }
7684
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007685 else if (pp == &p_window)
7686 {
7687 if (p_window < 1)
7688 p_window = 1;
7689 else if (p_window >= Rows)
7690 p_window = Rows - 1;
7691 }
7692
Bram Moolenaar071d4272004-06-13 20:20:40 +00007693 else if (pp == &curbuf->b_p_imsearch)
7694 {
7695 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7696 {
7697 errmsg = e_invarg;
7698 curbuf->b_p_imsearch = B_IMODE_NONE;
7699 }
7700 p_imsearch = curbuf->b_p_imsearch;
7701 }
7702
7703#ifdef FEAT_TITLE
7704 /* if 'titlelen' has changed, redraw the title */
7705 else if (pp == &p_titlelen)
7706 {
7707 if (p_titlelen < 0)
7708 {
7709 errmsg = e_positive;
7710 p_titlelen = 85;
7711 }
7712 if (starting != NO_SCREEN && old_value != p_titlelen)
7713 need_maketitle = TRUE;
7714 }
7715#endif
7716
7717 /* if p_ch changed value, change the command line height */
7718 else if (pp == &p_ch)
7719 {
7720 if (p_ch < 1)
7721 {
7722 errmsg = e_positive;
7723 p_ch = 1;
7724 }
7725
7726 /* Only compute the new window layout when startup has been
7727 * completed. Otherwise the frame sizes may be wrong. */
7728 if (p_ch != old_value && full_screen
7729#ifdef FEAT_GUI
7730 && !gui.starting
7731#endif
7732 )
7733 command_height(old_value);
7734 }
7735
7736 /* when 'updatecount' changes from zero to non-zero, open swap files */
7737 else if (pp == &p_uc)
7738 {
7739 if (p_uc < 0)
7740 {
7741 errmsg = e_positive;
7742 p_uc = 100;
7743 }
7744 if (p_uc && !old_value)
7745 ml_open_files();
7746 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007747#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007748 else if (pp == &p_mzq)
7749 mzvim_reset_timer();
7750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007751
7752 /* sync undo before 'undolevels' changes */
7753 else if (pp == &p_ul)
7754 {
7755 /* use the old value, otherwise u_sync() may not work properly */
7756 p_ul = old_value;
7757 u_sync();
7758 p_ul = value;
7759 }
7760
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007761#ifdef FEAT_LINEBREAK
7762 /* 'numberwidth' must be positive */
7763 else if (pp == &curwin->w_p_nuw)
7764 {
7765 if (curwin->w_p_nuw < 1)
7766 {
7767 errmsg = e_positive;
7768 curwin->w_p_nuw = 1;
7769 }
7770 if (curwin->w_p_nuw > 10)
7771 {
7772 errmsg = e_invarg;
7773 curwin->w_p_nuw = 10;
7774 }
7775 curwin->w_nrwidth_line_count = 0;
7776 }
7777#endif
7778
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 /*
7780 * Check the bounds for numeric options here
7781 */
7782 if (Rows < min_rows() && full_screen)
7783 {
7784 if (errbuf != NULL)
7785 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007786 vim_snprintf((char *)errbuf, errbuflen,
7787 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007788 errmsg = errbuf;
7789 }
7790 Rows = min_rows();
7791 }
7792 if (Columns < MIN_COLUMNS && full_screen)
7793 {
7794 if (errbuf != NULL)
7795 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007796 vim_snprintf((char *)errbuf, errbuflen,
7797 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798 errmsg = errbuf;
7799 }
7800 Columns = MIN_COLUMNS;
7801 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007802 /* Limit the values to avoid an overflow in Rows * Columns. */
7803 if (Columns > 10000)
7804 Columns = 10000;
7805 if (Rows > 1000)
7806 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007807
7808#ifdef DJGPP
7809 /* avoid a crash by checking for a too large value of 'columns' */
7810 if (old_Columns != Columns && full_screen && term_console)
7811 mch_check_columns();
7812#endif
7813
7814 /*
7815 * If the screen (shell) height has been changed, assume it is the
7816 * physical screenheight.
7817 */
7818 if (old_Rows != Rows || old_Columns != Columns)
7819 {
7820 /* Changing the screen size is not allowed while updating the screen. */
7821 if (updating_screen)
7822 *pp = old_value;
7823 else if (full_screen
7824#ifdef FEAT_GUI
7825 && !gui.starting
7826#endif
7827 )
7828 set_shellsize((int)Columns, (int)Rows, TRUE);
7829 else
7830 {
7831 /* Postpone the resizing; check the size and cmdline position for
7832 * messages. */
7833 check_shellsize();
7834 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7835 cmdline_row = Rows - p_ch;
7836 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007837 if (p_window >= Rows)
7838 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839 }
7840
7841 if (curbuf->b_p_sts < 0)
7842 {
7843 errmsg = e_positive;
7844 curbuf->b_p_sts = 0;
7845 }
7846 if (curbuf->b_p_ts <= 0)
7847 {
7848 errmsg = e_positive;
7849 curbuf->b_p_ts = 8;
7850 }
7851 if (curbuf->b_p_tw < 0)
7852 {
7853 errmsg = e_positive;
7854 curbuf->b_p_tw = 0;
7855 }
7856 if (p_tm < 0)
7857 {
7858 errmsg = e_positive;
7859 p_tm = 0;
7860 }
7861 if ((curwin->w_p_scr <= 0
7862 || (curwin->w_p_scr > curwin->w_height
7863 && curwin->w_height > 0))
7864 && full_screen)
7865 {
7866 if (pp == &(curwin->w_p_scr))
7867 {
7868 if (curwin->w_p_scr != 0)
7869 errmsg = e_scroll;
7870 win_comp_scroll(curwin);
7871 }
7872 /* If 'scroll' became invalid because of a side effect silently adjust
7873 * it. */
7874 else if (curwin->w_p_scr <= 0)
7875 curwin->w_p_scr = 1;
7876 else /* curwin->w_p_scr > curwin->w_height */
7877 curwin->w_p_scr = curwin->w_height;
7878 }
7879 if (p_report < 0)
7880 {
7881 errmsg = e_positive;
7882 p_report = 1;
7883 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007884 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007885 {
7886 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7887 p_sj = Rows / 2;
7888 else
7889 {
7890 errmsg = e_scroll;
7891 p_sj = 1;
7892 }
7893 }
7894 if (p_so < 0 && full_screen)
7895 {
7896 errmsg = e_scroll;
7897 p_so = 0;
7898 }
7899 if (p_siso < 0 && full_screen)
7900 {
7901 errmsg = e_positive;
7902 p_siso = 0;
7903 }
7904#ifdef FEAT_CMDWIN
7905 if (p_cwh < 1)
7906 {
7907 errmsg = e_positive;
7908 p_cwh = 1;
7909 }
7910#endif
7911 if (p_ut < 0)
7912 {
7913 errmsg = e_positive;
7914 p_ut = 2000;
7915 }
7916 if (p_ss < 0)
7917 {
7918 errmsg = e_positive;
7919 p_ss = 0;
7920 }
7921
7922 /* May set global value for local option. */
7923 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7924 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7925
7926 options[opt_idx].flags |= P_WAS_SET;
7927
7928 comp_col(); /* in case 'columns' or 'ls' changed */
7929 if (curwin->w_curswant != MAXCOL)
7930 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7931 check_redraw(options[opt_idx].flags);
7932
7933 return errmsg;
7934}
7935
7936/*
7937 * Called after an option changed: check if something needs to be redrawn.
7938 */
7939 static void
7940check_redraw(flags)
7941 long_u flags;
7942{
7943 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7944 int clear = (flags & P_RCLR) == P_RCLR;
7945 int all = ((flags & P_RALL) == P_RALL || clear);
7946
7947#ifdef FEAT_WINDOWS
7948 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7949 status_redraw_all();
7950#endif
7951
7952 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7953 changed_window_setting();
7954 if (flags & P_RBUF)
7955 redraw_curbuf_later(NOT_VALID);
7956 if (clear)
7957 redraw_all_later(CLEAR);
7958 else if (all)
7959 redraw_all_later(NOT_VALID);
7960}
7961
7962/*
7963 * Find index for option 'arg'.
7964 * Return -1 if not found.
7965 */
7966 static int
7967findoption(arg)
7968 char_u *arg;
7969{
7970 int opt_idx;
7971 char *s, *p;
7972 static short quick_tab[27] = {0, 0}; /* quick access table */
7973 int is_term_opt;
7974
7975 /*
7976 * For first call: Initialize the quick-access table.
7977 * It contains the index for the first option that starts with a certain
7978 * letter. There are 26 letters, plus the first "t_" option.
7979 */
7980 if (quick_tab[1] == 0)
7981 {
7982 p = options[0].fullname;
7983 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7984 {
7985 if (s[0] != p[0])
7986 {
7987 if (s[0] == 't' && s[1] == '_')
7988 quick_tab[26] = opt_idx;
7989 else
7990 quick_tab[CharOrdLow(s[0])] = opt_idx;
7991 }
7992 p = s;
7993 }
7994 }
7995
7996 /*
7997 * Check for name starting with an illegal character.
7998 */
7999#ifdef EBCDIC
8000 if (!islower(arg[0]))
8001#else
8002 if (arg[0] < 'a' || arg[0] > 'z')
8003#endif
8004 return -1;
8005
8006 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8007 if (is_term_opt)
8008 opt_idx = quick_tab[26];
8009 else
8010 opt_idx = quick_tab[CharOrdLow(arg[0])];
8011 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8012 {
8013 if (STRCMP(arg, s) == 0) /* match full name */
8014 break;
8015 }
8016 if (s == NULL && !is_term_opt)
8017 {
8018 opt_idx = quick_tab[CharOrdLow(arg[0])];
8019 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8020 {
8021 s = options[opt_idx].shortname;
8022 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8023 break;
8024 s = NULL;
8025 }
8026 }
8027 if (s == NULL)
8028 opt_idx = -1;
8029 return opt_idx;
8030}
8031
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008032#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008033/*
8034 * Get the value for an option.
8035 *
8036 * Returns:
8037 * Number or Toggle option: 1, *numval gets value.
8038 * String option: 0, *stringval gets allocated string.
8039 * Hidden Number or Toggle option: -1.
8040 * hidden String option: -2.
8041 * unknown option: -3.
8042 */
8043 int
8044get_option_value(name, numval, stringval, opt_flags)
8045 char_u *name;
8046 long *numval;
8047 char_u **stringval; /* NULL when only checking existance */
8048 int opt_flags;
8049{
8050 int opt_idx;
8051 char_u *varp;
8052
8053 opt_idx = findoption(name);
8054 if (opt_idx < 0) /* unknown option */
8055 return -3;
8056
8057 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8058
8059 if (options[opt_idx].flags & P_STRING)
8060 {
8061 if (varp == NULL) /* hidden option */
8062 return -2;
8063 if (stringval != NULL)
8064 {
8065#ifdef FEAT_CRYPT
8066 /* never return the value of the crypt key */
8067 if ((char_u **)varp == &curbuf->b_p_key)
8068 *stringval = vim_strsave((char_u *)"*****");
8069 else
8070#endif
8071 *stringval = vim_strsave(*(char_u **)(varp));
8072 }
8073 return 0;
8074 }
8075
8076 if (varp == NULL) /* hidden option */
8077 return -1;
8078 if (options[opt_idx].flags & P_NUM)
8079 *numval = *(long *)varp;
8080 else
8081 {
8082 /* Special case: 'modified' is b_changed, but we also want to consider
8083 * it set when 'ff' or 'fenc' changed. */
8084 if ((int *)varp == &curbuf->b_changed)
8085 *numval = curbufIsChanged();
8086 else
8087 *numval = *(int *)varp;
8088 }
8089 return 1;
8090}
8091#endif
8092
8093/*
8094 * Set the value of option "name".
8095 * Use "string" for string options, use "number" for other options.
8096 */
8097 void
8098set_option_value(name, number, string, opt_flags)
8099 char_u *name;
8100 long number;
8101 char_u *string;
8102 int opt_flags; /* OPT_LOCAL or 0 (both) */
8103{
8104 int opt_idx;
8105 char_u *varp;
8106 int flags;
8107
8108 opt_idx = findoption(name);
8109 if (opt_idx == -1)
8110 EMSG2(_("E355: Unknown option: %s"), name);
8111 else
8112 {
8113 flags = options[opt_idx].flags;
8114#ifdef HAVE_SANDBOX
8115 /* Disallow changing some options in the sandbox */
8116 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008117 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008119 return;
8120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008121#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008122 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123 set_string_option(opt_idx, string, opt_flags);
8124 else
8125 {
8126 varp = get_varp(&options[opt_idx]);
8127 if (varp != NULL) /* hidden option is not changed */
8128 {
8129 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008130 (void)set_num_option(opt_idx, varp, number,
8131 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008133 (void)set_bool_option(opt_idx, varp, (int)number,
8134 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 }
8136 }
8137 }
8138}
8139
8140/*
8141 * Get the terminal code for a terminal option.
8142 * Returns NULL when not found.
8143 */
8144 char_u *
8145get_term_code(tname)
8146 char_u *tname;
8147{
8148 int opt_idx;
8149 char_u *varp;
8150
8151 if (tname[0] != 't' || tname[1] != '_' ||
8152 tname[2] == NUL || tname[3] == NUL)
8153 return NULL;
8154 if ((opt_idx = findoption(tname)) >= 0)
8155 {
8156 varp = get_varp(&(options[opt_idx]));
8157 if (varp != NULL)
8158 varp = *(char_u **)(varp);
8159 return varp;
8160 }
8161 return find_termcode(tname + 2);
8162}
8163
8164 char_u *
8165get_highlight_default()
8166{
8167 int i;
8168
8169 i = findoption((char_u *)"hl");
8170 if (i >= 0)
8171 return options[i].def_val[VI_DEFAULT];
8172 return (char_u *)NULL;
8173}
8174
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008175#if defined(FEAT_MBYTE) || defined(PROTO)
8176 char_u *
8177get_encoding_default()
8178{
8179 int i;
8180
8181 i = findoption((char_u *)"enc");
8182 if (i >= 0)
8183 return options[i].def_val[VI_DEFAULT];
8184 return (char_u *)NULL;
8185}
8186#endif
8187
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188/*
8189 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8190 */
8191 static int
8192find_key_option(arg)
8193 char_u *arg;
8194{
8195 int key;
8196 int modifiers;
8197
8198 /*
8199 * Don't use get_special_key_code() for t_xx, we don't want it to call
8200 * add_termcap_entry().
8201 */
8202 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8203 key = TERMCAP2KEY(arg[2], arg[3]);
8204 else
8205 {
8206 --arg; /* put arg at the '<' */
8207 modifiers = 0;
8208 key = find_special_key(&arg, &modifiers, TRUE);
8209 if (modifiers) /* can't handle modifiers here */
8210 key = 0;
8211 }
8212 return key;
8213}
8214
8215/*
8216 * if 'all' == 0: show changed options
8217 * if 'all' == 1: show all normal options
8218 * if 'all' == 2: show all terminal options
8219 */
8220 static void
8221showoptions(all, opt_flags)
8222 int all;
8223 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8224{
8225 struct vimoption *p;
8226 int col;
8227 int isterm;
8228 char_u *varp;
8229 struct vimoption **items;
8230 int item_count;
8231 int run;
8232 int row, rows;
8233 int cols;
8234 int i;
8235 int len;
8236
8237#define INC 20
8238#define GAP 3
8239
8240 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8241 PARAM_COUNT));
8242 if (items == NULL)
8243 return;
8244
8245 /* Highlight title */
8246 if (all == 2)
8247 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8248 else if (opt_flags & OPT_GLOBAL)
8249 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8250 else if (opt_flags & OPT_LOCAL)
8251 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8252 else
8253 MSG_PUTS_TITLE(_("\n--- Options ---"));
8254
8255 /*
8256 * do the loop two times:
8257 * 1. display the short items
8258 * 2. display the long items (only strings and numbers)
8259 */
8260 for (run = 1; run <= 2 && !got_int; ++run)
8261 {
8262 /*
8263 * collect the items in items[]
8264 */
8265 item_count = 0;
8266 for (p = &options[0]; p->fullname != NULL; p++)
8267 {
8268 varp = NULL;
8269 isterm = istermoption(p);
8270 if (opt_flags != 0)
8271 {
8272 if (p->indir != PV_NONE && !isterm)
8273 varp = get_varp_scope(p, opt_flags);
8274 }
8275 else
8276 varp = get_varp(p);
8277 if (varp != NULL
8278 && ((all == 2 && isterm)
8279 || (all == 1 && !isterm)
8280 || (all == 0 && !optval_default(p, varp))))
8281 {
8282 if (p->flags & P_BOOL)
8283 len = 1; /* a toggle option fits always */
8284 else
8285 {
8286 option_value2string(p, opt_flags);
8287 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8288 }
8289 if ((len <= INC - GAP && run == 1) ||
8290 (len > INC - GAP && run == 2))
8291 items[item_count++] = p;
8292 }
8293 }
8294
8295 /*
8296 * display the items
8297 */
8298 if (run == 1)
8299 {
8300 cols = (Columns + GAP - 3) / INC;
8301 if (cols == 0)
8302 cols = 1;
8303 rows = (item_count + cols - 1) / cols;
8304 }
8305 else /* run == 2 */
8306 rows = item_count;
8307 for (row = 0; row < rows && !got_int; ++row)
8308 {
8309 msg_putchar('\n'); /* go to next line */
8310 if (got_int) /* 'q' typed in more */
8311 break;
8312 col = 0;
8313 for (i = row; i < item_count; i += rows)
8314 {
8315 msg_col = col; /* make columns */
8316 showoneopt(items[i], opt_flags);
8317 col += INC;
8318 }
8319 out_flush();
8320 ui_breakcheck();
8321 }
8322 }
8323 vim_free(items);
8324}
8325
8326/*
8327 * Return TRUE if option "p" has its default value.
8328 */
8329 static int
8330optval_default(p, varp)
8331 struct vimoption *p;
8332 char_u *varp;
8333{
8334 int dvi;
8335
8336 if (varp == NULL)
8337 return TRUE; /* hidden option is always at default */
8338 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8339 if (p->flags & P_NUM)
8340 return (*(long *)varp == (long)p->def_val[dvi]);
8341 if (p->flags & P_BOOL)
8342 /* the cast to long is required for Manx C */
8343 return (*(int *)varp == (int)(long)p->def_val[dvi]);
8344 /* P_STRING */
8345 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8346}
8347
8348/*
8349 * showoneopt: show the value of one option
8350 * must not be called with a hidden option!
8351 */
8352 static void
8353showoneopt(p, opt_flags)
8354 struct vimoption *p;
8355 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8356{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008357 char_u *varp;
8358 int save_silent = silent_mode;
8359
8360 silent_mode = FALSE;
8361 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362
8363 varp = get_varp_scope(p, opt_flags);
8364
8365 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8366 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8367 ? !curbufIsChanged() : !*(int *)varp))
8368 MSG_PUTS("no");
8369 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8370 MSG_PUTS("--");
8371 else
8372 MSG_PUTS(" ");
8373 MSG_PUTS(p->fullname);
8374 if (!(p->flags & P_BOOL))
8375 {
8376 msg_putchar('=');
8377 /* put value string in NameBuff */
8378 option_value2string(p, opt_flags);
8379 msg_outtrans(NameBuff);
8380 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008381
8382 silent_mode = save_silent;
8383 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008384}
8385
8386/*
8387 * Write modified options as ":set" commands to a file.
8388 *
8389 * There are three values for "opt_flags":
8390 * OPT_GLOBAL: Write global option values and fresh values of
8391 * buffer-local options (used for start of a session
8392 * file).
8393 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8394 * curwin (used for a vimrc file).
8395 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8396 * and local values for window-local options of
8397 * curwin. Local values are also written when at the
8398 * default value, because a modeline or autocommand
8399 * may have set them when doing ":edit file" and the
8400 * user has set them back at the default or fresh
8401 * value.
8402 * When "local_only" is TRUE, don't write fresh
8403 * values, only local values (for ":mkview").
8404 * (fresh value = value used for a new buffer or window for a local option).
8405 *
8406 * Return FAIL on error, OK otherwise.
8407 */
8408 int
8409makeset(fd, opt_flags, local_only)
8410 FILE *fd;
8411 int opt_flags;
8412 int local_only;
8413{
8414 struct vimoption *p;
8415 char_u *varp; /* currently used value */
8416 char_u *varp_fresh; /* local value */
8417 char_u *varp_local = NULL; /* fresh value */
8418 char *cmd;
8419 int round;
8420
8421 /*
8422 * The options that don't have a default (terminal name, columns, lines)
8423 * are never written. Terminal options are also not written.
8424 */
8425 for (p = &options[0]; !istermoption(p); p++)
8426 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
8427 {
8428 /* skip global option when only doing locals */
8429 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8430 continue;
8431
8432 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8433 * file, they are always buffer-specific. */
8434 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8435 continue;
8436
8437 /* Global values are only written when not at the default value. */
8438 varp = get_varp_scope(p, opt_flags);
8439 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8440 continue;
8441
8442 round = 2;
8443 if (p->indir != PV_NONE)
8444 {
8445 if (p->var == VAR_WIN)
8446 {
8447 /* skip window-local option when only doing globals */
8448 if (!(opt_flags & OPT_LOCAL))
8449 continue;
8450 /* When fresh value of window-local option is not at the
8451 * default, need to write it too. */
8452 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8453 {
8454 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8455 if (!optval_default(p, varp_fresh))
8456 {
8457 round = 1;
8458 varp_local = varp;
8459 varp = varp_fresh;
8460 }
8461 }
8462 }
8463 }
8464
8465 /* Round 1: fresh value for window-local options.
8466 * Round 2: other values */
8467 for ( ; round <= 2; varp = varp_local, ++round)
8468 {
8469 if (round == 1 || (opt_flags & OPT_GLOBAL))
8470 cmd = "set";
8471 else
8472 cmd = "setlocal";
8473
8474 if (p->flags & P_BOOL)
8475 {
8476 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8477 return FAIL;
8478 }
8479 else if (p->flags & P_NUM)
8480 {
8481 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8482 return FAIL;
8483 }
8484 else /* P_STRING */
8485 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008486#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8487 int do_endif = FALSE;
8488
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489 /* Don't set 'syntax' and 'filetype' again if the value is
8490 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008491 if (
8492# if defined(FEAT_SYN_HL)
8493 p->indir == PV_SYN
8494# if defined(FEAT_AUTOCMD)
8495 ||
8496# endif
8497# endif
8498# if defined(FEAT_AUTOCMD)
8499 p->indir == PV_FT)
8500# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008501 {
8502 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8503 *(char_u **)(varp)) < 0
8504 || put_eol(fd) < 0)
8505 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008506 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008508#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8510 (p->flags & P_EXPAND) != 0) == FAIL)
8511 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008512#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8513 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008514 {
8515 if (put_line(fd, "endif") == FAIL)
8516 return FAIL;
8517 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008518#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519 }
8520 }
8521 }
8522 return OK;
8523}
8524
8525#if defined(FEAT_FOLDING) || defined(PROTO)
8526/*
8527 * Generate set commands for the local fold options only. Used when
8528 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8529 */
8530 int
8531makefoldset(fd)
8532 FILE *fd;
8533{
8534 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8535# ifdef FEAT_EVAL
8536 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8537 == FAIL
8538# endif
8539 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8540 == FAIL
8541 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8542 == FAIL
8543 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8544 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8545 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8546 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8547 )
8548 return FAIL;
8549
8550 return OK;
8551}
8552#endif
8553
8554 static int
8555put_setstring(fd, cmd, name, valuep, expand)
8556 FILE *fd;
8557 char *cmd;
8558 char *name;
8559 char_u **valuep;
8560 int expand;
8561{
8562 char_u *s;
8563 char_u buf[MAXPATHL];
8564
8565 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8566 return FAIL;
8567 if (*valuep != NULL)
8568 {
8569 /* Output 'pastetoggle' as key names. For other
8570 * options some characters have to be escaped with
8571 * CTRL-V or backslash */
8572 if (valuep == &p_pt)
8573 {
8574 s = *valuep;
8575 while (*s != NUL)
8576 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8577 return FAIL;
8578 }
8579 else if (expand)
8580 {
8581 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8582 if (put_escstr(fd, buf, 2) == FAIL)
8583 return FAIL;
8584 }
8585 else if (put_escstr(fd, *valuep, 2) == FAIL)
8586 return FAIL;
8587 }
8588 if (put_eol(fd) < 0)
8589 return FAIL;
8590 return OK;
8591}
8592
8593 static int
8594put_setnum(fd, cmd, name, valuep)
8595 FILE *fd;
8596 char *cmd;
8597 char *name;
8598 long *valuep;
8599{
8600 long wc;
8601
8602 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8603 return FAIL;
8604 if (wc_use_keyname((char_u *)valuep, &wc))
8605 {
8606 /* print 'wildchar' and 'wildcharm' as a key name */
8607 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8608 return FAIL;
8609 }
8610 else if (fprintf(fd, "%ld", *valuep) < 0)
8611 return FAIL;
8612 if (put_eol(fd) < 0)
8613 return FAIL;
8614 return OK;
8615}
8616
8617 static int
8618put_setbool(fd, cmd, name, value)
8619 FILE *fd;
8620 char *cmd;
8621 char *name;
8622 int value;
8623{
8624 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8625 || put_eol(fd) < 0)
8626 return FAIL;
8627 return OK;
8628}
8629
8630/*
8631 * Clear all the terminal options.
8632 * If the option has been allocated, free the memory.
8633 * Terminal options are never hidden or indirect.
8634 */
8635 void
8636clear_termoptions()
8637{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638 /*
8639 * Reset a few things before clearing the old options. This may cause
8640 * outputting a few things that the terminal doesn't understand, but the
8641 * screen will be cleared later, so this is OK.
8642 */
8643#ifdef FEAT_MOUSE_TTY
8644 mch_setmouse(FALSE); /* switch mouse off */
8645#endif
8646#ifdef FEAT_TITLE
8647 mch_restore_title(3); /* restore window titles */
8648#endif
8649#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8650 /* When starting the GUI close the display opened for the clipboard.
8651 * After restoring the title, because that will need the display. */
8652 if (gui.starting)
8653 clear_xterm_clip();
8654#endif
8655#ifdef WIN3264
8656 /*
8657 * Check if this is allowed now.
8658 */
8659 if (can_end_termcap_mode(FALSE) == TRUE)
8660#endif
8661 stoptermcap(); /* stop termcap mode */
8662
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008663 free_termoptions();
8664}
8665
8666 void
8667free_termoptions()
8668{
8669 struct vimoption *p;
8670
Bram Moolenaar071d4272004-06-13 20:20:40 +00008671 for (p = &options[0]; p->fullname != NULL; p++)
8672 if (istermoption(p))
8673 {
8674 if (p->flags & P_ALLOCED)
8675 free_string_option(*(char_u **)(p->var));
8676 if (p->flags & P_DEF_ALLOCED)
8677 free_string_option(p->def_val[VI_DEFAULT]);
8678 *(char_u **)(p->var) = empty_option;
8679 p->def_val[VI_DEFAULT] = empty_option;
8680 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8681 }
8682 clear_termcodes();
8683}
8684
8685/*
8686 * Set the terminal option defaults to the current value.
8687 * Used after setting the terminal name.
8688 */
8689 void
8690set_term_defaults()
8691{
8692 struct vimoption *p;
8693
8694 for (p = &options[0]; p->fullname != NULL; p++)
8695 {
8696 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8697 {
8698 if (p->flags & P_DEF_ALLOCED)
8699 {
8700 free_string_option(p->def_val[VI_DEFAULT]);
8701 p->flags &= ~P_DEF_ALLOCED;
8702 }
8703 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8704 if (p->flags & P_ALLOCED)
8705 {
8706 p->flags |= P_DEF_ALLOCED;
8707 p->flags &= ~P_ALLOCED; /* don't free the value now */
8708 }
8709 }
8710 }
8711}
8712
8713/*
8714 * return TRUE if 'p' starts with 't_'
8715 */
8716 static int
8717istermoption(p)
8718 struct vimoption *p;
8719{
8720 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8721}
8722
8723/*
8724 * Compute columns for ruler and shown command. 'sc_col' is also used to
8725 * decide what the maximum length of a message on the status line can be.
8726 * If there is a status line for the last window, 'sc_col' is independent
8727 * of 'ru_col'.
8728 */
8729
8730#define COL_RULER 17 /* columns needed by standard ruler */
8731
8732 void
8733comp_col()
8734{
8735#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8736 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8737
8738 sc_col = 0;
8739 ru_col = 0;
8740 if (p_ru)
8741 {
8742#ifdef FEAT_STL_OPT
8743 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8744#else
8745 ru_col = COL_RULER + 1;
8746#endif
8747 /* no last status line, adjust sc_col */
8748 if (!last_has_status)
8749 sc_col = ru_col;
8750 }
8751 if (p_sc)
8752 {
8753 sc_col += SHOWCMD_COLS;
8754 if (!p_ru || last_has_status) /* no need for separating space */
8755 ++sc_col;
8756 }
8757 sc_col = Columns - sc_col;
8758 ru_col = Columns - ru_col;
8759 if (sc_col <= 0) /* screen too narrow, will become a mess */
8760 sc_col = 1;
8761 if (ru_col <= 0)
8762 ru_col = 1;
8763#else
8764 sc_col = Columns;
8765 ru_col = Columns;
8766#endif
8767}
8768
8769/*
8770 * Get pointer to option variable, depending on local or global scope.
8771 */
8772 static char_u *
8773get_varp_scope(p, opt_flags)
8774 struct vimoption *p;
8775 int opt_flags;
8776{
8777 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8778 {
8779 if (p->var == VAR_WIN)
8780 return (char_u *)GLOBAL_WO(get_varp(p));
8781 return p->var;
8782 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008783 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784 {
8785 switch ((int)p->indir)
8786 {
8787#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008788 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
8789 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
8790 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008792 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
8793 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
8794 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008795 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008796 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008798 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
8799 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800#endif
8801#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008802 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
8803 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00008805#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
8806 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
8807#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008808#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008809 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008811 }
8812 return NULL; /* "cannot happen" */
8813 }
8814 return get_varp(p);
8815}
8816
8817/*
8818 * Get pointer to option variable.
8819 */
8820 static char_u *
8821get_varp(p)
8822 struct vimoption *p;
8823{
8824 /* hidden option, always return NULL */
8825 if (p->var == NULL)
8826 return NULL;
8827
8828 switch ((int)p->indir)
8829 {
8830 case PV_NONE: return p->var;
8831
8832 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008833 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008835 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008837 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008839 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008841 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008842 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8843#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008844 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008846 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8848#endif
8849#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008850 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008852 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8854#endif
8855#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008856 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008858 case PV_GP: return *curbuf->b_p_gp != NUL
8859 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8860 case PV_MP: return *curbuf->b_p_mp != NUL
8861 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00008863#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
8864 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
8865 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
8866#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008867#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008868 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008869 ? (char_u *)&(curwin->w_p_stl) : p->var;
8870#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008871
8872#ifdef FEAT_ARABIC
8873 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8874#endif
8875 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008876#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00008877 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8878#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008879#ifdef FEAT_SYN_HL
8880 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
8881 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
8882#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008883#ifdef FEAT_DIFF
8884 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8885#endif
8886#ifdef FEAT_FOLDING
8887 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8888 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8889 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8890 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8891 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8892 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8893 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8894# ifdef FEAT_EVAL
8895 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8896 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8897# endif
8898 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8899#endif
8900 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008901#ifdef FEAT_LINEBREAK
8902 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8903#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008904#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8906#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00008907#ifdef FEAT_VERTSPLIT
8908 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
8909#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8911 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8912#endif
8913#ifdef FEAT_RIGHTLEFT
8914 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8915 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8916#endif
8917 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8918 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8919#ifdef FEAT_LINEBREAK
8920 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8921#endif
8922#ifdef FEAT_SCROLLBIND
8923 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8924#endif
8925
8926 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8927 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8928#ifdef FEAT_MBYTE
8929 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8930#endif
8931#if defined(FEAT_QUICKFIX)
8932 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8933 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8934#endif
8935 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8936 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8937#ifdef FEAT_CINDENT
8938 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8939 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8940 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8941#endif
8942#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8943 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8944#endif
8945#ifdef FEAT_COMMENTS
8946 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8947#endif
8948#ifdef FEAT_FOLDING
8949 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8950#endif
8951#ifdef FEAT_INS_EXPAND
8952 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8953#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008954#ifdef FEAT_COMPL_FUNC
8955 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008956 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008958 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8959 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8960#ifdef FEAT_MBYTE
8961 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8962#endif
8963 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8964#ifdef FEAT_AUTOCMD
8965 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8966#endif
8967 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008968 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008969 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8970 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8971 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8972 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8973#ifdef FEAT_FIND_ID
8974# ifdef FEAT_EVAL
8975 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8976# endif
8977#endif
8978#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8979 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8980 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8981#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008982#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008983 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
8984#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985#ifdef FEAT_CRYPT
8986 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8987#endif
8988#ifdef FEAT_LISP
8989 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8990#endif
8991 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8992 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8993 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8994 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8995 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8996#ifdef FEAT_OSFILETYPE
8997 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8998#endif
8999 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009000#ifdef FEAT_TEXTOBJ
9001 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009003 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9004#ifdef FEAT_SMARTINDENT
9005 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9006#endif
9007#ifndef SHORT_FNAME
9008 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9009#endif
9010 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9011#ifdef FEAT_SEARCHPATH
9012 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9013#endif
9014 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9015#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009016 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009017 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9018#endif
9019#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009020 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009021 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009022 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009023#endif
9024 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9025 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9026 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9027 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9028 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9029#ifdef FEAT_KEYMAP
9030 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9031#endif
9032 default: EMSG(_("E356: get_varp ERROR"));
9033 }
9034 /* always return a valid pointer to avoid a crash! */
9035 return (char_u *)&(curbuf->b_p_wm);
9036}
9037
9038/*
9039 * Get the value of 'equalprg', either the buffer-local one or the global one.
9040 */
9041 char_u *
9042get_equalprg()
9043{
9044 if (*curbuf->b_p_ep == NUL)
9045 return p_ep;
9046 return curbuf->b_p_ep;
9047}
9048
9049#if defined(FEAT_WINDOWS) || defined(PROTO)
9050/*
9051 * Copy options from one window to another.
9052 * Used when splitting a window.
9053 */
9054 void
9055win_copy_options(wp_from, wp_to)
9056 win_T *wp_from;
9057 win_T *wp_to;
9058{
9059 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9060 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9061# ifdef FEAT_RIGHTLEFT
9062# ifdef FEAT_FKMAP
9063 /* Is this right? */
9064 wp_to->w_farsi = wp_from->w_farsi;
9065# endif
9066# endif
9067}
9068#endif
9069
9070/*
9071 * Copy the options from one winopt_T to another.
9072 * Doesn't free the old option values in "to", use clear_winopt() for that.
9073 * The 'scroll' option is not copied, because it depends on the window height.
9074 * The 'previewwindow' option is reset, there can be only one preview window.
9075 */
9076 void
9077copy_winopt(from, to)
9078 winopt_T *from;
9079 winopt_T *to;
9080{
9081#ifdef FEAT_ARABIC
9082 to->wo_arab = from->wo_arab;
9083#endif
9084 to->wo_list = from->wo_list;
9085 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009086#ifdef FEAT_LINEBREAK
9087 to->wo_nuw = from->wo_nuw;
9088#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009089#ifdef FEAT_RIGHTLEFT
9090 to->wo_rl = from->wo_rl;
9091 to->wo_rlc = vim_strsave(from->wo_rlc);
9092#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009093#ifdef FEAT_STL_OPT
9094 to->wo_stl = vim_strsave(from->wo_stl);
9095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 to->wo_wrap = from->wo_wrap;
9097#ifdef FEAT_LINEBREAK
9098 to->wo_lbr = from->wo_lbr;
9099#endif
9100#ifdef FEAT_SCROLLBIND
9101 to->wo_scb = from->wo_scb;
9102#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009103#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009104 to->wo_spell = from->wo_spell;
9105#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009106#ifdef FEAT_SYN_HL
9107 to->wo_cuc = from->wo_cuc;
9108 to->wo_cul = from->wo_cul;
9109#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009110#ifdef FEAT_DIFF
9111 to->wo_diff = from->wo_diff;
9112#endif
9113#ifdef FEAT_FOLDING
9114 to->wo_fdc = from->wo_fdc;
9115 to->wo_fen = from->wo_fen;
9116 to->wo_fdi = vim_strsave(from->wo_fdi);
9117 to->wo_fml = from->wo_fml;
9118 to->wo_fdl = from->wo_fdl;
9119 to->wo_fdm = vim_strsave(from->wo_fdm);
9120 to->wo_fdn = from->wo_fdn;
9121# ifdef FEAT_EVAL
9122 to->wo_fde = vim_strsave(from->wo_fde);
9123 to->wo_fdt = vim_strsave(from->wo_fdt);
9124# endif
9125 to->wo_fmr = vim_strsave(from->wo_fmr);
9126#endif
9127 check_winopt(to); /* don't want NULL pointers */
9128}
9129
9130/*
9131 * Check string options in a window for a NULL value.
9132 */
9133 void
9134check_win_options(win)
9135 win_T *win;
9136{
9137 check_winopt(&win->w_onebuf_opt);
9138 check_winopt(&win->w_allbuf_opt);
9139}
9140
9141/*
9142 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9143 */
9144/*ARGSUSED*/
9145 void
9146check_winopt(wop)
9147 winopt_T *wop;
9148{
9149#ifdef FEAT_FOLDING
9150 check_string_option(&wop->wo_fdi);
9151 check_string_option(&wop->wo_fdm);
9152# ifdef FEAT_EVAL
9153 check_string_option(&wop->wo_fde);
9154 check_string_option(&wop->wo_fdt);
9155# endif
9156 check_string_option(&wop->wo_fmr);
9157#endif
9158#ifdef FEAT_RIGHTLEFT
9159 check_string_option(&wop->wo_rlc);
9160#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009161#ifdef FEAT_STL_OPT
9162 check_string_option(&wop->wo_stl);
9163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009164}
9165
9166/*
9167 * Free the allocated memory inside a winopt_T.
9168 */
9169/*ARGSUSED*/
9170 void
9171clear_winopt(wop)
9172 winopt_T *wop;
9173{
9174#ifdef FEAT_FOLDING
9175 clear_string_option(&wop->wo_fdi);
9176 clear_string_option(&wop->wo_fdm);
9177# ifdef FEAT_EVAL
9178 clear_string_option(&wop->wo_fde);
9179 clear_string_option(&wop->wo_fdt);
9180# endif
9181 clear_string_option(&wop->wo_fmr);
9182#endif
9183#ifdef FEAT_RIGHTLEFT
9184 clear_string_option(&wop->wo_rlc);
9185#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009186#ifdef FEAT_STL_OPT
9187 clear_string_option(&wop->wo_stl);
9188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009189}
9190
9191/*
9192 * Copy global option values to local options for one buffer.
9193 * Used when creating a new buffer and sometimes when entering a buffer.
9194 * flags:
9195 * BCO_ENTER We will enter the buf buffer.
9196 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9197 * appropriate.
9198 * BCO_NOHELP Don't copy the values to a help buffer.
9199 */
9200 void
9201buf_copy_options(buf, flags)
9202 buf_T *buf;
9203 int flags;
9204{
9205 int should_copy = TRUE;
9206 char_u *save_p_isk = NULL; /* init for GCC */
9207 int dont_do_help;
9208 int did_isk = FALSE;
9209
9210 /*
9211 * Don't do anything of the buffer is invalid.
9212 */
9213 if (buf == NULL || !buf_valid(buf))
9214 return;
9215
9216 /*
9217 * Skip this when the option defaults have not been set yet. Happens when
9218 * main() allocates the first buffer.
9219 */
9220 if (p_cpo != NULL)
9221 {
9222 /*
9223 * Always copy when entering and 'cpo' contains 'S'.
9224 * Don't copy when already initialized.
9225 * Don't copy when 'cpo' contains 's' and not entering.
9226 * 'S' BCO_ENTER initialized 's' should_copy
9227 * yes yes X X TRUE
9228 * yes no yes X FALSE
9229 * no X yes X FALSE
9230 * X no no yes FALSE
9231 * X no no no TRUE
9232 * no yes no X TRUE
9233 */
9234 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9235 && (buf->b_p_initialized
9236 || (!(flags & BCO_ENTER)
9237 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9238 should_copy = FALSE;
9239
9240 if (should_copy || (flags & BCO_ALWAYS))
9241 {
9242 /* Don't copy the options specific to a help buffer when
9243 * BCO_NOHELP is given or the options were initialized already
9244 * (jumping back to a help file with CTRL-T or CTRL-O) */
9245 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9246 || buf->b_p_initialized;
9247 if (dont_do_help) /* don't free b_p_isk */
9248 {
9249 save_p_isk = buf->b_p_isk;
9250 buf->b_p_isk = NULL;
9251 }
9252 /*
9253 * Always free the allocated strings.
9254 * If not already initialized, set 'readonly' and copy 'fileformat'.
9255 */
9256 if (!buf->b_p_initialized)
9257 {
9258 free_buf_options(buf, TRUE);
9259 buf->b_p_ro = FALSE; /* don't copy readonly */
9260 buf->b_p_tx = p_tx;
9261#ifdef FEAT_MBYTE
9262 buf->b_p_fenc = vim_strsave(p_fenc);
9263#endif
9264 buf->b_p_ff = vim_strsave(p_ff);
9265#if defined(FEAT_QUICKFIX)
9266 buf->b_p_bh = empty_option;
9267 buf->b_p_bt = empty_option;
9268#endif
9269 }
9270 else
9271 free_buf_options(buf, FALSE);
9272
9273 buf->b_p_ai = p_ai;
9274 buf->b_p_ai_nopaste = p_ai_nopaste;
9275 buf->b_p_sw = p_sw;
9276 buf->b_p_tw = p_tw;
9277 buf->b_p_tw_nopaste = p_tw_nopaste;
9278 buf->b_p_tw_nobin = p_tw_nobin;
9279 buf->b_p_wm = p_wm;
9280 buf->b_p_wm_nopaste = p_wm_nopaste;
9281 buf->b_p_wm_nobin = p_wm_nobin;
9282 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009283#ifdef FEAT_MBYTE
9284 buf->b_p_bomb = p_bomb;
9285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009286 buf->b_p_et = p_et;
9287 buf->b_p_et_nobin = p_et_nobin;
9288 buf->b_p_ml = p_ml;
9289 buf->b_p_ml_nobin = p_ml_nobin;
9290 buf->b_p_inf = p_inf;
9291 buf->b_p_swf = p_swf;
9292#ifdef FEAT_INS_EXPAND
9293 buf->b_p_cpt = vim_strsave(p_cpt);
9294#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009295#ifdef FEAT_COMPL_FUNC
9296 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009297 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009299 buf->b_p_sts = p_sts;
9300 buf->b_p_sts_nopaste = p_sts_nopaste;
9301#ifndef SHORT_FNAME
9302 buf->b_p_sn = p_sn;
9303#endif
9304#ifdef FEAT_COMMENTS
9305 buf->b_p_com = vim_strsave(p_com);
9306#endif
9307#ifdef FEAT_FOLDING
9308 buf->b_p_cms = vim_strsave(p_cms);
9309#endif
9310 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009311 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312 buf->b_p_nf = vim_strsave(p_nf);
9313 buf->b_p_mps = vim_strsave(p_mps);
9314#ifdef FEAT_SMARTINDENT
9315 buf->b_p_si = p_si;
9316#endif
9317 buf->b_p_ci = p_ci;
9318#ifdef FEAT_CINDENT
9319 buf->b_p_cin = p_cin;
9320 buf->b_p_cink = vim_strsave(p_cink);
9321 buf->b_p_cino = vim_strsave(p_cino);
9322#endif
9323#ifdef FEAT_AUTOCMD
9324 /* Don't copy 'filetype', it must be detected */
9325 buf->b_p_ft = empty_option;
9326#endif
9327#ifdef FEAT_OSFILETYPE
9328 buf->b_p_oft = vim_strsave(p_oft);
9329#endif
9330 buf->b_p_pi = p_pi;
9331#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9332 buf->b_p_cinw = vim_strsave(p_cinw);
9333#endif
9334#ifdef FEAT_LISP
9335 buf->b_p_lisp = p_lisp;
9336#endif
9337#ifdef FEAT_SYN_HL
9338 /* Don't copy 'syntax', it must be set */
9339 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009340 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009341#endif
9342#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009343 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009344 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009345 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009346 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347#endif
9348#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9349 buf->b_p_inde = vim_strsave(p_inde);
9350 buf->b_p_indk = vim_strsave(p_indk);
9351#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009352#if defined(FEAT_EVAL)
9353 buf->b_p_fex = vim_strsave(p_fex);
9354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355#ifdef FEAT_CRYPT
9356 buf->b_p_key = vim_strsave(p_key);
9357#endif
9358#ifdef FEAT_SEARCHPATH
9359 buf->b_p_sua = vim_strsave(p_sua);
9360#endif
9361#ifdef FEAT_KEYMAP
9362 buf->b_p_keymap = vim_strsave(p_keymap);
9363 buf->b_kmap_state |= KEYMAP_INIT;
9364#endif
9365 /* This isn't really an option, but copying the langmap and IME
9366 * state from the current buffer is better than resetting it. */
9367 buf->b_p_iminsert = p_iminsert;
9368 buf->b_p_imsearch = p_imsearch;
9369
9370 /* options that are normally global but also have a local value
9371 * are not copied, start using the global value */
9372 buf->b_p_ar = -1;
9373#ifdef FEAT_QUICKFIX
9374 buf->b_p_gp = empty_option;
9375 buf->b_p_mp = empty_option;
9376 buf->b_p_efm = empty_option;
9377#endif
9378 buf->b_p_ep = empty_option;
9379 buf->b_p_kp = empty_option;
9380 buf->b_p_path = empty_option;
9381 buf->b_p_tags = empty_option;
9382#ifdef FEAT_FIND_ID
9383 buf->b_p_def = empty_option;
9384 buf->b_p_inc = empty_option;
9385# ifdef FEAT_EVAL
9386 buf->b_p_inex = vim_strsave(p_inex);
9387# endif
9388#endif
9389#ifdef FEAT_INS_EXPAND
9390 buf->b_p_dict = empty_option;
9391 buf->b_p_tsr = empty_option;
9392#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009393#ifdef FEAT_TEXTOBJ
9394 buf->b_p_qe = vim_strsave(p_qe);
9395#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009396#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9397 buf->b_p_bexpr = empty_option;
9398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009399
9400 /*
9401 * Don't copy the options set by ex_help(), use the saved values,
9402 * when going from a help buffer to a non-help buffer.
9403 * Don't touch these at all when BCO_NOHELP is used and going from
9404 * or to a help buffer.
9405 */
9406 if (dont_do_help)
9407 buf->b_p_isk = save_p_isk;
9408 else
9409 {
9410 buf->b_p_isk = vim_strsave(p_isk);
9411 did_isk = TRUE;
9412 buf->b_p_ts = p_ts;
9413 buf->b_help = FALSE;
9414#ifdef FEAT_QUICKFIX
9415 if (buf->b_p_bt[0] == 'h')
9416 clear_string_option(&buf->b_p_bt);
9417#endif
9418 buf->b_p_ma = p_ma;
9419 }
9420 }
9421
9422 /*
9423 * When the options should be copied (ignoring BCO_ALWAYS), set the
9424 * flag that indicates that the options have been initialized.
9425 */
9426 if (should_copy)
9427 buf->b_p_initialized = TRUE;
9428 }
9429
9430 check_buf_options(buf); /* make sure we don't have NULLs */
9431 if (did_isk)
9432 (void)buf_init_chartab(buf, FALSE);
9433}
9434
9435/*
9436 * Reset the 'modifiable' option and its default value.
9437 */
9438 void
9439reset_modifiable()
9440{
9441 int opt_idx;
9442
9443 curbuf->b_p_ma = FALSE;
9444 p_ma = FALSE;
9445 opt_idx = findoption((char_u *)"ma");
9446 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9447}
9448
9449/*
9450 * Set the global value for 'iminsert' to the local value.
9451 */
9452 void
9453set_iminsert_global()
9454{
9455 p_iminsert = curbuf->b_p_iminsert;
9456}
9457
9458/*
9459 * Set the global value for 'imsearch' to the local value.
9460 */
9461 void
9462set_imsearch_global()
9463{
9464 p_imsearch = curbuf->b_p_imsearch;
9465}
9466
9467#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9468static int expand_option_idx = -1;
9469static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9470static int expand_option_flags = 0;
9471
9472 void
9473set_context_in_set_cmd(xp, arg, opt_flags)
9474 expand_T *xp;
9475 char_u *arg;
9476 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9477{
9478 int nextchar;
9479 long_u flags = 0; /* init for GCC */
9480 int opt_idx = 0; /* init for GCC */
9481 char_u *p;
9482 char_u *s;
9483 int is_term_option = FALSE;
9484 int key;
9485
9486 expand_option_flags = opt_flags;
9487
9488 xp->xp_context = EXPAND_SETTINGS;
9489 if (*arg == NUL)
9490 {
9491 xp->xp_pattern = arg;
9492 return;
9493 }
9494 p = arg + STRLEN(arg) - 1;
9495 if (*p == ' ' && *(p - 1) != '\\')
9496 {
9497 xp->xp_pattern = p + 1;
9498 return;
9499 }
9500 while (p > arg)
9501 {
9502 s = p;
9503 /* count number of backslashes before ' ' or ',' */
9504 if (*p == ' ' || *p == ',')
9505 {
9506 while (s > arg && *(s - 1) == '\\')
9507 --s;
9508 }
9509 /* break at a space with an even number of backslashes */
9510 if (*p == ' ' && ((p - s) & 1) == 0)
9511 {
9512 ++p;
9513 break;
9514 }
9515 --p;
9516 }
9517 if (STRNCMP(p, "no", 2) == 0)
9518 {
9519 xp->xp_context = EXPAND_BOOL_SETTINGS;
9520 p += 2;
9521 }
9522 if (STRNCMP(p, "inv", 3) == 0)
9523 {
9524 xp->xp_context = EXPAND_BOOL_SETTINGS;
9525 p += 3;
9526 }
9527 xp->xp_pattern = arg = p;
9528 if (*arg == '<')
9529 {
9530 while (*p != '>')
9531 if (*p++ == NUL) /* expand terminal option name */
9532 return;
9533 key = get_special_key_code(arg + 1);
9534 if (key == 0) /* unknown name */
9535 {
9536 xp->xp_context = EXPAND_NOTHING;
9537 return;
9538 }
9539 nextchar = *++p;
9540 is_term_option = TRUE;
9541 expand_option_name[2] = KEY2TERMCAP0(key);
9542 expand_option_name[3] = KEY2TERMCAP1(key);
9543 }
9544 else
9545 {
9546 if (p[0] == 't' && p[1] == '_')
9547 {
9548 p += 2;
9549 if (*p != NUL)
9550 ++p;
9551 if (*p == NUL)
9552 return; /* expand option name */
9553 nextchar = *++p;
9554 is_term_option = TRUE;
9555 expand_option_name[2] = p[-2];
9556 expand_option_name[3] = p[-1];
9557 }
9558 else
9559 {
9560 /* Allow * wildcard */
9561 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9562 p++;
9563 if (*p == NUL)
9564 return;
9565 nextchar = *p;
9566 *p = NUL;
9567 opt_idx = findoption(arg);
9568 *p = nextchar;
9569 if (opt_idx == -1 || options[opt_idx].var == NULL)
9570 {
9571 xp->xp_context = EXPAND_NOTHING;
9572 return;
9573 }
9574 flags = options[opt_idx].flags;
9575 if (flags & P_BOOL)
9576 {
9577 xp->xp_context = EXPAND_NOTHING;
9578 return;
9579 }
9580 }
9581 }
9582 /* handle "-=" and "+=" */
9583 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9584 {
9585 ++p;
9586 nextchar = '=';
9587 }
9588 if ((nextchar != '=' && nextchar != ':')
9589 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9590 {
9591 xp->xp_context = EXPAND_UNSUCCESSFUL;
9592 return;
9593 }
9594 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9595 {
9596 xp->xp_context = EXPAND_OLD_SETTING;
9597 if (is_term_option)
9598 expand_option_idx = -1;
9599 else
9600 expand_option_idx = opt_idx;
9601 xp->xp_pattern = p + 1;
9602 return;
9603 }
9604 xp->xp_context = EXPAND_NOTHING;
9605 if (is_term_option || (flags & P_NUM))
9606 return;
9607
9608 xp->xp_pattern = p + 1;
9609
9610 if (flags & P_EXPAND)
9611 {
9612 p = options[opt_idx].var;
9613 if (p == (char_u *)&p_bdir
9614 || p == (char_u *)&p_dir
9615 || p == (char_u *)&p_path
9616 || p == (char_u *)&p_rtp
9617#ifdef FEAT_SEARCHPATH
9618 || p == (char_u *)&p_cdpath
9619#endif
9620#ifdef FEAT_SESSION
9621 || p == (char_u *)&p_vdir
9622#endif
9623 )
9624 {
9625 xp->xp_context = EXPAND_DIRECTORIES;
9626 if (p == (char_u *)&p_path
9627#ifdef FEAT_SEARCHPATH
9628 || p == (char_u *)&p_cdpath
9629#endif
9630 )
9631 xp->xp_backslash = XP_BS_THREE;
9632 else
9633 xp->xp_backslash = XP_BS_ONE;
9634 }
9635 else
9636 {
9637 xp->xp_context = EXPAND_FILES;
9638 /* for 'tags' need three backslashes for a space */
9639 if (p == (char_u *)&p_tags)
9640 xp->xp_backslash = XP_BS_THREE;
9641 else
9642 xp->xp_backslash = XP_BS_ONE;
9643 }
9644 }
9645
9646 /* For an option that is a list of file names, find the start of the
9647 * last file name. */
9648 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9649 {
9650 /* count number of backslashes before ' ' or ',' */
9651 if (*p == ' ' || *p == ',')
9652 {
9653 s = p;
9654 while (s > xp->xp_pattern && *(s - 1) == '\\')
9655 --s;
9656 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9657 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9658 {
9659 xp->xp_pattern = p + 1;
9660 break;
9661 }
9662 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009663
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009664#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009665 /* for 'spellsuggest' start at "file:" */
9666 if (options[opt_idx].var == (char_u *)&p_sps
9667 && STRNCMP(p, "file:", 5) == 0)
9668 {
9669 xp->xp_pattern = p + 5;
9670 break;
9671 }
9672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009673 }
9674
9675 return;
9676}
9677
9678 int
9679ExpandSettings(xp, regmatch, num_file, file)
9680 expand_T *xp;
9681 regmatch_T *regmatch;
9682 int *num_file;
9683 char_u ***file;
9684{
9685 int num_normal = 0; /* Nr of matching non-term-code settings */
9686 int num_term = 0; /* Nr of matching terminal code settings */
9687 int opt_idx;
9688 int match;
9689 int count = 0;
9690 char_u *str;
9691 int loop;
9692 int is_term_opt;
9693 char_u name_buf[MAX_KEY_NAME_LEN];
9694 static char *(names[]) = {"all", "termcap"};
9695 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9696
9697 /* do this loop twice:
9698 * loop == 0: count the number of matching options
9699 * loop == 1: copy the matching options into allocated memory
9700 */
9701 for (loop = 0; loop <= 1; ++loop)
9702 {
9703 regmatch->rm_ic = ic;
9704 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9705 {
9706 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9707 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9708 {
9709 if (loop == 0)
9710 num_normal++;
9711 else
9712 (*file)[count++] = vim_strsave((char_u *)names[match]);
9713 }
9714 }
9715 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9716 opt_idx++)
9717 {
9718 if (options[opt_idx].var == NULL)
9719 continue;
9720 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9721 && !(options[opt_idx].flags & P_BOOL))
9722 continue;
9723 is_term_opt = istermoption(&options[opt_idx]);
9724 if (is_term_opt && num_normal > 0)
9725 continue;
9726 match = FALSE;
9727 if (vim_regexec(regmatch, str, (colnr_T)0)
9728 || (options[opt_idx].shortname != NULL
9729 && vim_regexec(regmatch,
9730 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9731 match = TRUE;
9732 else if (is_term_opt)
9733 {
9734 name_buf[0] = '<';
9735 name_buf[1] = 't';
9736 name_buf[2] = '_';
9737 name_buf[3] = str[2];
9738 name_buf[4] = str[3];
9739 name_buf[5] = '>';
9740 name_buf[6] = NUL;
9741 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9742 {
9743 match = TRUE;
9744 str = name_buf;
9745 }
9746 }
9747 if (match)
9748 {
9749 if (loop == 0)
9750 {
9751 if (is_term_opt)
9752 num_term++;
9753 else
9754 num_normal++;
9755 }
9756 else
9757 (*file)[count++] = vim_strsave(str);
9758 }
9759 }
9760 /*
9761 * Check terminal key codes, these are not in the option table
9762 */
9763 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9764 {
9765 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9766 {
9767 if (!isprint(str[0]) || !isprint(str[1]))
9768 continue;
9769
9770 name_buf[0] = 't';
9771 name_buf[1] = '_';
9772 name_buf[2] = str[0];
9773 name_buf[3] = str[1];
9774 name_buf[4] = NUL;
9775
9776 match = FALSE;
9777 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9778 match = TRUE;
9779 else
9780 {
9781 name_buf[0] = '<';
9782 name_buf[1] = 't';
9783 name_buf[2] = '_';
9784 name_buf[3] = str[0];
9785 name_buf[4] = str[1];
9786 name_buf[5] = '>';
9787 name_buf[6] = NUL;
9788
9789 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9790 match = TRUE;
9791 }
9792 if (match)
9793 {
9794 if (loop == 0)
9795 num_term++;
9796 else
9797 (*file)[count++] = vim_strsave(name_buf);
9798 }
9799 }
9800
9801 /*
9802 * Check special key names.
9803 */
9804 regmatch->rm_ic = TRUE; /* ignore case here */
9805 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9806 {
9807 name_buf[0] = '<';
9808 STRCPY(name_buf + 1, str);
9809 STRCAT(name_buf, ">");
9810
9811 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9812 {
9813 if (loop == 0)
9814 num_term++;
9815 else
9816 (*file)[count++] = vim_strsave(name_buf);
9817 }
9818 }
9819 }
9820 if (loop == 0)
9821 {
9822 if (num_normal > 0)
9823 *num_file = num_normal;
9824 else if (num_term > 0)
9825 *num_file = num_term;
9826 else
9827 return OK;
9828 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9829 if (*file == NULL)
9830 {
9831 *file = (char_u **)"";
9832 return FAIL;
9833 }
9834 }
9835 }
9836 return OK;
9837}
9838
9839 int
9840ExpandOldSetting(num_file, file)
9841 int *num_file;
9842 char_u ***file;
9843{
9844 char_u *var = NULL; /* init for GCC */
9845 char_u *buf;
9846
9847 *num_file = 0;
9848 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9849 if (*file == NULL)
9850 return FAIL;
9851
9852 /*
9853 * For a terminal key code expand_option_idx is < 0.
9854 */
9855 if (expand_option_idx < 0)
9856 {
9857 var = find_termcode(expand_option_name + 2);
9858 if (var == NULL)
9859 expand_option_idx = findoption(expand_option_name);
9860 }
9861
9862 if (expand_option_idx >= 0)
9863 {
9864 /* put string of option value in NameBuff */
9865 option_value2string(&options[expand_option_idx], expand_option_flags);
9866 var = NameBuff;
9867 }
9868 else if (var == NULL)
9869 var = (char_u *)"";
9870
9871 /* A backslash is required before some characters. This is the reverse of
9872 * what happens in do_set(). */
9873 buf = vim_strsave_escaped(var, escape_chars);
9874
9875 if (buf == NULL)
9876 {
9877 vim_free(*file);
9878 *file = NULL;
9879 return FAIL;
9880 }
9881
9882#ifdef BACKSLASH_IN_FILENAME
9883 /* For MS-Windows et al. we don't double backslashes at the start and
9884 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009885 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009886 if (var[0] == '\\' && var[1] == '\\'
9887 && expand_option_idx >= 0
9888 && (options[expand_option_idx].flags & P_EXPAND)
9889 && vim_isfilec(var[2])
9890 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9891 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892#endif
9893
9894 *file[0] = buf;
9895 *num_file = 1;
9896 return OK;
9897}
9898#endif
9899
9900/*
9901 * Get the value for the numeric or string option *opp in a nice format into
9902 * NameBuff[]. Must not be called with a hidden option!
9903 */
9904 static void
9905option_value2string(opp, opt_flags)
9906 struct vimoption *opp;
9907 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9908{
9909 char_u *varp;
9910
9911 varp = get_varp_scope(opp, opt_flags);
9912
9913 if (opp->flags & P_NUM)
9914 {
9915 long wc = 0;
9916
9917 if (wc_use_keyname(varp, &wc))
9918 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9919 else if (wc != 0)
9920 STRCPY(NameBuff, transchar((int)wc));
9921 else
9922 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9923 }
9924 else /* P_STRING */
9925 {
9926 varp = *(char_u **)(varp);
9927 if (varp == NULL) /* just in case */
9928 NameBuff[0] = NUL;
9929#ifdef FEAT_CRYPT
9930 /* don't show the actual value of 'key', only that it's set */
9931 if (opp->var == (char_u *)&p_key && *varp)
9932 STRCPY(NameBuff, "*****");
9933#endif
9934 else if (opp->flags & P_EXPAND)
9935 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9936 /* Translate 'pastetoggle' into special key names */
9937 else if ((char_u **)opp->var == &p_pt)
9938 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9939 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009940 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009941 }
9942}
9943
9944/*
9945 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9946 * printed as a keyname.
9947 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9948 */
9949 static int
9950wc_use_keyname(varp, wcp)
9951 char_u *varp;
9952 long *wcp;
9953{
9954 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9955 {
9956 *wcp = *(long *)varp;
9957 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9958 return TRUE;
9959 }
9960 return FALSE;
9961}
9962
9963#ifdef FEAT_LANGMAP
9964/*
9965 * Any character has an equivalent character. This is used for keyboards that
9966 * have a special language mode that sends characters above 128 (although
9967 * other characters can be translated too).
9968 */
9969
9970/*
9971 * char_u langmap_mapchar[256];
9972 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9973 * "translate" native lang chars in normal mode or some cases of
9974 * insert mode without having to tediously switch lang mode back&forth.
9975 */
9976
9977 static void
9978langmap_init()
9979{
9980 int i;
9981
9982 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9983 langmap_mapchar[i] = i;
9984}
9985
9986/*
9987 * Called when langmap option is set; the language map can be
9988 * changed at any time!
9989 */
9990 static void
9991langmap_set()
9992{
9993 char_u *p;
9994 char_u *p2;
9995 int from, to;
9996
9997 langmap_init(); /* back to one-to-one map first */
9998
9999 for (p = p_langmap; p[0] != NUL; )
10000 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010001 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10002 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003 {
10004 if (p2[0] == '\\' && p2[1] != NUL)
10005 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006 }
10007 if (p2[0] == ';')
10008 ++p2; /* abcd;ABCD form, p2 points to A */
10009 else
10010 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10011 while (p[0])
10012 {
10013 if (p[0] == '\\' && p[1] != NUL)
10014 ++p;
10015#ifdef FEAT_MBYTE
10016 from = (*mb_ptr2char)(p);
10017#else
10018 from = p[0];
10019#endif
10020 if (p2 == NULL)
10021 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010022 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010023 if (p[0] == '\\')
10024 ++p;
10025#ifdef FEAT_MBYTE
10026 to = (*mb_ptr2char)(p);
10027#else
10028 to = p[0];
10029#endif
10030 }
10031 else
10032 {
10033 if (p2[0] == '\\')
10034 ++p2;
10035#ifdef FEAT_MBYTE
10036 to = (*mb_ptr2char)(p2);
10037#else
10038 to = p2[0];
10039#endif
10040 }
10041 if (to == NUL)
10042 {
10043 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10044 transchar(from));
10045 return;
10046 }
10047 langmap_mapchar[from & 255] = to;
10048
10049 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010050 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010051 if (p2 == NULL)
10052 {
10053 if (p[0] == ',')
10054 {
10055 ++p;
10056 break;
10057 }
10058 }
10059 else
10060 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010061 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062 if (*p == ';')
10063 {
10064 p = p2;
10065 if (p[0] != NUL)
10066 {
10067 if (p[0] != ',')
10068 {
10069 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10070 return;
10071 }
10072 ++p;
10073 }
10074 break;
10075 }
10076 }
10077 }
10078 }
10079}
10080#endif
10081
10082/*
10083 * Return TRUE if format option 'x' is in effect.
10084 * Take care of no formatting when 'paste' is set.
10085 */
10086 int
10087has_format_option(x)
10088 int x;
10089{
10090 if (p_paste)
10091 return FALSE;
10092 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10093}
10094
10095/*
10096 * Return TRUE if "x" is present in 'shortmess' option, or
10097 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10098 */
10099 int
10100shortmess(x)
10101 int x;
10102{
10103 return ( vim_strchr(p_shm, x) != NULL
10104 || (vim_strchr(p_shm, 'a') != NULL
10105 && vim_strchr((char_u *)SHM_A, x) != NULL));
10106}
10107
10108/*
10109 * paste_option_changed() - Called after p_paste was set or reset.
10110 */
10111 static void
10112paste_option_changed()
10113{
10114 static int old_p_paste = FALSE;
10115 static int save_sm = 0;
10116#ifdef FEAT_CMDL_INFO
10117 static int save_ru = 0;
10118#endif
10119#ifdef FEAT_RIGHTLEFT
10120 static int save_ri = 0;
10121 static int save_hkmap = 0;
10122#endif
10123 buf_T *buf;
10124
10125 if (p_paste)
10126 {
10127 /*
10128 * Paste switched from off to on.
10129 * Save the current values, so they can be restored later.
10130 */
10131 if (!old_p_paste)
10132 {
10133 /* save options for each buffer */
10134 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10135 {
10136 buf->b_p_tw_nopaste = buf->b_p_tw;
10137 buf->b_p_wm_nopaste = buf->b_p_wm;
10138 buf->b_p_sts_nopaste = buf->b_p_sts;
10139 buf->b_p_ai_nopaste = buf->b_p_ai;
10140 }
10141
10142 /* save global options */
10143 save_sm = p_sm;
10144#ifdef FEAT_CMDL_INFO
10145 save_ru = p_ru;
10146#endif
10147#ifdef FEAT_RIGHTLEFT
10148 save_ri = p_ri;
10149 save_hkmap = p_hkmap;
10150#endif
10151 /* save global values for local buffer options */
10152 p_tw_nopaste = p_tw;
10153 p_wm_nopaste = p_wm;
10154 p_sts_nopaste = p_sts;
10155 p_ai_nopaste = p_ai;
10156 }
10157
10158 /*
10159 * Always set the option values, also when 'paste' is set when it is
10160 * already on.
10161 */
10162 /* set options for each buffer */
10163 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10164 {
10165 buf->b_p_tw = 0; /* textwidth is 0 */
10166 buf->b_p_wm = 0; /* wrapmargin is 0 */
10167 buf->b_p_sts = 0; /* softtabstop is 0 */
10168 buf->b_p_ai = 0; /* no auto-indent */
10169 }
10170
10171 /* set global options */
10172 p_sm = 0; /* no showmatch */
10173#ifdef FEAT_CMDL_INFO
10174# ifdef FEAT_WINDOWS
10175 if (p_ru)
10176 status_redraw_all(); /* redraw to remove the ruler */
10177# endif
10178 p_ru = 0; /* no ruler */
10179#endif
10180#ifdef FEAT_RIGHTLEFT
10181 p_ri = 0; /* no reverse insert */
10182 p_hkmap = 0; /* no Hebrew keyboard */
10183#endif
10184 /* set global values for local buffer options */
10185 p_tw = 0;
10186 p_wm = 0;
10187 p_sts = 0;
10188 p_ai = 0;
10189 }
10190
10191 /*
10192 * Paste switched from on to off: Restore saved values.
10193 */
10194 else if (old_p_paste)
10195 {
10196 /* restore options for each buffer */
10197 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10198 {
10199 buf->b_p_tw = buf->b_p_tw_nopaste;
10200 buf->b_p_wm = buf->b_p_wm_nopaste;
10201 buf->b_p_sts = buf->b_p_sts_nopaste;
10202 buf->b_p_ai = buf->b_p_ai_nopaste;
10203 }
10204
10205 /* restore global options */
10206 p_sm = save_sm;
10207#ifdef FEAT_CMDL_INFO
10208# ifdef FEAT_WINDOWS
10209 if (p_ru != save_ru)
10210 status_redraw_all(); /* redraw to draw the ruler */
10211# endif
10212 p_ru = save_ru;
10213#endif
10214#ifdef FEAT_RIGHTLEFT
10215 p_ri = save_ri;
10216 p_hkmap = save_hkmap;
10217#endif
10218 /* set global values for local buffer options */
10219 p_tw = p_tw_nopaste;
10220 p_wm = p_wm_nopaste;
10221 p_sts = p_sts_nopaste;
10222 p_ai = p_ai_nopaste;
10223 }
10224
10225 old_p_paste = p_paste;
10226}
10227
10228/*
10229 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10230 *
10231 * Reset 'compatible' and set the values for options that didn't get set yet
10232 * to the Vim defaults.
10233 * Don't do this if the 'compatible' option has been set or reset before.
10234 */
10235 void
10236vimrc_found()
10237{
10238 int opt_idx;
10239
10240 if (!option_was_set((char_u *)"cp"))
10241 {
10242 p_cp = FALSE;
10243 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10244 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10245 set_option_default(opt_idx, OPT_FREE, FALSE);
10246 didset_options();
10247 }
10248}
10249
10250/*
10251 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10252 */
10253 void
10254change_compatible(on)
10255 int on;
10256{
10257 if (p_cp != on)
10258 {
10259 p_cp = on;
10260 compatible_set();
10261 }
10262 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
10263}
10264
10265/*
10266 * Return TRUE when option "name" has been set.
10267 */
10268 int
10269option_was_set(name)
10270 char_u *name;
10271{
10272 int idx;
10273
10274 idx = findoption(name);
10275 if (idx < 0) /* unknown option */
10276 return FALSE;
10277 if (options[idx].flags & P_WAS_SET)
10278 return TRUE;
10279 return FALSE;
10280}
10281
10282/*
10283 * compatible_set() - Called when 'compatible' has been set or unset.
10284 *
10285 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10286 * flag) to a Vi compatible value.
10287 * When 'compatible' is unset: Set all options that have a different default
10288 * for Vim (without the P_VI_DEF flag) to that default.
10289 */
10290 static void
10291compatible_set()
10292{
10293 int opt_idx;
10294
10295 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10296 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10297 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10298 set_option_default(opt_idx, OPT_FREE, p_cp);
10299 didset_options();
10300}
10301
10302#ifdef FEAT_LINEBREAK
10303
10304# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10305 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010306 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307# endif
10308
10309/*
10310 * fill_breakat_flags() -- called when 'breakat' changes value.
10311 */
10312 static void
10313fill_breakat_flags()
10314{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010315 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316 int i;
10317
10318 for (i = 0; i < 256; i++)
10319 breakat_flags[i] = FALSE;
10320
10321 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010322 for (p = p_breakat; *p; p++)
10323 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324}
10325
10326# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010327 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010328# endif
10329
10330#endif
10331
10332/*
10333 * Check an option that can be a range of string values.
10334 *
10335 * Return OK for correct value, FAIL otherwise.
10336 * Empty is always OK.
10337 */
10338 static int
10339check_opt_strings(val, values, list)
10340 char_u *val;
10341 char **values;
10342 int list; /* when TRUE: accept a list of values */
10343{
10344 return opt_strings_flags(val, values, NULL, list);
10345}
10346
10347/*
10348 * Handle an option that can be a range of string values.
10349 * Set a flag in "*flagp" for each string present.
10350 *
10351 * Return OK for correct value, FAIL otherwise.
10352 * Empty is always OK.
10353 */
10354 static int
10355opt_strings_flags(val, values, flagp, list)
10356 char_u *val; /* new value */
10357 char **values; /* array of valid string values */
10358 unsigned *flagp;
10359 int list; /* when TRUE: accept a list of values */
10360{
10361 int i;
10362 int len;
10363 unsigned new_flags = 0;
10364
10365 while (*val)
10366 {
10367 for (i = 0; ; ++i)
10368 {
10369 if (values[i] == NULL) /* val not found in values[] */
10370 return FAIL;
10371
10372 len = (int)STRLEN(values[i]);
10373 if (STRNCMP(values[i], val, len) == 0
10374 && ((list && val[len] == ',') || val[len] == NUL))
10375 {
10376 val += len + (val[len] == ',');
10377 new_flags |= (1 << i);
10378 break; /* check next item in val list */
10379 }
10380 }
10381 }
10382 if (flagp != NULL)
10383 *flagp = new_flags;
10384
10385 return OK;
10386}
10387
10388/*
10389 * Read the 'wildmode' option, fill wim_flags[].
10390 */
10391 static int
10392check_opt_wim()
10393{
10394 char_u new_wim_flags[4];
10395 char_u *p;
10396 int i;
10397 int idx = 0;
10398
10399 for (i = 0; i < 4; ++i)
10400 new_wim_flags[i] = 0;
10401
10402 for (p = p_wim; *p; ++p)
10403 {
10404 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10405 ;
10406 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10407 return FAIL;
10408 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10409 new_wim_flags[idx] |= WIM_LONGEST;
10410 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10411 new_wim_flags[idx] |= WIM_FULL;
10412 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10413 new_wim_flags[idx] |= WIM_LIST;
10414 else
10415 return FAIL;
10416 p += i;
10417 if (*p == NUL)
10418 break;
10419 if (*p == ',')
10420 {
10421 if (idx == 3)
10422 return FAIL;
10423 ++idx;
10424 }
10425 }
10426
10427 /* fill remaining entries with last flag */
10428 while (idx < 3)
10429 {
10430 new_wim_flags[idx + 1] = new_wim_flags[idx];
10431 ++idx;
10432 }
10433
10434 /* only when there are no errors, wim_flags[] is changed */
10435 for (i = 0; i < 4; ++i)
10436 wim_flags[i] = new_wim_flags[i];
10437 return OK;
10438}
10439
10440/*
10441 * Check if backspacing over something is allowed.
10442 */
10443 int
10444can_bs(what)
10445 int what; /* BS_INDENT, BS_EOL or BS_START */
10446{
10447 switch (*p_bs)
10448 {
10449 case '2': return TRUE;
10450 case '1': return (what != BS_START);
10451 case '0': return FALSE;
10452 }
10453 return vim_strchr(p_bs, what) != NULL;
10454}
10455
10456/*
10457 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10458 * the file must be considered changed when the value is different.
10459 */
10460 void
10461save_file_ff(buf)
10462 buf_T *buf;
10463{
10464 buf->b_start_ffc = *buf->b_p_ff;
10465 buf->b_start_eol = buf->b_p_eol;
10466#ifdef FEAT_MBYTE
10467 /* Only use free/alloc when necessary, they take time. */
10468 if (buf->b_start_fenc == NULL
10469 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10470 {
10471 vim_free(buf->b_start_fenc);
10472 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10473 }
10474#endif
10475}
10476
10477/*
10478 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10479 * from when editing started (save_file_ff() called).
10480 * Also when 'endofline' was changed and 'binary' is set.
10481 * Don't consider a new, empty buffer to be changed.
10482 */
10483 int
10484file_ff_differs(buf)
10485 buf_T *buf;
10486{
10487 if ((buf->b_flags & BF_NEW)
10488 && buf->b_ml.ml_line_count == 1
10489 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10490 return FALSE;
10491 if (buf->b_start_ffc != *buf->b_p_ff)
10492 return TRUE;
10493 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10494 return TRUE;
10495#ifdef FEAT_MBYTE
10496 if (buf->b_start_fenc == NULL)
10497 return (*buf->b_p_fenc != NUL);
10498 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10499#else
10500 return FALSE;
10501#endif
10502}
10503
10504/*
10505 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10506 */
10507 int
10508check_ff_value(p)
10509 char_u *p;
10510{
10511 return check_opt_strings(p, p_ff_values, FALSE);
10512}