blob: 73933b4dd10ec4ab3ddf7a39f83d386d8ab0ada8 [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,
652 (char_u *)&p_cmp, PV_NONE,
653 {(char_u *)"internal,keepascii", (char_u *)0L}
654 },
655 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
656#ifdef FEAT_SEARCHPATH
657 (char_u *)&p_cdpath, PV_NONE,
658 {(char_u *)",,", (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
663 },
664 {"cedit", NULL, P_STRING,
665#ifdef FEAT_CMDWIN
666 (char_u *)&p_cedit, PV_NONE,
667 {(char_u *)"", (char_u *)CTRL_F_STR}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)0L, (char_u *)0L}
671#endif
672 },
673 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
674#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
675 (char_u *)&p_ccv, PV_NONE,
676 {(char_u *)"", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
681 },
682 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
683#ifdef FEAT_CINDENT
684 (char_u *)&p_cin, PV_CIN,
685#else
686 (char_u *)NULL, PV_NONE,
687#endif
688 {(char_u *)FALSE, (char_u *)0L}},
689 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
690#ifdef FEAT_CINDENT
691 (char_u *)&p_cink, PV_CINK,
692 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
697 },
698 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
699#ifdef FEAT_CINDENT
700 (char_u *)&p_cino, PV_CINO,
701#else
702 (char_u *)NULL, PV_NONE,
703#endif
704 {(char_u *)"", (char_u *)0L}},
705 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
706#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
707 (char_u *)&p_cinw, PV_CINW,
708 {(char_u *)"if,else,while,do,for,switch",
709 (char_u *)0L}
710#else
711 (char_u *)NULL, PV_NONE,
712 {(char_u *)0L, (char_u *)0L}
713#endif
714 },
715 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
716#ifdef FEAT_CLIPBOARD
717 (char_u *)&p_cb, PV_NONE,
718# ifdef FEAT_XCLIPBOARD
719 {(char_u *)"autoselect,exclude:cons\\|linux",
720 (char_u *)0L}
721# else
722 {(char_u *)"", (char_u *)0L}
723# endif
724#else
725 (char_u *)NULL, PV_NONE,
726 {(char_u *)"", (char_u *)0L}
727#endif
728 },
729 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
730 (char_u *)&p_ch, PV_NONE,
731 {(char_u *)1L, (char_u *)0L}},
732 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
733#ifdef FEAT_CMDWIN
734 (char_u *)&p_cwh, PV_NONE,
735#else
736 (char_u *)NULL, PV_NONE,
737#endif
738 {(char_u *)7L, (char_u *)0L}},
739 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
740 (char_u *)&Columns, PV_NONE,
741 {(char_u *)80L, (char_u *)0L}},
742 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
743#ifdef FEAT_COMMENTS
744 (char_u *)&p_com, PV_COM,
745 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
746 (char_u *)0L}
747#else
748 (char_u *)NULL, PV_NONE,
749 {(char_u *)0L, (char_u *)0L}
750#endif
751 },
752 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
753#ifdef FEAT_FOLDING
754 (char_u *)&p_cms, PV_CMS,
755 {(char_u *)"/*%s*/", (char_u *)0L}
756#else
757 (char_u *)NULL, PV_NONE,
758 {(char_u *)0L, (char_u *)0L}
759#endif
760 },
761 {"compatible", "cp", P_BOOL|P_RALL,
762 (char_u *)&p_cp, PV_NONE,
763 {(char_u *)TRUE, (char_u *)FALSE}},
764 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
765#ifdef FEAT_INS_EXPAND
766 (char_u *)&p_cpt, PV_CPT,
767 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
768#else
769 (char_u *)NULL, PV_NONE,
770 {(char_u *)0L, (char_u *)0L}
771#endif
772 },
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000773 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
774#ifdef FEAT_COMPL_FUNC
775 (char_u *)&p_cfu, PV_CFU,
776 {(char_u *)"", (char_u *)0L}
777#else
778 (char_u *)NULL, PV_NONE,
779 {(char_u *)0L, (char_u *)0L}
780#endif
781 },
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000782 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
783#ifdef FEAT_INS_EXPAND
784 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000785 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
790 },
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791 {"confirm", "cf", P_BOOL|P_VI_DEF,
792#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
793 (char_u *)&p_confirm, PV_NONE,
794#else
795 (char_u *)NULL, PV_NONE,
796#endif
797 {(char_u *)FALSE, (char_u *)0L}},
798 {"conskey", "consk",P_BOOL|P_VI_DEF,
799#ifdef MSDOS
800 (char_u *)&p_consk, PV_NONE,
801#else
802 (char_u *)NULL, PV_NONE,
803#endif
804 {(char_u *)FALSE, (char_u *)0L}},
805 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
806 (char_u *)&p_ci, PV_CI,
807 {(char_u *)FALSE, (char_u *)0L}},
808 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
809 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar4399ef42005-02-12 14:29:27 +0000810 {(char_u *)CPO_VI, (char_u *)CPO_VIM}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000811 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
812#ifdef FEAT_CSCOPE
813 (char_u *)&p_cspc, PV_NONE,
814#else
815 (char_u *)NULL, PV_NONE,
816#endif
817 {(char_u *)0L, (char_u *)0L}},
818 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
819#ifdef FEAT_CSCOPE
820 (char_u *)&p_csprg, PV_NONE,
821 {(char_u *)"cscope", (char_u *)0L}
822#else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)0L, (char_u *)0L}
825#endif
826 },
827 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
828#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
829 (char_u *)&p_csqf, PV_NONE,
830 {(char_u *)"", (char_u *)0L}
831#else
832 (char_u *)NULL, PV_NONE,
833 {(char_u *)0L, (char_u *)0L}
834#endif
835 },
836 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
837#ifdef FEAT_CSCOPE
838 (char_u *)&p_cst, PV_NONE,
839#else
840 (char_u *)NULL, PV_NONE,
841#endif
842 {(char_u *)0L, (char_u *)0L}},
843 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
844#ifdef FEAT_CSCOPE
845 (char_u *)&p_csto, PV_NONE,
846#else
847 (char_u *)NULL, PV_NONE,
848#endif
849 {(char_u *)0L, (char_u *)0L}},
850 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
851#ifdef FEAT_CSCOPE
852 (char_u *)&p_csverbose, PV_NONE,
853#else
854 (char_u *)NULL, PV_NONE,
855#endif
856 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000857 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
858#ifdef FEAT_SYN_HL
859 (char_u *)VAR_WIN, PV_CUC,
860#else
861 (char_u *)NULL, PV_NONE,
862#endif
863 {(char_u *)FALSE, (char_u *)0L}},
864 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
865#ifdef FEAT_SYN_HL
866 (char_u *)VAR_WIN, PV_CUL,
867#else
868 (char_u *)NULL, PV_NONE,
869#endif
870 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000871 {"debug", NULL, P_STRING|P_VI_DEF,
872 (char_u *)&p_debug, PV_NONE,
873 {(char_u *)"", (char_u *)0L}},
874 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
875#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000876 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000877 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000878#else
879 (char_u *)NULL, PV_NONE,
880 {(char_u *)NULL, (char_u *)0L}
881#endif
882 },
883 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
884#ifdef FEAT_MBYTE
885 (char_u *)&p_deco, PV_NONE,
886#else
887 (char_u *)NULL, PV_NONE,
888#endif
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000889 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
891#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000892 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893#else
894 (char_u *)NULL, PV_NONE,
895#endif
896 {(char_u *)"", (char_u *)0L}},
897 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
898#ifdef FEAT_DIFF
899 (char_u *)VAR_WIN, PV_DIFF,
900#else
901 (char_u *)NULL, PV_NONE,
902#endif
903 {(char_u *)FALSE, (char_u *)0L}},
904 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
905#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
906 (char_u *)&p_dex, PV_NONE,
907 {(char_u *)"", (char_u *)0L}
908#else
909 (char_u *)NULL, PV_NONE,
910 {(char_u *)0L, (char_u *)0L}
911#endif
912 },
913 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
914#ifdef FEAT_DIFF
915 (char_u *)&p_dip, PV_NONE,
916 {(char_u *)"filler", (char_u *)NULL}
917#else
918 (char_u *)NULL, PV_NONE,
919 {(char_u *)"", (char_u *)NULL}
920#endif
921 },
922 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
923#ifdef FEAT_DIGRAPHS
924 (char_u *)&p_dg, PV_NONE,
925#else
926 (char_u *)NULL, PV_NONE,
927#endif
928 {(char_u *)FALSE, (char_u *)0L}},
929 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
930 (char_u *)&p_dir, PV_NONE,
931 {(char_u *)DFLT_DIR, (char_u *)0L}},
932 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
933 (char_u *)&p_dy, PV_NONE,
934 {(char_u *)"", (char_u *)0L}},
935 {"eadirection", "ead", P_STRING|P_VI_DEF,
936#ifdef FEAT_VERTSPLIT
937 (char_u *)&p_ead, PV_NONE,
938 {(char_u *)"both", (char_u *)0L}
939#else
940 (char_u *)NULL, PV_NONE,
941 {(char_u *)NULL, (char_u *)0L}
942#endif
943 },
944 {"edcompatible","ed", P_BOOL|P_VI_DEF,
945 (char_u *)&p_ed, PV_NONE,
946 {(char_u *)FALSE, (char_u *)0L}},
947 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
948#ifdef FEAT_MBYTE
949 (char_u *)&p_enc, PV_NONE,
950 {(char_u *)ENC_DFLT, (char_u *)0L}
951#else
952 (char_u *)NULL, PV_NONE,
953 {(char_u *)0L, (char_u *)0L}
954#endif
955 },
956 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
957 (char_u *)&p_eol, PV_EOL,
958 {(char_u *)TRUE, (char_u *)0L}},
959 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
960 (char_u *)&p_ea, PV_NONE,
961 {(char_u *)TRUE, (char_u *)0L}},
962 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000963 (char_u *)&p_ep, PV_EP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {(char_u *)"", (char_u *)0L}},
965 {"errorbells", "eb", P_BOOL|P_VI_DEF,
966 (char_u *)&p_eb, PV_NONE,
967 {(char_u *)FALSE, (char_u *)0L}},
968 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
969#ifdef FEAT_QUICKFIX
970 (char_u *)&p_ef, PV_NONE,
971 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
972#else
973 (char_u *)NULL, PV_NONE,
974 {(char_u *)NULL, (char_u *)0L}
975#endif
976 },
977 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
978#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000979 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980 {(char_u *)DFLT_EFM, (char_u *)0L},
981#else
982 (char_u *)NULL, PV_NONE,
983 {(char_u *)NULL, (char_u *)0L}
984#endif
985 },
986 {"esckeys", "ek", P_BOOL|P_VIM,
987 (char_u *)&p_ek, PV_NONE,
988 {(char_u *)FALSE, (char_u *)TRUE}},
989 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
990#ifdef FEAT_AUTOCMD
991 (char_u *)&p_ei, PV_NONE,
992#else
993 (char_u *)NULL, PV_NONE,
994#endif
995 {(char_u *)"", (char_u *)0L}},
996 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
997 (char_u *)&p_et, PV_ET,
998 {(char_u *)FALSE, (char_u *)0L}},
999 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1000 (char_u *)&p_exrc, PV_NONE,
1001 {(char_u *)FALSE, (char_u *)0L}},
1002 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1003#ifdef FEAT_MBYTE
1004 (char_u *)&p_fenc, PV_FENC,
1005 {(char_u *)"", (char_u *)0L}
1006#else
1007 (char_u *)NULL, PV_NONE,
1008 {(char_u *)0L, (char_u *)0L}
1009#endif
1010 },
1011 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1012#ifdef FEAT_MBYTE
1013 (char_u *)&p_fencs, PV_NONE,
1014 {(char_u *)"ucs-bom", (char_u *)0L}
1015#else
1016 (char_u *)NULL, PV_NONE,
1017 {(char_u *)0L, (char_u *)0L}
1018#endif
1019 },
1020 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1021 (char_u *)&p_ff, PV_FF,
1022 {(char_u *)DFLT_FF, (char_u *)0L}},
1023 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1024 (char_u *)&p_ffs, PV_NONE,
1025 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001026 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027#ifdef FEAT_AUTOCMD
1028 (char_u *)&p_ft, PV_FT,
1029 {(char_u *)"", (char_u *)0L}
1030#else
1031 (char_u *)NULL, PV_NONE,
1032 {(char_u *)0L, (char_u *)0L}
1033#endif
1034 },
1035 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1036#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1037 (char_u *)&p_fcs, PV_NONE,
1038 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1039#else
1040 (char_u *)NULL, PV_NONE,
1041 {(char_u *)"", (char_u *)0L}
1042#endif
1043 },
1044 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1045#ifdef FEAT_FKMAP
1046 (char_u *)&p_fkmap, PV_NONE,
1047#else
1048 (char_u *)NULL, PV_NONE,
1049#endif
1050 {(char_u *)FALSE, (char_u *)0L}},
1051 {"flash", "fl", P_BOOL|P_VI_DEF,
1052 (char_u *)NULL, PV_NONE,
1053 {(char_u *)FALSE, (char_u *)0L}},
1054#ifdef FEAT_FOLDING
1055 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1056 (char_u *)&p_fcl, PV_NONE,
1057 {(char_u *)"", (char_u *)0L}},
1058 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1059 (char_u *)VAR_WIN, PV_FDC,
1060 {(char_u *)FALSE, (char_u *)0L}},
1061 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1062 (char_u *)VAR_WIN, PV_FEN,
1063 {(char_u *)TRUE, (char_u *)0L}},
1064 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1065# ifdef FEAT_EVAL
1066 (char_u *)VAR_WIN, PV_FDE,
1067 {(char_u *)"0", (char_u *)NULL}
1068# else
1069 (char_u *)NULL, PV_NONE,
1070 {(char_u *)NULL, (char_u *)0L}
1071# endif
1072 },
1073 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1074 (char_u *)VAR_WIN, PV_FDI,
1075 {(char_u *)"#", (char_u *)NULL}},
1076 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1077 (char_u *)VAR_WIN, PV_FDL,
1078 {(char_u *)0L, (char_u *)0L}},
1079 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1080 (char_u *)&p_fdls, PV_NONE,
1081 {(char_u *)-1L, (char_u *)0L}},
1082 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1083 P_RWIN|P_COMMA|P_NODUP,
1084 (char_u *)VAR_WIN, PV_FMR,
1085 {(char_u *)"{{{,}}}", (char_u *)NULL}},
1086 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1087 (char_u *)VAR_WIN, PV_FDM,
1088 {(char_u *)"manual", (char_u *)NULL}},
1089 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1090 (char_u *)VAR_WIN, PV_FML,
1091 {(char_u *)1L, (char_u *)0L}},
1092 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1093 (char_u *)VAR_WIN, PV_FDN,
1094 {(char_u *)20L, (char_u *)0L}},
1095 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1096 (char_u *)&p_fdo, PV_NONE,
1097 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1098 (char_u *)0L}},
1099 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1100# ifdef FEAT_EVAL
1101 (char_u *)VAR_WIN, PV_FDT,
1102 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001103# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 (char_u *)NULL, PV_NONE,
1105 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001106# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 },
1108#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001109 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001110#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001111 (char_u *)&p_fex, PV_FEX,
1112 {(char_u *)"", (char_u *)0L}
1113#else
1114 (char_u *)NULL, PV_NONE,
1115 {(char_u *)0L, (char_u *)0L}
1116#endif
1117 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1119 (char_u *)&p_fo, PV_FO,
1120 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001121 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1122 (char_u *)&p_flp, PV_FLP,
1123 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1125 (char_u *)&p_fp, PV_NONE,
1126 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001127 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1128#ifdef HAVE_FSYNC
1129 (char_u *)&p_fs, PV_NONE,
1130 {(char_u *)TRUE, (char_u *)0L}
1131#else
1132 (char_u *)NULL, PV_NONE,
1133 {(char_u *)FALSE, (char_u *)0L}
1134#endif
1135 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1137 (char_u *)&p_gd, PV_NONE,
1138 {(char_u *)FALSE, (char_u *)0L}},
1139 {"graphic", "gr", P_BOOL|P_VI_DEF,
1140 (char_u *)NULL, PV_NONE,
1141 {(char_u *)FALSE, (char_u *)0L}},
1142 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1143#ifdef FEAT_QUICKFIX
1144 (char_u *)&p_gefm, PV_NONE,
1145 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L},
1146#else
1147 (char_u *)NULL, PV_NONE,
1148 {(char_u *)NULL, (char_u *)0L}
1149#endif
1150 },
1151 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1152#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001153 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {
1155# ifdef WIN3264
1156 /* may be changed to "grep -n" in os_win32.c */
1157 (char_u *)"findstr /n",
1158# else
1159# ifdef UNIX
1160 /* Add an extra file name so that grep will always
1161 * insert a file name in the match line. */
1162 (char_u *)"grep -n $* /dev/null",
1163# else
1164# ifdef VMS
1165 (char_u *)"SEARCH/NUMBERS ",
1166# else
1167 (char_u *)"grep -n ",
1168#endif
1169#endif
1170# endif
1171 (char_u *)0L},
1172#else
1173 (char_u *)NULL, PV_NONE,
1174 {(char_u *)NULL, (char_u *)0L}
1175#endif
1176 },
1177 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1178#ifdef CURSOR_SHAPE
1179 (char_u *)&p_guicursor, PV_NONE,
1180 {
1181# ifdef FEAT_GUI
1182 (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",
1183# else /* MSDOS or Win32 console */
1184 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1185# endif
1186 (char_u *)0L}
1187#else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)NULL, (char_u *)0L}
1190#endif
1191 },
1192 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1193#ifdef FEAT_GUI
1194 (char_u *)&p_guifont, PV_NONE,
1195 {(char_u *)"", (char_u *)0L}
1196#else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)NULL, (char_u *)0L}
1199#endif
1200 },
1201 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1202#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1203 (char_u *)&p_guifontset, PV_NONE,
1204 {(char_u *)"", (char_u *)0L}
1205#else
1206 (char_u *)NULL, PV_NONE,
1207 {(char_u *)NULL, (char_u *)0L}
1208#endif
1209 },
1210 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1211#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1212 (char_u *)&p_guifontwide, PV_NONE,
1213 {(char_u *)"", (char_u *)0L}
1214#else
1215 (char_u *)NULL, PV_NONE,
1216 {(char_u *)NULL, (char_u *)0L}
1217#endif
1218 },
1219 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001220#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 (char_u *)&p_ghr, PV_NONE,
1222#else
1223 (char_u *)NULL, PV_NONE,
1224#endif
1225 {(char_u *)50L, (char_u *)0L}},
1226 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001227#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 (char_u *)&p_go, PV_NONE,
1229# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001230 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001232 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233# endif
1234#else
1235 (char_u *)NULL, PV_NONE,
1236 {(char_u *)NULL, (char_u *)0L}
1237#endif
1238 },
1239 {"guipty", NULL, P_BOOL|P_VI_DEF,
1240#if defined(FEAT_GUI)
1241 (char_u *)&p_guipty, PV_NONE,
1242#else
1243 (char_u *)NULL, PV_NONE,
1244#endif
1245 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001246 {"guitablabel", "gtl", P_STRING|P_VI_DEF,
1247#if defined(FEAT_GUI_TABLINE)
1248 (char_u *)&p_gtl, PV_NONE,
1249 {(char_u *)"", (char_u *)0L}
1250#else
1251 (char_u *)NULL, PV_NONE,
1252 {(char_u *)NULL, (char_u *)0L}
1253#endif
1254 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1256 (char_u *)NULL, PV_NONE,
1257 {(char_u *)0L, (char_u *)0L}},
1258 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1259 (char_u *)&p_hf, PV_NONE,
1260 {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
1261 {"helpheight", "hh", P_NUM|P_VI_DEF,
1262#ifdef FEAT_WINDOWS
1263 (char_u *)&p_hh, PV_NONE,
1264#else
1265 (char_u *)NULL, PV_NONE,
1266#endif
1267 {(char_u *)20L, (char_u *)0L}},
1268 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1269#ifdef FEAT_MULTI_LANG
1270 (char_u *)&p_hlg, PV_NONE,
1271 {(char_u *)"", (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)0L, (char_u *)0L}
1275#endif
1276 },
1277 {"hidden", "hid", P_BOOL|P_VI_DEF,
1278 (char_u *)&p_hid, PV_NONE,
1279 {(char_u *)FALSE, (char_u *)0L}},
1280 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1281 (char_u *)&p_hl, PV_NONE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001282 {(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 +00001283 (char_u *)0L}},
1284 {"history", "hi", P_NUM|P_VIM,
1285 (char_u *)&p_hi, PV_NONE,
1286 {(char_u *)0L, (char_u *)20L}},
1287 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1288#ifdef FEAT_RIGHTLEFT
1289 (char_u *)&p_hkmap, PV_NONE,
1290#else
1291 (char_u *)NULL, PV_NONE,
1292#endif
1293 {(char_u *)FALSE, (char_u *)0L}},
1294 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1295#ifdef FEAT_RIGHTLEFT
1296 (char_u *)&p_hkmapp, PV_NONE,
1297#else
1298 (char_u *)NULL, PV_NONE,
1299#endif
1300 {(char_u *)FALSE, (char_u *)0L}},
1301 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1302 (char_u *)&p_hls, PV_NONE,
1303 {(char_u *)FALSE, (char_u *)0L}},
1304 {"icon", NULL, P_BOOL|P_VI_DEF,
1305#ifdef FEAT_TITLE
1306 (char_u *)&p_icon, PV_NONE,
1307#else
1308 (char_u *)NULL, PV_NONE,
1309#endif
1310 {(char_u *)FALSE, (char_u *)0L}},
1311 {"iconstring", NULL, P_STRING|P_VI_DEF,
1312#ifdef FEAT_TITLE
1313 (char_u *)&p_iconstring, PV_NONE,
1314#else
1315 (char_u *)NULL, PV_NONE,
1316#endif
1317 {(char_u *)"", (char_u *)0L}},
1318 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1319 (char_u *)&p_ic, PV_NONE,
1320 {(char_u *)FALSE, (char_u *)0L}},
1321 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001322#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323 (char_u *)&p_imak, PV_NONE,
1324#else
1325 (char_u *)NULL, PV_NONE,
1326#endif
1327 {(char_u *)"", (char_u *)0L}},
1328 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1329#ifdef USE_IM_CONTROL
1330 (char_u *)&p_imcmdline, PV_NONE,
1331#else
1332 (char_u *)NULL, PV_NONE,
1333#endif
1334 {(char_u *)FALSE, (char_u *)0L}},
1335 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1336#ifdef USE_IM_CONTROL
1337 (char_u *)&p_imdisable, PV_NONE,
1338#else
1339 (char_u *)NULL, PV_NONE,
1340#endif
1341#ifdef __sgi
1342 {(char_u *)TRUE, (char_u *)0L}
1343#else
1344 {(char_u *)FALSE, (char_u *)0L}
1345#endif
1346 },
1347 {"iminsert", "imi", P_NUM|P_VI_DEF,
1348 (char_u *)&p_iminsert, PV_IMI,
1349#ifdef B_IMODE_IM
1350 {(char_u *)B_IMODE_IM, (char_u *)0L}
1351#else
1352 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1353#endif
1354 },
1355 {"imsearch", "ims", P_NUM|P_VI_DEF,
1356 (char_u *)&p_imsearch, PV_IMS,
1357#ifdef B_IMODE_IM
1358 {(char_u *)B_IMODE_IM, (char_u *)0L}
1359#else
1360 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1361#endif
1362 },
1363 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1364#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001365 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1367#else
1368 (char_u *)NULL, PV_NONE,
1369 {(char_u *)0L, (char_u *)0L}
1370#endif
1371 },
1372 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1373#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1374 (char_u *)&p_inex, PV_INEX,
1375 {(char_u *)"", (char_u *)0L}
1376#else
1377 (char_u *)NULL, PV_NONE,
1378 {(char_u *)0L, (char_u *)0L}
1379#endif
1380 },
1381 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1382 (char_u *)&p_is, PV_NONE,
1383 {(char_u *)FALSE, (char_u *)0L}},
1384 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1385#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1386 (char_u *)&p_inde, PV_INDE,
1387 {(char_u *)"", (char_u *)0L}
1388#else
1389 (char_u *)NULL, PV_NONE,
1390 {(char_u *)0L, (char_u *)0L}
1391#endif
1392 },
1393 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1394#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1395 (char_u *)&p_indk, PV_INDK,
1396 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1397#else
1398 (char_u *)NULL, PV_NONE,
1399 {(char_u *)0L, (char_u *)0L}
1400#endif
1401 },
1402 {"infercase", "inf", P_BOOL|P_VI_DEF,
1403 (char_u *)&p_inf, PV_INF,
1404 {(char_u *)FALSE, (char_u *)0L}},
1405 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1406 (char_u *)&p_im, PV_NONE,
1407 {(char_u *)FALSE, (char_u *)0L}},
1408 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1409 (char_u *)&p_isf, PV_NONE,
1410 {
1411#ifdef BACKSLASH_IN_FILENAME
1412 /* Excluded are: & and ^ are special in cmd.exe
1413 * ( and ) are used in text separating fnames */
1414 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1415#else
1416# ifdef AMIGA
1417 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1418# else
1419# ifdef VMS
1420 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1421# else /* UNIX et al. */
1422# ifdef EBCDIC
1423 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1424# else
1425 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1426# endif
1427# endif
1428# endif
1429#endif
1430 (char_u *)0L}},
1431 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1432 (char_u *)&p_isi, PV_NONE,
1433 {
1434#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1435 (char_u *)"@,48-57,_,128-167,224-235",
1436#else
1437# ifdef EBCDIC
1438 /* TODO: EBCDIC Check this! @ == isalpha()*/
1439 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1440 "112-120,128,140-142,156,158,172,"
1441 "174,186,191,203-207,219-225,235-239,"
1442 "251-254",
1443# else
1444 (char_u *)"@,48-57,_,192-255",
1445# endif
1446#endif
1447 (char_u *)0L}},
1448 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1449 (char_u *)&p_isk, PV_ISK,
1450 {
1451#ifdef EBCDIC
1452 (char_u *)"@,240-249,_",
1453 /* TODO: EBCDIC Check this! @ == isalpha()*/
1454 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1455 "112-120,128,140-142,156,158,172,"
1456 "174,186,191,203-207,219-225,235-239,"
1457 "251-254",
1458#else
1459 (char_u *)"@,48-57,_",
1460# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1461 (char_u *)"@,48-57,_,128-167,224-235"
1462# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001463 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464# endif
1465#endif
1466 }},
1467 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1468 (char_u *)&p_isp, PV_NONE,
1469 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001470#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1471 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 || defined(VMS)
1473 (char_u *)"@,~-255",
1474#else
1475# ifdef EBCDIC
1476 /* all chars above 63 are printable */
1477 (char_u *)"63-255",
1478# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001479 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480# endif
1481#endif
1482 (char_u *)0L}},
1483 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1484 (char_u *)&p_js, PV_NONE,
1485 {(char_u *)TRUE, (char_u *)0L}},
1486 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1487#ifdef FEAT_CRYPT
1488 (char_u *)&p_key, PV_KEY,
1489 {(char_u *)"", (char_u *)0L}
1490#else
1491 (char_u *)NULL, PV_NONE,
1492 {(char_u *)0L, (char_u *)0L}
1493#endif
1494 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001495 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496#ifdef FEAT_KEYMAP
1497 (char_u *)&p_keymap, PV_KMAP,
1498 {(char_u *)"", (char_u *)0L}
1499#else
1500 (char_u *)NULL, PV_NONE,
1501 {(char_u *)"", (char_u *)0L}
1502#endif
1503 },
1504 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1505#ifdef FEAT_VISUAL
1506 (char_u *)&p_km, PV_NONE,
1507#else
1508 (char_u *)NULL, PV_NONE,
1509#endif
1510 {(char_u *)"", (char_u *)0L}},
1511 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001512 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {
1514#if defined(MSDOS) || defined(MSWIN)
1515 (char_u *)":help",
1516#else
1517#ifdef VMS
1518 (char_u *)"help",
1519#else
1520# if defined(OS2)
1521 (char_u *)"view /",
1522# else
1523# ifdef USEMAN_S
1524 (char_u *)"man -s",
1525# else
1526 (char_u *)"man",
1527# endif
1528# endif
1529#endif
1530#endif
1531 (char_u *)0L}},
1532 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1533#ifdef FEAT_LANGMAP
1534 (char_u *)&p_langmap, PV_NONE,
1535 {(char_u *)"", /* unmatched } */
1536#else
1537 (char_u *)NULL, PV_NONE,
1538 {(char_u *)NULL,
1539#endif
1540 (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001541 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1543 (char_u *)&p_lm, PV_NONE,
1544#else
1545 (char_u *)NULL, PV_NONE,
1546#endif
1547 {(char_u *)"", (char_u *)0L}},
1548 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1549#ifdef FEAT_WINDOWS
1550 (char_u *)&p_ls, PV_NONE,
1551#else
1552 (char_u *)NULL, PV_NONE,
1553#endif
1554 {(char_u *)1L, (char_u *)0L}},
1555 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1556 (char_u *)&p_lz, PV_NONE,
1557 {(char_u *)FALSE, (char_u *)0L}},
1558 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1559#ifdef FEAT_LINEBREAK
1560 (char_u *)VAR_WIN, PV_LBR,
1561#else
1562 (char_u *)NULL, PV_NONE,
1563#endif
1564 {(char_u *)FALSE, (char_u *)0L}},
1565 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1566 (char_u *)&Rows, PV_NONE,
1567 {
1568#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1569 (char_u *)25L,
1570#else
1571 (char_u *)24L,
1572#endif
1573 (char_u *)0L}},
1574 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1575#ifdef FEAT_GUI
1576 (char_u *)&p_linespace, PV_NONE,
1577#else
1578 (char_u *)NULL, PV_NONE,
1579#endif
1580#ifdef FEAT_GUI_W32
1581 {(char_u *)1L, (char_u *)0L}
1582#else
1583 {(char_u *)0L, (char_u *)0L}
1584#endif
1585 },
1586 {"lisp", NULL, P_BOOL|P_VI_DEF,
1587#ifdef FEAT_LISP
1588 (char_u *)&p_lisp, PV_LISP,
1589#else
1590 (char_u *)NULL, PV_NONE,
1591#endif
1592 {(char_u *)FALSE, (char_u *)0L}},
1593 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1594#ifdef FEAT_LISP
1595 (char_u *)&p_lispwords, PV_NONE,
1596 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)"", (char_u *)0L}
1600#endif
1601 },
1602 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1603 (char_u *)VAR_WIN, PV_LIST,
1604 {(char_u *)FALSE, (char_u *)0L}},
1605 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1606 (char_u *)&p_lcs, PV_NONE,
1607 {(char_u *)"eol:$", (char_u *)0L}},
1608 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1609 (char_u *)&p_lpl, PV_NONE,
1610 {(char_u *)TRUE, (char_u *)0L}},
1611 {"magic", NULL, P_BOOL|P_VI_DEF,
1612 (char_u *)&p_magic, PV_NONE,
1613 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001614 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615#ifdef FEAT_QUICKFIX
1616 (char_u *)&p_mef, PV_NONE,
1617 {(char_u *)"", (char_u *)0L}
1618#else
1619 (char_u *)NULL, PV_NONE,
1620 {(char_u *)NULL, (char_u *)0L}
1621#endif
1622 },
1623 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1624#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001625 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626# ifdef VMS
1627 {(char_u *)"MMS", (char_u *)0L}
1628# else
1629 {(char_u *)"make", (char_u *)0L}
1630# endif
1631#else
1632 (char_u *)NULL, PV_NONE,
1633 {(char_u *)NULL, (char_u *)0L}
1634#endif
1635 },
1636 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1637 (char_u *)&p_mps, PV_MPS,
1638 {(char_u *)"(:),{:},[:]", (char_u *)0L}},
1639 {"matchtime", "mat", P_NUM|P_VI_DEF,
1640 (char_u *)&p_mat, PV_NONE,
1641 {(char_u *)5L, (char_u *)0L}},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001642 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1643#ifdef FEAT_MBYTE
1644 (char_u *)&p_mco, PV_NONE,
1645#else
1646 (char_u *)NULL, PV_NONE,
1647#endif
1648 {(char_u *)2, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1650#ifdef FEAT_EVAL
1651 (char_u *)&p_mfd, PV_NONE,
1652#else
1653 (char_u *)NULL, PV_NONE,
1654#endif
1655 {(char_u *)100L, (char_u *)0L}},
1656 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1657 (char_u *)&p_mmd, PV_NONE,
1658 {(char_u *)1000L, (char_u *)0L}},
1659 {"maxmem", "mm", P_NUM|P_VI_DEF,
1660 (char_u *)&p_mm, PV_NONE,
1661 {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001662 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1663 (char_u *)&p_mmp, PV_NONE,
1664 {(char_u *)1000L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1666 (char_u *)&p_mmt, PV_NONE,
1667 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
1668 {"menuitems", "mis", P_NUM|P_VI_DEF,
1669#ifdef FEAT_MENU
1670 (char_u *)&p_mis, PV_NONE,
1671#else
1672 (char_u *)NULL, PV_NONE,
1673#endif
1674 {(char_u *)25L, (char_u *)0L}},
1675 {"mesg", NULL, P_BOOL|P_VI_DEF,
1676 (char_u *)NULL, PV_NONE,
1677 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001678 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001679#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001680 (char_u *)&p_msm, PV_NONE,
1681 {(char_u *)"460000,2000,500", (char_u *)0L}
1682#else
1683 (char_u *)NULL, PV_NONE,
1684 {(char_u *)0L, (char_u *)0L}
1685#endif
1686 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"modeline", "ml", P_BOOL|P_VIM,
1688 (char_u *)&p_ml, PV_ML,
1689 {(char_u *)FALSE, (char_u *)TRUE}},
1690 {"modelines", "mls", P_NUM|P_VI_DEF,
1691 (char_u *)&p_mls, PV_NONE,
1692 {(char_u *)5L, (char_u *)0L}},
1693 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1694 (char_u *)&p_ma, PV_MA,
1695 {(char_u *)TRUE, (char_u *)0L}},
1696 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1697 (char_u *)&p_mod, PV_MOD,
1698 {(char_u *)FALSE, (char_u *)0L}},
1699 {"more", NULL, P_BOOL|P_VIM,
1700 (char_u *)&p_more, PV_NONE,
1701 {(char_u *)FALSE, (char_u *)TRUE}},
1702 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1703 (char_u *)&p_mouse, PV_NONE,
1704 {
1705#if defined(MSDOS) || defined(WIN3264)
1706 (char_u *)"a",
1707#else
1708 (char_u *)"",
1709#endif
1710 (char_u *)0L}},
1711 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1712#ifdef FEAT_GUI
1713 (char_u *)&p_mousef, PV_NONE,
1714#else
1715 (char_u *)NULL, PV_NONE,
1716#endif
1717 {(char_u *)FALSE, (char_u *)0L}},
1718 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1719#ifdef FEAT_GUI
1720 (char_u *)&p_mh, PV_NONE,
1721#else
1722 (char_u *)NULL, PV_NONE,
1723#endif
1724 {(char_u *)TRUE, (char_u *)0L}},
1725 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1726 (char_u *)&p_mousem, PV_NONE,
1727 {
1728#if defined(MSDOS) || defined(MSWIN)
1729 (char_u *)"popup",
1730#else
1731# if defined(MACOS)
1732 (char_u *)"popup_setpos",
1733# else
1734 (char_u *)"extend",
1735# endif
1736#endif
1737 (char_u *)0L}},
1738 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1739#ifdef FEAT_MOUSESHAPE
1740 (char_u *)&p_mouseshape, PV_NONE,
1741 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1742#else
1743 (char_u *)NULL, PV_NONE,
1744 {(char_u *)NULL, (char_u *)0L}
1745#endif
1746 },
1747 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1748 (char_u *)&p_mouset, PV_NONE,
1749 {(char_u *)500L, (char_u *)0L}},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001750 {"mzquantum", "mzq", P_NUM,
1751#ifdef FEAT_MZSCHEME
1752 (char_u *)&p_mzq, PV_NONE,
1753#else
1754 (char_u *)NULL, PV_NONE,
1755#endif
1756 {(char_u *)100L, (char_u *)100L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 {"novice", NULL, P_BOOL|P_VI_DEF,
1758 (char_u *)NULL, PV_NONE,
1759 {(char_u *)FALSE, (char_u *)0L}},
1760 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1761 (char_u *)&p_nf, PV_NF,
1762 {(char_u *)"octal,hex", (char_u *)0L}},
1763 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1764 (char_u *)VAR_WIN, PV_NU,
1765 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001766 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1767#ifdef FEAT_LINEBREAK
1768 (char_u *)VAR_WIN, PV_NUW,
1769#else
1770 (char_u *)NULL, PV_NONE,
1771#endif
1772 {(char_u *)8L, (char_u *)4L}},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001773 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001774#ifdef FEAT_COMPL_FUNC
1775 (char_u *)&p_ofu, PV_OFU,
1776 {(char_u *)"", (char_u *)0L}
1777#else
1778 (char_u *)NULL, PV_NONE,
1779 {(char_u *)0L, (char_u *)0L}
1780#endif
1781 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"open", NULL, P_BOOL|P_VI_DEF,
1783 (char_u *)NULL, PV_NONE,
1784 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001785 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1786 (char_u *)&p_opfunc, PV_NONE,
1787 {(char_u *)"", (char_u *)0L} },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"optimize", "opt", P_BOOL|P_VI_DEF,
1789 (char_u *)NULL, PV_NONE,
1790 {(char_u *)FALSE, (char_u *)0L}},
1791 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1792#ifdef FEAT_OSFILETYPE
1793 (char_u *)&p_oft, PV_OFT,
1794 {(char_u *)DFLT_OFT, (char_u *)0L}
1795#else
1796 (char_u *)NULL, PV_NONE,
1797 {(char_u *)0L, (char_u *)0L}
1798#endif
1799 },
1800 {"paragraphs", "para", P_STRING|P_VI_DEF,
1801 (char_u *)&p_para, PV_NONE,
1802 {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}},
1803 {"paste", NULL, P_BOOL|P_VI_DEF,
1804 (char_u *)&p_paste, PV_NONE,
1805 {(char_u *)FALSE, (char_u *)0L}},
1806 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1807 (char_u *)&p_pt, PV_NONE,
1808 {(char_u *)"", (char_u *)0L}},
1809 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1810#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1811 (char_u *)&p_pex, PV_NONE,
1812 {(char_u *)"", (char_u *)0L}
1813#else
1814 (char_u *)NULL, PV_NONE,
1815 {(char_u *)0L, (char_u *)0L}
1816#endif
1817 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001818 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 (char_u *)&p_pm, PV_NONE,
1820 {(char_u *)"", (char_u *)0L}},
1821 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001822 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {
1824#if defined AMIGA || defined MSDOS || defined MSWIN
1825 (char_u *)".,,",
1826#else
1827# if defined(__EMX__)
1828 (char_u *)".,/emx/include,,",
1829# else /* Unix, probably */
1830 (char_u *)".,/usr/include,,",
1831# endif
1832#endif
1833 (char_u *)0L}},
1834 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1835 (char_u *)&p_pi, PV_PI,
1836 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001837 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1839 (char_u *)&p_pvh, PV_NONE,
1840#else
1841 (char_u *)NULL, PV_NONE,
1842#endif
1843 {(char_u *)12L, (char_u *)0L}},
1844 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1845#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1846 (char_u *)VAR_WIN, PV_PVW,
1847#else
1848 (char_u *)NULL, PV_NONE,
1849#endif
1850 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001851 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852#ifdef FEAT_PRINTER
1853 (char_u *)&p_pdev, PV_NONE,
1854 {(char_u *)"", (char_u *)0L}
1855#else
1856 (char_u *)NULL, PV_NONE,
1857 {(char_u *)NULL, (char_u *)0L}
1858#endif
1859 },
1860 {"printencoding", "penc", P_STRING|P_VI_DEF,
1861#ifdef FEAT_POSTSCRIPT
1862 (char_u *)&p_penc, PV_NONE,
1863 {(char_u *)"", (char_u *)0L}
1864#else
1865 (char_u *)NULL, PV_NONE,
1866 {(char_u *)NULL, (char_u *)0L}
1867#endif
1868 },
1869 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1870#ifdef FEAT_POSTSCRIPT
1871 (char_u *)&p_pexpr, PV_NONE,
1872 {(char_u *)"", (char_u *)0L}
1873#else
1874 (char_u *)NULL, PV_NONE,
1875 {(char_u *)NULL, (char_u *)0L}
1876#endif
1877 },
1878 {"printfont", "pfn", P_STRING|P_VI_DEF,
1879#ifdef FEAT_PRINTER
1880 (char_u *)&p_pfn, PV_NONE,
1881 {
1882# ifdef MSWIN
1883 (char_u *)"Courier_New:h10",
1884# else
1885 (char_u *)"courier",
1886# endif
1887 (char_u *)0L}
1888#else
1889 (char_u *)NULL, PV_NONE,
1890 {(char_u *)NULL, (char_u *)0L}
1891#endif
1892 },
1893 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1894#ifdef FEAT_PRINTER
1895 (char_u *)&p_header, PV_NONE,
1896 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1897#else
1898 (char_u *)NULL, PV_NONE,
1899 {(char_u *)NULL, (char_u *)0L}
1900#endif
1901 },
Bram Moolenaar8299df92004-07-10 09:47:34 +00001902 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1903#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1904 (char_u *)&p_pmcs, PV_NONE,
1905 {(char_u *)"", (char_u *)0L}
1906#else
1907 (char_u *)NULL, PV_NONE,
1908 {(char_u *)NULL, (char_u *)0L}
1909#endif
1910 },
1911 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1912#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1913 (char_u *)&p_pmfn, PV_NONE,
1914 {(char_u *)"", (char_u *)0L}
1915#else
1916 (char_u *)NULL, PV_NONE,
1917 {(char_u *)NULL, (char_u *)0L}
1918#endif
1919 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1921#ifdef FEAT_PRINTER
1922 (char_u *)&p_popt, PV_NONE,
1923 {(char_u *)"", (char_u *)0L}
1924#else
1925 (char_u *)NULL, PV_NONE,
1926 {(char_u *)NULL, (char_u *)0L}
1927#endif
1928 },
1929 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001930 (char_u *)&p_prompt, PV_NONE,
1931 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00001932 {"pumheight", "ph", P_NUM|P_VI_DEF,
1933#ifdef FEAT_INS_EXPAND
1934 (char_u *)&p_ph, PV_NONE,
1935#else
1936 (char_u *)NULL, PV_NONE,
1937#endif
1938 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001939 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
1940#ifdef FEAT_TEXTOBJ
1941 (char_u *)&p_qe, PV_QE,
1942 {(char_u *)"\\", (char_u *)0L}
1943#else
1944 (char_u *)NULL, PV_NONE,
1945 {(char_u *)NULL, (char_u *)0L}
1946#endif
1947 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1949 (char_u *)&p_ro, PV_RO,
1950 {(char_u *)FALSE, (char_u *)0L}},
1951 {"redraw", NULL, P_BOOL|P_VI_DEF,
1952 (char_u *)NULL, PV_NONE,
1953 {(char_u *)FALSE, (char_u *)0L}},
1954 {"remap", NULL, P_BOOL|P_VI_DEF,
1955 (char_u *)&p_remap, PV_NONE,
1956 {(char_u *)TRUE, (char_u *)0L}},
1957 {"report", NULL, P_NUM|P_VI_DEF,
1958 (char_u *)&p_report, PV_NONE,
1959 {(char_u *)2L, (char_u *)0L}},
1960 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
1961#ifdef WIN3264
1962 (char_u *)&p_rs, PV_NONE,
1963#else
1964 (char_u *)NULL, PV_NONE,
1965#endif
1966 {(char_u *)TRUE, (char_u *)0L}},
1967 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
1968#ifdef FEAT_RIGHTLEFT
1969 (char_u *)&p_ri, PV_NONE,
1970#else
1971 (char_u *)NULL, PV_NONE,
1972#endif
1973 {(char_u *)FALSE, (char_u *)0L}},
1974 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
1975#ifdef FEAT_RIGHTLEFT
1976 (char_u *)VAR_WIN, PV_RL,
1977#else
1978 (char_u *)NULL, PV_NONE,
1979#endif
1980 {(char_u *)FALSE, (char_u *)0L}},
1981 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
1982#ifdef FEAT_RIGHTLEFT
1983 (char_u *)VAR_WIN, PV_RLC,
1984 {(char_u *)"search", (char_u *)NULL}
1985#else
1986 (char_u *)NULL, PV_NONE,
1987 {(char_u *)NULL, (char_u *)0L}
1988#endif
1989 },
1990 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
1991#ifdef FEAT_CMDL_INFO
1992 (char_u *)&p_ru, PV_NONE,
1993#else
1994 (char_u *)NULL, PV_NONE,
1995#endif
1996 {(char_u *)FALSE, (char_u *)0L}},
1997 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
1998#ifdef FEAT_STL_OPT
1999 (char_u *)&p_ruf, PV_NONE,
2000#else
2001 (char_u *)NULL, PV_NONE,
2002#endif
2003 {(char_u *)"", (char_u *)0L}},
2004 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2005 (char_u *)&p_rtp, PV_NONE,
2006 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
2007 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2008 (char_u *)VAR_WIN, PV_SCROLL,
2009 {(char_u *)12L, (char_u *)0L}},
2010 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2011#ifdef FEAT_SCROLLBIND
2012 (char_u *)VAR_WIN, PV_SCBIND,
2013#else
2014 (char_u *)NULL, PV_NONE,
2015#endif
2016 {(char_u *)FALSE, (char_u *)0L}},
2017 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2018 (char_u *)&p_sj, PV_NONE,
2019 {(char_u *)1L, (char_u *)0L}},
2020 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2021 (char_u *)&p_so, PV_NONE,
2022 {(char_u *)0L, (char_u *)0L}},
2023 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2024#ifdef FEAT_SCROLLBIND
2025 (char_u *)&p_sbo, PV_NONE,
2026 {(char_u *)"ver,jump", (char_u *)0L}
2027#else
2028 (char_u *)NULL, PV_NONE,
2029 {(char_u *)0L, (char_u *)0L}
2030#endif
2031 },
2032 {"sections", "sect", P_STRING|P_VI_DEF,
2033 (char_u *)&p_sections, PV_NONE,
2034 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
2035 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2036 (char_u *)&p_secure, PV_NONE,
2037 {(char_u *)FALSE, (char_u *)0L}},
2038 {"selection", "sel", P_STRING|P_VI_DEF,
2039#ifdef FEAT_VISUAL
2040 (char_u *)&p_sel, PV_NONE,
2041#else
2042 (char_u *)NULL, PV_NONE,
2043#endif
2044 {(char_u *)"inclusive", (char_u *)0L}},
2045 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2046#ifdef FEAT_VISUAL
2047 (char_u *)&p_slm, PV_NONE,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
2051 {(char_u *)"", (char_u *)0L}},
2052 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2053#ifdef FEAT_SESSION
2054 (char_u *)&p_ssop, PV_NONE,
2055 {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
2056 (char_u *)0L}
2057#else
2058 (char_u *)NULL, PV_NONE,
2059 {(char_u *)0L, (char_u *)0L}
2060#endif
2061 },
2062 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2063 (char_u *)&p_sh, PV_NONE,
2064 {
2065#ifdef VMS
2066 (char_u *)"-",
2067#else
2068# if defined(MSDOS)
2069 (char_u *)"command",
2070# else
2071# if defined(WIN16)
2072 (char_u *)"command.com",
2073# else
2074# if defined(WIN3264)
2075 (char_u *)"", /* set in set_init_1() */
2076# else
2077# if defined(OS2)
2078 (char_u *)"cmd.exe",
2079# else
2080# if defined(ARCHIE)
2081 (char_u *)"gos",
2082# else
2083 (char_u *)"sh",
2084# endif
2085# endif
2086# endif
2087# endif
2088# endif
2089#endif /* VMS */
2090 (char_u *)0L}},
2091 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2092 (char_u *)&p_shcf, PV_NONE,
2093 {
2094#if defined(MSDOS) || defined(MSWIN)
2095 (char_u *)"/c",
2096#else
2097# if defined(OS2)
2098 (char_u *)"/c",
2099# else
2100 (char_u *)"-c",
2101# endif
2102#endif
2103 (char_u *)0L}},
2104 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2105#ifdef FEAT_QUICKFIX
2106 (char_u *)&p_sp, PV_NONE,
2107 {
2108#if defined(UNIX) || defined(OS2)
2109# ifdef ARCHIE
2110 (char_u *)"2>",
2111# else
2112 (char_u *)"| tee",
2113# endif
2114#else
2115 (char_u *)">",
2116#endif
2117 (char_u *)0L}
2118#else
2119 (char_u *)NULL, PV_NONE,
2120 {(char_u *)0L, (char_u *)0L}
2121#endif
2122 },
2123 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2124 (char_u *)&p_shq, PV_NONE,
2125 {(char_u *)"", (char_u *)0L}},
2126 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2127 (char_u *)&p_srr, PV_NONE,
2128 {(char_u *)">", (char_u *)0L}},
2129 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2130#ifdef BACKSLASH_IN_FILENAME
2131 (char_u *)&p_ssl, PV_NONE,
2132#else
2133 (char_u *)NULL, PV_NONE,
2134#endif
2135 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002136 {"shelltemp", "stmp", P_BOOL,
2137 (char_u *)&p_stmp, PV_NONE,
2138 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139 {"shelltype", "st", P_NUM|P_VI_DEF,
2140#ifdef AMIGA
2141 (char_u *)&p_st, PV_NONE,
2142#else
2143 (char_u *)NULL, PV_NONE,
2144#endif
2145 {(char_u *)0L, (char_u *)0L}},
2146 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2147 (char_u *)&p_sxq, PV_NONE,
2148 {
2149#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2150 (char_u *)"\"",
2151#else
2152 (char_u *)"",
2153#endif
2154 (char_u *)0L}},
2155 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2156 (char_u *)&p_sr, PV_NONE,
2157 {(char_u *)FALSE, (char_u *)0L}},
2158 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2159 (char_u *)&p_sw, PV_SW,
2160 {(char_u *)8L, (char_u *)0L}},
2161 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2162 (char_u *)&p_shm, PV_NONE,
2163 {(char_u *)"", (char_u *)"filnxtToO"}},
2164 {"shortname", "sn", P_BOOL|P_VI_DEF,
2165#ifdef SHORT_FNAME
2166 (char_u *)NULL, PV_NONE,
2167#else
2168 (char_u *)&p_sn, PV_SN,
2169#endif
2170 {(char_u *)FALSE, (char_u *)0L}},
2171 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2172#ifdef FEAT_LINEBREAK
2173 (char_u *)&p_sbr, PV_NONE,
2174#else
2175 (char_u *)NULL, PV_NONE,
2176#endif
2177 {(char_u *)"", (char_u *)0L}},
2178 {"showcmd", "sc", P_BOOL|P_VIM,
2179#ifdef FEAT_CMDL_INFO
2180 (char_u *)&p_sc, PV_NONE,
2181#else
2182 (char_u *)NULL, PV_NONE,
2183#endif
2184 {(char_u *)FALSE,
2185#ifdef UNIX
2186 (char_u *)FALSE
2187#else
2188 (char_u *)TRUE
2189#endif
2190 }},
2191 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2192 (char_u *)&p_sft, PV_NONE,
2193 {(char_u *)FALSE, (char_u *)0L}},
2194 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2195 (char_u *)&p_sm, PV_NONE,
2196 {(char_u *)FALSE, (char_u *)0L}},
2197 {"showmode", "smd", P_BOOL|P_VIM,
2198 (char_u *)&p_smd, PV_NONE,
2199 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002200 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2201#ifdef FEAT_WINDOWS
2202 (char_u *)&p_stal, PV_NONE,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
2206 {(char_u *)1L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2208 (char_u *)&p_ss, PV_NONE,
2209 {(char_u *)0L, (char_u *)0L}},
2210 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2211 (char_u *)&p_siso, PV_NONE,
2212 {(char_u *)0L, (char_u *)0L}},
2213 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2214 (char_u *)NULL, PV_NONE,
2215 {(char_u *)FALSE, (char_u *)0L}},
2216 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2217 (char_u *)&p_scs, PV_NONE,
2218 {(char_u *)FALSE, (char_u *)0L}},
2219 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2220#ifdef FEAT_SMARTINDENT
2221 (char_u *)&p_si, PV_SI,
2222#else
2223 (char_u *)NULL, PV_NONE,
2224#endif
2225 {(char_u *)FALSE, (char_u *)0L}},
2226 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2227 (char_u *)&p_sta, PV_NONE,
2228 {(char_u *)FALSE, (char_u *)0L}},
2229 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2230 (char_u *)&p_sts, PV_STS,
2231 {(char_u *)0L, (char_u *)0L}},
2232 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2233 (char_u *)NULL, PV_NONE,
2234 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002235 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002236#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002237 (char_u *)VAR_WIN, PV_SPELL,
2238#else
2239 (char_u *)NULL, PV_NONE,
2240#endif
2241 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002242 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002243#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002244 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002245 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002246#else
2247 (char_u *)NULL, PV_NONE,
2248 {(char_u *)0L, (char_u *)0L}
2249#endif
2250 },
2251 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002252#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002253 (char_u *)&p_spf, PV_SPF,
2254 {(char_u *)"", (char_u *)0L}
2255#else
2256 (char_u *)NULL, PV_NONE,
2257 {(char_u *)0L, (char_u *)0L}
2258#endif
2259 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002260 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002261#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002262 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002263 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002264#else
2265 (char_u *)NULL, PV_NONE,
2266 {(char_u *)0L, (char_u *)0L}
2267#endif
2268 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002269 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002270#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002271 (char_u *)&p_sps, PV_NONE,
2272 {(char_u *)"best", (char_u *)0L}
2273#else
2274 (char_u *)NULL, PV_NONE,
2275 {(char_u *)0L, (char_u *)0L}
2276#endif
2277 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2279#ifdef FEAT_WINDOWS
2280 (char_u *)&p_sb, PV_NONE,
2281#else
2282 (char_u *)NULL, PV_NONE,
2283#endif
2284 {(char_u *)FALSE, (char_u *)0L}},
2285 {"splitright", "spr", P_BOOL|P_VI_DEF,
2286#ifdef FEAT_VERTSPLIT
2287 (char_u *)&p_spr, PV_NONE,
2288#else
2289 (char_u *)NULL, PV_NONE,
2290#endif
2291 {(char_u *)FALSE, (char_u *)0L}},
2292 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2293 (char_u *)&p_sol, PV_NONE,
2294 {(char_u *)TRUE, (char_u *)0L}},
2295 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2296#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002297 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298#else
2299 (char_u *)NULL, PV_NONE,
2300#endif
2301 {(char_u *)"", (char_u *)0L}},
2302 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2303 (char_u *)&p_su, PV_NONE,
2304 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2305 (char_u *)0L}},
2306 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002307#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 (char_u *)&p_sua, PV_SUA,
2309 {(char_u *)"", (char_u *)0L}
2310#else
2311 (char_u *)NULL, PV_NONE,
2312 {(char_u *)0L, (char_u *)0L}
2313#endif
2314 },
2315 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2316 (char_u *)&p_swf, PV_SWF,
2317 {(char_u *)TRUE, (char_u *)0L}},
2318 {"swapsync", "sws", P_STRING|P_VI_DEF,
2319 (char_u *)&p_sws, PV_NONE,
2320 {(char_u *)"fsync", (char_u *)0L}},
2321 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2322 (char_u *)&p_swb, PV_NONE,
2323 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002324 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2325#ifdef FEAT_SYN_HL
2326 (char_u *)&p_smc, PV_SMC,
2327 {(char_u *)3000L, (char_u *)0L}
2328#else
2329 (char_u *)NULL, PV_NONE,
2330 {(char_u *)0L, (char_u *)0L}
2331#endif
2332 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002333 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334#ifdef FEAT_SYN_HL
2335 (char_u *)&p_syn, PV_SYN,
2336 {(char_u *)"", (char_u *)0L}
2337#else
2338 (char_u *)NULL, PV_NONE,
2339 {(char_u *)0L, (char_u *)0L}
2340#endif
2341 },
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002342 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2343#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002344 (char_u *)&p_tal, PV_NONE,
2345#else
2346 (char_u *)NULL, PV_NONE,
2347#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002348 {(char_u *)"", (char_u *)0L}},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002349 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2350#ifdef FEAT_WINDOWS
2351 (char_u *)&p_tpm, PV_NONE,
2352#else
2353 (char_u *)NULL, PV_NONE,
2354#endif
2355 {(char_u *)10L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2357 (char_u *)&p_ts, PV_TS,
2358 {(char_u *)8L, (char_u *)0L}},
2359 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2360 (char_u *)&p_tbs, PV_NONE,
2361#ifdef VMS /* binary searching doesn't appear to work on VMS */
2362 {(char_u *)0L, (char_u *)0L}
2363#else
2364 {(char_u *)TRUE, (char_u *)0L}
2365#endif
2366 },
2367 {"taglength", "tl", P_NUM|P_VI_DEF,
2368 (char_u *)&p_tl, PV_NONE,
2369 {(char_u *)0L, (char_u *)0L}},
2370 {"tagrelative", "tr", P_BOOL|P_VIM,
2371 (char_u *)&p_tr, PV_NONE,
2372 {(char_u *)FALSE, (char_u *)TRUE}},
2373 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002374 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {
2376#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2377 (char_u *)"./tags,./TAGS,tags,TAGS",
2378#else
2379 (char_u *)"./tags,tags",
2380#endif
2381 (char_u *)0L}},
2382 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2383 (char_u *)&p_tgst, PV_NONE,
2384 {(char_u *)TRUE, (char_u *)0L}},
2385 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2386 (char_u *)&T_NAME, PV_NONE,
2387 {(char_u *)"", (char_u *)0L}},
2388 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2389#ifdef FEAT_ARABIC
2390 (char_u *)&p_tbidi, PV_NONE,
2391#else
2392 (char_u *)NULL, PV_NONE,
2393#endif
2394 {(char_u *)FALSE, (char_u *)0L}},
2395 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2396#ifdef FEAT_MBYTE
2397 (char_u *)&p_tenc, PV_NONE,
2398 {(char_u *)"", (char_u *)0L}
2399#else
2400 (char_u *)NULL, PV_NONE,
2401 {(char_u *)0L, (char_u *)0L}
2402#endif
2403 },
2404 {"terse", NULL, P_BOOL|P_VI_DEF,
2405 (char_u *)&p_terse, PV_NONE,
2406 {(char_u *)FALSE, (char_u *)0L}},
2407 {"textauto", "ta", P_BOOL|P_VIM,
2408 (char_u *)&p_ta, PV_NONE,
2409 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2410 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2411 (char_u *)&p_tx, PV_TX,
2412 {
2413#ifdef USE_CRNL
2414 (char_u *)TRUE,
2415#else
2416 (char_u *)FALSE,
2417#endif
2418 (char_u *)0L}},
2419 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2420 (char_u *)&p_tw, PV_TW,
2421 {(char_u *)0L, (char_u *)0L}},
2422 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2423#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002424 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425#else
2426 (char_u *)NULL, PV_NONE,
2427#endif
2428 {(char_u *)"", (char_u *)0L}},
2429 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2430 (char_u *)&p_to, PV_NONE,
2431 {(char_u *)FALSE, (char_u *)0L}},
2432 {"timeout", "to", P_BOOL|P_VI_DEF,
2433 (char_u *)&p_timeout, PV_NONE,
2434 {(char_u *)TRUE, (char_u *)0L}},
2435 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2436 (char_u *)&p_tm, PV_NONE,
2437 {(char_u *)1000L, (char_u *)0L}},
2438 {"title", NULL, P_BOOL|P_VI_DEF,
2439#ifdef FEAT_TITLE
2440 (char_u *)&p_title, PV_NONE,
2441#else
2442 (char_u *)NULL, PV_NONE,
2443#endif
2444 {(char_u *)FALSE, (char_u *)0L}},
2445 {"titlelen", NULL, P_NUM|P_VI_DEF,
2446#ifdef FEAT_TITLE
2447 (char_u *)&p_titlelen, PV_NONE,
2448#else
2449 (char_u *)NULL, PV_NONE,
2450#endif
2451 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002452 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453#ifdef FEAT_TITLE
2454 (char_u *)&p_titleold, PV_NONE,
2455 {(char_u *)N_("Thanks for flying Vim"),
2456 (char_u *)0L}
2457#else
2458 (char_u *)NULL, PV_NONE,
2459 {(char_u *)0L, (char_u *)0L}
2460#endif
2461 },
2462 {"titlestring", NULL, P_STRING|P_VI_DEF,
2463#ifdef FEAT_TITLE
2464 (char_u *)&p_titlestring, PV_NONE,
2465#else
2466 (char_u *)NULL, PV_NONE,
2467#endif
2468 {(char_u *)"", (char_u *)0L}},
2469#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2470 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2471 (char_u *)&p_toolbar, PV_NONE,
2472 {(char_u *)"icons,tooltips", (char_u *)0L}},
2473#endif
2474#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2475 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2476 (char_u *)&p_tbis, PV_NONE,
2477 {(char_u *)"small", (char_u *)0L}},
2478#endif
2479 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2480 (char_u *)&p_ttimeout, PV_NONE,
2481 {(char_u *)FALSE, (char_u *)0L}},
2482 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2483 (char_u *)&p_ttm, PV_NONE,
2484 {(char_u *)-1L, (char_u *)0L}},
2485 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2486 (char_u *)&p_tbi, PV_NONE,
2487 {(char_u *)TRUE, (char_u *)0L}},
2488 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2489 (char_u *)&p_tf, PV_NONE,
2490 {(char_u *)FALSE, (char_u *)0L}},
2491 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2492#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2493 (char_u *)&p_ttym, PV_NONE,
2494#else
2495 (char_u *)NULL, PV_NONE,
2496#endif
2497 {(char_u *)"", (char_u *)0L}},
2498 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2499 (char_u *)&p_ttyscroll, PV_NONE,
2500 {(char_u *)999L, (char_u *)0L}},
2501 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2502 (char_u *)&T_NAME, PV_NONE,
2503 {(char_u *)"", (char_u *)0L}},
2504 {"undolevels", "ul", P_NUM|P_VI_DEF,
2505 (char_u *)&p_ul, PV_NONE,
2506 {
2507#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2508 (char_u *)1000L,
2509#else
2510 (char_u *)100L,
2511#endif
2512 (char_u *)0L}},
2513 {"updatecount", "uc", P_NUM|P_VI_DEF,
2514 (char_u *)&p_uc, PV_NONE,
2515 {(char_u *)200L, (char_u *)0L}},
2516 {"updatetime", "ut", P_NUM|P_VI_DEF,
2517 (char_u *)&p_ut, PV_NONE,
2518 {(char_u *)4000L, (char_u *)0L}},
2519 {"verbose", "vbs", P_NUM|P_VI_DEF,
2520 (char_u *)&p_verbose, PV_NONE,
2521 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002522 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2523 (char_u *)&p_vfile, PV_NONE,
2524 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2526#ifdef FEAT_SESSION
2527 (char_u *)&p_vdir, PV_NONE,
2528 {(char_u *)DFLT_VDIR, (char_u *)0L}
2529#else
2530 (char_u *)NULL, PV_NONE,
2531 {(char_u *)0L, (char_u *)0L}
2532#endif
2533 },
2534 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2535#ifdef FEAT_SESSION
2536 (char_u *)&p_vop, PV_NONE,
2537 {(char_u *)"folds,options,cursor", (char_u *)0L}
2538#else
2539 (char_u *)NULL, PV_NONE,
2540 {(char_u *)0L, (char_u *)0L}
2541#endif
2542 },
2543 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2544#ifdef FEAT_VIMINFO
2545 (char_u *)&p_viminfo, PV_NONE,
2546#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2547 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2548#else
2549# ifdef AMIGA
2550 {(char_u *)"",
2551 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2552# else
2553 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2554# endif
2555#endif
2556#else
2557 (char_u *)NULL, PV_NONE,
2558 {(char_u *)0L, (char_u *)0L}
2559#endif
2560 },
2561 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2562#ifdef FEAT_VIRTUALEDIT
2563 (char_u *)&p_ve, PV_NONE,
2564 {(char_u *)"", (char_u *)""}
2565#else
2566 (char_u *)NULL, PV_NONE,
2567 {(char_u *)0L, (char_u *)0L}
2568#endif
2569 },
2570 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2571 (char_u *)&p_vb, PV_NONE,
2572 {(char_u *)FALSE, (char_u *)0L}},
2573 {"w300", NULL, P_NUM|P_VI_DEF,
2574 (char_u *)NULL, PV_NONE,
2575 {(char_u *)0L, (char_u *)0L}},
2576 {"w1200", NULL, P_NUM|P_VI_DEF,
2577 (char_u *)NULL, PV_NONE,
2578 {(char_u *)0L, (char_u *)0L}},
2579 {"w9600", NULL, P_NUM|P_VI_DEF,
2580 (char_u *)NULL, PV_NONE,
2581 {(char_u *)0L, (char_u *)0L}},
2582 {"warn", NULL, P_BOOL|P_VI_DEF,
2583 (char_u *)&p_warn, PV_NONE,
2584 {(char_u *)TRUE, (char_u *)0L}},
2585 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2586 (char_u *)&p_wiv, PV_NONE,
2587 {(char_u *)FALSE, (char_u *)0L}},
2588 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2589 (char_u *)&p_ww, PV_NONE,
2590 {(char_u *)"", (char_u *)"b,s"}},
2591 {"wildchar", "wc", P_NUM|P_VIM,
2592 (char_u *)&p_wc, PV_NONE,
2593 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2594 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2595 (char_u *)&p_wcm, PV_NONE,
2596 {(char_u *)0L, (char_u *)0L}},
2597 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2598#ifdef FEAT_WILDIGN
2599 (char_u *)&p_wig, PV_NONE,
2600#else
2601 (char_u *)NULL, PV_NONE,
2602#endif
2603 {(char_u *)"", (char_u *)0L}},
2604 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2605#ifdef FEAT_WILDMENU
2606 (char_u *)&p_wmnu, PV_NONE,
2607#else
2608 (char_u *)NULL, PV_NONE,
2609#endif
2610 {(char_u *)FALSE, (char_u *)0L}},
2611 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2612 (char_u *)&p_wim, PV_NONE,
2613 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002614 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2615#ifdef FEAT_CMDL_COMPL
2616 (char_u *)&p_wop, PV_NONE,
2617 {(char_u *)"", (char_u *)0L}
2618#else
2619 (char_u *)NULL, PV_NONE,
2620 {(char_u *)NULL, (char_u *)0L}
2621#endif
2622 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2624#ifdef FEAT_WAK
2625 (char_u *)&p_wak, PV_NONE,
2626 {(char_u *)"menu", (char_u *)0L}
2627#else
2628 (char_u *)NULL, PV_NONE,
2629 {(char_u *)NULL, (char_u *)0L}
2630#endif
2631 },
2632 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002633 (char_u *)&p_window, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {(char_u *)0L, (char_u *)0L}},
2635 {"winheight", "wh", P_NUM|P_VI_DEF,
2636#ifdef FEAT_WINDOWS
2637 (char_u *)&p_wh, PV_NONE,
2638#else
2639 (char_u *)NULL, PV_NONE,
2640#endif
2641 {(char_u *)1L, (char_u *)0L}},
2642 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002643#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 (char_u *)VAR_WIN, PV_WFH,
2645#else
2646 (char_u *)NULL, PV_NONE,
2647#endif
2648 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002649 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2650#ifdef FEAT_VERTSPLIT
2651 (char_u *)VAR_WIN, PV_WFW,
2652#else
2653 (char_u *)NULL, PV_NONE,
2654#endif
2655 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2657#ifdef FEAT_WINDOWS
2658 (char_u *)&p_wmh, PV_NONE,
2659#else
2660 (char_u *)NULL, PV_NONE,
2661#endif
2662 {(char_u *)1L, (char_u *)0L}},
2663 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2664#ifdef FEAT_VERTSPLIT
2665 (char_u *)&p_wmw, PV_NONE,
2666#else
2667 (char_u *)NULL, PV_NONE,
2668#endif
2669 {(char_u *)1L, (char_u *)0L}},
2670 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2671#ifdef FEAT_VERTSPLIT
2672 (char_u *)&p_wiw, PV_NONE,
2673#else
2674 (char_u *)NULL, PV_NONE,
2675#endif
2676 {(char_u *)20L, (char_u *)0L}},
2677 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2678 (char_u *)VAR_WIN, PV_WRAP,
2679 {(char_u *)TRUE, (char_u *)0L}},
2680 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2681 (char_u *)&p_wm, PV_WM,
2682 {(char_u *)0L, (char_u *)0L}},
2683 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2684 (char_u *)&p_ws, PV_NONE,
2685 {(char_u *)TRUE, (char_u *)0L}},
2686 {"write", NULL, P_BOOL|P_VI_DEF,
2687 (char_u *)&p_write, PV_NONE,
2688 {(char_u *)TRUE, (char_u *)0L}},
2689 {"writeany", "wa", P_BOOL|P_VI_DEF,
2690 (char_u *)&p_wa, PV_NONE,
2691 {(char_u *)FALSE, (char_u *)0L}},
2692 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2693 (char_u *)&p_wb, PV_NONE,
2694 {
2695#ifdef FEAT_WRITEBACKUP
2696 (char_u *)TRUE,
2697#else
2698 (char_u *)FALSE,
2699#endif
2700 (char_u *)0L}},
2701 {"writedelay", "wd", P_NUM|P_VI_DEF,
2702 (char_u *)&p_wd, PV_NONE,
2703 {(char_u *)0L, (char_u *)0L}},
2704
2705/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002706#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 (char_u *)&vvv, PV_NONE, \
2708 {(char_u *)"", (char_u *)0L}},
2709
2710 p_term("t_AB", T_CAB)
2711 p_term("t_AF", T_CAF)
2712 p_term("t_AL", T_CAL)
2713 p_term("t_al", T_AL)
2714 p_term("t_bc", T_BC)
2715 p_term("t_cd", T_CD)
2716 p_term("t_ce", T_CE)
2717 p_term("t_cl", T_CL)
2718 p_term("t_cm", T_CM)
2719 p_term("t_Co", T_CCO)
2720 p_term("t_CS", T_CCS)
2721 p_term("t_cs", T_CS)
2722#ifdef FEAT_VERTSPLIT
2723 p_term("t_CV", T_CSV)
2724#endif
2725 p_term("t_ut", T_UT)
2726 p_term("t_da", T_DA)
2727 p_term("t_db", T_DB)
2728 p_term("t_DL", T_CDL)
2729 p_term("t_dl", T_DL)
2730 p_term("t_fs", T_FS)
2731 p_term("t_IE", T_CIE)
2732 p_term("t_IS", T_CIS)
2733 p_term("t_ke", T_KE)
2734 p_term("t_ks", T_KS)
2735 p_term("t_le", T_LE)
2736 p_term("t_mb", T_MB)
2737 p_term("t_md", T_MD)
2738 p_term("t_me", T_ME)
2739 p_term("t_mr", T_MR)
2740 p_term("t_ms", T_MS)
2741 p_term("t_nd", T_ND)
2742 p_term("t_op", T_OP)
2743 p_term("t_RI", T_CRI)
2744 p_term("t_RV", T_CRV)
2745 p_term("t_Sb", T_CSB)
2746 p_term("t_Sf", T_CSF)
2747 p_term("t_se", T_SE)
2748 p_term("t_so", T_SO)
2749 p_term("t_sr", T_SR)
2750 p_term("t_ts", T_TS)
2751 p_term("t_te", T_TE)
2752 p_term("t_ti", T_TI)
2753 p_term("t_ue", T_UE)
2754 p_term("t_us", T_US)
2755 p_term("t_vb", T_VB)
2756 p_term("t_ve", T_VE)
2757 p_term("t_vi", T_VI)
2758 p_term("t_vs", T_VS)
2759 p_term("t_WP", T_CWP)
2760 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002761 p_term("t_SI", T_CSI)
2762 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 p_term("t_xs", T_XS)
2764 p_term("t_ZH", T_CZH)
2765 p_term("t_ZR", T_CZR)
2766
2767/* terminal key codes are not in here */
2768
2769 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2770};
2771
2772#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2773
2774#ifdef FEAT_MBYTE
2775static char *(p_ambw_values[]) = {"single", "double", NULL};
2776#endif
2777static char *(p_bg_values[]) = {"light", "dark", NULL};
2778static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2779static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002780#ifdef FEAT_CMDL_COMPL
2781static char *(p_wop_values[]) = {"tagfile", NULL};
2782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783#ifdef FEAT_WAK
2784static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2785#endif
2786static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2787#ifdef FEAT_VISUAL
2788static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2789static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2790#endif
2791#ifdef FEAT_VISUAL
2792static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2793#endif
2794#ifdef FEAT_BROWSE
2795static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2796#endif
2797#ifdef FEAT_SCROLLBIND
2798static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2799#endif
2800static char *(p_swb_values[]) = {"useopen", "split", NULL};
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002801static char *(p_debug_values[]) = {"msg", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802#ifdef FEAT_VERTSPLIT
2803static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2804#endif
2805#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002806# ifdef FEAT_AUTOCMD
2807static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2808# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002810# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2812#endif
2813static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2814#ifdef FEAT_FOLDING
2815static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002816# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002818# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 NULL};
2820static char *(p_fcl_values[]) = {"all", NULL};
2821#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002822#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002823static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825
2826static void set_option_default __ARGS((int, int opt_flags, int compatible));
2827static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002828static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002829static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830static char_u *illegal_char __ARGS((char_u *, int));
2831static int string_to_key __ARGS((char_u *arg));
2832#ifdef FEAT_CMDWIN
2833static char_u *check_cedit __ARGS((void));
2834#endif
2835#ifdef FEAT_TITLE
2836static void did_set_title __ARGS((int icon));
2837#endif
2838static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2839static void didset_options __ARGS((void));
2840static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002841#if defined(FEAT_EVAL) || defined(PROTO)
2842static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2843#else
2844# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2847static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2848static 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));
2849static char_u *set_chars_option __ARGS((char_u **varp));
2850#ifdef FEAT_CLIPBOARD
2851static char_u *check_clipboard_option __ARGS((void));
2852#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002853#ifdef FEAT_SPELL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002854static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002855#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002856#ifdef FEAT_EVAL
2857static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2858#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002860static 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 +00002861static void check_redraw __ARGS((long_u flags));
2862static int findoption __ARGS((char_u *));
2863static int find_key_option __ARGS((char_u *));
2864static void showoptions __ARGS((int all, int opt_flags));
2865static int optval_default __ARGS((struct vimoption *, char_u *varp));
2866static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2867static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2868static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2869static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2870static int istermoption __ARGS((struct vimoption *));
2871static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2872static char_u *get_varp __ARGS((struct vimoption *));
2873static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2874static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2875#ifdef FEAT_LANGMAP
2876static void langmap_init __ARGS((void));
2877static void langmap_set __ARGS((void));
2878#endif
2879static void paste_option_changed __ARGS((void));
2880static void compatible_set __ARGS((void));
2881#ifdef FEAT_LINEBREAK
2882static void fill_breakat_flags __ARGS((void));
2883#endif
2884static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2885static int check_opt_strings __ARGS((char_u *val, char **values, int));
2886static int check_opt_wim __ARGS((void));
2887
2888/*
2889 * Initialize the options, first part.
2890 *
2891 * Called only once from main(), just after creating the first buffer.
2892 */
2893 void
2894set_init_1()
2895{
2896 char_u *p;
2897 int opt_idx;
2898 long n;
2899
2900#ifdef FEAT_LANGMAP
2901 langmap_init();
2902#endif
2903
2904 /* Be Vi compatible by default */
2905 p_cp = TRUE;
2906
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002907 /* Use POSIX compatibility when $VIM_POSIX is set. */
2908 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002909 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002910 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002911 set_string_default("shm", (char_u *)"A");
2912 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002913
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 /*
2915 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002916 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002918 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2920# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002921 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002923 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002925 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926# endif
2927#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002928 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 set_string_default("sh", p);
2930
2931#ifdef FEAT_WILDIGN
2932 /*
2933 * Set the default for 'backupskip' to include environment variables for
2934 * temp files.
2935 */
2936 {
2937# ifdef UNIX
2938 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2939# else
2940 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2941# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002942 int len;
2943 garray_T ga;
2944 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945
2946 ga_init2(&ga, 1, 100);
2947 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2948 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002949 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950# ifdef UNIX
2951 if (*names[n] == NUL)
2952 p = (char_u *)"/tmp";
2953 else
2954# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002955 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 if (p != NULL && *p != NUL)
2957 {
2958 /* First time count the NUL, otherwise count the ','. */
2959 len = STRLEN(p) + 3;
2960 if (ga_grow(&ga, len) == OK)
2961 {
2962 if (ga.ga_len > 0)
2963 STRCAT(ga.ga_data, ",");
2964 STRCAT(ga.ga_data, p);
2965 add_pathsep(ga.ga_data);
2966 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 ga.ga_len += len;
2968 }
2969 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002970 if (mustfree)
2971 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 }
2973 if (ga.ga_data != NULL)
2974 {
2975 set_string_default("bsk", ga.ga_data);
2976 vim_free(ga.ga_data);
2977 }
2978 }
2979#endif
2980
2981 /*
2982 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2983 */
2984 opt_idx = findoption((char_u *)"maxmemtot");
2985#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2986 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2987#endif
2988 {
2989#ifdef HAVE_AVAIL_MEM
2990 /* Use amount of memory available at this moment. */
2991 n = (mch_avail_mem(FALSE) >> 11);
2992#else
2993# ifdef HAVE_TOTAL_MEM
2994 /* Use amount of memory available to Vim. */
2995 n = (mch_total_mem(FALSE) >> 11);
2996# else
2997 n = (0x7fffffff >> 11);
2998# endif
2999#endif
3000 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3001 opt_idx = findoption((char_u *)"maxmem");
3002#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3003 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3004 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3005#endif
3006 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3007 }
3008
3009#ifdef FEAT_GUI_W32
3010 /* force 'shortname' for Win32s */
3011 if (gui_is_win32s())
3012 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
3013 (char_u *)TRUE;
3014#endif
3015
3016#ifdef FEAT_SEARCHPATH
3017 {
3018 char_u *cdpath;
3019 char_u *buf;
3020 int i;
3021 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003022 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023
3024 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003025 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 if (cdpath != NULL)
3027 {
3028 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3029 if (buf != NULL)
3030 {
3031 buf[0] = ','; /* start with ",", current dir first */
3032 j = 1;
3033 for (i = 0; cdpath[i] != NUL; ++i)
3034 {
3035 if (vim_ispathlistsep(cdpath[i]))
3036 buf[j++] = ',';
3037 else
3038 {
3039 if (cdpath[i] == ' ' || cdpath[i] == ',')
3040 buf[j++] = '\\';
3041 buf[j++] = cdpath[i];
3042 }
3043 }
3044 buf[j] = NUL;
3045 opt_idx = findoption((char_u *)"cdpath");
3046 options[opt_idx].def_val[VI_DEFAULT] = buf;
3047 options[opt_idx].flags |= P_DEF_ALLOCED;
3048 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003049 if (mustfree)
3050 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 }
3052 }
3053#endif
3054
3055#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3056 /* Set print encoding on platforms that don't default to latin1 */
3057 set_string_default("penc",
3058# if defined(MSWIN) || defined(OS2)
3059 (char_u *)"cp1252"
3060# else
3061# ifdef VMS
3062 (char_u *)"dec-mcs"
3063# else
3064# ifdef EBCDIC
3065 (char_u *)"ebcdic-uk"
3066# else
3067# ifdef MAC
3068 (char_u *)"mac-roman"
3069# else /* HPUX */
3070 (char_u *)"hp-roman8"
3071# endif
3072# endif
3073# endif
3074# endif
3075 );
3076#endif
3077
3078#ifdef FEAT_POSTSCRIPT
3079 /* 'printexpr' must be allocated to be able to evaluate it. */
3080 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003081# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3082 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083# else
3084# ifdef VMS
3085 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3086
3087# else
3088 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3089# endif
3090# endif
3091 );
3092#endif
3093
3094 /*
3095 * Set all the options (except the terminal options) to their default
3096 * value. Also set the global value for local options.
3097 */
3098 set_options_default(0);
3099
3100#ifdef FEAT_GUI
3101 if (found_reverse_arg)
3102 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3103#endif
3104
3105 curbuf->b_p_initialized = TRUE;
3106 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3107 check_buf_options(curbuf);
3108 check_win_options(curwin);
3109 check_options();
3110
3111 /* Must be before option_expand(), because that one needs vim_isIDc() */
3112 didset_options();
3113
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003114#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003115 /* Use the current chartab for the generic chartab. */
3116 init_spell_chartab();
3117#endif
3118
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119#ifdef FEAT_LINEBREAK
3120 /*
3121 * initialize the table for 'breakat'.
3122 */
3123 fill_breakat_flags();
3124#endif
3125
3126 /*
3127 * Expand environment variables and things like "~" for the defaults.
3128 * If option_expand() returns non-NULL the variable is expanded. This can
3129 * only happen for non-indirect options.
3130 * Also set the default to the expanded value, so ":set" does not list
3131 * them.
3132 * Don't set the P_ALLOCED flag, because we don't want to free the
3133 * default.
3134 */
3135 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3136 {
3137 if ((options[opt_idx].flags & P_GETTEXT)
3138 && options[opt_idx].var != NULL)
3139 p = (char_u *)_(*(char **)options[opt_idx].var);
3140 else
3141 p = option_expand(opt_idx, NULL);
3142 if (p != NULL && (p = vim_strsave(p)) != NULL)
3143 {
3144 *(char_u **)options[opt_idx].var = p;
3145 /* VIMEXP
3146 * Defaults for all expanded options are currently the same for Vi
3147 * and Vim. When this changes, add some code here! Also need to
3148 * split P_DEF_ALLOCED in two.
3149 */
3150 if (options[opt_idx].flags & P_DEF_ALLOCED)
3151 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3152 options[opt_idx].def_val[VI_DEFAULT] = p;
3153 options[opt_idx].flags |= P_DEF_ALLOCED;
3154 }
3155 }
3156
3157 /* Initialize the highlight_attr[] table. */
3158 highlight_changed();
3159
3160 save_file_ff(curbuf); /* Buffer is unchanged */
3161
3162 /* Parse default for 'wildmode' */
3163 check_opt_wim();
3164
3165#if defined(FEAT_ARABIC)
3166 /* Detect use of mlterm.
3167 * Mlterm is a terminal emulator akin to xterm that has some special
3168 * abilities (bidi namely).
3169 * NOTE: mlterm's author is being asked to 'set' a variable
3170 * instead of an environment variable due to inheritance.
3171 */
3172 if (mch_getenv((char_u *)"MLTERM") != NULL)
3173 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3174#endif
3175
3176#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3177 /* Parse default for 'fillchars'. */
3178 (void)set_chars_option(&p_fcs);
3179#endif
3180
3181#ifdef FEAT_CLIPBOARD
3182 /* Parse default for 'clipboard' */
3183 (void)check_clipboard_option();
3184#endif
3185
3186#ifdef FEAT_MBYTE
3187# if defined(WIN3264) && defined(FEAT_GETTEXT)
3188 /*
3189 * If $LANG isn't set, try to get a good value for it. This makes the
3190 * right language be used automatically. Don't do this for English.
3191 */
3192 if (mch_getenv((char_u *)"LANG") == NULL)
3193 {
3194 char buf[20];
3195
3196 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3197 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3198 * only the first two. */
3199 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3200 (LPTSTR)buf, 20);
3201 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3202 {
3203 /* There are a few exceptions (probably more) */
3204 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3205 STRCPY(buf, "zh_TW");
3206 else if (STRNICMP(buf, "chs", 3) == 0
3207 || STRNICMP(buf, "zhc", 3) == 0)
3208 STRCPY(buf, "zh_CN");
3209 else if (STRNICMP(buf, "jp", 2) == 0)
3210 STRCPY(buf, "ja");
3211 else
3212 buf[2] = NUL; /* truncate to two-letter code */
3213 vim_setenv("LANG", buf);
3214 }
3215 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003216# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003217# ifdef MACOS_CONVERT
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003218 if (mch_getenv((char_u *)"LANG") == NULL)
3219 {
3220 char buf[20];
3221 if (LocaleRefGetPartString(NULL,
3222 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3223 kLocaleRegionMask | kLocaleRegionVariantMask,
3224 sizeof buf, buf) == noErr && *buf)
3225 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003226 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003227# ifdef HAVE_LOCALE_H
3228 setlocale(LC_ALL, "");
3229# endif
3230 }
3231 }
3232# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233# endif
3234
3235 /* enc_locale() will try to find the encoding of the current locale. */
3236 p = enc_locale();
3237 if (p != NULL)
3238 {
3239 char_u *save_enc;
3240
3241 /* Try setting 'encoding' and check if the value is valid.
3242 * If not, go back to the default "latin1". */
3243 save_enc = p_enc;
3244 p_enc = p;
3245 if (mb_init() == NULL)
3246 {
3247 opt_idx = findoption((char_u *)"encoding");
3248 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3249 options[opt_idx].flags |= P_DEF_ALLOCED;
3250
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003251#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3252 || defined(VMS)
3253 if (STRCMP(p_enc, "latin1") == 0
3254# ifdef FEAT_MBYTE
3255 || enc_utf8
3256# endif
3257 )
3258 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003259 /* Adjust the default for 'isprint' and 'iskeyword' to match
3260 * latin1. Also set the defaults for when 'nocompatible' is
3261 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003262 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003263 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003264 set_string_option_direct((char_u *)"isk", -1,
3265 ISK_LATIN1, OPT_FREE, SID_NONE);
3266 opt_idx = findoption((char_u *)"isp");
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003267 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003268 opt_idx = findoption((char_u *)"isk");
3269 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003270 (void)init_chartab();
3271 }
3272#endif
3273
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274# if defined(WIN3264) && !defined(FEAT_GUI)
3275 /* Win32 console: When GetACP() returns a different value from
3276 * GetConsoleCP() set 'termencoding'. */
3277 if (GetACP() != GetConsoleCP())
3278 {
3279 char buf[50];
3280
3281 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3282 p_tenc = vim_strsave((char_u *)buf);
3283 if (p_tenc != NULL)
3284 {
3285 opt_idx = findoption((char_u *)"termencoding");
3286 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3287 options[opt_idx].flags |= P_DEF_ALLOCED;
3288 convert_setup(&input_conv, p_tenc, p_enc);
3289 convert_setup(&output_conv, p_enc, p_tenc);
3290 }
3291 else
3292 p_tenc = empty_option;
3293 }
3294# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003295# if defined(WIN3264) && defined(FEAT_MBYTE)
3296 /* $HOME may have characters in active code page. */
3297 init_homedir();
3298# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299 }
3300 else
3301 {
3302 vim_free(p_enc);
3303 p_enc = save_enc;
3304 }
3305 }
3306#endif
3307
3308#ifdef FEAT_MULTI_LANG
3309 /* Set the default for 'helplang'. */
3310 set_helplang_default(get_mess_lang());
3311#endif
3312}
3313
3314/*
3315 * Set an option to its default value.
3316 * This does not take care of side effects!
3317 */
3318 static void
3319set_option_default(opt_idx, opt_flags, compatible)
3320 int opt_idx;
3321 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3322 int compatible; /* use Vi default value */
3323{
3324 char_u *varp; /* pointer to variable for current option */
3325 int dvi; /* index in def_val[] */
3326 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003327 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3329
3330 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3331 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003332 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 {
3334 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3335 if (flags & P_STRING)
3336 {
3337 /* Use set_string_option_direct() for local options to handle
3338 * freeing and allocating the value. */
3339 if (options[opt_idx].indir != PV_NONE)
3340 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003341 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342 else
3343 {
3344 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3345 free_string_option(*(char_u **)(varp));
3346 *(char_u **)varp = options[opt_idx].def_val[dvi];
3347 options[opt_idx].flags &= ~P_ALLOCED;
3348 }
3349 }
3350 else if (flags & P_NUM)
3351 {
3352 if (varp == (char_u *)PV_SCROLL)
3353 win_comp_scroll(curwin);
3354 else
3355 {
3356 *(long *)varp = (long)options[opt_idx].def_val[dvi];
3357 /* May also set global value for local option. */
3358 if (both)
3359 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3360 *(long *)varp;
3361 }
3362 }
3363 else /* P_BOOL */
3364 {
3365 /* the cast to long is required for Manx C */
3366 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3367 /* May also set global value for local option. */
3368 if (both)
3369 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3370 *(int *)varp;
3371 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003372
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003373 /* The default value is not insecure. */
3374 flagsp = insecure_flag(opt_idx, opt_flags);
3375 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376 }
3377
3378#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003379 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380#endif
3381}
3382
3383/*
3384 * Set all options (except terminal options) to their default value.
3385 */
3386 static void
3387set_options_default(opt_flags)
3388 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3389{
3390 int i;
3391#ifdef FEAT_WINDOWS
3392 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003393 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003394#endif
3395
3396 for (i = 0; !istermoption(&options[i]); i++)
3397 if (!(options[i].flags & P_NODEFAULT))
3398 set_option_default(i, opt_flags, p_cp);
3399
3400#ifdef FEAT_WINDOWS
3401 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003402 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403 win_comp_scroll(wp);
3404#else
3405 win_comp_scroll(curwin);
3406#endif
3407}
3408
3409/*
3410 * Set the Vi-default value of a string option.
3411 * Used for 'sh', 'backupskip' and 'term'.
3412 */
3413 void
3414set_string_default(name, val)
3415 char *name;
3416 char_u *val;
3417{
3418 char_u *p;
3419 int opt_idx;
3420
3421 p = vim_strsave(val);
3422 if (p != NULL) /* we don't want a NULL */
3423 {
3424 opt_idx = findoption((char_u *)name);
3425 if (options[opt_idx].flags & P_DEF_ALLOCED)
3426 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3427 options[opt_idx].def_val[VI_DEFAULT] = p;
3428 options[opt_idx].flags |= P_DEF_ALLOCED;
3429 }
3430}
3431
3432/*
3433 * Set the Vi-default value of a number option.
3434 * Used for 'lines' and 'columns'.
3435 */
3436 void
3437set_number_default(name, val)
3438 char *name;
3439 long val;
3440{
3441 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3442}
3443
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003444#if defined(EXITFREE) || defined(PROTO)
3445/*
3446 * Free all options.
3447 */
3448 void
3449free_all_options()
3450{
3451 int i;
3452
3453 for (i = 0; !istermoption(&options[i]); i++)
3454 {
3455 if (options[i].indir == PV_NONE)
3456 {
3457 /* global option: free value and default value. */
3458 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3459 free_string_option(*(char_u **)options[i].var);
3460 if (options[i].flags & P_DEF_ALLOCED)
3461 free_string_option(options[i].def_val[VI_DEFAULT]);
3462 }
3463 else if (options[i].var != VAR_WIN
3464 && (options[i].flags & P_STRING))
3465 /* buffer-local option: free global value */
3466 free_string_option(*(char_u **)options[i].var);
3467 }
3468}
3469#endif
3470
3471
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472/*
3473 * Initialize the options, part two: After getting Rows and Columns and
3474 * setting 'term'.
3475 */
3476 void
3477set_init_2()
3478{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003479 int idx;
3480
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481 /*
3482 * 'scroll' defaults to half the window height. Note that this default is
3483 * wrong when the window height changes.
3484 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003485 set_number_default("scroll", (long_u)Rows >> 1);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003486 idx = findoption((char_u *)"scroll");
3487 if (!(options[idx].flags & P_WAS_SET))
3488 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003489 comp_col();
3490
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003491 /*
3492 * 'window' is only for backwards compatibility with Vi.
3493 * Default is Rows - 1.
3494 */
3495 idx = findoption((char_u *)"wi");
3496 if (!(options[idx].flags & P_WAS_SET))
3497 p_window = Rows - 1;
3498 set_number_default("window", Rows - 1);
3499
Bram Moolenaarf740b292006-02-16 22:11:02 +00003500 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003501#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003502 /*
3503 * If 'background' wasn't set by the user, try guessing the value,
3504 * depending on the terminal name. Only need to check for terminals
3505 * with a dark background, that can handle color.
3506 */
3507 idx = findoption((char_u *)"bg");
3508 if (!(options[idx].flags & P_WAS_SET) && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003510 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003511 /* don't mark it as set, when starting the GUI it may be
3512 * changed again */
3513 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514 }
3515#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003516
3517#ifdef CURSOR_SHAPE
3518 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3519#endif
3520#ifdef FEAT_MOUSESHAPE
3521 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3522#endif
3523#ifdef FEAT_PRINTER
3524 (void)parse_printoptions(); /* parse 'printoptions' default value */
3525#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526}
3527
3528/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003529 * Return "dark" or "light" depending on the kind of terminal.
3530 * This is just guessing! Recognized are:
3531 * "linux" Linux console
3532 * "screen.linux" Linux console with screen
3533 * "cygwin" Cygwin shell
3534 * "putty" Putty program
3535 * We also check the COLORFGBG environment variable, which is set by
3536 * rxvt and derivatives. This variable contains either two or three
3537 * values separated by semicolons; we want the last value in either
3538 * case. If this value is 0-6 or 8, our background is dark.
3539 */
3540 static char_u *
3541term_bg_default()
3542{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003543#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3544 /* DOS console nearly always black */
3545 return (char_u *)"dark";
3546#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003547 char_u *p;
3548
Bram Moolenaarf740b292006-02-16 22:11:02 +00003549 if (STRCMP(T_NAME, "linux") == 0
3550 || STRCMP(T_NAME, "screen.linux") == 0
3551 || STRCMP(T_NAME, "cygwin") == 0
3552 || STRCMP(T_NAME, "putty") == 0
3553 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3554 && (p = vim_strrchr(p, ';')) != NULL
3555 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3556 && p[2] == NUL))
3557 return (char_u *)"dark";
3558 return (char_u *)"light";
3559#endif
3560}
3561
3562/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003563 * Initialize the options, part three: After reading the .vimrc
3564 */
3565 void
3566set_init_3()
3567{
3568#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3569/*
3570 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3571 * This is done after other initializations, where 'shell' might have been
3572 * set, but only if they have not been set before.
3573 */
3574 char_u *p;
3575 int idx_srr;
3576 int do_srr;
3577#ifdef FEAT_QUICKFIX
3578 int idx_sp;
3579 int do_sp;
3580#endif
3581
3582 idx_srr = findoption((char_u *)"srr");
3583 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3584#ifdef FEAT_QUICKFIX
3585 idx_sp = findoption((char_u *)"sp");
3586 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3587#endif
3588
3589 /*
3590 * Isolate the name of the shell:
3591 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3592 * - Remove any argument. E.g., "csh -f" -> "csh".
3593 */
3594 p = gettail(p_sh);
3595 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3596 if (p != NULL)
3597 {
3598 /*
3599 * Default for p_sp is "| tee", for p_srr is ">".
3600 * For known shells it is changed here to include stderr.
3601 */
3602 if ( fnamecmp(p, "csh") == 0
3603 || fnamecmp(p, "tcsh") == 0
3604# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3605 || fnamecmp(p, "csh.exe") == 0
3606 || fnamecmp(p, "tcsh.exe") == 0
3607# endif
3608 )
3609 {
3610#if defined(FEAT_QUICKFIX)
3611 if (do_sp)
3612 {
3613# ifdef WIN3264
3614 p_sp = (char_u *)">&";
3615# else
3616 p_sp = (char_u *)"|& tee";
3617# endif
3618 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3619 }
3620#endif
3621 if (do_srr)
3622 {
3623 p_srr = (char_u *)">&";
3624 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3625 }
3626 }
3627 else
3628# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3629 if ( fnamecmp(p, "sh") == 0
3630 || fnamecmp(p, "ksh") == 0
3631 || fnamecmp(p, "zsh") == 0
3632 || fnamecmp(p, "bash") == 0
3633# ifdef WIN3264
3634 || fnamecmp(p, "cmd") == 0
3635 || fnamecmp(p, "sh.exe") == 0
3636 || fnamecmp(p, "ksh.exe") == 0
3637 || fnamecmp(p, "zsh.exe") == 0
3638 || fnamecmp(p, "bash.exe") == 0
3639 || fnamecmp(p, "cmd.exe") == 0
3640# endif
3641 )
3642# endif
3643 {
3644#if defined(FEAT_QUICKFIX)
3645 if (do_sp)
3646 {
3647# ifdef WIN3264
3648 p_sp = (char_u *)">%s 2>&1";
3649# else
3650 p_sp = (char_u *)"2>&1| tee";
3651# endif
3652 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3653 }
3654#endif
3655 if (do_srr)
3656 {
3657 p_srr = (char_u *)">%s 2>&1";
3658 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3659 }
3660 }
3661 vim_free(p);
3662 }
3663#endif
3664
3665#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3666 /*
3667 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3668 * This is done after other initializations, where 'shell' might have been
3669 * set, but only if they have not been set before. Default for p_shcf is
3670 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3671 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3672 * command.com. And for Win32 we need to set p_sxq instead.
3673 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003674 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003675 {
3676 int idx3;
3677
3678 idx3 = findoption((char_u *)"shcf");
3679 if (!(options[idx3].flags & P_WAS_SET))
3680 {
3681 p_shcf = (char_u *)"-c";
3682 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3683 }
3684
3685# ifndef DJGPP
3686# ifdef WIN3264
3687 /* Somehow Win32 requires the quotes around the redirection too */
3688 idx3 = findoption((char_u *)"sxq");
3689 if (!(options[idx3].flags & P_WAS_SET))
3690 {
3691 p_sxq = (char_u *)"\"";
3692 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3693 }
3694# else
3695 idx3 = findoption((char_u *)"shq");
3696 if (!(options[idx3].flags & P_WAS_SET))
3697 {
3698 p_shq = (char_u *)"\"";
3699 options[idx3].def_val[VI_DEFAULT] = p_shq;
3700 }
3701# endif
3702# endif
3703 }
3704#endif
3705
3706#ifdef FEAT_TITLE
3707 set_title_defaults();
3708#endif
3709}
3710
3711#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3712/*
3713 * When 'helplang' is still at its default value, set it to "lang".
3714 * Only the first two characters of "lang" are used.
3715 */
3716 void
3717set_helplang_default(lang)
3718 char_u *lang;
3719{
3720 int idx;
3721
3722 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3723 return;
3724 idx = findoption((char_u *)"hlg");
3725 if (!(options[idx].flags & P_WAS_SET))
3726 {
3727 if (options[idx].flags & P_ALLOCED)
3728 free_string_option(p_hlg);
3729 p_hlg = vim_strsave(lang);
3730 if (p_hlg == NULL)
3731 p_hlg = empty_option;
3732 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003733 {
3734 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3735 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3736 {
3737 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3738 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3739 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003741 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 options[idx].flags |= P_ALLOCED;
3743 }
3744}
3745#endif
3746
3747#ifdef FEAT_GUI
3748static char_u *gui_bg_default __ARGS((void));
3749
3750 static char_u *
3751gui_bg_default()
3752{
3753 if (gui_get_lightness(gui.back_pixel) < 127)
3754 return (char_u *)"dark";
3755 return (char_u *)"light";
3756}
3757
3758/*
3759 * Option initializations that can only be done after opening the GUI window.
3760 */
3761 void
3762init_gui_options()
3763{
3764 /* Set the 'background' option according to the lightness of the
3765 * background color, unless the user has set it already. */
3766 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3767 {
3768 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3769 highlight_changed();
3770 }
3771}
3772#endif
3773
3774#ifdef FEAT_TITLE
3775/*
3776 * 'title' and 'icon' only default to true if they have not been set or reset
3777 * in .vimrc and we can read the old value.
3778 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3779 * they can be reset. This reduces startup time when using X on a remote
3780 * machine.
3781 */
3782 void
3783set_title_defaults()
3784{
3785 int idx1;
3786 long val;
3787
3788 /*
3789 * If GUI is (going to be) used, we can always set the window title and
3790 * icon name. Saves a bit of time, because the X11 display server does
3791 * not need to be contacted.
3792 */
3793 idx1 = findoption((char_u *)"title");
3794 if (!(options[idx1].flags & P_WAS_SET))
3795 {
3796#ifdef FEAT_GUI
3797 if (gui.starting || gui.in_use)
3798 val = TRUE;
3799 else
3800#endif
3801 val = mch_can_restore_title();
3802 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3803 p_title = val;
3804 }
3805 idx1 = findoption((char_u *)"icon");
3806 if (!(options[idx1].flags & P_WAS_SET))
3807 {
3808#ifdef FEAT_GUI
3809 if (gui.starting || gui.in_use)
3810 val = TRUE;
3811 else
3812#endif
3813 val = mch_can_restore_icon();
3814 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3815 p_icon = val;
3816 }
3817}
3818#endif
3819
3820/*
3821 * Parse 'arg' for option settings.
3822 *
3823 * 'arg' may be IObuff, but only when no errors can be present and option
3824 * does not need to be expanded with option_expand().
3825 * "opt_flags":
3826 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00003827 * OPT_GLOBAL for ":setglobal"
3828 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00003830 * OPT_WINONLY to only set window-local options
3831 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00003832 *
3833 * returns FAIL if an error is detected, OK otherwise
3834 */
3835 int
3836do_set(arg, opt_flags)
3837 char_u *arg; /* option string (may be written to!) */
3838 int opt_flags;
3839{
3840 int opt_idx;
3841 char_u *errmsg;
3842 char_u errbuf[80];
3843 char_u *startarg;
3844 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3845 int nextchar; /* next non-white char after option name */
3846 int afterchar; /* character just after option name */
3847 int len;
3848 int i;
3849 long value;
3850 int key;
3851 long_u flags; /* flags for current option */
3852 char_u *varp = NULL; /* pointer to variable for current option */
3853 int did_show = FALSE; /* already showed one value */
3854 int adding; /* "opt+=arg" */
3855 int prepending; /* "opt^=arg" */
3856 int removing; /* "opt-=arg" */
3857 int cp_val = 0;
3858 char_u key_name[2];
3859
3860 if (*arg == NUL)
3861 {
3862 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003863 did_show = TRUE;
3864 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865 }
3866
3867 while (*arg != NUL) /* loop to process all options */
3868 {
3869 errmsg = NULL;
3870 startarg = arg; /* remember for error message */
3871
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003872 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3873 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874 {
3875 /*
3876 * ":set all" show all options.
3877 * ":set all&" set all options to their default value.
3878 */
3879 arg += 3;
3880 if (*arg == '&')
3881 {
3882 ++arg;
3883 /* Only for :set command set global value of local options. */
3884 set_options_default(OPT_FREE | opt_flags);
3885 }
3886 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003887 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003889 did_show = TRUE;
3890 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003892 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 {
3894 showoptions(2, opt_flags);
3895 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003896 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 arg += 7;
3898 }
3899 else
3900 {
3901 prefix = 1;
3902 if (STRNCMP(arg, "no", 2) == 0)
3903 {
3904 prefix = 0;
3905 arg += 2;
3906 }
3907 else if (STRNCMP(arg, "inv", 3) == 0)
3908 {
3909 prefix = 2;
3910 arg += 3;
3911 }
3912
3913 /* find end of name */
3914 key = 0;
3915 if (*arg == '<')
3916 {
3917 nextchar = 0;
3918 opt_idx = -1;
3919 /* look out for <t_>;> */
3920 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3921 len = 5;
3922 else
3923 {
3924 len = 1;
3925 while (arg[len] != NUL && arg[len] != '>')
3926 ++len;
3927 }
3928 if (arg[len] != '>')
3929 {
3930 errmsg = e_invarg;
3931 goto skip;
3932 }
3933 arg[len] = NUL; /* put NUL after name */
3934 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3935 opt_idx = findoption(arg + 1);
3936 arg[len++] = '>'; /* restore '>' */
3937 if (opt_idx == -1)
3938 key = find_key_option(arg + 1);
3939 }
3940 else
3941 {
3942 len = 0;
3943 /*
3944 * The two characters after "t_" may not be alphanumeric.
3945 */
3946 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3947 len = 4;
3948 else
3949 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3950 ++len;
3951 nextchar = arg[len];
3952 arg[len] = NUL; /* put NUL after name */
3953 opt_idx = findoption(arg);
3954 arg[len] = nextchar; /* restore nextchar */
3955 if (opt_idx == -1)
3956 key = find_key_option(arg);
3957 }
3958
3959 /* remember character after option name */
3960 afterchar = arg[len];
3961
3962 /* skip white space, allow ":set ai ?" */
3963 while (vim_iswhite(arg[len]))
3964 ++len;
3965
3966 adding = FALSE;
3967 prepending = FALSE;
3968 removing = FALSE;
3969 if (arg[len] != NUL && arg[len + 1] == '=')
3970 {
3971 if (arg[len] == '+')
3972 {
3973 adding = TRUE; /* "+=" */
3974 ++len;
3975 }
3976 else if (arg[len] == '^')
3977 {
3978 prepending = TRUE; /* "^=" */
3979 ++len;
3980 }
3981 else if (arg[len] == '-')
3982 {
3983 removing = TRUE; /* "-=" */
3984 ++len;
3985 }
3986 }
3987 nextchar = arg[len];
3988
3989 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3990 {
3991 errmsg = (char_u *)N_("E518: Unknown option");
3992 goto skip;
3993 }
3994
3995 if (opt_idx >= 0)
3996 {
3997 if (options[opt_idx].var == NULL) /* hidden option: skip */
3998 {
3999 /* Only give an error message when requesting the value of
4000 * a hidden option, ignore setting it. */
4001 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4002 && (!(options[opt_idx].flags & P_BOOL)
4003 || nextchar == '?'))
4004 errmsg = (char_u *)N_("E519: Option not supported");
4005 goto skip;
4006 }
4007
4008 flags = options[opt_idx].flags;
4009 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4010 }
4011 else
4012 {
4013 flags = P_STRING;
4014 if (key < 0)
4015 {
4016 key_name[0] = KEY2TERMCAP0(key);
4017 key_name[1] = KEY2TERMCAP1(key);
4018 }
4019 else
4020 {
4021 key_name[0] = KS_KEY;
4022 key_name[1] = (key & 0xff);
4023 }
4024 }
4025
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004026 /* Skip all options that are not window-local (used when showing
4027 * an already loaded buffer in a window). */
4028 if ((opt_flags & OPT_WINONLY)
4029 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4030 goto skip;
4031
Bram Moolenaara3227e22006-03-08 21:32:40 +00004032 /* Skip all options that are window-local (used for :vimgrep). */
4033 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4034 && options[opt_idx].var == VAR_WIN)
4035 goto skip;
4036
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 /* Disallow changing some options from modelines */
4038 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
4039 {
4040 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4041 goto skip;
4042 }
4043
4044#ifdef HAVE_SANDBOX
4045 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004046 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 {
4048 errmsg = (char_u *)_(e_sandbox);
4049 goto skip;
4050 }
4051#endif
4052
4053 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4054 {
4055 arg += len;
4056 cp_val = p_cp;
4057 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4058 {
4059 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4060 {
4061 cp_val = FALSE;
4062 arg += 3;
4063 }
4064 else /* "opt&vi": set to Vi default */
4065 {
4066 cp_val = TRUE;
4067 arg += 2;
4068 }
4069 }
4070 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4071 && arg[1] != NUL && !vim_iswhite(arg[1]))
4072 {
4073 errmsg = e_trailing;
4074 goto skip;
4075 }
4076 }
4077
4078 /*
4079 * allow '=' and ':' as MSDOS command.com allows only one
4080 * '=' character per "set" command line. grrr. (jw)
4081 */
4082 if (nextchar == '?'
4083 || (prefix == 1
4084 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4085 && !(flags & P_BOOL)))
4086 {
4087 /*
4088 * print value
4089 */
4090 if (did_show)
4091 msg_putchar('\n'); /* cursor below last one */
4092 else
4093 {
4094 gotocmdline(TRUE); /* cursor at status line */
4095 did_show = TRUE; /* remember that we did a line */
4096 }
4097 if (opt_idx >= 0)
4098 {
4099 showoneopt(&options[opt_idx], opt_flags);
4100#ifdef FEAT_EVAL
4101 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004102 {
4103 /* Mention where the option was last set. */
4104 if (varp == options[opt_idx].var)
4105 last_set_msg(options[opt_idx].scriptID);
4106 else if ((int)options[opt_idx].indir & PV_WIN)
4107 last_set_msg(curwin->w_p_scriptID[
4108 (int)options[opt_idx].indir & PV_MASK]);
4109 else if ((int)options[opt_idx].indir & PV_BUF)
4110 last_set_msg(curbuf->b_p_scriptID[
4111 (int)options[opt_idx].indir & PV_MASK]);
4112 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113#endif
4114 }
4115 else
4116 {
4117 char_u *p;
4118
4119 p = find_termcode(key_name);
4120 if (p == NULL)
4121 {
4122 errmsg = (char_u *)N_("E518: Unknown option");
4123 goto skip;
4124 }
4125 else
4126 (void)show_one_termcode(key_name, p, TRUE);
4127 }
4128 if (nextchar != '?'
4129 && nextchar != NUL && !vim_iswhite(afterchar))
4130 errmsg = e_trailing;
4131 }
4132 else
4133 {
4134 if (flags & P_BOOL) /* boolean */
4135 {
4136 if (nextchar == '=' || nextchar == ':')
4137 {
4138 errmsg = e_invarg;
4139 goto skip;
4140 }
4141
4142 /*
4143 * ":set opt!": invert
4144 * ":set opt&": reset to default value
4145 * ":set opt<": reset to global value
4146 */
4147 if (nextchar == '!')
4148 value = *(int *)(varp) ^ 1;
4149 else if (nextchar == '&')
4150 value = (int)(long)options[opt_idx].def_val[
4151 ((flags & P_VI_DEF) || cp_val)
4152 ? VI_DEFAULT : VIM_DEFAULT];
4153 else if (nextchar == '<')
4154 {
4155 /* For 'autoread' -1 means to use global value. */
4156 if ((int *)varp == &curbuf->b_p_ar
4157 && opt_flags == OPT_LOCAL)
4158 value = -1;
4159 else
4160 value = *(int *)get_varp_scope(&(options[opt_idx]),
4161 OPT_GLOBAL);
4162 }
4163 else
4164 {
4165 /*
4166 * ":set invopt": invert
4167 * ":set opt" or ":set noopt": set or reset
4168 */
4169 if (nextchar != NUL && !vim_iswhite(afterchar))
4170 {
4171 errmsg = e_trailing;
4172 goto skip;
4173 }
4174 if (prefix == 2) /* inv */
4175 value = *(int *)(varp) ^ 1;
4176 else
4177 value = prefix;
4178 }
4179
4180 errmsg = set_bool_option(opt_idx, varp, (int)value,
4181 opt_flags);
4182 }
4183 else /* numeric or string */
4184 {
4185 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4186 || prefix != 1)
4187 {
4188 errmsg = e_invarg;
4189 goto skip;
4190 }
4191
4192 if (flags & P_NUM) /* numeric */
4193 {
4194 /*
4195 * Different ways to set a number option:
4196 * & set to default value
4197 * < set to global value
4198 * <xx> accept special key codes for 'wildchar'
4199 * c accept any non-digit for 'wildchar'
4200 * [-]0-9 set number
4201 * other error
4202 */
4203 ++arg;
4204 if (nextchar == '&')
4205 value = (long)options[opt_idx].def_val[
4206 ((flags & P_VI_DEF) || cp_val)
4207 ? VI_DEFAULT : VIM_DEFAULT];
4208 else if (nextchar == '<')
4209 value = *(long *)get_varp_scope(&(options[opt_idx]),
4210 OPT_GLOBAL);
4211 else if (((long *)varp == &p_wc
4212 || (long *)varp == &p_wcm)
4213 && (*arg == '<'
4214 || *arg == '^'
4215 || ((!arg[1] || vim_iswhite(arg[1]))
4216 && !VIM_ISDIGIT(*arg))))
4217 {
4218 value = string_to_key(arg);
4219 if (value == 0 && (long *)varp != &p_wcm)
4220 {
4221 errmsg = e_invarg;
4222 goto skip;
4223 }
4224 }
4225 /* allow negative numbers (for 'undolevels') */
4226 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4227 {
4228 i = 0;
4229 if (*arg == '-')
4230 i = 1;
4231#ifdef HAVE_STRTOL
4232 value = strtol((char *)arg, NULL, 0);
4233 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4234 i += 2;
4235#else
4236 value = atol((char *)arg);
4237#endif
4238 while (VIM_ISDIGIT(arg[i]))
4239 ++i;
4240 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4241 {
4242 errmsg = e_invarg;
4243 goto skip;
4244 }
4245 }
4246 else
4247 {
4248 errmsg = (char_u *)N_("E521: Number required after =");
4249 goto skip;
4250 }
4251
4252 if (adding)
4253 value = *(long *)varp + value;
4254 if (prepending)
4255 value = *(long *)varp * value;
4256 if (removing)
4257 value = *(long *)varp - value;
4258 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004259 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260 }
4261 else if (opt_idx >= 0) /* string */
4262 {
4263 char_u *save_arg = NULL;
4264 char_u *s = NULL;
4265 char_u *oldval; /* previous value if *varp */
4266 char_u *newval;
4267 char_u *origval;
4268 unsigned newlen;
4269 int comma;
4270 int bs;
4271 int new_value_alloced; /* new string option
4272 was allocated */
4273
4274 /* When using ":set opt=val" for a global option
4275 * with a local value the local value will be
4276 * reset, use the global value here. */
4277 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004278 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279 varp = options[opt_idx].var;
4280
4281 /* The old value is kept until we are sure that the
4282 * new value is valid. */
4283 oldval = *(char_u **)varp;
4284 if (nextchar == '&') /* set to default val */
4285 {
4286 newval = options[opt_idx].def_val[
4287 ((flags & P_VI_DEF) || cp_val)
4288 ? VI_DEFAULT : VIM_DEFAULT];
4289 if ((char_u **)varp == &p_bg)
4290 {
4291 /* guess the value of 'background' */
4292#ifdef FEAT_GUI
4293 if (gui.in_use)
4294 newval = gui_bg_default();
4295 else
4296#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004297 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298 }
4299
4300 /* expand environment variables and ~ (since the
4301 * default value was already expanded, only
4302 * required when an environment variable was set
4303 * later */
4304 if (newval == NULL)
4305 newval = empty_option;
4306 else
4307 {
4308 s = option_expand(opt_idx, newval);
4309 if (s == NULL)
4310 s = newval;
4311 newval = vim_strsave(s);
4312 }
4313 new_value_alloced = TRUE;
4314 }
4315 else if (nextchar == '<') /* set to global val */
4316 {
4317 newval = vim_strsave(*(char_u **)get_varp_scope(
4318 &(options[opt_idx]), OPT_GLOBAL));
4319 new_value_alloced = TRUE;
4320 }
4321 else
4322 {
4323 ++arg; /* jump to after the '=' or ':' */
4324
4325 /*
4326 * Set 'keywordprg' to ":help" if an empty
4327 * value was passed to :set by the user.
4328 * Misuse errbuf[] for the resulting string.
4329 */
4330 if (varp == (char_u *)&p_kp
4331 && (*arg == NUL || *arg == ' '))
4332 {
4333 STRCPY(errbuf, ":help");
4334 save_arg = arg;
4335 arg = errbuf;
4336 }
4337 /*
4338 * Convert 'whichwrap' number to string, for
4339 * backwards compatibility with Vim 3.0.
4340 * Misuse errbuf[] for the resulting string.
4341 */
4342 else if (varp == (char_u *)&p_ww
4343 && VIM_ISDIGIT(*arg))
4344 {
4345 *errbuf = NUL;
4346 i = getdigits(&arg);
4347 if (i & 1)
4348 STRCAT(errbuf, "b,");
4349 if (i & 2)
4350 STRCAT(errbuf, "s,");
4351 if (i & 4)
4352 STRCAT(errbuf, "h,l,");
4353 if (i & 8)
4354 STRCAT(errbuf, "<,>,");
4355 if (i & 16)
4356 STRCAT(errbuf, "[,],");
4357 if (*errbuf != NUL) /* remove trailing , */
4358 errbuf[STRLEN(errbuf) - 1] = NUL;
4359 save_arg = arg;
4360 arg = errbuf;
4361 }
4362 /*
4363 * Remove '>' before 'dir' and 'bdir', for
4364 * backwards compatibility with version 3.0
4365 */
4366 else if ( *arg == '>'
4367 && (varp == (char_u *)&p_dir
4368 || varp == (char_u *)&p_bdir))
4369 {
4370 ++arg;
4371 }
4372
4373 /* When setting the local value of a global
4374 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004375 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004376 && (opt_flags & OPT_LOCAL))
4377 origval = *(char_u **)get_varp(
4378 &options[opt_idx]);
4379 else
4380 origval = oldval;
4381
4382 /*
4383 * Copy the new string into allocated memory.
4384 * Can't use set_string_option_direct(), because
4385 * we need to remove the backslashes.
4386 */
4387 /* get a bit too much */
4388 newlen = (unsigned)STRLEN(arg) + 1;
4389 if (adding || prepending || removing)
4390 newlen += (unsigned)STRLEN(origval) + 1;
4391 newval = alloc(newlen);
4392 if (newval == NULL) /* out of mem, don't change */
4393 break;
4394 s = newval;
4395
4396 /*
4397 * Copy the string, skip over escaped chars.
4398 * For MS-DOS and WIN32 backslashes before normal
4399 * file name characters are not removed, and keep
4400 * backslash at start, for "\\machine\path", but
4401 * do remove it for "\\\\machine\\path".
4402 * The reverse is found in ExpandOldSetting().
4403 */
4404 while (*arg && !vim_iswhite(*arg))
4405 {
4406 if (*arg == '\\' && arg[1] != NUL
4407#ifdef BACKSLASH_IN_FILENAME
4408 && !((flags & P_EXPAND)
4409 && vim_isfilec(arg[1])
4410 && (arg[1] != '\\'
4411 || (s == newval
4412 && arg[2] != '\\')))
4413#endif
4414 )
4415 ++arg; /* remove backslash */
4416#ifdef FEAT_MBYTE
4417 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004418 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004419 {
4420 /* copy multibyte char */
4421 mch_memmove(s, arg, (size_t)i);
4422 arg += i;
4423 s += i;
4424 }
4425 else
4426#endif
4427 *s++ = *arg++;
4428 }
4429 *s = NUL;
4430
4431 /*
4432 * Expand environment variables and ~.
4433 * Don't do it when adding without inserting a
4434 * comma.
4435 */
4436 if (!(adding || prepending || removing)
4437 || (flags & P_COMMA))
4438 {
4439 s = option_expand(opt_idx, newval);
4440 if (s != NULL)
4441 {
4442 vim_free(newval);
4443 newlen = (unsigned)STRLEN(s) + 1;
4444 if (adding || prepending || removing)
4445 newlen += (unsigned)STRLEN(origval) + 1;
4446 newval = alloc(newlen);
4447 if (newval == NULL)
4448 break;
4449 STRCPY(newval, s);
4450 }
4451 }
4452
4453 /* locate newval[] in origval[] when removing it
4454 * and when adding to avoid duplicates */
4455 i = 0; /* init for GCC */
4456 if (removing || (flags & P_NODUP))
4457 {
4458 i = (int)STRLEN(newval);
4459 bs = 0;
4460 for (s = origval; *s; ++s)
4461 {
4462 if ((!(flags & P_COMMA)
4463 || s == origval
4464 || (s[-1] == ',' && !(bs & 1)))
4465 && STRNCMP(s, newval, i) == 0
4466 && (!(flags & P_COMMA)
4467 || s[i] == ','
4468 || s[i] == NUL))
4469 break;
4470 /* Count backspaces. Only a comma with an
4471 * even number of backspaces before it is
4472 * recognized as a separator */
4473 if (s > origval && s[-1] == '\\')
4474 ++bs;
4475 else
4476 bs = 0;
4477 }
4478
4479 /* do not add if already there */
4480 if ((adding || prepending) && *s)
4481 {
4482 prepending = FALSE;
4483 adding = FALSE;
4484 STRCPY(newval, origval);
4485 }
4486 }
4487
4488 /* concatenate the two strings; add a ',' if
4489 * needed */
4490 if (adding || prepending)
4491 {
4492 comma = ((flags & P_COMMA) && *origval != NUL
4493 && *newval != NUL);
4494 if (adding)
4495 {
4496 i = (int)STRLEN(origval);
4497 mch_memmove(newval + i + comma, newval,
4498 STRLEN(newval) + 1);
4499 mch_memmove(newval, origval, (size_t)i);
4500 }
4501 else
4502 {
4503 i = (int)STRLEN(newval);
4504 mch_memmove(newval + i + comma, origval,
4505 STRLEN(origval) + 1);
4506 }
4507 if (comma)
4508 newval[i] = ',';
4509 }
4510
4511 /* Remove newval[] from origval[]. (Note: "i" has
4512 * been set above and is used here). */
4513 if (removing)
4514 {
4515 STRCPY(newval, origval);
4516 if (*s)
4517 {
4518 /* may need to remove a comma */
4519 if (flags & P_COMMA)
4520 {
4521 if (s == origval)
4522 {
4523 /* include comma after string */
4524 if (s[i] == ',')
4525 ++i;
4526 }
4527 else
4528 {
4529 /* include comma before string */
4530 --s;
4531 ++i;
4532 }
4533 }
4534 mch_memmove(newval + (s - origval), s + i,
4535 STRLEN(s + i) + 1);
4536 }
4537 }
4538
4539 if (flags & P_FLAGLIST)
4540 {
4541 /* Remove flags that appear twice. */
4542 for (s = newval; *s; ++s)
4543 if ((!(flags & P_COMMA) || *s != ',')
4544 && vim_strchr(s + 1, *s) != NULL)
4545 {
4546 STRCPY(s, s + 1);
4547 --s;
4548 }
4549 }
4550
4551 if (save_arg != NULL) /* number for 'whichwrap' */
4552 arg = save_arg;
4553 new_value_alloced = TRUE;
4554 }
4555
4556 /* Set the new value. */
4557 *(char_u **)(varp) = newval;
4558
4559 /* Handle side effects, and set the global value for
4560 * ":set" on local options. */
4561 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4562 new_value_alloced, oldval, errbuf, opt_flags);
4563
4564 /* If error detected, print the error message. */
4565 if (errmsg != NULL)
4566 goto skip;
4567 }
4568 else /* key code option */
4569 {
4570 char_u *p;
4571
4572 if (nextchar == '&')
4573 {
4574 if (add_termcap_entry(key_name, TRUE) == FAIL)
4575 errmsg = (char_u *)N_("E522: Not found in termcap");
4576 }
4577 else
4578 {
4579 ++arg; /* jump to after the '=' or ':' */
4580 for (p = arg; *p && !vim_iswhite(*p); ++p)
4581 if (*p == '\\' && p[1] != NUL)
4582 ++p;
4583 nextchar = *p;
4584 *p = NUL;
4585 add_termcode(key_name, arg, FALSE);
4586 *p = nextchar;
4587 }
4588 if (full_screen)
4589 ttest(FALSE);
4590 redraw_all_later(CLEAR);
4591 }
4592 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004593
Bram Moolenaar071d4272004-06-13 20:20:40 +00004594 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004595 did_set_option(opt_idx, opt_flags,
4596 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004597 }
4598
4599skip:
4600 /*
4601 * Advance to next argument.
4602 * - skip until a blank found, taking care of backslashes
4603 * - skip blanks
4604 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4605 */
4606 for (i = 0; i < 2 ; ++i)
4607 {
4608 while (*arg != NUL && !vim_iswhite(*arg))
4609 if (*arg++ == '\\' && *arg != NUL)
4610 ++arg;
4611 arg = skipwhite(arg);
4612 if (*arg != '=')
4613 break;
4614 }
4615 }
4616
4617 if (errmsg != NULL)
4618 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004619 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004620 i = STRLEN(IObuff) + 2;
4621 if (i + (arg - startarg) < IOSIZE)
4622 {
4623 /* append the argument with the error */
4624 STRCAT(IObuff, ": ");
4625 mch_memmove(IObuff + i, startarg, (arg - startarg));
4626 IObuff[i + (arg - startarg)] = NUL;
4627 }
4628 /* make sure all characters are printable */
4629 trans_characters(IObuff, IOSIZE);
4630
4631 ++no_wait_return; /* wait_return done later */
4632 emsg(IObuff); /* show error highlighted */
4633 --no_wait_return;
4634
4635 return FAIL;
4636 }
4637
4638 arg = skipwhite(arg);
4639 }
4640
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004641theend:
4642 if (silent_mode && did_show)
4643 {
4644 /* After displaying option values in silent mode. */
4645 silent_mode = FALSE;
4646 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4647 msg_putchar('\n');
4648 cursor_on(); /* msg_start() switches it off */
4649 out_flush();
4650 silent_mode = TRUE;
4651 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4652 }
4653
Bram Moolenaar071d4272004-06-13 20:20:40 +00004654 return OK;
4655}
4656
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004657/*
4658 * Call this when an option has been given a new value through a user command.
4659 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4660 */
4661 static void
4662did_set_option(opt_idx, opt_flags, new_value)
4663 int opt_idx;
4664 int opt_flags; /* possibly with OPT_MODELINE */
4665 int new_value; /* value was replaced completely */
4666{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004667 long_u *p;
4668
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004669 options[opt_idx].flags |= P_WAS_SET;
4670
4671 /* When an option is set in the sandbox, from a modeline or in secure mode
4672 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004673 * flag. */
4674 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004675 if (secure
4676#ifdef HAVE_SANDBOX
4677 || sandbox != 0
4678#endif
4679 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004680 *p = *p | P_INSECURE;
4681 else if (new_value)
4682 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004683}
4684
Bram Moolenaar071d4272004-06-13 20:20:40 +00004685 static char_u *
4686illegal_char(errbuf, c)
4687 char_u *errbuf;
4688 int c;
4689{
4690 if (errbuf == NULL)
4691 return (char_u *)"";
4692 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004693 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004694 return errbuf;
4695}
4696
4697/*
4698 * Convert a key name or string into a key value.
4699 * Used for 'wildchar' and 'cedit' options.
4700 */
4701 static int
4702string_to_key(arg)
4703 char_u *arg;
4704{
4705 if (*arg == '<')
4706 return find_key_option(arg + 1);
4707 if (*arg == '^')
4708 return Ctrl_chr(arg[1]);
4709 return *arg;
4710}
4711
4712#ifdef FEAT_CMDWIN
4713/*
4714 * Check value of 'cedit' and set cedit_key.
4715 * Returns NULL if value is OK, error message otherwise.
4716 */
4717 static char_u *
4718check_cedit()
4719{
4720 int n;
4721
4722 if (*p_cedit == NUL)
4723 cedit_key = -1;
4724 else
4725 {
4726 n = string_to_key(p_cedit);
4727 if (vim_isprintc(n))
4728 return e_invarg;
4729 cedit_key = n;
4730 }
4731 return NULL;
4732}
4733#endif
4734
4735#ifdef FEAT_TITLE
4736/*
4737 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4738 * maketitle() to create and display it.
4739 * When switching the title or icon off, call mch_restore_title() to get
4740 * the old value back.
4741 */
4742 static void
4743did_set_title(icon)
4744 int icon; /* Did set icon instead of title */
4745{
4746 if (starting != NO_SCREEN
4747#ifdef FEAT_GUI
4748 && !gui.starting
4749#endif
4750 )
4751 {
4752 maketitle();
4753 if (icon)
4754 {
4755 if (!p_icon)
4756 mch_restore_title(2);
4757 }
4758 else
4759 {
4760 if (!p_title)
4761 mch_restore_title(1);
4762 }
4763 }
4764}
4765#endif
4766
4767/*
4768 * set_options_bin - called when 'bin' changes value.
4769 */
4770 void
4771set_options_bin(oldval, newval, opt_flags)
4772 int oldval;
4773 int newval;
4774 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4775{
4776 /*
4777 * The option values that are changed when 'bin' changes are
4778 * copied when 'bin is set and restored when 'bin' is reset.
4779 */
4780 if (newval)
4781 {
4782 if (!oldval) /* switched on */
4783 {
4784 if (!(opt_flags & OPT_GLOBAL))
4785 {
4786 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4787 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4788 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4789 curbuf->b_p_et_nobin = curbuf->b_p_et;
4790 }
4791 if (!(opt_flags & OPT_LOCAL))
4792 {
4793 p_tw_nobin = p_tw;
4794 p_wm_nobin = p_wm;
4795 p_ml_nobin = p_ml;
4796 p_et_nobin = p_et;
4797 }
4798 }
4799
4800 if (!(opt_flags & OPT_GLOBAL))
4801 {
4802 curbuf->b_p_tw = 0; /* no automatic line wrap */
4803 curbuf->b_p_wm = 0; /* no automatic line wrap */
4804 curbuf->b_p_ml = 0; /* no modelines */
4805 curbuf->b_p_et = 0; /* no expandtab */
4806 }
4807 if (!(opt_flags & OPT_LOCAL))
4808 {
4809 p_tw = 0;
4810 p_wm = 0;
4811 p_ml = FALSE;
4812 p_et = FALSE;
4813 p_bin = TRUE; /* needed when called for the "-b" argument */
4814 }
4815 }
4816 else if (oldval) /* switched off */
4817 {
4818 if (!(opt_flags & OPT_GLOBAL))
4819 {
4820 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4821 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4822 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4823 curbuf->b_p_et = curbuf->b_p_et_nobin;
4824 }
4825 if (!(opt_flags & OPT_LOCAL))
4826 {
4827 p_tw = p_tw_nobin;
4828 p_wm = p_wm_nobin;
4829 p_ml = p_ml_nobin;
4830 p_et = p_et_nobin;
4831 }
4832 }
4833}
4834
4835#ifdef FEAT_VIMINFO
4836/*
4837 * Find the parameter represented by the given character (eg ', :, ", or /),
4838 * and return its associated value in the 'viminfo' string.
4839 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004840 * If the parameter is not specified in the string or there is no following
4841 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004842 */
4843 int
4844get_viminfo_parameter(type)
4845 int type;
4846{
4847 char_u *p;
4848
4849 p = find_viminfo_parameter(type);
4850 if (p != NULL && VIM_ISDIGIT(*p))
4851 return atoi((char *)p);
4852 return -1;
4853}
4854
4855/*
4856 * Find the parameter represented by the given character (eg ''', ':', '"', or
4857 * '/') in the 'viminfo' option and return a pointer to the string after it.
4858 * Return NULL if the parameter is not specified in the string.
4859 */
4860 char_u *
4861find_viminfo_parameter(type)
4862 int type;
4863{
4864 char_u *p;
4865
4866 for (p = p_viminfo; *p; ++p)
4867 {
4868 if (*p == type)
4869 return p + 1;
4870 if (*p == 'n') /* 'n' is always the last one */
4871 break;
4872 p = vim_strchr(p, ','); /* skip until next ',' */
4873 if (p == NULL) /* hit the end without finding parameter */
4874 break;
4875 }
4876 return NULL;
4877}
4878#endif
4879
4880/*
4881 * Expand environment variables for some string options.
4882 * These string options cannot be indirect!
4883 * If "val" is NULL expand the current value of the option.
4884 * Return pointer to NameBuff, or NULL when not expanded.
4885 */
4886 static char_u *
4887option_expand(opt_idx, val)
4888 int opt_idx;
4889 char_u *val;
4890{
4891 /* if option doesn't need expansion nothing to do */
4892 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4893 return NULL;
4894
4895 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4896 * expand_env() would truncate the string. */
4897 if (val != NULL && STRLEN(val) > MAXPATHL)
4898 return NULL;
4899
4900 if (val == NULL)
4901 val = *(char_u **)options[opt_idx].var;
4902
4903 /*
4904 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4905 * Escape spaces when expanding 'tags', they are used to separate file
4906 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004907 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004908 */
4909 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004910 (char_u **)options[opt_idx].var == &p_tags,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00004911#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004912 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4913#endif
4914 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004915 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4916 return NULL;
4917
4918 return NameBuff;
4919}
4920
4921/*
4922 * After setting various option values: recompute variables that depend on
4923 * option values.
4924 */
4925 static void
4926didset_options()
4927{
4928 /* initialize the table for 'iskeyword' et.al. */
4929 (void)init_chartab();
4930
4931 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4932 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4933#ifdef FEAT_SESSION
4934 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4935 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4936#endif
4937#ifdef FEAT_FOLDING
4938 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4939#endif
4940 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4941#ifdef FEAT_VIRTUALEDIT
4942 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4943#endif
4944#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4945 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4946#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00004947#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004948 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004949 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004950 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004951#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004952#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4953 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4954#endif
4955#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4956 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4957#endif
4958#ifdef FEAT_CMDWIN
4959 /* set cedit_key */
4960 (void)check_cedit();
4961#endif
4962}
4963
4964/*
4965 * Check for string options that are NULL (normally only termcap options).
4966 */
4967 void
4968check_options()
4969{
4970 int opt_idx;
4971
4972 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4973 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4974 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4975}
4976
4977/*
4978 * Check string options in a buffer for NULL value.
4979 */
4980 void
4981check_buf_options(buf)
4982 buf_T *buf;
4983{
4984#if defined(FEAT_QUICKFIX)
4985 check_string_option(&buf->b_p_bh);
4986 check_string_option(&buf->b_p_bt);
4987#endif
4988#ifdef FEAT_MBYTE
4989 check_string_option(&buf->b_p_fenc);
4990#endif
4991 check_string_option(&buf->b_p_ff);
4992#ifdef FEAT_FIND_ID
4993 check_string_option(&buf->b_p_def);
4994 check_string_option(&buf->b_p_inc);
4995# ifdef FEAT_EVAL
4996 check_string_option(&buf->b_p_inex);
4997# endif
4998#endif
4999#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5000 check_string_option(&buf->b_p_inde);
5001 check_string_option(&buf->b_p_indk);
5002#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005003#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5004 check_string_option(&buf->b_p_bexpr);
5005#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005006#if defined(FEAT_EVAL)
5007 check_string_option(&buf->b_p_fex);
5008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005009#ifdef FEAT_CRYPT
5010 check_string_option(&buf->b_p_key);
5011#endif
5012 check_string_option(&buf->b_p_kp);
5013 check_string_option(&buf->b_p_mps);
5014 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005015 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 check_string_option(&buf->b_p_isk);
5017#ifdef FEAT_COMMENTS
5018 check_string_option(&buf->b_p_com);
5019#endif
5020#ifdef FEAT_FOLDING
5021 check_string_option(&buf->b_p_cms);
5022#endif
5023 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005024#ifdef FEAT_TEXTOBJ
5025 check_string_option(&buf->b_p_qe);
5026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005027#ifdef FEAT_SYN_HL
5028 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005029#endif
5030#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005031 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00005032 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00005033 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005034#endif
5035#ifdef FEAT_SEARCHPATH
5036 check_string_option(&buf->b_p_sua);
5037#endif
5038#ifdef FEAT_CINDENT
5039 check_string_option(&buf->b_p_cink);
5040 check_string_option(&buf->b_p_cino);
5041#endif
5042#ifdef FEAT_AUTOCMD
5043 check_string_option(&buf->b_p_ft);
5044#endif
5045#ifdef FEAT_OSFILETYPE
5046 check_string_option(&buf->b_p_oft);
5047#endif
5048#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5049 check_string_option(&buf->b_p_cinw);
5050#endif
5051#ifdef FEAT_INS_EXPAND
5052 check_string_option(&buf->b_p_cpt);
5053#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005054#ifdef FEAT_COMPL_FUNC
5055 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005056 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005057#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005058#ifdef FEAT_KEYMAP
5059 check_string_option(&buf->b_p_keymap);
5060#endif
5061#ifdef FEAT_QUICKFIX
5062 check_string_option(&buf->b_p_gp);
5063 check_string_option(&buf->b_p_mp);
5064 check_string_option(&buf->b_p_efm);
5065#endif
5066 check_string_option(&buf->b_p_ep);
5067 check_string_option(&buf->b_p_path);
5068 check_string_option(&buf->b_p_tags);
5069#ifdef FEAT_INS_EXPAND
5070 check_string_option(&buf->b_p_dict);
5071 check_string_option(&buf->b_p_tsr);
5072#endif
5073}
5074
5075/*
5076 * Free the string allocated for an option.
5077 * Checks for the string being empty_option. This may happen if we're out of
5078 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5079 * check_options().
5080 * Does NOT check for P_ALLOCED flag!
5081 */
5082 void
5083free_string_option(p)
5084 char_u *p;
5085{
5086 if (p != empty_option)
5087 vim_free(p);
5088}
5089
5090 void
5091clear_string_option(pp)
5092 char_u **pp;
5093{
5094 if (*pp != empty_option)
5095 vim_free(*pp);
5096 *pp = empty_option;
5097}
5098
5099 static void
5100check_string_option(pp)
5101 char_u **pp;
5102{
5103 if (*pp == NULL)
5104 *pp = empty_option;
5105}
5106
5107/*
5108 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5109 */
5110 void
5111set_term_option_alloced(p)
5112 char_u **p;
5113{
5114 int opt_idx;
5115
5116 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5117 if (options[opt_idx].var == (char_u *)p)
5118 {
5119 options[opt_idx].flags |= P_ALLOCED;
5120 return;
5121 }
5122 return; /* cannot happen: didn't find it! */
5123}
5124
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005125#if defined(FEAT_EVAL) || defined(PROTO)
5126/*
5127 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5128 * Return FALSE when it wasn't.
5129 * Return -1 for an unknown option.
5130 */
5131 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005132was_set_insecurely(opt, opt_flags)
5133 char_u *opt;
5134 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005135{
5136 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005137 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005138
5139 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005140 {
5141 flagp = insecure_flag(idx, opt_flags);
5142 return (*flagp & P_INSECURE) != 0;
5143 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005144 EMSG2(_(e_intern2), "was_set_insecurely()");
5145 return -1;
5146}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005147
5148/*
5149 * Get a pointer to the flags used for the P_INSECURE flag of option
5150 * "opt_idx". For some local options a local flags field is used.
5151 */
5152 static long_u *
5153insecure_flag(opt_idx, opt_flags)
5154 int opt_idx;
5155 int opt_flags;
5156{
5157 if (opt_flags & OPT_LOCAL)
5158 switch ((int)options[opt_idx].indir)
5159 {
5160#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005161 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005162#endif
5163#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005164 case PV_FDE: return &curwin->w_p_fde_flags;
5165 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005166# ifdef FEAT_BEVAL
5167 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5168# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005169#endif
5170#if defined(FEAT_EVAL)
5171# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005172 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005173# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005174 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005175# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005176 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005177# endif
5178#endif
5179 }
5180
5181 /* Nothing special, return global flags field. */
5182 return &options[opt_idx].flags;
5183}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005184#endif
5185
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186/*
5187 * Set a string option to a new value (without checking the effect).
5188 * The string is copied into allocated memory.
5189 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005190 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
5191 * SID_NONE don't set the scriptID. Otherwose set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005193/*ARGSUSED*/
Bram Moolenaar071d4272004-06-13 20:20:40 +00005194 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005195set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005196 char_u *name;
5197 int opt_idx;
5198 char_u *val;
5199 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005200 int set_sid;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005201{
5202 char_u *s;
5203 char_u **varp;
5204 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5205
5206 if (opt_idx == -1) /* use name */
5207 {
5208 opt_idx = findoption(name);
5209 if (opt_idx == -1) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005210 {
5211 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005212 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005213 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005214 }
5215
5216 if (options[opt_idx].var == NULL) /* can't set hidden option */
5217 return;
5218
5219 s = vim_strsave(val);
5220 if (s != NULL)
5221 {
5222 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5223 both ? OPT_LOCAL : opt_flags);
5224 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
5225 free_string_option(*varp);
5226 *varp = s;
5227
5228 /* For buffer/window local option may also set the global value. */
5229 if (both)
5230 set_string_option_global(opt_idx, varp);
5231
5232 options[opt_idx].flags |= P_ALLOCED;
5233
5234 /* When setting both values of a global option with a local value,
5235 * make the local value empty, so that the global value is used. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005236 if (((int)options[opt_idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005237 {
5238 free_string_option(*varp);
5239 *varp = empty_option;
5240 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005241# ifdef FEAT_EVAL
5242 if (set_sid != SID_NONE)
5243 set_option_scriptID_idx(opt_idx, opt_flags,
5244 set_sid == 0 ? current_SID : set_sid);
5245# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005246 }
5247}
5248
5249/*
5250 * Set global value for string option when it's a local option.
5251 */
5252 static void
5253set_string_option_global(opt_idx, varp)
5254 int opt_idx; /* option index */
5255 char_u **varp; /* pointer to option variable */
5256{
5257 char_u **p, *s;
5258
5259 /* the global value is always allocated */
5260 if (options[opt_idx].var == VAR_WIN)
5261 p = (char_u **)GLOBAL_WO(varp);
5262 else
5263 p = (char_u **)options[opt_idx].var;
5264 if (options[opt_idx].indir != PV_NONE
5265 && p != varp
5266 && (s = vim_strsave(*varp)) != NULL)
5267 {
5268 free_string_option(*p);
5269 *p = s;
5270 }
5271}
5272
5273/*
5274 * Set a string option to a new value, and handle the effects.
5275 */
5276 static void
5277set_string_option(opt_idx, value, opt_flags)
5278 int opt_idx;
5279 char_u *value;
5280 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5281{
5282 char_u *s;
5283 char_u **varp;
5284 char_u *oldval;
5285
5286 if (options[opt_idx].var == NULL) /* don't set hidden option */
5287 return;
5288
5289 s = vim_strsave(value);
5290 if (s != NULL)
5291 {
5292 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5293 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005294 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005295 ? OPT_GLOBAL : OPT_LOCAL)
5296 : opt_flags);
5297 oldval = *varp;
5298 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005299 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5300 opt_flags) == NULL)
5301 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005302 }
5303}
5304
5305/*
5306 * Handle string options that need some action to perform when changed.
5307 * Returns NULL for success, or an error message for an error.
5308 */
5309 static char_u *
5310did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5311 opt_flags)
5312 int opt_idx; /* index in options[] table */
5313 char_u **varp; /* pointer to the option variable */
5314 int new_value_alloced; /* new value was allocated */
5315 char_u *oldval; /* previous value of the option */
5316 char_u *errbuf; /* buffer for errors, or NULL */
5317 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5318{
5319 char_u *errmsg = NULL;
5320 char_u *s, *p;
5321 int did_chartab = FALSE;
5322 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005323 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005324
5325 /* Get the global option to compare with, otherwise we would have to check
5326 * two values for all local options. */
5327 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5328
5329 /* Disallow changing some options from secure mode */
5330 if ((secure
5331#ifdef HAVE_SANDBOX
5332 || sandbox != 0
5333#endif
5334 ) && (options[opt_idx].flags & P_SECURE))
5335 {
5336 errmsg = e_secure;
5337 }
5338
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005339 /* Check for a "normal" file name in some options. Disallow a path
5340 * separator (slash and/or backslash), wildcards and characters that are
5341 * often illegal in a file name. */
5342 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005343 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005344 {
5345 errmsg = e_invarg;
5346 }
5347
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 /* 'term' */
5349 else if (varp == &T_NAME)
5350 {
5351 if (T_NAME[0] == NUL)
5352 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5353#ifdef FEAT_GUI
5354 if (gui.in_use)
5355 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5356 else if (term_is_gui(T_NAME))
5357 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5358#endif
5359 else if (set_termname(T_NAME) == FAIL)
5360 errmsg = (char_u *)N_("E522: Not found in termcap");
5361 else
5362 /* Screen colors may have changed. */
5363 redraw_later_clear();
5364 }
5365
5366 /* 'backupcopy' */
5367 else if (varp == &p_bkc)
5368 {
5369 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5370 errmsg = e_invarg;
5371 if (((bkc_flags & BKC_AUTO) != 0)
5372 + ((bkc_flags & BKC_YES) != 0)
5373 + ((bkc_flags & BKC_NO) != 0) != 1)
5374 {
5375 /* Must have exactly one of "auto", "yes" and "no". */
5376 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5377 errmsg = e_invarg;
5378 }
5379 }
5380
5381 /* 'backupext' and 'patchmode' */
5382 else if (varp == &p_bex || varp == &p_pm)
5383 {
5384 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5385 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5386 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5387 }
5388
5389 /*
5390 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5391 * If the new option is invalid, use old value. 'lisp' option: refill
5392 * chartab[] for '-' char
5393 */
5394 else if ( varp == &p_isi
5395 || varp == &(curbuf->b_p_isk)
5396 || varp == &p_isp
5397 || varp == &p_isf)
5398 {
5399 if (init_chartab() == FAIL)
5400 {
5401 did_chartab = TRUE; /* need to restore it below */
5402 errmsg = e_invarg; /* error in value */
5403 }
5404 }
5405
5406 /* 'helpfile' */
5407 else if (varp == &p_hf)
5408 {
5409 /* May compute new values for $VIM and $VIMRUNTIME */
5410 if (didset_vim)
5411 {
5412 vim_setenv((char_u *)"VIM", (char_u *)"");
5413 didset_vim = FALSE;
5414 }
5415 if (didset_vimruntime)
5416 {
5417 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5418 didset_vimruntime = FALSE;
5419 }
5420 }
5421
5422#ifdef FEAT_MULTI_LANG
5423 /* 'helplang' */
5424 else if (varp == &p_hlg)
5425 {
5426 /* Check for "", "ab", "ab,cd", etc. */
5427 for (s = p_hlg; *s != NUL; s += 3)
5428 {
5429 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5430 {
5431 errmsg = e_invarg;
5432 break;
5433 }
5434 if (s[2] == NUL)
5435 break;
5436 }
5437 }
5438#endif
5439
5440 /* 'highlight' */
5441 else if (varp == &p_hl)
5442 {
5443 if (highlight_changed() == FAIL)
5444 errmsg = e_invarg; /* invalid flags */
5445 }
5446
5447 /* 'nrformats' */
5448 else if (gvarp == &p_nf)
5449 {
5450 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5451 errmsg = e_invarg;
5452 }
5453
5454#ifdef FEAT_SESSION
5455 /* 'sessionoptions' */
5456 else if (varp == &p_ssop)
5457 {
5458 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5459 errmsg = e_invarg;
5460 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5461 {
5462 /* Don't allow both "sesdir" and "curdir". */
5463 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5464 errmsg = e_invarg;
5465 }
5466 }
5467 /* 'viewoptions' */
5468 else if (varp == &p_vop)
5469 {
5470 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5471 errmsg = e_invarg;
5472 }
5473#endif
5474
5475 /* 'scrollopt' */
5476#ifdef FEAT_SCROLLBIND
5477 else if (varp == &p_sbo)
5478 {
5479 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5480 errmsg = e_invarg;
5481 }
5482#endif
5483
5484 /* 'ambiwidth' */
5485#ifdef FEAT_MBYTE
5486 else if (varp == &p_ambw)
5487 {
5488 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5489 errmsg = e_invarg;
5490 }
5491#endif
5492
5493 /* 'background' */
5494 else if (varp == &p_bg)
5495 {
5496 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5497 {
5498#ifdef FEAT_EVAL
5499 int dark = (*p_bg == 'd');
5500#endif
5501
5502 init_highlight(FALSE, FALSE);
5503
5504#ifdef FEAT_EVAL
5505 if (dark != (*p_bg == 'd')
5506 && get_var_value((char_u *)"g:colors_name") != NULL)
5507 {
5508 /* The color scheme must have set 'background' back to another
5509 * value, that's not what we want here. Disable the color
5510 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005511 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005512 free_string_option(p_bg);
5513 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5514 check_string_option(&p_bg);
5515 init_highlight(FALSE, FALSE);
5516 }
5517#endif
5518 }
5519 else
5520 errmsg = e_invarg;
5521 }
5522
5523 /* 'wildmode' */
5524 else if (varp == &p_wim)
5525 {
5526 if (check_opt_wim() == FAIL)
5527 errmsg = e_invarg;
5528 }
5529
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005530#ifdef FEAT_CMDL_COMPL
5531 /* 'wildoptions' */
5532 else if (varp == &p_wop)
5533 {
5534 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5535 errmsg = e_invarg;
5536 }
5537#endif
5538
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539#ifdef FEAT_WAK
5540 /* 'winaltkeys' */
5541 else if (varp == &p_wak)
5542 {
5543 if (*p_wak == NUL
5544 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5545 errmsg = e_invarg;
5546# ifdef FEAT_MENU
5547# ifdef FEAT_GUI_MOTIF
5548 else if (gui.in_use)
5549 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5550# else
5551# ifdef FEAT_GUI_GTK
5552 else if (gui.in_use)
5553 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5554# endif
5555# endif
5556# endif
5557 }
5558#endif
5559
5560#ifdef FEAT_AUTOCMD
5561 /* 'eventignore' */
5562 else if (varp == &p_ei)
5563 {
5564 if (check_ei() == FAIL)
5565 errmsg = e_invarg;
5566 }
5567#endif
5568
5569#ifdef FEAT_MBYTE
5570 /* 'encoding' and 'fileencoding' */
5571 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5572 {
5573 if (gvarp == &p_fenc)
5574 {
5575 if (!curbuf->b_p_ma)
5576 errmsg = e_modifiable;
5577 else if (vim_strchr(*varp, ',') != NULL)
5578 /* No comma allowed in 'fileencoding'; catches confusing it
5579 * with 'fileencodings'. */
5580 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005582 {
5583# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 /* May show a "+" in the title now. */
5585 need_maketitle = TRUE;
5586# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005587 /* Add 'fileencoding' to the swap file. */
5588 ml_setflags(curbuf);
5589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590 }
5591 if (errmsg == NULL)
5592 {
5593 /* canonize the value, so that STRCMP() can be used on it */
5594 p = enc_canonize(*varp);
5595 if (p != NULL)
5596 {
5597 vim_free(*varp);
5598 *varp = p;
5599 }
5600 if (varp == &p_enc)
5601 {
5602 errmsg = mb_init();
5603# ifdef FEAT_TITLE
5604 need_maketitle = TRUE;
5605# endif
5606 }
5607 }
5608
5609# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5610 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5611 {
5612 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5613 if (STRCMP(p_tenc, "utf-8") != 0)
5614 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5615 }
5616# endif
5617
5618 if (errmsg == NULL)
5619 {
5620# ifdef FEAT_KEYMAP
5621 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5622 * (with another encoding). */
5623 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5624 (void)keymap_init();
5625# endif
5626
5627 /* When 'termencoding' is not empty and 'encoding' changes or when
5628 * 'termencoding' changes, need to setup for keyboard input and
5629 * display output conversion. */
5630 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5631 {
5632 convert_setup(&input_conv, p_tenc, p_enc);
5633 convert_setup(&output_conv, p_enc, p_tenc);
5634 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005635
5636# if defined(WIN3264) && defined(FEAT_MBYTE)
5637 /* $HOME may have characters in active code page. */
5638 if (varp == &p_enc)
5639 init_homedir();
5640# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005641 }
5642 }
5643#endif
5644
5645#if defined(FEAT_POSTSCRIPT)
5646 else if (varp == &p_penc)
5647 {
5648 /* Canonize printencoding if VIM standard one */
5649 p = enc_canonize(p_penc);
5650 if (p != NULL)
5651 {
5652 vim_free(p_penc);
5653 p_penc = p;
5654 }
5655 else
5656 {
5657 /* Ensure lower case and '-' for '_' */
5658 for (s = p_penc; *s != NUL; s++)
5659 {
5660 if (*s == '_')
5661 *s = '-';
5662 else
5663 *s = TOLOWER_ASC(*s);
5664 }
5665 }
5666 }
5667#endif
5668
Bram Moolenaar9372a112005-12-06 19:59:18 +00005669#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 else if (varp == &p_imak)
5671 {
5672 if (gui.in_use && !im_xim_isvalid_imactivate())
5673 errmsg = e_invarg;
5674 }
5675#endif
5676
5677#ifdef FEAT_KEYMAP
5678 else if (varp == &curbuf->b_p_keymap)
5679 {
5680 /* load or unload key mapping tables */
5681 errmsg = keymap_init();
5682
5683 /* When successfully installed a new keymap switch on using it. */
5684 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5685 {
5686 curbuf->b_p_iminsert = B_IMODE_LMAP;
5687 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5688 curbuf->b_p_imsearch = B_IMODE_LMAP;
5689 set_iminsert_global();
5690 set_imsearch_global();
5691# ifdef FEAT_WINDOWS
5692 status_redraw_curbuf();
5693# endif
5694 }
5695 }
5696#endif
5697
5698 /* 'fileformat' */
5699 else if (gvarp == &p_ff)
5700 {
5701 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5702 errmsg = e_modifiable;
5703 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5704 errmsg = e_invarg;
5705 else
5706 {
5707 /* may also change 'textmode' */
5708 if (get_fileformat(curbuf) == EOL_DOS)
5709 curbuf->b_p_tx = TRUE;
5710 else
5711 curbuf->b_p_tx = FALSE;
5712#ifdef FEAT_TITLE
5713 need_maketitle = TRUE;
5714#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005715 /* update flag in swap file */
5716 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717 }
5718 }
5719
5720 /* 'fileformats' */
5721 else if (varp == &p_ffs)
5722 {
5723 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5724 errmsg = e_invarg;
5725 else
5726 {
5727 /* also change 'textauto' */
5728 if (*p_ffs == NUL)
5729 p_ta = FALSE;
5730 else
5731 p_ta = TRUE;
5732 }
5733 }
5734
5735#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5736 /* 'cryptkey' */
5737 else if (gvarp == &p_key)
5738 {
5739 /* Make sure the ":set" command doesn't show the new value in the
5740 * history. */
5741 remove_key_from_history();
5742 }
5743#endif
5744
5745 /* 'matchpairs' */
5746 else if (gvarp == &p_mps)
5747 {
5748 /* Check for "x:y,x:y" */
5749 for (p = *varp; *p != NUL; p += 4)
5750 {
5751 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5752 {
5753 errmsg = e_invarg;
5754 break;
5755 }
5756 if (p[3] == NUL)
5757 break;
5758 }
5759 }
5760
5761#ifdef FEAT_COMMENTS
5762 /* 'comments' */
5763 else if (gvarp == &p_com)
5764 {
5765 for (s = *varp; *s; )
5766 {
5767 while (*s && *s != ':')
5768 {
5769 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5770 && !VIM_ISDIGIT(*s) && *s != '-')
5771 {
5772 errmsg = illegal_char(errbuf, *s);
5773 break;
5774 }
5775 ++s;
5776 }
5777 if (*s++ == NUL)
5778 errmsg = (char_u *)N_("E524: Missing colon");
5779 else if (*s == ',' || *s == NUL)
5780 errmsg = (char_u *)N_("E525: Zero length string");
5781 if (errmsg != NULL)
5782 break;
5783 while (*s && *s != ',')
5784 {
5785 if (*s == '\\' && s[1] != NUL)
5786 ++s;
5787 ++s;
5788 }
5789 s = skip_to_option_part(s);
5790 }
5791 }
5792#endif
5793
5794 /* 'listchars' */
5795 else if (varp == &p_lcs)
5796 {
5797 errmsg = set_chars_option(varp);
5798 }
5799
5800#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5801 /* 'fillchars' */
5802 else if (varp == &p_fcs)
5803 {
5804 errmsg = set_chars_option(varp);
5805 }
5806#endif
5807
5808#ifdef FEAT_CMDWIN
5809 /* 'cedit' */
5810 else if (varp == &p_cedit)
5811 {
5812 errmsg = check_cedit();
5813 }
5814#endif
5815
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005816 /* 'verbosefile' */
5817 else if (varp == &p_vfile)
5818 {
5819 verbose_stop();
5820 if (*p_vfile != NUL && verbose_open() == FAIL)
5821 errmsg = e_invarg;
5822 }
5823
Bram Moolenaar071d4272004-06-13 20:20:40 +00005824#ifdef FEAT_VIMINFO
5825 /* 'viminfo' */
5826 else if (varp == &p_viminfo)
5827 {
5828 for (s = p_viminfo; *s;)
5829 {
5830 /* Check it's a valid character */
5831 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5832 {
5833 errmsg = illegal_char(errbuf, *s);
5834 break;
5835 }
5836 if (*s == 'n') /* name is always last one */
5837 {
5838 break;
5839 }
5840 else if (*s == 'r') /* skip until next ',' */
5841 {
5842 while (*++s && *s != ',')
5843 ;
5844 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005845 else if (*s == '%')
5846 {
5847 /* optional number */
5848 while (vim_isdigit(*++s))
5849 ;
5850 }
5851 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 ++s; /* no extra chars */
5853 else /* must have a number */
5854 {
5855 while (vim_isdigit(*++s))
5856 ;
5857
5858 if (!VIM_ISDIGIT(*(s - 1)))
5859 {
5860 if (errbuf != NULL)
5861 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005862 sprintf((char *)errbuf,
5863 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864 transchar_byte(*(s - 1)));
5865 errmsg = errbuf;
5866 }
5867 else
5868 errmsg = (char_u *)"";
5869 break;
5870 }
5871 }
5872 if (*s == ',')
5873 ++s;
5874 else if (*s)
5875 {
5876 if (errbuf != NULL)
5877 errmsg = (char_u *)N_("E527: Missing comma");
5878 else
5879 errmsg = (char_u *)"";
5880 break;
5881 }
5882 }
5883 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5884 errmsg = (char_u *)N_("E528: Must specify a ' value");
5885 }
5886#endif /* FEAT_VIMINFO */
5887
5888 /* terminal options */
5889 else if (istermoption(&options[opt_idx]) && full_screen)
5890 {
5891 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5892 if (varp == &T_CCO)
5893 {
5894 t_colors = atoi((char *)T_CCO);
5895 if (t_colors <= 1)
5896 {
5897 if (new_value_alloced)
5898 vim_free(T_CCO);
5899 T_CCO = empty_option;
5900 }
5901 /* We now have a different color setup, initialize it again. */
5902 init_highlight(TRUE, FALSE);
5903 }
5904 ttest(FALSE);
5905 if (varp == &T_ME)
5906 {
5907 out_str(T_ME);
5908 redraw_later(CLEAR);
5909#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5910 /* Since t_me has been set, this probably means that the user
5911 * wants to use this as default colors. Need to reset default
5912 * background/foreground colors. */
5913 mch_set_normal_colors();
5914#endif
5915 }
5916 }
5917
5918#ifdef FEAT_LINEBREAK
5919 /* 'showbreak' */
5920 else if (varp == &p_sbr)
5921 {
5922 for (s = p_sbr; *s; )
5923 {
5924 if (ptr2cells(s) != 1)
5925 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005926 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927 }
5928 }
5929#endif
5930
5931#ifdef FEAT_GUI
5932 /* 'guifont' */
5933 else if (varp == &p_guifont)
5934 {
5935 if (gui.in_use)
5936 {
5937 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00005938# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939 /*
5940 * Put up a font dialog and let the user select a new value.
5941 * If this is cancelled go back to the old value but don't
5942 * give an error message.
5943 */
5944 if (STRCMP(p, "*") == 0)
5945 {
5946 p = gui_mch_font_dialog(oldval);
5947
5948 if (new_value_alloced)
5949 free_string_option(p_guifont);
5950
5951 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5952 new_value_alloced = TRUE;
5953 }
5954# endif
5955 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5956 {
5957# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5958 if (STRCMP(p_guifont, "*") == 0)
5959 {
5960 /* Dialog was cancelled: Keep the old value without giving
5961 * an error message. */
5962 if (new_value_alloced)
5963 free_string_option(p_guifont);
5964 p_guifont = vim_strsave(oldval);
5965 new_value_alloced = TRUE;
5966 }
5967 else
5968# endif
5969 errmsg = (char_u *)N_("E596: Invalid font(s)");
5970 }
5971 }
5972 }
5973# ifdef FEAT_XFONTSET
5974 else if (varp == &p_guifontset)
5975 {
5976 if (STRCMP(p_guifontset, "*") == 0)
5977 errmsg = (char_u *)N_("E597: can't select fontset");
5978 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5979 errmsg = (char_u *)N_("E598: Invalid fontset");
5980 }
5981# endif
5982# ifdef FEAT_MBYTE
5983 else if (varp == &p_guifontwide)
5984 {
5985 if (STRCMP(p_guifontwide, "*") == 0)
5986 errmsg = (char_u *)N_("E533: can't select wide font");
5987 else if (gui_get_wide_font() == FAIL)
5988 errmsg = (char_u *)N_("E534: Invalid wide font");
5989 }
5990# endif
5991#endif
5992
5993#ifdef CURSOR_SHAPE
5994 /* 'guicursor' */
5995 else if (varp == &p_guicursor)
5996 errmsg = parse_shape_opt(SHAPE_CURSOR);
5997#endif
5998
5999#ifdef FEAT_MOUSESHAPE
6000 /* 'mouseshape' */
6001 else if (varp == &p_mouseshape)
6002 {
6003 errmsg = parse_shape_opt(SHAPE_MOUSE);
6004 update_mouseshape(-1);
6005 }
6006#endif
6007
6008#ifdef FEAT_PRINTER
6009 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006010 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006011# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006012 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006013 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006014# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006015#endif
6016
6017#ifdef FEAT_LANGMAP
6018 /* 'langmap' */
6019 else if (varp == &p_langmap)
6020 langmap_set();
6021#endif
6022
6023#ifdef FEAT_LINEBREAK
6024 /* 'breakat' */
6025 else if (varp == &p_breakat)
6026 fill_breakat_flags();
6027#endif
6028
6029#ifdef FEAT_TITLE
6030 /* 'titlestring' and 'iconstring' */
6031 else if (varp == &p_titlestring || varp == &p_iconstring)
6032 {
6033# ifdef FEAT_STL_OPT
6034 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6035
6036 /* NULL => statusline syntax */
6037 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6038 stl_syntax |= flagval;
6039 else
6040 stl_syntax &= ~flagval;
6041# endif
6042 did_set_title(varp == &p_iconstring);
6043
6044 }
6045#endif
6046
6047#ifdef FEAT_GUI
6048 /* 'guioptions' */
6049 else if (varp == &p_go)
6050 gui_init_which_components(oldval);
6051#endif
6052
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006053#if defined(FEAT_GUI_TABLINE)
6054 /* 'guitablabel' */
6055 else if (varp == &p_gtl)
6056 gui_update_tabline();
6057#endif
6058
Bram Moolenaar071d4272004-06-13 20:20:40 +00006059#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6060 /* 'ttymouse' */
6061 else if (varp == &p_ttym)
6062 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006063 /* Switch the mouse off before changing the escape sequences used for
6064 * that. */
6065 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6067 errmsg = e_invarg;
6068 else
6069 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006070 if (termcap_active)
6071 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006072 }
6073#endif
6074
6075#ifdef FEAT_VISUAL
6076 /* 'selection' */
6077 else if (varp == &p_sel)
6078 {
6079 if (*p_sel == NUL
6080 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6081 errmsg = e_invarg;
6082 }
6083
6084 /* 'selectmode' */
6085 else if (varp == &p_slm)
6086 {
6087 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6088 errmsg = e_invarg;
6089 }
6090#endif
6091
6092#ifdef FEAT_BROWSE
6093 /* 'browsedir' */
6094 else if (varp == &p_bsdir)
6095 {
6096 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6097 && !mch_isdir(p_bsdir))
6098 errmsg = e_invarg;
6099 }
6100#endif
6101
6102#ifdef FEAT_VISUAL
6103 /* 'keymodel' */
6104 else if (varp == &p_km)
6105 {
6106 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6107 errmsg = e_invarg;
6108 else
6109 {
6110 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6111 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6112 }
6113 }
6114#endif
6115
6116 /* 'mousemodel' */
6117 else if (varp == &p_mousem)
6118 {
6119 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6120 errmsg = e_invarg;
6121#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6122 else if (*p_mousem != *oldval)
6123 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6124 * to create or delete the popup menus. */
6125 gui_motif_update_mousemodel(root_menu);
6126#endif
6127 }
6128
6129 /* 'switchbuf' */
6130 else if (varp == &p_swb)
6131 {
6132 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
6133 errmsg = e_invarg;
6134 }
6135
6136 /* 'debug' */
6137 else if (varp == &p_debug)
6138 {
6139 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
6140 errmsg = e_invarg;
6141 }
6142
6143 /* 'display' */
6144 else if (varp == &p_dy)
6145 {
6146 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6147 errmsg = e_invarg;
6148 else
6149 (void)init_chartab();
6150
6151 }
6152
6153#ifdef FEAT_VERTSPLIT
6154 /* 'eadirection' */
6155 else if (varp == &p_ead)
6156 {
6157 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6158 errmsg = e_invarg;
6159 }
6160#endif
6161
6162#ifdef FEAT_CLIPBOARD
6163 /* 'clipboard' */
6164 else if (varp == &p_cb)
6165 errmsg = check_clipboard_option();
6166#endif
6167
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006168#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006169 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6170 * buffer in which 'spell' is set load the wordlists. */
6171 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006172 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006173 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006174 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006175
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006176 if (varp == &(curbuf->b_p_spf))
6177 {
6178 l = STRLEN(curbuf->b_p_spf);
6179 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6180 ".add") != 0))
6181 errmsg = e_invarg;
6182 }
6183
6184 if (errmsg == NULL)
6185 {
6186 FOR_ALL_WINDOWS(wp)
6187 if (wp->w_buffer == curbuf && wp->w_p_spell)
6188 {
6189 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006190# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006191 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006192# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006193 }
6194 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006195 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006196 /* When 'spellcapcheck' is set compile the regexp program. */
6197 else if (varp == &(curbuf->b_p_spc))
6198 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006199 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006200 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006201 /* 'spellsuggest' */
6202 else if (varp == &p_sps)
6203 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006204 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006205 errmsg = e_invarg;
6206 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006207 /* 'mkspellmem' */
6208 else if (varp == &p_msm)
6209 {
6210 if (spell_check_msm() != OK)
6211 errmsg = e_invarg;
6212 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006213#endif
6214
Bram Moolenaar071d4272004-06-13 20:20:40 +00006215#ifdef FEAT_QUICKFIX
6216 /* When 'bufhidden' is set, check for valid value. */
6217 else if (gvarp == &p_bh)
6218 {
6219 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6220 errmsg = e_invarg;
6221 }
6222
6223 /* When 'buftype' is set, check for valid value. */
6224 else if (gvarp == &p_bt)
6225 {
6226 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6227 errmsg = e_invarg;
6228 else
6229 {
6230# ifdef FEAT_WINDOWS
6231 if (curwin->w_status_height)
6232 {
6233 curwin->w_redr_status = TRUE;
6234 redraw_later(VALID);
6235 }
6236# endif
6237 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6238 }
6239 }
6240#endif
6241
6242#ifdef FEAT_STL_OPT
6243 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006244 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006245 {
6246 int wid;
6247
6248 if (varp == &p_ruf) /* reset ru_wid first */
6249 ru_wid = 0;
6250 s = *varp;
6251 if (varp == &p_ruf && *s == '%')
6252 {
6253 /* set ru_wid if 'ruf' starts with "%99(" */
6254 if (*++s == '-') /* ignore a '-' */
6255 s++;
6256 wid = getdigits(&s);
6257 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6258 ru_wid = wid;
6259 else
6260 errmsg = check_stl_option(p_ruf);
6261 }
6262 else
6263 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006264 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265 comp_col();
6266 }
6267#endif
6268
6269#ifdef FEAT_INS_EXPAND
6270 /* check if it is a valid value for 'complete' -- Acevedo */
6271 else if (gvarp == &p_cpt)
6272 {
6273 for (s = *varp; *s;)
6274 {
6275 while(*s == ',' || *s == ' ')
6276 s++;
6277 if (!*s)
6278 break;
6279 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6280 {
6281 errmsg = illegal_char(errbuf, *s);
6282 break;
6283 }
6284 if (*++s != NUL && *s != ',' && *s != ' ')
6285 {
6286 if (s[-1] == 'k' || s[-1] == 's')
6287 {
6288 /* skip optional filename after 'k' and 's' */
6289 while (*s && *s != ',' && *s != ' ')
6290 {
6291 if (*s == '\\')
6292 ++s;
6293 ++s;
6294 }
6295 }
6296 else
6297 {
6298 if (errbuf != NULL)
6299 {
6300 sprintf((char *)errbuf,
6301 _("E535: Illegal character after <%c>"),
6302 *--s);
6303 errmsg = errbuf;
6304 }
6305 else
6306 errmsg = (char_u *)"";
6307 break;
6308 }
6309 }
6310 }
6311 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006312
6313 /* 'completeopt' */
6314 else if (varp == &p_cot)
6315 {
6316 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6317 errmsg = e_invarg;
6318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319#endif /* FEAT_INS_EXPAND */
6320
6321
6322#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6323 else if (varp == &p_toolbar)
6324 {
6325 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6326 &toolbar_flags, TRUE) != OK)
6327 errmsg = e_invarg;
6328 else
6329 {
6330 out_flush();
6331 gui_mch_show_toolbar((toolbar_flags &
6332 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6333 }
6334 }
6335#endif
6336
6337#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6338 /* 'toolbariconsize': GTK+ 2 only */
6339 else if (varp == &p_tbis)
6340 {
6341 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6342 errmsg = e_invarg;
6343 else
6344 {
6345 out_flush();
6346 gui_mch_show_toolbar((toolbar_flags &
6347 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6348 }
6349 }
6350#endif
6351
6352 /* 'pastetoggle': translate key codes like in a mapping */
6353 else if (varp == &p_pt)
6354 {
6355 if (*p_pt)
6356 {
6357 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
6358 if (p != NULL)
6359 {
6360 if (new_value_alloced)
6361 free_string_option(p_pt);
6362 p_pt = p;
6363 new_value_alloced = TRUE;
6364 }
6365 }
6366 }
6367
6368 /* 'backspace' */
6369 else if (varp == &p_bs)
6370 {
6371 if (VIM_ISDIGIT(*p_bs))
6372 {
6373 if (*p_bs >'2' || p_bs[1] != NUL)
6374 errmsg = e_invarg;
6375 }
6376 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6377 errmsg = e_invarg;
6378 }
6379
6380 /* 'casemap' */
6381 else if (varp == &p_cmp)
6382 {
6383 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6384 errmsg = e_invarg;
6385 }
6386
6387#ifdef FEAT_DIFF
6388 /* 'diffopt' */
6389 else if (varp == &p_dip)
6390 {
6391 if (diffopt_changed() == FAIL)
6392 errmsg = e_invarg;
6393 }
6394#endif
6395
6396#ifdef FEAT_FOLDING
6397 /* 'foldmethod' */
6398 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6399 {
6400 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6401 || *curwin->w_p_fdm == NUL)
6402 errmsg = e_invarg;
6403 else
6404 foldUpdateAll(curwin);
6405 }
6406# ifdef FEAT_EVAL
6407 /* 'foldexpr' */
6408 else if (varp == &curwin->w_p_fde)
6409 {
6410 if (foldmethodIsExpr(curwin))
6411 foldUpdateAll(curwin);
6412 }
6413# endif
6414 /* 'foldmarker' */
6415 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6416 {
6417 p = vim_strchr(*varp, ',');
6418 if (p == NULL)
6419 errmsg = (char_u *)N_("E536: comma required");
6420 else if (p == *varp || p[1] == NUL)
6421 errmsg = e_invarg;
6422 else if (foldmethodIsMarker(curwin))
6423 foldUpdateAll(curwin);
6424 }
6425 /* 'commentstring' */
6426 else if (gvarp == &p_cms)
6427 {
6428 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6429 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6430 }
6431 /* 'foldopen' */
6432 else if (varp == &p_fdo)
6433 {
6434 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6435 errmsg = e_invarg;
6436 }
6437 /* 'foldclose' */
6438 else if (varp == &p_fcl)
6439 {
6440 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6441 errmsg = e_invarg;
6442 }
6443#endif
6444
6445#ifdef FEAT_VIRTUALEDIT
6446 /* 'virtualedit' */
6447 else if (varp == &p_ve)
6448 {
6449 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6450 errmsg = e_invarg;
6451 else if (STRCMP(p_ve, oldval) != 0)
6452 {
6453 /* Recompute cursor position in case the new 've' setting
6454 * changes something. */
6455 validate_virtcol();
6456 coladvance(curwin->w_virtcol);
6457 }
6458 }
6459#endif
6460
6461#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6462 else if (varp == &p_csqf)
6463 {
6464 if (p_csqf != NULL)
6465 {
6466 p = p_csqf;
6467 while (*p != NUL)
6468 {
6469 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6470 || p[1] == NUL
6471 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6472 || (p[2] != NUL && p[2] != ','))
6473 {
6474 errmsg = e_invarg;
6475 break;
6476 }
6477 else if (p[2] == NUL)
6478 break;
6479 else
6480 p += 3;
6481 }
6482 }
6483 }
6484#endif
6485
6486 /* Options that are a list of flags. */
6487 else
6488 {
6489 p = NULL;
6490 if (varp == &p_ww)
6491 p = (char_u *)WW_ALL;
6492 if (varp == &p_shm)
6493 p = (char_u *)SHM_ALL;
6494 else if (varp == &(p_cpo))
6495 p = (char_u *)CPO_ALL;
6496 else if (varp == &(curbuf->b_p_fo))
6497 p = (char_u *)FO_ALL;
6498 else if (varp == &p_mouse)
6499 {
6500#ifdef FEAT_MOUSE
6501 p = (char_u *)MOUSE_ALL;
6502#else
6503 if (*p_mouse != NUL)
6504 errmsg = (char_u *)N_("E538: No mouse support");
6505#endif
6506 }
6507#if defined(FEAT_GUI)
6508 else if (varp == &p_go)
6509 p = (char_u *)GO_ALL;
6510#endif
6511 if (p != NULL)
6512 {
6513 for (s = *varp; *s; ++s)
6514 if (vim_strchr(p, *s) == NULL)
6515 {
6516 errmsg = illegal_char(errbuf, *s);
6517 break;
6518 }
6519 }
6520 }
6521
6522 /*
6523 * If error detected, restore the previous value.
6524 */
6525 if (errmsg != NULL)
6526 {
6527 if (new_value_alloced)
6528 free_string_option(*varp);
6529 *varp = oldval;
6530 /*
6531 * When resetting some values, need to act on it.
6532 */
6533 if (did_chartab)
6534 (void)init_chartab();
6535 if (varp == &p_hl)
6536 (void)highlight_changed();
6537 }
6538 else
6539 {
6540#ifdef FEAT_EVAL
6541 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006542 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006543#endif
6544 /*
6545 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006546 * Use "free_oldval", because recursiveness may change the flags under
6547 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006549 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006550 free_string_option(oldval);
6551 if (new_value_alloced)
6552 options[opt_idx].flags |= P_ALLOCED;
6553 else
6554 options[opt_idx].flags &= ~P_ALLOCED;
6555
6556 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006557 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006558 {
6559 /* global option with local value set to use global value; free
6560 * the local value and make it empty */
6561 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6562 free_string_option(*(char_u **)p);
6563 *(char_u **)p = empty_option;
6564 }
6565
6566 /* May set global value for local option. */
6567 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6568 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006569
6570#ifdef FEAT_AUTOCMD
6571 /*
6572 * Trigger the autocommand only after setting the flags.
6573 */
6574# ifdef FEAT_SYN_HL
6575 /* When 'syntax' is set, load the syntax of that name */
6576 if (varp == &(curbuf->b_p_syn))
6577 {
6578 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6579 curbuf->b_fname, TRUE, curbuf);
6580 }
6581# endif
6582 else if (varp == &(curbuf->b_p_ft))
6583 {
6584 /* 'filetype' is set, trigger the FileType autocommand */
6585 did_filetype = TRUE;
6586 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6587 curbuf->b_fname, TRUE, curbuf);
6588 }
6589#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006590#ifdef FEAT_SPELL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006591 if (varp == &(curbuf->b_p_spl))
6592 {
6593 char_u fname[200];
6594
6595 /*
6596 * Source the spell/LANG.vim in 'runtimepath'.
6597 * They could set 'spellcapcheck' depending on the language.
6598 * Use the first name in 'spelllang' up to '_region' or
6599 * '.encoding'.
6600 */
6601 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6602 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6603 break;
6604 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6605 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6606 source_runtime(fname, TRUE);
6607 }
6608#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006609 }
6610
6611#ifdef FEAT_MOUSE
6612 if (varp == &p_mouse)
6613 {
6614# ifdef FEAT_MOUSE_TTY
6615 if (*p_mouse == NUL)
6616 mch_setmouse(FALSE); /* switch mouse off */
6617 else
6618# endif
6619 setmouse(); /* in case 'mouse' changed */
6620 }
6621#endif
6622
6623 if (curwin->w_curswant != MAXCOL)
6624 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6625 check_redraw(options[opt_idx].flags);
6626
6627 return errmsg;
6628}
6629
6630/*
6631 * Handle setting 'listchars' or 'fillchars'.
6632 * Returns error message, NULL if it's OK.
6633 */
6634 static char_u *
6635set_chars_option(varp)
6636 char_u **varp;
6637{
6638 int round, i, len, entries;
6639 char_u *p, *s;
6640 int c1, c2 = 0;
6641 struct charstab
6642 {
6643 int *cp;
6644 char *name;
6645 };
6646#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6647 static struct charstab filltab[] =
6648 {
6649 {&fill_stl, "stl"},
6650 {&fill_stlnc, "stlnc"},
6651 {&fill_vert, "vert"},
6652 {&fill_fold, "fold"},
6653 {&fill_diff, "diff"},
6654 };
6655#endif
6656 static struct charstab lcstab[] =
6657 {
6658 {&lcs_eol, "eol"},
6659 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006660 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006661 {&lcs_prec, "precedes"},
6662 {&lcs_tab2, "tab"},
6663 {&lcs_trail, "trail"},
6664 };
6665 struct charstab *tab;
6666
6667#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6668 if (varp == &p_lcs)
6669#endif
6670 {
6671 tab = lcstab;
6672 entries = sizeof(lcstab) / sizeof(struct charstab);
6673 }
6674#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6675 else
6676 {
6677 tab = filltab;
6678 entries = sizeof(filltab) / sizeof(struct charstab);
6679 }
6680#endif
6681
6682 /* first round: check for valid value, second round: assign values */
6683 for (round = 0; round <= 1; ++round)
6684 {
6685 if (round)
6686 {
6687 /* After checking that the value is valid: set defaults: space for
6688 * 'fillchars', NUL for 'listchars' */
6689 for (i = 0; i < entries; ++i)
6690 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6691 if (varp == &p_lcs)
6692 lcs_tab1 = NUL;
6693#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6694 else
6695 fill_diff = '-';
6696#endif
6697 }
6698 p = *varp;
6699 while (*p)
6700 {
6701 for (i = 0; i < entries; ++i)
6702 {
6703 len = (int)STRLEN(tab[i].name);
6704 if (STRNCMP(p, tab[i].name, len) == 0
6705 && p[len] == ':'
6706 && p[len + 1] != NUL)
6707 {
6708 s = p + len + 1;
6709#ifdef FEAT_MBYTE
6710 c1 = mb_ptr2char_adv(&s);
6711#else
6712 c1 = *s++;
6713#endif
6714 if (tab[i].cp == &lcs_tab2)
6715 {
6716 if (*s == NUL)
6717 continue;
6718#ifdef FEAT_MBYTE
6719 c2 = mb_ptr2char_adv(&s);
6720#else
6721 c2 = *s++;
6722#endif
6723 }
6724 if (*s == ',' || *s == NUL)
6725 {
6726 if (round)
6727 {
6728 if (tab[i].cp == &lcs_tab2)
6729 {
6730 lcs_tab1 = c1;
6731 lcs_tab2 = c2;
6732 }
6733 else
6734 *(tab[i].cp) = c1;
6735
6736 }
6737 p = s;
6738 break;
6739 }
6740 }
6741 }
6742
6743 if (i == entries)
6744 return e_invarg;
6745 if (*p == ',')
6746 ++p;
6747 }
6748 }
6749
6750 return NULL; /* no error */
6751}
6752
6753#ifdef FEAT_STL_OPT
6754/*
6755 * Check validity of options with the 'statusline' format.
6756 * Return error message or NULL.
6757 */
6758 char_u *
6759check_stl_option(s)
6760 char_u *s;
6761{
6762 int itemcnt = 0;
6763 int groupdepth = 0;
6764 static char_u errbuf[80];
6765
6766 while (*s && itemcnt < STL_MAX_ITEM)
6767 {
6768 /* Check for valid keys after % sequences */
6769 while (*s && *s != '%')
6770 s++;
6771 if (!*s)
6772 break;
6773 s++;
6774 if (*s != '%' && *s != ')')
6775 ++itemcnt;
6776 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6777 {
6778 s++;
6779 continue;
6780 }
6781 if (*s == ')')
6782 {
6783 s++;
6784 if (--groupdepth < 0)
6785 break;
6786 continue;
6787 }
6788 if (*s == '-')
6789 s++;
6790 while (VIM_ISDIGIT(*s))
6791 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006792 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 continue;
6794 if (*s == '.')
6795 {
6796 s++;
6797 while (*s && VIM_ISDIGIT(*s))
6798 s++;
6799 }
6800 if (*s == '(')
6801 {
6802 groupdepth++;
6803 continue;
6804 }
6805 if (vim_strchr(STL_ALL, *s) == NULL)
6806 {
6807 return illegal_char(errbuf, *s);
6808 }
6809 if (*s == '{')
6810 {
6811 s++;
6812 while (*s != '}' && *s)
6813 s++;
6814 if (*s != '}')
6815 return (char_u *)N_("E540: Unclosed expression sequence");
6816 }
6817 }
6818 if (itemcnt >= STL_MAX_ITEM)
6819 return (char_u *)N_("E541: too many items");
6820 if (groupdepth != 0)
6821 return (char_u *)N_("E542: unbalanced groups");
6822 return NULL;
6823}
6824#endif
6825
6826#ifdef FEAT_CLIPBOARD
6827/*
6828 * Extract the items in the 'clipboard' option and set global values.
6829 */
6830 static char_u *
6831check_clipboard_option()
6832{
6833 int new_unnamed = FALSE;
6834 int new_autoselect = FALSE;
6835 int new_autoselectml = FALSE;
6836 regprog_T *new_exclude_prog = NULL;
6837 char_u *errmsg = NULL;
6838 char_u *p;
6839
6840 for (p = p_cb; *p != NUL; )
6841 {
6842 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6843 {
6844 new_unnamed = TRUE;
6845 p += 7;
6846 }
6847 else if (STRNCMP(p, "autoselect", 10) == 0
6848 && (p[10] == ',' || p[10] == NUL))
6849 {
6850 new_autoselect = TRUE;
6851 p += 10;
6852 }
6853 else if (STRNCMP(p, "autoselectml", 12) == 0
6854 && (p[12] == ',' || p[12] == NUL))
6855 {
6856 new_autoselectml = TRUE;
6857 p += 12;
6858 }
6859 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6860 {
6861 p += 8;
6862 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6863 if (new_exclude_prog == NULL)
6864 errmsg = e_invarg;
6865 break;
6866 }
6867 else
6868 {
6869 errmsg = e_invarg;
6870 break;
6871 }
6872 if (*p == ',')
6873 ++p;
6874 }
6875 if (errmsg == NULL)
6876 {
6877 clip_unnamed = new_unnamed;
6878 clip_autoselect = new_autoselect;
6879 clip_autoselectml = new_autoselectml;
6880 vim_free(clip_exclude_prog);
6881 clip_exclude_prog = new_exclude_prog;
6882 }
6883 else
6884 vim_free(new_exclude_prog);
6885
6886 return errmsg;
6887}
6888#endif
6889
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006890#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006891/*
6892 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6893 * Return error message when failed, NULL when OK.
6894 */
6895 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006896compile_cap_prog(buf)
6897 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006898{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006899 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006900 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006901
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006902 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006903 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006904 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006905 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006906 /* Prepend a ^ so that we only match at one column */
6907 re = concat_str((char_u *)"^", buf->b_p_spc);
6908 if (re != NULL)
6909 {
6910 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
6911 if (buf->b_cap_prog == NULL)
6912 {
6913 buf->b_cap_prog = rp; /* restore the previous program */
6914 return e_invarg;
6915 }
6916 vim_free(re);
6917 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006918 }
6919
6920 vim_free(rp);
6921 return NULL;
6922}
6923#endif
6924
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006925#if defined(FEAT_EVAL) || defined(PROTO)
6926/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006927 * Set the scriptID for an option, taking care of setting the buffer- or
6928 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006929 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006930 static void
6931set_option_scriptID_idx(opt_idx, opt_flags, id)
6932 int opt_idx;
6933 int opt_flags;
6934 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006935{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006936 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
6937 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006938
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006939 /* Remember where the option was set. For local options need to do that
6940 * in the buffer or window structure. */
6941 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006942 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006943 if (both || (opt_flags & OPT_LOCAL))
6944 {
6945 if (indir & PV_BUF)
6946 curbuf->b_p_scriptID[indir & PV_MASK] = id;
6947 else if (indir & PV_WIN)
6948 curwin->w_p_scriptID[indir & PV_MASK] = id;
6949 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006950}
6951#endif
6952
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953/*
6954 * Set the value of a boolean option, and take care of side effects.
6955 * Returns NULL for success, or an error message for an error.
6956 */
6957 static char_u *
6958set_bool_option(opt_idx, varp, value, opt_flags)
6959 int opt_idx; /* index in options[] table */
6960 char_u *varp; /* pointer to the option variable */
6961 int value; /* new value */
6962 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6963{
6964 int old_value = *(int *)varp;
6965
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966 /* Disallow changing some options from secure mode */
6967 if ((secure
6968#ifdef HAVE_SANDBOX
6969 || sandbox != 0
6970#endif
6971 ) && (options[opt_idx].flags & P_SECURE))
6972 return e_secure;
6973
6974 *(int *)varp = value; /* set the new value */
6975#ifdef FEAT_EVAL
6976 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006977 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006978#endif
6979
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006980#ifdef FEAT_GUI
6981 need_mouse_correct = TRUE;
6982#endif
6983
Bram Moolenaar071d4272004-06-13 20:20:40 +00006984 /* May set global value for local option. */
6985 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6986 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6987
6988 /*
6989 * Handle side effects of changing a bool option.
6990 */
6991
6992 /* 'compatible' */
6993 if ((int *)varp == &p_cp)
6994 {
6995 compatible_set();
6996 }
6997
Bram Moolenaar071d4272004-06-13 20:20:40 +00006998 else if ((int *)varp == &curbuf->b_p_ro)
6999 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007000 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7002 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007003
7004 /* when 'readonly' is set may give W10 again */
7005 if (curbuf->b_p_ro)
7006 curbuf->b_did_warn = FALSE;
7007
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008#ifdef FEAT_TITLE
7009 need_maketitle = TRUE;
7010#endif
7011 }
7012
7013#ifdef FEAT_TITLE
7014 /* when 'modifiable' is changed, redraw the window title */
7015 else if ((int *)varp == &curbuf->b_p_ma)
7016 need_maketitle = TRUE;
7017 /* when 'endofline' is changed, redraw the window title */
7018 else if ((int *)varp == &curbuf->b_p_eol)
7019 need_maketitle = TRUE;
7020#endif
7021
7022 /* when 'bin' is set also set some other options */
7023 else if ((int *)varp == &curbuf->b_p_bin)
7024 {
7025 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7026#ifdef FEAT_TITLE
7027 need_maketitle = TRUE;
7028#endif
7029 }
7030
7031#ifdef FEAT_AUTOCMD
7032 /* when 'buflisted' changes, trigger autocommands */
7033 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7034 {
7035 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7036 NULL, NULL, TRUE, curbuf);
7037 }
7038#endif
7039
7040 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7041 else if ((int *)varp == &curbuf->b_p_swf)
7042 {
7043 if (curbuf->b_p_swf && p_uc)
7044 ml_open_file(curbuf); /* create the swap file */
7045 else
7046 mf_close_file(curbuf, TRUE); /* remove the swap file */
7047 }
7048
7049 /* when 'terse' is set change 'shortmess' */
7050 else if ((int *)varp == &p_terse)
7051 {
7052 char_u *p;
7053
7054 p = vim_strchr(p_shm, SHM_SEARCH);
7055
7056 /* insert 's' in p_shm */
7057 if (p_terse && p == NULL)
7058 {
7059 STRCPY(IObuff, p_shm);
7060 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007061 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007062 }
7063 /* remove 's' from p_shm */
7064 else if (!p_terse && p != NULL)
7065 mch_memmove(p, p + 1, STRLEN(p));
7066 }
7067
7068 /* when 'paste' is set or reset also change other options */
7069 else if ((int *)varp == &p_paste)
7070 {
7071 paste_option_changed();
7072 }
7073
7074 /* when 'insertmode' is set from an autocommand need to do work here */
7075 else if ((int *)varp == &p_im)
7076 {
7077 if (p_im)
7078 {
7079 if ((State & INSERT) == 0)
7080 need_start_insertmode = TRUE;
7081 stop_insert_mode = FALSE;
7082 }
7083 else
7084 {
7085 need_start_insertmode = FALSE;
7086 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007087 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007088 clear_cmdline = TRUE; /* remove "(insert)" */
7089 restart_edit = 0;
7090 }
7091 }
7092
7093 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7094 else if ((int *)varp == &p_ic && p_hls)
7095 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007096 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007097 }
7098
7099#ifdef FEAT_SEARCH_EXTRA
7100 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7101 else if ((int *)varp == &p_hls)
7102 {
7103 no_hlsearch = FALSE;
7104 }
7105#endif
7106
7107#ifdef FEAT_SCROLLBIND
7108 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7109 * at the end of normal_cmd() */
7110 else if ((int *)varp == &curwin->w_p_scb)
7111 {
7112 if (curwin->w_p_scb)
7113 do_check_scrollbind(FALSE);
7114 }
7115#endif
7116
7117#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7118 /* There can be only one window with 'previewwindow' set. */
7119 else if ((int *)varp == &curwin->w_p_pvw)
7120 {
7121 if (curwin->w_p_pvw)
7122 {
7123 win_T *win;
7124
7125 for (win = firstwin; win != NULL; win = win->w_next)
7126 if (win->w_p_pvw && win != curwin)
7127 {
7128 curwin->w_p_pvw = FALSE;
7129 return (char_u *)N_("E590: A preview window already exists");
7130 }
7131 }
7132 }
7133#endif
7134
7135 /* when 'textmode' is set or reset also change 'fileformat' */
7136 else if ((int *)varp == &curbuf->b_p_tx)
7137 {
7138 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7139 }
7140
7141 /* when 'textauto' is set or reset also change 'fileformats' */
7142 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143 set_string_option_direct((char_u *)"ffs", -1,
7144 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007145 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146
7147 /*
7148 * When 'lisp' option changes include/exclude '-' in
7149 * keyword characters.
7150 */
7151#ifdef FEAT_LISP
7152 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7153 {
7154 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7155 }
7156#endif
7157
7158#ifdef FEAT_TITLE
7159 /* when 'title' changed, may need to change the title; same for 'icon' */
7160 else if ((int *)varp == &p_title)
7161 {
7162 did_set_title(FALSE);
7163 }
7164
7165 else if ((int *)varp == &p_icon)
7166 {
7167 did_set_title(TRUE);
7168 }
7169#endif
7170
7171 else if ((int *)varp == &curbuf->b_changed)
7172 {
7173 if (!value)
7174 save_file_ff(curbuf); /* Buffer is unchanged */
7175#ifdef FEAT_TITLE
7176 need_maketitle = TRUE;
7177#endif
7178#ifdef FEAT_AUTOCMD
7179 modified_was_set = value;
7180#endif
7181 }
7182
7183#ifdef BACKSLASH_IN_FILENAME
7184 else if ((int *)varp == &p_ssl)
7185 {
7186 if (p_ssl)
7187 {
7188 psepc = '/';
7189 psepcN = '\\';
7190 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191 }
7192 else
7193 {
7194 psepc = '\\';
7195 psepcN = '/';
7196 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 }
7198
7199 /* need to adjust the file name arguments and buffer names. */
7200 buflist_slash_adjust();
7201 alist_slash_adjust();
7202# ifdef FEAT_EVAL
7203 scriptnames_slash_adjust();
7204# endif
7205 }
7206#endif
7207
7208 /* If 'wrap' is set, set w_leftcol to zero. */
7209 else if ((int *)varp == &curwin->w_p_wrap)
7210 {
7211 if (curwin->w_p_wrap)
7212 curwin->w_leftcol = 0;
7213 }
7214
7215#ifdef FEAT_WINDOWS
7216 else if ((int *)varp == &p_ea)
7217 {
7218 if (p_ea && !old_value)
7219 win_equal(curwin, FALSE, 0);
7220 }
7221#endif
7222
7223 else if ((int *)varp == &p_wiv)
7224 {
7225 /*
7226 * When 'weirdinvert' changed, set/reset 't_xs'.
7227 * Then set 'weirdinvert' according to value of 't_xs'.
7228 */
7229 if (p_wiv && !old_value)
7230 T_XS = (char_u *)"y";
7231 else if (!p_wiv && old_value)
7232 T_XS = empty_option;
7233 p_wiv = (*T_XS != NUL);
7234 }
7235
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007236#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007237 else if ((int *)varp == &p_beval)
7238 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239 if (p_beval == TRUE)
7240 gui_mch_enable_beval_area(balloonEval);
7241 else
7242 gui_mch_disable_beval_area(balloonEval);
7243 }
7244
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007245# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007246 else if ((int *)varp == &p_acd)
7247 {
7248 if (p_acd && curbuf->b_ffname != NULL
7249 && vim_chdirfile(curbuf->b_ffname) == OK)
7250 shorten_fnames(TRUE);
7251 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007252# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007253#endif
7254
7255#ifdef FEAT_DIFF
7256 /* 'diff' */
7257 else if ((int *)varp == &curwin->w_p_diff)
7258 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007259 /* May add or remove the buffer from the list of diff buffers. */
7260 diff_buf_adjust(curwin);
7261# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262 if (foldmethodIsDiff(curwin))
7263 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007264# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265 }
7266#endif
7267
7268#ifdef USE_IM_CONTROL
7269 /* 'imdisable' */
7270 else if ((int *)varp == &p_imdisable)
7271 {
7272 /* Only de-activate it here, it will be enabled when changing mode. */
7273 if (p_imdisable)
7274 im_set_active(FALSE);
7275 }
7276#endif
7277
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007278#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007279 /* 'spell' */
7280 else if ((int *)varp == &curwin->w_p_spell)
7281 {
7282 if (curwin->w_p_spell)
7283 {
7284 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007285
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007286 if (errmsg != NULL)
7287 EMSG(_(errmsg));
7288 }
7289 }
7290#endif
7291
Bram Moolenaar071d4272004-06-13 20:20:40 +00007292#ifdef FEAT_FKMAP
7293 else if ((int *)varp == &p_altkeymap)
7294 {
7295 if (old_value != p_altkeymap)
7296 {
7297 if (!p_altkeymap)
7298 {
7299 p_hkmap = p_fkmap;
7300 p_fkmap = 0;
7301 }
7302 else
7303 {
7304 p_fkmap = p_hkmap;
7305 p_hkmap = 0;
7306 }
7307 (void)init_chartab();
7308 }
7309 }
7310
7311 /*
7312 * In case some second language keymapping options have changed, check
7313 * and correct the setting in a consistent way.
7314 */
7315
7316 /*
7317 * If hkmap or fkmap are set, reset Arabic keymapping.
7318 */
7319 if ((p_hkmap || p_fkmap) && p_altkeymap)
7320 {
7321 p_altkeymap = p_fkmap;
7322# ifdef FEAT_ARABIC
7323 curwin->w_p_arab = FALSE;
7324# endif
7325 (void)init_chartab();
7326 }
7327
7328 /*
7329 * If hkmap set, reset Farsi keymapping.
7330 */
7331 if (p_hkmap && p_altkeymap)
7332 {
7333 p_altkeymap = 0;
7334 p_fkmap = 0;
7335# ifdef FEAT_ARABIC
7336 curwin->w_p_arab = FALSE;
7337# endif
7338 (void)init_chartab();
7339 }
7340
7341 /*
7342 * If fkmap set, reset Hebrew keymapping.
7343 */
7344 if (p_fkmap && !p_altkeymap)
7345 {
7346 p_altkeymap = 1;
7347 p_hkmap = 0;
7348# ifdef FEAT_ARABIC
7349 curwin->w_p_arab = FALSE;
7350# endif
7351 (void)init_chartab();
7352 }
7353#endif
7354
7355#ifdef FEAT_ARABIC
7356 if ((int *)varp == &curwin->w_p_arab)
7357 {
7358 if (curwin->w_p_arab)
7359 {
7360 /*
7361 * 'arabic' is set, handle various sub-settings.
7362 */
7363 if (!p_tbidi)
7364 {
7365 /* set rightleft mode */
7366 if (!curwin->w_p_rl)
7367 {
7368 curwin->w_p_rl = TRUE;
7369 changed_window_setting();
7370 }
7371
7372 /* Enable Arabic shaping (major part of what Arabic requires) */
7373 if (!p_arshape)
7374 {
7375 p_arshape = TRUE;
7376 redraw_later_clear();
7377 }
7378 }
7379
7380 /* Arabic requires a utf-8 encoding, inform the user if its not
7381 * set. */
7382 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007383 {
7384 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
7386 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007387 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007388
7389# ifdef FEAT_MBYTE
7390 /* set 'delcombine' */
7391 p_deco = TRUE;
7392# endif
7393
7394# ifdef FEAT_KEYMAP
7395 /* Force-set the necessary keymap for arabic */
7396 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7397 OPT_LOCAL);
7398# endif
7399# ifdef FEAT_FKMAP
7400 p_altkeymap = 0;
7401 p_hkmap = 0;
7402 p_fkmap = 0;
7403 (void)init_chartab();
7404# endif
7405 }
7406 else
7407 {
7408 /*
7409 * 'arabic' is reset, handle various sub-settings.
7410 */
7411 if (!p_tbidi)
7412 {
7413 /* reset rightleft mode */
7414 if (curwin->w_p_rl)
7415 {
7416 curwin->w_p_rl = FALSE;
7417 changed_window_setting();
7418 }
7419
7420 /* 'arabicshape' isn't reset, it is a global option and
7421 * another window may still need it "on". */
7422 }
7423
7424 /* 'delcombine' isn't reset, it is a global option and another
7425 * window may still want it "on". */
7426
7427# ifdef FEAT_KEYMAP
7428 /* Revert to the default keymap */
7429 curbuf->b_p_iminsert = B_IMODE_NONE;
7430 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7431# endif
7432 }
7433 }
7434#endif
7435
7436 /*
7437 * End of handling side effects for bool options.
7438 */
7439
7440 options[opt_idx].flags |= P_WAS_SET;
7441
7442 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7443 if (curwin->w_curswant != MAXCOL)
7444 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7445 check_redraw(options[opt_idx].flags);
7446
7447 return NULL;
7448}
7449
7450/*
7451 * Set the value of a number option, and take care of side effects.
7452 * Returns NULL for success, or an error message for an error.
7453 */
7454 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007455set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007456 int opt_idx; /* index in options[] table */
7457 char_u *varp; /* pointer to the option variable */
7458 long value; /* new value */
7459 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007460 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007461 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7462 OPT_MODELINE */
7463{
7464 char_u *errmsg = NULL;
7465 long old_value = *(long *)varp;
7466 long old_Rows = Rows; /* remember old Rows */
7467 long old_Columns = Columns; /* remember old Columns */
7468 long *pp = (long *)varp;
7469
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007470 /* Disallow changing some options from secure mode. */
7471 if ((secure
7472#ifdef HAVE_SANDBOX
7473 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007474#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007475 ) && (options[opt_idx].flags & P_SECURE))
7476 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477
7478 *pp = value;
7479#ifdef FEAT_EVAL
7480 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007481 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007483#ifdef FEAT_GUI
7484 need_mouse_correct = TRUE;
7485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486
7487 if (curbuf->b_p_sw <= 0)
7488 {
7489 errmsg = e_positive;
7490 curbuf->b_p_sw = curbuf->b_p_ts;
7491 }
7492
7493 /*
7494 * Number options that need some action when changed
7495 */
7496#ifdef FEAT_WINDOWS
7497 if (pp == &p_wh || pp == &p_hh)
7498 {
7499 if (p_wh < 1)
7500 {
7501 errmsg = e_positive;
7502 p_wh = 1;
7503 }
7504 if (p_wmh > p_wh)
7505 {
7506 errmsg = e_winheight;
7507 p_wh = p_wmh;
7508 }
7509 if (p_hh < 0)
7510 {
7511 errmsg = e_positive;
7512 p_hh = 0;
7513 }
7514
7515 /* Change window height NOW */
7516 if (lastwin != firstwin)
7517 {
7518 if (pp == &p_wh && curwin->w_height < p_wh)
7519 win_setheight((int)p_wh);
7520 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7521 win_setheight((int)p_hh);
7522 }
7523 }
7524
7525 /* 'winminheight' */
7526 else if (pp == &p_wmh)
7527 {
7528 if (p_wmh < 0)
7529 {
7530 errmsg = e_positive;
7531 p_wmh = 0;
7532 }
7533 if (p_wmh > p_wh)
7534 {
7535 errmsg = e_winheight;
7536 p_wmh = p_wh;
7537 }
7538 win_setminheight();
7539 }
7540
7541# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007542 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543 {
7544 if (p_wiw < 1)
7545 {
7546 errmsg = e_positive;
7547 p_wiw = 1;
7548 }
7549 if (p_wmw > p_wiw)
7550 {
7551 errmsg = e_winwidth;
7552 p_wiw = p_wmw;
7553 }
7554
7555 /* Change window width NOW */
7556 if (lastwin != firstwin && curwin->w_width < p_wiw)
7557 win_setwidth((int)p_wiw);
7558 }
7559
7560 /* 'winminwidth' */
7561 else if (pp == &p_wmw)
7562 {
7563 if (p_wmw < 0)
7564 {
7565 errmsg = e_positive;
7566 p_wmw = 0;
7567 }
7568 if (p_wmw > p_wiw)
7569 {
7570 errmsg = e_winwidth;
7571 p_wmw = p_wiw;
7572 }
7573 win_setminheight();
7574 }
7575# endif
7576
7577#endif
7578
7579#ifdef FEAT_WINDOWS
7580 /* (re)set last window status line */
7581 else if (pp == &p_ls)
7582 {
7583 last_status(FALSE);
7584 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007585
7586 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007587 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007588 {
7589 shell_new_rows(); /* recompute window positions and heights */
7590 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007591#endif
7592
7593#ifdef FEAT_GUI
7594 else if (pp == &p_linespace)
7595 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007596 /* Recompute gui.char_height and resize the Vim window to keep the
7597 * same number of lines. */
7598 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007599 gui_set_shellsize(FALSE, FALSE);
7600 }
7601#endif
7602
7603#ifdef FEAT_FOLDING
7604 /* 'foldlevel' */
7605 else if (pp == &curwin->w_p_fdl)
7606 {
7607 if (curwin->w_p_fdl < 0)
7608 curwin->w_p_fdl = 0;
7609 newFoldLevel();
7610 }
7611
7612 /* 'foldminlevel' */
7613 else if (pp == &curwin->w_p_fml)
7614 {
7615 foldUpdateAll(curwin);
7616 }
7617
7618 /* 'foldnestmax' */
7619 else if (pp == &curwin->w_p_fdn)
7620 {
7621 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7622 foldUpdateAll(curwin);
7623 }
7624
7625 /* 'foldcolumn' */
7626 else if (pp == &curwin->w_p_fdc)
7627 {
7628 if (curwin->w_p_fdc < 0)
7629 {
7630 errmsg = e_positive;
7631 curwin->w_p_fdc = 0;
7632 }
7633 else if (curwin->w_p_fdc > 12)
7634 {
7635 errmsg = e_invarg;
7636 curwin->w_p_fdc = 12;
7637 }
7638 }
7639
7640 /* 'shiftwidth' or 'tabstop' */
7641 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7642 {
7643 if (foldmethodIsIndent(curwin))
7644 foldUpdateAll(curwin);
7645 }
7646#endif /* FEAT_FOLDING */
7647
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007648#ifdef FEAT_MBYTE
7649 /* 'maxcombine' */
7650 else if (pp == &p_mco)
7651 {
7652 if (p_mco > MAX_MCO)
7653 p_mco = MAX_MCO;
7654 else if (p_mco < 0)
7655 p_mco = 0;
7656 screenclear(); /* will re-allocate the screen */
7657 }
7658#endif
7659
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660 else if (pp == &curbuf->b_p_iminsert)
7661 {
7662 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7663 {
7664 errmsg = e_invarg;
7665 curbuf->b_p_iminsert = B_IMODE_NONE;
7666 }
7667 p_iminsert = curbuf->b_p_iminsert;
7668 if (termcap_active) /* don't do this in the alternate screen */
7669 showmode();
7670#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7671 /* Show/unshow value of 'keymap' in status lines. */
7672 status_redraw_curbuf();
7673#endif
7674 }
7675
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007676 else if (pp == &p_window)
7677 {
7678 if (p_window < 1)
7679 p_window = 1;
7680 else if (p_window >= Rows)
7681 p_window = Rows - 1;
7682 }
7683
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684 else if (pp == &curbuf->b_p_imsearch)
7685 {
7686 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7687 {
7688 errmsg = e_invarg;
7689 curbuf->b_p_imsearch = B_IMODE_NONE;
7690 }
7691 p_imsearch = curbuf->b_p_imsearch;
7692 }
7693
7694#ifdef FEAT_TITLE
7695 /* if 'titlelen' has changed, redraw the title */
7696 else if (pp == &p_titlelen)
7697 {
7698 if (p_titlelen < 0)
7699 {
7700 errmsg = e_positive;
7701 p_titlelen = 85;
7702 }
7703 if (starting != NO_SCREEN && old_value != p_titlelen)
7704 need_maketitle = TRUE;
7705 }
7706#endif
7707
7708 /* if p_ch changed value, change the command line height */
7709 else if (pp == &p_ch)
7710 {
7711 if (p_ch < 1)
7712 {
7713 errmsg = e_positive;
7714 p_ch = 1;
7715 }
7716
7717 /* Only compute the new window layout when startup has been
7718 * completed. Otherwise the frame sizes may be wrong. */
7719 if (p_ch != old_value && full_screen
7720#ifdef FEAT_GUI
7721 && !gui.starting
7722#endif
7723 )
7724 command_height(old_value);
7725 }
7726
7727 /* when 'updatecount' changes from zero to non-zero, open swap files */
7728 else if (pp == &p_uc)
7729 {
7730 if (p_uc < 0)
7731 {
7732 errmsg = e_positive;
7733 p_uc = 100;
7734 }
7735 if (p_uc && !old_value)
7736 ml_open_files();
7737 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007738#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007739 else if (pp == &p_mzq)
7740 mzvim_reset_timer();
7741#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007742
7743 /* sync undo before 'undolevels' changes */
7744 else if (pp == &p_ul)
7745 {
7746 /* use the old value, otherwise u_sync() may not work properly */
7747 p_ul = old_value;
7748 u_sync();
7749 p_ul = value;
7750 }
7751
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007752#ifdef FEAT_LINEBREAK
7753 /* 'numberwidth' must be positive */
7754 else if (pp == &curwin->w_p_nuw)
7755 {
7756 if (curwin->w_p_nuw < 1)
7757 {
7758 errmsg = e_positive;
7759 curwin->w_p_nuw = 1;
7760 }
7761 if (curwin->w_p_nuw > 10)
7762 {
7763 errmsg = e_invarg;
7764 curwin->w_p_nuw = 10;
7765 }
7766 curwin->w_nrwidth_line_count = 0;
7767 }
7768#endif
7769
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770 /*
7771 * Check the bounds for numeric options here
7772 */
7773 if (Rows < min_rows() && full_screen)
7774 {
7775 if (errbuf != NULL)
7776 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007777 vim_snprintf((char *)errbuf, errbuflen,
7778 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 errmsg = errbuf;
7780 }
7781 Rows = min_rows();
7782 }
7783 if (Columns < MIN_COLUMNS && full_screen)
7784 {
7785 if (errbuf != NULL)
7786 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007787 vim_snprintf((char *)errbuf, errbuflen,
7788 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007789 errmsg = errbuf;
7790 }
7791 Columns = MIN_COLUMNS;
7792 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007793 /* Limit the values to avoid an overflow in Rows * Columns. */
7794 if (Columns > 10000)
7795 Columns = 10000;
7796 if (Rows > 1000)
7797 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798
7799#ifdef DJGPP
7800 /* avoid a crash by checking for a too large value of 'columns' */
7801 if (old_Columns != Columns && full_screen && term_console)
7802 mch_check_columns();
7803#endif
7804
7805 /*
7806 * If the screen (shell) height has been changed, assume it is the
7807 * physical screenheight.
7808 */
7809 if (old_Rows != Rows || old_Columns != Columns)
7810 {
7811 /* Changing the screen size is not allowed while updating the screen. */
7812 if (updating_screen)
7813 *pp = old_value;
7814 else if (full_screen
7815#ifdef FEAT_GUI
7816 && !gui.starting
7817#endif
7818 )
7819 set_shellsize((int)Columns, (int)Rows, TRUE);
7820 else
7821 {
7822 /* Postpone the resizing; check the size and cmdline position for
7823 * messages. */
7824 check_shellsize();
7825 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7826 cmdline_row = Rows - p_ch;
7827 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007828 if (p_window >= Rows)
7829 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830 }
7831
7832 if (curbuf->b_p_sts < 0)
7833 {
7834 errmsg = e_positive;
7835 curbuf->b_p_sts = 0;
7836 }
7837 if (curbuf->b_p_ts <= 0)
7838 {
7839 errmsg = e_positive;
7840 curbuf->b_p_ts = 8;
7841 }
7842 if (curbuf->b_p_tw < 0)
7843 {
7844 errmsg = e_positive;
7845 curbuf->b_p_tw = 0;
7846 }
7847 if (p_tm < 0)
7848 {
7849 errmsg = e_positive;
7850 p_tm = 0;
7851 }
7852 if ((curwin->w_p_scr <= 0
7853 || (curwin->w_p_scr > curwin->w_height
7854 && curwin->w_height > 0))
7855 && full_screen)
7856 {
7857 if (pp == &(curwin->w_p_scr))
7858 {
7859 if (curwin->w_p_scr != 0)
7860 errmsg = e_scroll;
7861 win_comp_scroll(curwin);
7862 }
7863 /* If 'scroll' became invalid because of a side effect silently adjust
7864 * it. */
7865 else if (curwin->w_p_scr <= 0)
7866 curwin->w_p_scr = 1;
7867 else /* curwin->w_p_scr > curwin->w_height */
7868 curwin->w_p_scr = curwin->w_height;
7869 }
7870 if (p_report < 0)
7871 {
7872 errmsg = e_positive;
7873 p_report = 1;
7874 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007875 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876 {
7877 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7878 p_sj = Rows / 2;
7879 else
7880 {
7881 errmsg = e_scroll;
7882 p_sj = 1;
7883 }
7884 }
7885 if (p_so < 0 && full_screen)
7886 {
7887 errmsg = e_scroll;
7888 p_so = 0;
7889 }
7890 if (p_siso < 0 && full_screen)
7891 {
7892 errmsg = e_positive;
7893 p_siso = 0;
7894 }
7895#ifdef FEAT_CMDWIN
7896 if (p_cwh < 1)
7897 {
7898 errmsg = e_positive;
7899 p_cwh = 1;
7900 }
7901#endif
7902 if (p_ut < 0)
7903 {
7904 errmsg = e_positive;
7905 p_ut = 2000;
7906 }
7907 if (p_ss < 0)
7908 {
7909 errmsg = e_positive;
7910 p_ss = 0;
7911 }
7912
7913 /* May set global value for local option. */
7914 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7915 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7916
7917 options[opt_idx].flags |= P_WAS_SET;
7918
7919 comp_col(); /* in case 'columns' or 'ls' changed */
7920 if (curwin->w_curswant != MAXCOL)
7921 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7922 check_redraw(options[opt_idx].flags);
7923
7924 return errmsg;
7925}
7926
7927/*
7928 * Called after an option changed: check if something needs to be redrawn.
7929 */
7930 static void
7931check_redraw(flags)
7932 long_u flags;
7933{
7934 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7935 int clear = (flags & P_RCLR) == P_RCLR;
7936 int all = ((flags & P_RALL) == P_RALL || clear);
7937
7938#ifdef FEAT_WINDOWS
7939 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7940 status_redraw_all();
7941#endif
7942
7943 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7944 changed_window_setting();
7945 if (flags & P_RBUF)
7946 redraw_curbuf_later(NOT_VALID);
7947 if (clear)
7948 redraw_all_later(CLEAR);
7949 else if (all)
7950 redraw_all_later(NOT_VALID);
7951}
7952
7953/*
7954 * Find index for option 'arg'.
7955 * Return -1 if not found.
7956 */
7957 static int
7958findoption(arg)
7959 char_u *arg;
7960{
7961 int opt_idx;
7962 char *s, *p;
7963 static short quick_tab[27] = {0, 0}; /* quick access table */
7964 int is_term_opt;
7965
7966 /*
7967 * For first call: Initialize the quick-access table.
7968 * It contains the index for the first option that starts with a certain
7969 * letter. There are 26 letters, plus the first "t_" option.
7970 */
7971 if (quick_tab[1] == 0)
7972 {
7973 p = options[0].fullname;
7974 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7975 {
7976 if (s[0] != p[0])
7977 {
7978 if (s[0] == 't' && s[1] == '_')
7979 quick_tab[26] = opt_idx;
7980 else
7981 quick_tab[CharOrdLow(s[0])] = opt_idx;
7982 }
7983 p = s;
7984 }
7985 }
7986
7987 /*
7988 * Check for name starting with an illegal character.
7989 */
7990#ifdef EBCDIC
7991 if (!islower(arg[0]))
7992#else
7993 if (arg[0] < 'a' || arg[0] > 'z')
7994#endif
7995 return -1;
7996
7997 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7998 if (is_term_opt)
7999 opt_idx = quick_tab[26];
8000 else
8001 opt_idx = quick_tab[CharOrdLow(arg[0])];
8002 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8003 {
8004 if (STRCMP(arg, s) == 0) /* match full name */
8005 break;
8006 }
8007 if (s == NULL && !is_term_opt)
8008 {
8009 opt_idx = quick_tab[CharOrdLow(arg[0])];
8010 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8011 {
8012 s = options[opt_idx].shortname;
8013 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8014 break;
8015 s = NULL;
8016 }
8017 }
8018 if (s == NULL)
8019 opt_idx = -1;
8020 return opt_idx;
8021}
8022
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008023#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024/*
8025 * Get the value for an option.
8026 *
8027 * Returns:
8028 * Number or Toggle option: 1, *numval gets value.
8029 * String option: 0, *stringval gets allocated string.
8030 * Hidden Number or Toggle option: -1.
8031 * hidden String option: -2.
8032 * unknown option: -3.
8033 */
8034 int
8035get_option_value(name, numval, stringval, opt_flags)
8036 char_u *name;
8037 long *numval;
8038 char_u **stringval; /* NULL when only checking existance */
8039 int opt_flags;
8040{
8041 int opt_idx;
8042 char_u *varp;
8043
8044 opt_idx = findoption(name);
8045 if (opt_idx < 0) /* unknown option */
8046 return -3;
8047
8048 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8049
8050 if (options[opt_idx].flags & P_STRING)
8051 {
8052 if (varp == NULL) /* hidden option */
8053 return -2;
8054 if (stringval != NULL)
8055 {
8056#ifdef FEAT_CRYPT
8057 /* never return the value of the crypt key */
8058 if ((char_u **)varp == &curbuf->b_p_key)
8059 *stringval = vim_strsave((char_u *)"*****");
8060 else
8061#endif
8062 *stringval = vim_strsave(*(char_u **)(varp));
8063 }
8064 return 0;
8065 }
8066
8067 if (varp == NULL) /* hidden option */
8068 return -1;
8069 if (options[opt_idx].flags & P_NUM)
8070 *numval = *(long *)varp;
8071 else
8072 {
8073 /* Special case: 'modified' is b_changed, but we also want to consider
8074 * it set when 'ff' or 'fenc' changed. */
8075 if ((int *)varp == &curbuf->b_changed)
8076 *numval = curbufIsChanged();
8077 else
8078 *numval = *(int *)varp;
8079 }
8080 return 1;
8081}
8082#endif
8083
8084/*
8085 * Set the value of option "name".
8086 * Use "string" for string options, use "number" for other options.
8087 */
8088 void
8089set_option_value(name, number, string, opt_flags)
8090 char_u *name;
8091 long number;
8092 char_u *string;
8093 int opt_flags; /* OPT_LOCAL or 0 (both) */
8094{
8095 int opt_idx;
8096 char_u *varp;
8097 int flags;
8098
8099 opt_idx = findoption(name);
8100 if (opt_idx == -1)
8101 EMSG2(_("E355: Unknown option: %s"), name);
8102 else
8103 {
8104 flags = options[opt_idx].flags;
8105#ifdef HAVE_SANDBOX
8106 /* Disallow changing some options in the sandbox */
8107 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008108 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008109 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008110 return;
8111 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008112#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008113 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114 set_string_option(opt_idx, string, opt_flags);
8115 else
8116 {
8117 varp = get_varp(&options[opt_idx]);
8118 if (varp != NULL) /* hidden option is not changed */
8119 {
8120 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008121 (void)set_num_option(opt_idx, varp, number,
8122 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008124 (void)set_bool_option(opt_idx, varp, (int)number,
8125 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 }
8127 }
8128 }
8129}
8130
8131/*
8132 * Get the terminal code for a terminal option.
8133 * Returns NULL when not found.
8134 */
8135 char_u *
8136get_term_code(tname)
8137 char_u *tname;
8138{
8139 int opt_idx;
8140 char_u *varp;
8141
8142 if (tname[0] != 't' || tname[1] != '_' ||
8143 tname[2] == NUL || tname[3] == NUL)
8144 return NULL;
8145 if ((opt_idx = findoption(tname)) >= 0)
8146 {
8147 varp = get_varp(&(options[opt_idx]));
8148 if (varp != NULL)
8149 varp = *(char_u **)(varp);
8150 return varp;
8151 }
8152 return find_termcode(tname + 2);
8153}
8154
8155 char_u *
8156get_highlight_default()
8157{
8158 int i;
8159
8160 i = findoption((char_u *)"hl");
8161 if (i >= 0)
8162 return options[i].def_val[VI_DEFAULT];
8163 return (char_u *)NULL;
8164}
8165
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008166#if defined(FEAT_MBYTE) || defined(PROTO)
8167 char_u *
8168get_encoding_default()
8169{
8170 int i;
8171
8172 i = findoption((char_u *)"enc");
8173 if (i >= 0)
8174 return options[i].def_val[VI_DEFAULT];
8175 return (char_u *)NULL;
8176}
8177#endif
8178
Bram Moolenaar071d4272004-06-13 20:20:40 +00008179/*
8180 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8181 */
8182 static int
8183find_key_option(arg)
8184 char_u *arg;
8185{
8186 int key;
8187 int modifiers;
8188
8189 /*
8190 * Don't use get_special_key_code() for t_xx, we don't want it to call
8191 * add_termcap_entry().
8192 */
8193 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8194 key = TERMCAP2KEY(arg[2], arg[3]);
8195 else
8196 {
8197 --arg; /* put arg at the '<' */
8198 modifiers = 0;
8199 key = find_special_key(&arg, &modifiers, TRUE);
8200 if (modifiers) /* can't handle modifiers here */
8201 key = 0;
8202 }
8203 return key;
8204}
8205
8206/*
8207 * if 'all' == 0: show changed options
8208 * if 'all' == 1: show all normal options
8209 * if 'all' == 2: show all terminal options
8210 */
8211 static void
8212showoptions(all, opt_flags)
8213 int all;
8214 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8215{
8216 struct vimoption *p;
8217 int col;
8218 int isterm;
8219 char_u *varp;
8220 struct vimoption **items;
8221 int item_count;
8222 int run;
8223 int row, rows;
8224 int cols;
8225 int i;
8226 int len;
8227
8228#define INC 20
8229#define GAP 3
8230
8231 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8232 PARAM_COUNT));
8233 if (items == NULL)
8234 return;
8235
8236 /* Highlight title */
8237 if (all == 2)
8238 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8239 else if (opt_flags & OPT_GLOBAL)
8240 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8241 else if (opt_flags & OPT_LOCAL)
8242 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8243 else
8244 MSG_PUTS_TITLE(_("\n--- Options ---"));
8245
8246 /*
8247 * do the loop two times:
8248 * 1. display the short items
8249 * 2. display the long items (only strings and numbers)
8250 */
8251 for (run = 1; run <= 2 && !got_int; ++run)
8252 {
8253 /*
8254 * collect the items in items[]
8255 */
8256 item_count = 0;
8257 for (p = &options[0]; p->fullname != NULL; p++)
8258 {
8259 varp = NULL;
8260 isterm = istermoption(p);
8261 if (opt_flags != 0)
8262 {
8263 if (p->indir != PV_NONE && !isterm)
8264 varp = get_varp_scope(p, opt_flags);
8265 }
8266 else
8267 varp = get_varp(p);
8268 if (varp != NULL
8269 && ((all == 2 && isterm)
8270 || (all == 1 && !isterm)
8271 || (all == 0 && !optval_default(p, varp))))
8272 {
8273 if (p->flags & P_BOOL)
8274 len = 1; /* a toggle option fits always */
8275 else
8276 {
8277 option_value2string(p, opt_flags);
8278 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8279 }
8280 if ((len <= INC - GAP && run == 1) ||
8281 (len > INC - GAP && run == 2))
8282 items[item_count++] = p;
8283 }
8284 }
8285
8286 /*
8287 * display the items
8288 */
8289 if (run == 1)
8290 {
8291 cols = (Columns + GAP - 3) / INC;
8292 if (cols == 0)
8293 cols = 1;
8294 rows = (item_count + cols - 1) / cols;
8295 }
8296 else /* run == 2 */
8297 rows = item_count;
8298 for (row = 0; row < rows && !got_int; ++row)
8299 {
8300 msg_putchar('\n'); /* go to next line */
8301 if (got_int) /* 'q' typed in more */
8302 break;
8303 col = 0;
8304 for (i = row; i < item_count; i += rows)
8305 {
8306 msg_col = col; /* make columns */
8307 showoneopt(items[i], opt_flags);
8308 col += INC;
8309 }
8310 out_flush();
8311 ui_breakcheck();
8312 }
8313 }
8314 vim_free(items);
8315}
8316
8317/*
8318 * Return TRUE if option "p" has its default value.
8319 */
8320 static int
8321optval_default(p, varp)
8322 struct vimoption *p;
8323 char_u *varp;
8324{
8325 int dvi;
8326
8327 if (varp == NULL)
8328 return TRUE; /* hidden option is always at default */
8329 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8330 if (p->flags & P_NUM)
8331 return (*(long *)varp == (long)p->def_val[dvi]);
8332 if (p->flags & P_BOOL)
8333 /* the cast to long is required for Manx C */
8334 return (*(int *)varp == (int)(long)p->def_val[dvi]);
8335 /* P_STRING */
8336 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8337}
8338
8339/*
8340 * showoneopt: show the value of one option
8341 * must not be called with a hidden option!
8342 */
8343 static void
8344showoneopt(p, opt_flags)
8345 struct vimoption *p;
8346 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8347{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008348 char_u *varp;
8349 int save_silent = silent_mode;
8350
8351 silent_mode = FALSE;
8352 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353
8354 varp = get_varp_scope(p, opt_flags);
8355
8356 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8357 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8358 ? !curbufIsChanged() : !*(int *)varp))
8359 MSG_PUTS("no");
8360 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8361 MSG_PUTS("--");
8362 else
8363 MSG_PUTS(" ");
8364 MSG_PUTS(p->fullname);
8365 if (!(p->flags & P_BOOL))
8366 {
8367 msg_putchar('=');
8368 /* put value string in NameBuff */
8369 option_value2string(p, opt_flags);
8370 msg_outtrans(NameBuff);
8371 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008372
8373 silent_mode = save_silent;
8374 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375}
8376
8377/*
8378 * Write modified options as ":set" commands to a file.
8379 *
8380 * There are three values for "opt_flags":
8381 * OPT_GLOBAL: Write global option values and fresh values of
8382 * buffer-local options (used for start of a session
8383 * file).
8384 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8385 * curwin (used for a vimrc file).
8386 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8387 * and local values for window-local options of
8388 * curwin. Local values are also written when at the
8389 * default value, because a modeline or autocommand
8390 * may have set them when doing ":edit file" and the
8391 * user has set them back at the default or fresh
8392 * value.
8393 * When "local_only" is TRUE, don't write fresh
8394 * values, only local values (for ":mkview").
8395 * (fresh value = value used for a new buffer or window for a local option).
8396 *
8397 * Return FAIL on error, OK otherwise.
8398 */
8399 int
8400makeset(fd, opt_flags, local_only)
8401 FILE *fd;
8402 int opt_flags;
8403 int local_only;
8404{
8405 struct vimoption *p;
8406 char_u *varp; /* currently used value */
8407 char_u *varp_fresh; /* local value */
8408 char_u *varp_local = NULL; /* fresh value */
8409 char *cmd;
8410 int round;
8411
8412 /*
8413 * The options that don't have a default (terminal name, columns, lines)
8414 * are never written. Terminal options are also not written.
8415 */
8416 for (p = &options[0]; !istermoption(p); p++)
8417 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
8418 {
8419 /* skip global option when only doing locals */
8420 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8421 continue;
8422
8423 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8424 * file, they are always buffer-specific. */
8425 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8426 continue;
8427
8428 /* Global values are only written when not at the default value. */
8429 varp = get_varp_scope(p, opt_flags);
8430 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8431 continue;
8432
8433 round = 2;
8434 if (p->indir != PV_NONE)
8435 {
8436 if (p->var == VAR_WIN)
8437 {
8438 /* skip window-local option when only doing globals */
8439 if (!(opt_flags & OPT_LOCAL))
8440 continue;
8441 /* When fresh value of window-local option is not at the
8442 * default, need to write it too. */
8443 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8444 {
8445 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8446 if (!optval_default(p, varp_fresh))
8447 {
8448 round = 1;
8449 varp_local = varp;
8450 varp = varp_fresh;
8451 }
8452 }
8453 }
8454 }
8455
8456 /* Round 1: fresh value for window-local options.
8457 * Round 2: other values */
8458 for ( ; round <= 2; varp = varp_local, ++round)
8459 {
8460 if (round == 1 || (opt_flags & OPT_GLOBAL))
8461 cmd = "set";
8462 else
8463 cmd = "setlocal";
8464
8465 if (p->flags & P_BOOL)
8466 {
8467 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8468 return FAIL;
8469 }
8470 else if (p->flags & P_NUM)
8471 {
8472 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8473 return FAIL;
8474 }
8475 else /* P_STRING */
8476 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008477#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8478 int do_endif = FALSE;
8479
Bram Moolenaar071d4272004-06-13 20:20:40 +00008480 /* Don't set 'syntax' and 'filetype' again if the value is
8481 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008482 if (
8483# if defined(FEAT_SYN_HL)
8484 p->indir == PV_SYN
8485# if defined(FEAT_AUTOCMD)
8486 ||
8487# endif
8488# endif
8489# if defined(FEAT_AUTOCMD)
8490 p->indir == PV_FT)
8491# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492 {
8493 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8494 *(char_u **)(varp)) < 0
8495 || put_eol(fd) < 0)
8496 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008497 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8501 (p->flags & P_EXPAND) != 0) == FAIL)
8502 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008503#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8504 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008505 {
8506 if (put_line(fd, "endif") == FAIL)
8507 return FAIL;
8508 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 }
8511 }
8512 }
8513 return OK;
8514}
8515
8516#if defined(FEAT_FOLDING) || defined(PROTO)
8517/*
8518 * Generate set commands for the local fold options only. Used when
8519 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8520 */
8521 int
8522makefoldset(fd)
8523 FILE *fd;
8524{
8525 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8526# ifdef FEAT_EVAL
8527 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8528 == FAIL
8529# endif
8530 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8531 == FAIL
8532 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8533 == FAIL
8534 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8535 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8536 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8537 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8538 )
8539 return FAIL;
8540
8541 return OK;
8542}
8543#endif
8544
8545 static int
8546put_setstring(fd, cmd, name, valuep, expand)
8547 FILE *fd;
8548 char *cmd;
8549 char *name;
8550 char_u **valuep;
8551 int expand;
8552{
8553 char_u *s;
8554 char_u buf[MAXPATHL];
8555
8556 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8557 return FAIL;
8558 if (*valuep != NULL)
8559 {
8560 /* Output 'pastetoggle' as key names. For other
8561 * options some characters have to be escaped with
8562 * CTRL-V or backslash */
8563 if (valuep == &p_pt)
8564 {
8565 s = *valuep;
8566 while (*s != NUL)
8567 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8568 return FAIL;
8569 }
8570 else if (expand)
8571 {
8572 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8573 if (put_escstr(fd, buf, 2) == FAIL)
8574 return FAIL;
8575 }
8576 else if (put_escstr(fd, *valuep, 2) == FAIL)
8577 return FAIL;
8578 }
8579 if (put_eol(fd) < 0)
8580 return FAIL;
8581 return OK;
8582}
8583
8584 static int
8585put_setnum(fd, cmd, name, valuep)
8586 FILE *fd;
8587 char *cmd;
8588 char *name;
8589 long *valuep;
8590{
8591 long wc;
8592
8593 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8594 return FAIL;
8595 if (wc_use_keyname((char_u *)valuep, &wc))
8596 {
8597 /* print 'wildchar' and 'wildcharm' as a key name */
8598 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8599 return FAIL;
8600 }
8601 else if (fprintf(fd, "%ld", *valuep) < 0)
8602 return FAIL;
8603 if (put_eol(fd) < 0)
8604 return FAIL;
8605 return OK;
8606}
8607
8608 static int
8609put_setbool(fd, cmd, name, value)
8610 FILE *fd;
8611 char *cmd;
8612 char *name;
8613 int value;
8614{
8615 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8616 || put_eol(fd) < 0)
8617 return FAIL;
8618 return OK;
8619}
8620
8621/*
8622 * Clear all the terminal options.
8623 * If the option has been allocated, free the memory.
8624 * Terminal options are never hidden or indirect.
8625 */
8626 void
8627clear_termoptions()
8628{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629 /*
8630 * Reset a few things before clearing the old options. This may cause
8631 * outputting a few things that the terminal doesn't understand, but the
8632 * screen will be cleared later, so this is OK.
8633 */
8634#ifdef FEAT_MOUSE_TTY
8635 mch_setmouse(FALSE); /* switch mouse off */
8636#endif
8637#ifdef FEAT_TITLE
8638 mch_restore_title(3); /* restore window titles */
8639#endif
8640#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8641 /* When starting the GUI close the display opened for the clipboard.
8642 * After restoring the title, because that will need the display. */
8643 if (gui.starting)
8644 clear_xterm_clip();
8645#endif
8646#ifdef WIN3264
8647 /*
8648 * Check if this is allowed now.
8649 */
8650 if (can_end_termcap_mode(FALSE) == TRUE)
8651#endif
8652 stoptermcap(); /* stop termcap mode */
8653
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008654 free_termoptions();
8655}
8656
8657 void
8658free_termoptions()
8659{
8660 struct vimoption *p;
8661
Bram Moolenaar071d4272004-06-13 20:20:40 +00008662 for (p = &options[0]; p->fullname != NULL; p++)
8663 if (istermoption(p))
8664 {
8665 if (p->flags & P_ALLOCED)
8666 free_string_option(*(char_u **)(p->var));
8667 if (p->flags & P_DEF_ALLOCED)
8668 free_string_option(p->def_val[VI_DEFAULT]);
8669 *(char_u **)(p->var) = empty_option;
8670 p->def_val[VI_DEFAULT] = empty_option;
8671 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8672 }
8673 clear_termcodes();
8674}
8675
8676/*
8677 * Set the terminal option defaults to the current value.
8678 * Used after setting the terminal name.
8679 */
8680 void
8681set_term_defaults()
8682{
8683 struct vimoption *p;
8684
8685 for (p = &options[0]; p->fullname != NULL; p++)
8686 {
8687 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8688 {
8689 if (p->flags & P_DEF_ALLOCED)
8690 {
8691 free_string_option(p->def_val[VI_DEFAULT]);
8692 p->flags &= ~P_DEF_ALLOCED;
8693 }
8694 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8695 if (p->flags & P_ALLOCED)
8696 {
8697 p->flags |= P_DEF_ALLOCED;
8698 p->flags &= ~P_ALLOCED; /* don't free the value now */
8699 }
8700 }
8701 }
8702}
8703
8704/*
8705 * return TRUE if 'p' starts with 't_'
8706 */
8707 static int
8708istermoption(p)
8709 struct vimoption *p;
8710{
8711 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8712}
8713
8714/*
8715 * Compute columns for ruler and shown command. 'sc_col' is also used to
8716 * decide what the maximum length of a message on the status line can be.
8717 * If there is a status line for the last window, 'sc_col' is independent
8718 * of 'ru_col'.
8719 */
8720
8721#define COL_RULER 17 /* columns needed by standard ruler */
8722
8723 void
8724comp_col()
8725{
8726#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8727 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8728
8729 sc_col = 0;
8730 ru_col = 0;
8731 if (p_ru)
8732 {
8733#ifdef FEAT_STL_OPT
8734 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8735#else
8736 ru_col = COL_RULER + 1;
8737#endif
8738 /* no last status line, adjust sc_col */
8739 if (!last_has_status)
8740 sc_col = ru_col;
8741 }
8742 if (p_sc)
8743 {
8744 sc_col += SHOWCMD_COLS;
8745 if (!p_ru || last_has_status) /* no need for separating space */
8746 ++sc_col;
8747 }
8748 sc_col = Columns - sc_col;
8749 ru_col = Columns - ru_col;
8750 if (sc_col <= 0) /* screen too narrow, will become a mess */
8751 sc_col = 1;
8752 if (ru_col <= 0)
8753 ru_col = 1;
8754#else
8755 sc_col = Columns;
8756 ru_col = Columns;
8757#endif
8758}
8759
8760/*
8761 * Get pointer to option variable, depending on local or global scope.
8762 */
8763 static char_u *
8764get_varp_scope(p, opt_flags)
8765 struct vimoption *p;
8766 int opt_flags;
8767{
8768 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8769 {
8770 if (p->var == VAR_WIN)
8771 return (char_u *)GLOBAL_WO(get_varp(p));
8772 return p->var;
8773 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008774 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008775 {
8776 switch ((int)p->indir)
8777 {
8778#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008779 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
8780 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
8781 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008782#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008783 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
8784 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
8785 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008786 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008787 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008788#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008789 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
8790 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791#endif
8792#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008793 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
8794 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00008796#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
8797 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
8798#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008799#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008800 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802 }
8803 return NULL; /* "cannot happen" */
8804 }
8805 return get_varp(p);
8806}
8807
8808/*
8809 * Get pointer to option variable.
8810 */
8811 static char_u *
8812get_varp(p)
8813 struct vimoption *p;
8814{
8815 /* hidden option, always return NULL */
8816 if (p->var == NULL)
8817 return NULL;
8818
8819 switch ((int)p->indir)
8820 {
8821 case PV_NONE: return p->var;
8822
8823 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008824 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008826 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008828 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008830 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008831 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008832 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8834#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008835 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008837 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8839#endif
8840#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008841 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008842 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008843 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008844 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8845#endif
8846#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008847 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008849 case PV_GP: return *curbuf->b_p_gp != NUL
8850 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8851 case PV_MP: return *curbuf->b_p_mp != NUL
8852 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00008854#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
8855 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
8856 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
8857#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008858#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008859 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008860 ? (char_u *)&(curwin->w_p_stl) : p->var;
8861#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862
8863#ifdef FEAT_ARABIC
8864 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8865#endif
8866 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008867#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00008868 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8869#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008870#ifdef FEAT_SYN_HL
8871 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
8872 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
8873#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874#ifdef FEAT_DIFF
8875 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8876#endif
8877#ifdef FEAT_FOLDING
8878 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8879 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8880 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8881 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8882 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8883 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8884 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8885# ifdef FEAT_EVAL
8886 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8887 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8888# endif
8889 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8890#endif
8891 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008892#ifdef FEAT_LINEBREAK
8893 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8894#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008895#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00008896 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8897#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00008898#ifdef FEAT_VERTSPLIT
8899 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
8900#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8902 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8903#endif
8904#ifdef FEAT_RIGHTLEFT
8905 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8906 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8907#endif
8908 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8909 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8910#ifdef FEAT_LINEBREAK
8911 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8912#endif
8913#ifdef FEAT_SCROLLBIND
8914 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8915#endif
8916
8917 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8918 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8919#ifdef FEAT_MBYTE
8920 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8921#endif
8922#if defined(FEAT_QUICKFIX)
8923 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8924 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8925#endif
8926 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8927 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8928#ifdef FEAT_CINDENT
8929 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8930 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8931 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8932#endif
8933#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8934 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8935#endif
8936#ifdef FEAT_COMMENTS
8937 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8938#endif
8939#ifdef FEAT_FOLDING
8940 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8941#endif
8942#ifdef FEAT_INS_EXPAND
8943 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8944#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008945#ifdef FEAT_COMPL_FUNC
8946 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008947 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008948#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008949 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8950 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8951#ifdef FEAT_MBYTE
8952 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8953#endif
8954 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8955#ifdef FEAT_AUTOCMD
8956 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8957#endif
8958 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008959 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008960 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8961 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8962 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8963 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8964#ifdef FEAT_FIND_ID
8965# ifdef FEAT_EVAL
8966 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8967# endif
8968#endif
8969#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8970 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8971 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8972#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008973#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008974 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
8975#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976#ifdef FEAT_CRYPT
8977 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8978#endif
8979#ifdef FEAT_LISP
8980 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8981#endif
8982 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8983 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8984 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8985 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8986 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8987#ifdef FEAT_OSFILETYPE
8988 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8989#endif
8990 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008991#ifdef FEAT_TEXTOBJ
8992 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8993#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8995#ifdef FEAT_SMARTINDENT
8996 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8997#endif
8998#ifndef SHORT_FNAME
8999 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9000#endif
9001 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9002#ifdef FEAT_SEARCHPATH
9003 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9004#endif
9005 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9006#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009007 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009008 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9009#endif
9010#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009011 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009012 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009013 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014#endif
9015 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9016 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9017 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9018 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9019 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9020#ifdef FEAT_KEYMAP
9021 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9022#endif
9023 default: EMSG(_("E356: get_varp ERROR"));
9024 }
9025 /* always return a valid pointer to avoid a crash! */
9026 return (char_u *)&(curbuf->b_p_wm);
9027}
9028
9029/*
9030 * Get the value of 'equalprg', either the buffer-local one or the global one.
9031 */
9032 char_u *
9033get_equalprg()
9034{
9035 if (*curbuf->b_p_ep == NUL)
9036 return p_ep;
9037 return curbuf->b_p_ep;
9038}
9039
9040#if defined(FEAT_WINDOWS) || defined(PROTO)
9041/*
9042 * Copy options from one window to another.
9043 * Used when splitting a window.
9044 */
9045 void
9046win_copy_options(wp_from, wp_to)
9047 win_T *wp_from;
9048 win_T *wp_to;
9049{
9050 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9051 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9052# ifdef FEAT_RIGHTLEFT
9053# ifdef FEAT_FKMAP
9054 /* Is this right? */
9055 wp_to->w_farsi = wp_from->w_farsi;
9056# endif
9057# endif
9058}
9059#endif
9060
9061/*
9062 * Copy the options from one winopt_T to another.
9063 * Doesn't free the old option values in "to", use clear_winopt() for that.
9064 * The 'scroll' option is not copied, because it depends on the window height.
9065 * The 'previewwindow' option is reset, there can be only one preview window.
9066 */
9067 void
9068copy_winopt(from, to)
9069 winopt_T *from;
9070 winopt_T *to;
9071{
9072#ifdef FEAT_ARABIC
9073 to->wo_arab = from->wo_arab;
9074#endif
9075 to->wo_list = from->wo_list;
9076 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009077#ifdef FEAT_LINEBREAK
9078 to->wo_nuw = from->wo_nuw;
9079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080#ifdef FEAT_RIGHTLEFT
9081 to->wo_rl = from->wo_rl;
9082 to->wo_rlc = vim_strsave(from->wo_rlc);
9083#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009084#ifdef FEAT_STL_OPT
9085 to->wo_stl = vim_strsave(from->wo_stl);
9086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 to->wo_wrap = from->wo_wrap;
9088#ifdef FEAT_LINEBREAK
9089 to->wo_lbr = from->wo_lbr;
9090#endif
9091#ifdef FEAT_SCROLLBIND
9092 to->wo_scb = from->wo_scb;
9093#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009094#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009095 to->wo_spell = from->wo_spell;
9096#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009097#ifdef FEAT_SYN_HL
9098 to->wo_cuc = from->wo_cuc;
9099 to->wo_cul = from->wo_cul;
9100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009101#ifdef FEAT_DIFF
9102 to->wo_diff = from->wo_diff;
9103#endif
9104#ifdef FEAT_FOLDING
9105 to->wo_fdc = from->wo_fdc;
9106 to->wo_fen = from->wo_fen;
9107 to->wo_fdi = vim_strsave(from->wo_fdi);
9108 to->wo_fml = from->wo_fml;
9109 to->wo_fdl = from->wo_fdl;
9110 to->wo_fdm = vim_strsave(from->wo_fdm);
9111 to->wo_fdn = from->wo_fdn;
9112# ifdef FEAT_EVAL
9113 to->wo_fde = vim_strsave(from->wo_fde);
9114 to->wo_fdt = vim_strsave(from->wo_fdt);
9115# endif
9116 to->wo_fmr = vim_strsave(from->wo_fmr);
9117#endif
9118 check_winopt(to); /* don't want NULL pointers */
9119}
9120
9121/*
9122 * Check string options in a window for a NULL value.
9123 */
9124 void
9125check_win_options(win)
9126 win_T *win;
9127{
9128 check_winopt(&win->w_onebuf_opt);
9129 check_winopt(&win->w_allbuf_opt);
9130}
9131
9132/*
9133 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9134 */
9135/*ARGSUSED*/
9136 void
9137check_winopt(wop)
9138 winopt_T *wop;
9139{
9140#ifdef FEAT_FOLDING
9141 check_string_option(&wop->wo_fdi);
9142 check_string_option(&wop->wo_fdm);
9143# ifdef FEAT_EVAL
9144 check_string_option(&wop->wo_fde);
9145 check_string_option(&wop->wo_fdt);
9146# endif
9147 check_string_option(&wop->wo_fmr);
9148#endif
9149#ifdef FEAT_RIGHTLEFT
9150 check_string_option(&wop->wo_rlc);
9151#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009152#ifdef FEAT_STL_OPT
9153 check_string_option(&wop->wo_stl);
9154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155}
9156
9157/*
9158 * Free the allocated memory inside a winopt_T.
9159 */
9160/*ARGSUSED*/
9161 void
9162clear_winopt(wop)
9163 winopt_T *wop;
9164{
9165#ifdef FEAT_FOLDING
9166 clear_string_option(&wop->wo_fdi);
9167 clear_string_option(&wop->wo_fdm);
9168# ifdef FEAT_EVAL
9169 clear_string_option(&wop->wo_fde);
9170 clear_string_option(&wop->wo_fdt);
9171# endif
9172 clear_string_option(&wop->wo_fmr);
9173#endif
9174#ifdef FEAT_RIGHTLEFT
9175 clear_string_option(&wop->wo_rlc);
9176#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009177#ifdef FEAT_STL_OPT
9178 clear_string_option(&wop->wo_stl);
9179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009180}
9181
9182/*
9183 * Copy global option values to local options for one buffer.
9184 * Used when creating a new buffer and sometimes when entering a buffer.
9185 * flags:
9186 * BCO_ENTER We will enter the buf buffer.
9187 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9188 * appropriate.
9189 * BCO_NOHELP Don't copy the values to a help buffer.
9190 */
9191 void
9192buf_copy_options(buf, flags)
9193 buf_T *buf;
9194 int flags;
9195{
9196 int should_copy = TRUE;
9197 char_u *save_p_isk = NULL; /* init for GCC */
9198 int dont_do_help;
9199 int did_isk = FALSE;
9200
9201 /*
9202 * Don't do anything of the buffer is invalid.
9203 */
9204 if (buf == NULL || !buf_valid(buf))
9205 return;
9206
9207 /*
9208 * Skip this when the option defaults have not been set yet. Happens when
9209 * main() allocates the first buffer.
9210 */
9211 if (p_cpo != NULL)
9212 {
9213 /*
9214 * Always copy when entering and 'cpo' contains 'S'.
9215 * Don't copy when already initialized.
9216 * Don't copy when 'cpo' contains 's' and not entering.
9217 * 'S' BCO_ENTER initialized 's' should_copy
9218 * yes yes X X TRUE
9219 * yes no yes X FALSE
9220 * no X yes X FALSE
9221 * X no no yes FALSE
9222 * X no no no TRUE
9223 * no yes no X TRUE
9224 */
9225 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9226 && (buf->b_p_initialized
9227 || (!(flags & BCO_ENTER)
9228 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9229 should_copy = FALSE;
9230
9231 if (should_copy || (flags & BCO_ALWAYS))
9232 {
9233 /* Don't copy the options specific to a help buffer when
9234 * BCO_NOHELP is given or the options were initialized already
9235 * (jumping back to a help file with CTRL-T or CTRL-O) */
9236 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9237 || buf->b_p_initialized;
9238 if (dont_do_help) /* don't free b_p_isk */
9239 {
9240 save_p_isk = buf->b_p_isk;
9241 buf->b_p_isk = NULL;
9242 }
9243 /*
9244 * Always free the allocated strings.
9245 * If not already initialized, set 'readonly' and copy 'fileformat'.
9246 */
9247 if (!buf->b_p_initialized)
9248 {
9249 free_buf_options(buf, TRUE);
9250 buf->b_p_ro = FALSE; /* don't copy readonly */
9251 buf->b_p_tx = p_tx;
9252#ifdef FEAT_MBYTE
9253 buf->b_p_fenc = vim_strsave(p_fenc);
9254#endif
9255 buf->b_p_ff = vim_strsave(p_ff);
9256#if defined(FEAT_QUICKFIX)
9257 buf->b_p_bh = empty_option;
9258 buf->b_p_bt = empty_option;
9259#endif
9260 }
9261 else
9262 free_buf_options(buf, FALSE);
9263
9264 buf->b_p_ai = p_ai;
9265 buf->b_p_ai_nopaste = p_ai_nopaste;
9266 buf->b_p_sw = p_sw;
9267 buf->b_p_tw = p_tw;
9268 buf->b_p_tw_nopaste = p_tw_nopaste;
9269 buf->b_p_tw_nobin = p_tw_nobin;
9270 buf->b_p_wm = p_wm;
9271 buf->b_p_wm_nopaste = p_wm_nopaste;
9272 buf->b_p_wm_nobin = p_wm_nobin;
9273 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009274#ifdef FEAT_MBYTE
9275 buf->b_p_bomb = p_bomb;
9276#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009277 buf->b_p_et = p_et;
9278 buf->b_p_et_nobin = p_et_nobin;
9279 buf->b_p_ml = p_ml;
9280 buf->b_p_ml_nobin = p_ml_nobin;
9281 buf->b_p_inf = p_inf;
9282 buf->b_p_swf = p_swf;
9283#ifdef FEAT_INS_EXPAND
9284 buf->b_p_cpt = vim_strsave(p_cpt);
9285#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009286#ifdef FEAT_COMPL_FUNC
9287 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009288 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009290 buf->b_p_sts = p_sts;
9291 buf->b_p_sts_nopaste = p_sts_nopaste;
9292#ifndef SHORT_FNAME
9293 buf->b_p_sn = p_sn;
9294#endif
9295#ifdef FEAT_COMMENTS
9296 buf->b_p_com = vim_strsave(p_com);
9297#endif
9298#ifdef FEAT_FOLDING
9299 buf->b_p_cms = vim_strsave(p_cms);
9300#endif
9301 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009302 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009303 buf->b_p_nf = vim_strsave(p_nf);
9304 buf->b_p_mps = vim_strsave(p_mps);
9305#ifdef FEAT_SMARTINDENT
9306 buf->b_p_si = p_si;
9307#endif
9308 buf->b_p_ci = p_ci;
9309#ifdef FEAT_CINDENT
9310 buf->b_p_cin = p_cin;
9311 buf->b_p_cink = vim_strsave(p_cink);
9312 buf->b_p_cino = vim_strsave(p_cino);
9313#endif
9314#ifdef FEAT_AUTOCMD
9315 /* Don't copy 'filetype', it must be detected */
9316 buf->b_p_ft = empty_option;
9317#endif
9318#ifdef FEAT_OSFILETYPE
9319 buf->b_p_oft = vim_strsave(p_oft);
9320#endif
9321 buf->b_p_pi = p_pi;
9322#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9323 buf->b_p_cinw = vim_strsave(p_cinw);
9324#endif
9325#ifdef FEAT_LISP
9326 buf->b_p_lisp = p_lisp;
9327#endif
9328#ifdef FEAT_SYN_HL
9329 /* Don't copy 'syntax', it must be set */
9330 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009331 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009332#endif
9333#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009334 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009335 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009336 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009337 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338#endif
9339#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9340 buf->b_p_inde = vim_strsave(p_inde);
9341 buf->b_p_indk = vim_strsave(p_indk);
9342#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009343#if defined(FEAT_EVAL)
9344 buf->b_p_fex = vim_strsave(p_fex);
9345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346#ifdef FEAT_CRYPT
9347 buf->b_p_key = vim_strsave(p_key);
9348#endif
9349#ifdef FEAT_SEARCHPATH
9350 buf->b_p_sua = vim_strsave(p_sua);
9351#endif
9352#ifdef FEAT_KEYMAP
9353 buf->b_p_keymap = vim_strsave(p_keymap);
9354 buf->b_kmap_state |= KEYMAP_INIT;
9355#endif
9356 /* This isn't really an option, but copying the langmap and IME
9357 * state from the current buffer is better than resetting it. */
9358 buf->b_p_iminsert = p_iminsert;
9359 buf->b_p_imsearch = p_imsearch;
9360
9361 /* options that are normally global but also have a local value
9362 * are not copied, start using the global value */
9363 buf->b_p_ar = -1;
9364#ifdef FEAT_QUICKFIX
9365 buf->b_p_gp = empty_option;
9366 buf->b_p_mp = empty_option;
9367 buf->b_p_efm = empty_option;
9368#endif
9369 buf->b_p_ep = empty_option;
9370 buf->b_p_kp = empty_option;
9371 buf->b_p_path = empty_option;
9372 buf->b_p_tags = empty_option;
9373#ifdef FEAT_FIND_ID
9374 buf->b_p_def = empty_option;
9375 buf->b_p_inc = empty_option;
9376# ifdef FEAT_EVAL
9377 buf->b_p_inex = vim_strsave(p_inex);
9378# endif
9379#endif
9380#ifdef FEAT_INS_EXPAND
9381 buf->b_p_dict = empty_option;
9382 buf->b_p_tsr = empty_option;
9383#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009384#ifdef FEAT_TEXTOBJ
9385 buf->b_p_qe = vim_strsave(p_qe);
9386#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009387#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9388 buf->b_p_bexpr = empty_option;
9389#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009390
9391 /*
9392 * Don't copy the options set by ex_help(), use the saved values,
9393 * when going from a help buffer to a non-help buffer.
9394 * Don't touch these at all when BCO_NOHELP is used and going from
9395 * or to a help buffer.
9396 */
9397 if (dont_do_help)
9398 buf->b_p_isk = save_p_isk;
9399 else
9400 {
9401 buf->b_p_isk = vim_strsave(p_isk);
9402 did_isk = TRUE;
9403 buf->b_p_ts = p_ts;
9404 buf->b_help = FALSE;
9405#ifdef FEAT_QUICKFIX
9406 if (buf->b_p_bt[0] == 'h')
9407 clear_string_option(&buf->b_p_bt);
9408#endif
9409 buf->b_p_ma = p_ma;
9410 }
9411 }
9412
9413 /*
9414 * When the options should be copied (ignoring BCO_ALWAYS), set the
9415 * flag that indicates that the options have been initialized.
9416 */
9417 if (should_copy)
9418 buf->b_p_initialized = TRUE;
9419 }
9420
9421 check_buf_options(buf); /* make sure we don't have NULLs */
9422 if (did_isk)
9423 (void)buf_init_chartab(buf, FALSE);
9424}
9425
9426/*
9427 * Reset the 'modifiable' option and its default value.
9428 */
9429 void
9430reset_modifiable()
9431{
9432 int opt_idx;
9433
9434 curbuf->b_p_ma = FALSE;
9435 p_ma = FALSE;
9436 opt_idx = findoption((char_u *)"ma");
9437 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9438}
9439
9440/*
9441 * Set the global value for 'iminsert' to the local value.
9442 */
9443 void
9444set_iminsert_global()
9445{
9446 p_iminsert = curbuf->b_p_iminsert;
9447}
9448
9449/*
9450 * Set the global value for 'imsearch' to the local value.
9451 */
9452 void
9453set_imsearch_global()
9454{
9455 p_imsearch = curbuf->b_p_imsearch;
9456}
9457
9458#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9459static int expand_option_idx = -1;
9460static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9461static int expand_option_flags = 0;
9462
9463 void
9464set_context_in_set_cmd(xp, arg, opt_flags)
9465 expand_T *xp;
9466 char_u *arg;
9467 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9468{
9469 int nextchar;
9470 long_u flags = 0; /* init for GCC */
9471 int opt_idx = 0; /* init for GCC */
9472 char_u *p;
9473 char_u *s;
9474 int is_term_option = FALSE;
9475 int key;
9476
9477 expand_option_flags = opt_flags;
9478
9479 xp->xp_context = EXPAND_SETTINGS;
9480 if (*arg == NUL)
9481 {
9482 xp->xp_pattern = arg;
9483 return;
9484 }
9485 p = arg + STRLEN(arg) - 1;
9486 if (*p == ' ' && *(p - 1) != '\\')
9487 {
9488 xp->xp_pattern = p + 1;
9489 return;
9490 }
9491 while (p > arg)
9492 {
9493 s = p;
9494 /* count number of backslashes before ' ' or ',' */
9495 if (*p == ' ' || *p == ',')
9496 {
9497 while (s > arg && *(s - 1) == '\\')
9498 --s;
9499 }
9500 /* break at a space with an even number of backslashes */
9501 if (*p == ' ' && ((p - s) & 1) == 0)
9502 {
9503 ++p;
9504 break;
9505 }
9506 --p;
9507 }
9508 if (STRNCMP(p, "no", 2) == 0)
9509 {
9510 xp->xp_context = EXPAND_BOOL_SETTINGS;
9511 p += 2;
9512 }
9513 if (STRNCMP(p, "inv", 3) == 0)
9514 {
9515 xp->xp_context = EXPAND_BOOL_SETTINGS;
9516 p += 3;
9517 }
9518 xp->xp_pattern = arg = p;
9519 if (*arg == '<')
9520 {
9521 while (*p != '>')
9522 if (*p++ == NUL) /* expand terminal option name */
9523 return;
9524 key = get_special_key_code(arg + 1);
9525 if (key == 0) /* unknown name */
9526 {
9527 xp->xp_context = EXPAND_NOTHING;
9528 return;
9529 }
9530 nextchar = *++p;
9531 is_term_option = TRUE;
9532 expand_option_name[2] = KEY2TERMCAP0(key);
9533 expand_option_name[3] = KEY2TERMCAP1(key);
9534 }
9535 else
9536 {
9537 if (p[0] == 't' && p[1] == '_')
9538 {
9539 p += 2;
9540 if (*p != NUL)
9541 ++p;
9542 if (*p == NUL)
9543 return; /* expand option name */
9544 nextchar = *++p;
9545 is_term_option = TRUE;
9546 expand_option_name[2] = p[-2];
9547 expand_option_name[3] = p[-1];
9548 }
9549 else
9550 {
9551 /* Allow * wildcard */
9552 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9553 p++;
9554 if (*p == NUL)
9555 return;
9556 nextchar = *p;
9557 *p = NUL;
9558 opt_idx = findoption(arg);
9559 *p = nextchar;
9560 if (opt_idx == -1 || options[opt_idx].var == NULL)
9561 {
9562 xp->xp_context = EXPAND_NOTHING;
9563 return;
9564 }
9565 flags = options[opt_idx].flags;
9566 if (flags & P_BOOL)
9567 {
9568 xp->xp_context = EXPAND_NOTHING;
9569 return;
9570 }
9571 }
9572 }
9573 /* handle "-=" and "+=" */
9574 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9575 {
9576 ++p;
9577 nextchar = '=';
9578 }
9579 if ((nextchar != '=' && nextchar != ':')
9580 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9581 {
9582 xp->xp_context = EXPAND_UNSUCCESSFUL;
9583 return;
9584 }
9585 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9586 {
9587 xp->xp_context = EXPAND_OLD_SETTING;
9588 if (is_term_option)
9589 expand_option_idx = -1;
9590 else
9591 expand_option_idx = opt_idx;
9592 xp->xp_pattern = p + 1;
9593 return;
9594 }
9595 xp->xp_context = EXPAND_NOTHING;
9596 if (is_term_option || (flags & P_NUM))
9597 return;
9598
9599 xp->xp_pattern = p + 1;
9600
9601 if (flags & P_EXPAND)
9602 {
9603 p = options[opt_idx].var;
9604 if (p == (char_u *)&p_bdir
9605 || p == (char_u *)&p_dir
9606 || p == (char_u *)&p_path
9607 || p == (char_u *)&p_rtp
9608#ifdef FEAT_SEARCHPATH
9609 || p == (char_u *)&p_cdpath
9610#endif
9611#ifdef FEAT_SESSION
9612 || p == (char_u *)&p_vdir
9613#endif
9614 )
9615 {
9616 xp->xp_context = EXPAND_DIRECTORIES;
9617 if (p == (char_u *)&p_path
9618#ifdef FEAT_SEARCHPATH
9619 || p == (char_u *)&p_cdpath
9620#endif
9621 )
9622 xp->xp_backslash = XP_BS_THREE;
9623 else
9624 xp->xp_backslash = XP_BS_ONE;
9625 }
9626 else
9627 {
9628 xp->xp_context = EXPAND_FILES;
9629 /* for 'tags' need three backslashes for a space */
9630 if (p == (char_u *)&p_tags)
9631 xp->xp_backslash = XP_BS_THREE;
9632 else
9633 xp->xp_backslash = XP_BS_ONE;
9634 }
9635 }
9636
9637 /* For an option that is a list of file names, find the start of the
9638 * last file name. */
9639 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9640 {
9641 /* count number of backslashes before ' ' or ',' */
9642 if (*p == ' ' || *p == ',')
9643 {
9644 s = p;
9645 while (s > xp->xp_pattern && *(s - 1) == '\\')
9646 --s;
9647 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9648 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9649 {
9650 xp->xp_pattern = p + 1;
9651 break;
9652 }
9653 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009654
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009655#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009656 /* for 'spellsuggest' start at "file:" */
9657 if (options[opt_idx].var == (char_u *)&p_sps
9658 && STRNCMP(p, "file:", 5) == 0)
9659 {
9660 xp->xp_pattern = p + 5;
9661 break;
9662 }
9663#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009664 }
9665
9666 return;
9667}
9668
9669 int
9670ExpandSettings(xp, regmatch, num_file, file)
9671 expand_T *xp;
9672 regmatch_T *regmatch;
9673 int *num_file;
9674 char_u ***file;
9675{
9676 int num_normal = 0; /* Nr of matching non-term-code settings */
9677 int num_term = 0; /* Nr of matching terminal code settings */
9678 int opt_idx;
9679 int match;
9680 int count = 0;
9681 char_u *str;
9682 int loop;
9683 int is_term_opt;
9684 char_u name_buf[MAX_KEY_NAME_LEN];
9685 static char *(names[]) = {"all", "termcap"};
9686 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9687
9688 /* do this loop twice:
9689 * loop == 0: count the number of matching options
9690 * loop == 1: copy the matching options into allocated memory
9691 */
9692 for (loop = 0; loop <= 1; ++loop)
9693 {
9694 regmatch->rm_ic = ic;
9695 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9696 {
9697 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9698 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9699 {
9700 if (loop == 0)
9701 num_normal++;
9702 else
9703 (*file)[count++] = vim_strsave((char_u *)names[match]);
9704 }
9705 }
9706 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9707 opt_idx++)
9708 {
9709 if (options[opt_idx].var == NULL)
9710 continue;
9711 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9712 && !(options[opt_idx].flags & P_BOOL))
9713 continue;
9714 is_term_opt = istermoption(&options[opt_idx]);
9715 if (is_term_opt && num_normal > 0)
9716 continue;
9717 match = FALSE;
9718 if (vim_regexec(regmatch, str, (colnr_T)0)
9719 || (options[opt_idx].shortname != NULL
9720 && vim_regexec(regmatch,
9721 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9722 match = TRUE;
9723 else if (is_term_opt)
9724 {
9725 name_buf[0] = '<';
9726 name_buf[1] = 't';
9727 name_buf[2] = '_';
9728 name_buf[3] = str[2];
9729 name_buf[4] = str[3];
9730 name_buf[5] = '>';
9731 name_buf[6] = NUL;
9732 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9733 {
9734 match = TRUE;
9735 str = name_buf;
9736 }
9737 }
9738 if (match)
9739 {
9740 if (loop == 0)
9741 {
9742 if (is_term_opt)
9743 num_term++;
9744 else
9745 num_normal++;
9746 }
9747 else
9748 (*file)[count++] = vim_strsave(str);
9749 }
9750 }
9751 /*
9752 * Check terminal key codes, these are not in the option table
9753 */
9754 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9755 {
9756 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9757 {
9758 if (!isprint(str[0]) || !isprint(str[1]))
9759 continue;
9760
9761 name_buf[0] = 't';
9762 name_buf[1] = '_';
9763 name_buf[2] = str[0];
9764 name_buf[3] = str[1];
9765 name_buf[4] = NUL;
9766
9767 match = FALSE;
9768 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9769 match = TRUE;
9770 else
9771 {
9772 name_buf[0] = '<';
9773 name_buf[1] = 't';
9774 name_buf[2] = '_';
9775 name_buf[3] = str[0];
9776 name_buf[4] = str[1];
9777 name_buf[5] = '>';
9778 name_buf[6] = NUL;
9779
9780 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9781 match = TRUE;
9782 }
9783 if (match)
9784 {
9785 if (loop == 0)
9786 num_term++;
9787 else
9788 (*file)[count++] = vim_strsave(name_buf);
9789 }
9790 }
9791
9792 /*
9793 * Check special key names.
9794 */
9795 regmatch->rm_ic = TRUE; /* ignore case here */
9796 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9797 {
9798 name_buf[0] = '<';
9799 STRCPY(name_buf + 1, str);
9800 STRCAT(name_buf, ">");
9801
9802 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9803 {
9804 if (loop == 0)
9805 num_term++;
9806 else
9807 (*file)[count++] = vim_strsave(name_buf);
9808 }
9809 }
9810 }
9811 if (loop == 0)
9812 {
9813 if (num_normal > 0)
9814 *num_file = num_normal;
9815 else if (num_term > 0)
9816 *num_file = num_term;
9817 else
9818 return OK;
9819 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9820 if (*file == NULL)
9821 {
9822 *file = (char_u **)"";
9823 return FAIL;
9824 }
9825 }
9826 }
9827 return OK;
9828}
9829
9830 int
9831ExpandOldSetting(num_file, file)
9832 int *num_file;
9833 char_u ***file;
9834{
9835 char_u *var = NULL; /* init for GCC */
9836 char_u *buf;
9837
9838 *num_file = 0;
9839 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9840 if (*file == NULL)
9841 return FAIL;
9842
9843 /*
9844 * For a terminal key code expand_option_idx is < 0.
9845 */
9846 if (expand_option_idx < 0)
9847 {
9848 var = find_termcode(expand_option_name + 2);
9849 if (var == NULL)
9850 expand_option_idx = findoption(expand_option_name);
9851 }
9852
9853 if (expand_option_idx >= 0)
9854 {
9855 /* put string of option value in NameBuff */
9856 option_value2string(&options[expand_option_idx], expand_option_flags);
9857 var = NameBuff;
9858 }
9859 else if (var == NULL)
9860 var = (char_u *)"";
9861
9862 /* A backslash is required before some characters. This is the reverse of
9863 * what happens in do_set(). */
9864 buf = vim_strsave_escaped(var, escape_chars);
9865
9866 if (buf == NULL)
9867 {
9868 vim_free(*file);
9869 *file = NULL;
9870 return FAIL;
9871 }
9872
9873#ifdef BACKSLASH_IN_FILENAME
9874 /* For MS-Windows et al. we don't double backslashes at the start and
9875 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009876 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877 if (var[0] == '\\' && var[1] == '\\'
9878 && expand_option_idx >= 0
9879 && (options[expand_option_idx].flags & P_EXPAND)
9880 && vim_isfilec(var[2])
9881 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9882 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009883#endif
9884
9885 *file[0] = buf;
9886 *num_file = 1;
9887 return OK;
9888}
9889#endif
9890
9891/*
9892 * Get the value for the numeric or string option *opp in a nice format into
9893 * NameBuff[]. Must not be called with a hidden option!
9894 */
9895 static void
9896option_value2string(opp, opt_flags)
9897 struct vimoption *opp;
9898 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9899{
9900 char_u *varp;
9901
9902 varp = get_varp_scope(opp, opt_flags);
9903
9904 if (opp->flags & P_NUM)
9905 {
9906 long wc = 0;
9907
9908 if (wc_use_keyname(varp, &wc))
9909 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9910 else if (wc != 0)
9911 STRCPY(NameBuff, transchar((int)wc));
9912 else
9913 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9914 }
9915 else /* P_STRING */
9916 {
9917 varp = *(char_u **)(varp);
9918 if (varp == NULL) /* just in case */
9919 NameBuff[0] = NUL;
9920#ifdef FEAT_CRYPT
9921 /* don't show the actual value of 'key', only that it's set */
9922 if (opp->var == (char_u *)&p_key && *varp)
9923 STRCPY(NameBuff, "*****");
9924#endif
9925 else if (opp->flags & P_EXPAND)
9926 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9927 /* Translate 'pastetoggle' into special key names */
9928 else if ((char_u **)opp->var == &p_pt)
9929 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9930 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009931 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932 }
9933}
9934
9935/*
9936 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9937 * printed as a keyname.
9938 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9939 */
9940 static int
9941wc_use_keyname(varp, wcp)
9942 char_u *varp;
9943 long *wcp;
9944{
9945 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9946 {
9947 *wcp = *(long *)varp;
9948 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9949 return TRUE;
9950 }
9951 return FALSE;
9952}
9953
9954#ifdef FEAT_LANGMAP
9955/*
9956 * Any character has an equivalent character. This is used for keyboards that
9957 * have a special language mode that sends characters above 128 (although
9958 * other characters can be translated too).
9959 */
9960
9961/*
9962 * char_u langmap_mapchar[256];
9963 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9964 * "translate" native lang chars in normal mode or some cases of
9965 * insert mode without having to tediously switch lang mode back&forth.
9966 */
9967
9968 static void
9969langmap_init()
9970{
9971 int i;
9972
9973 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9974 langmap_mapchar[i] = i;
9975}
9976
9977/*
9978 * Called when langmap option is set; the language map can be
9979 * changed at any time!
9980 */
9981 static void
9982langmap_set()
9983{
9984 char_u *p;
9985 char_u *p2;
9986 int from, to;
9987
9988 langmap_init(); /* back to one-to-one map first */
9989
9990 for (p = p_langmap; p[0] != NUL; )
9991 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009992 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9993 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009994 {
9995 if (p2[0] == '\\' && p2[1] != NUL)
9996 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009997 }
9998 if (p2[0] == ';')
9999 ++p2; /* abcd;ABCD form, p2 points to A */
10000 else
10001 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10002 while (p[0])
10003 {
10004 if (p[0] == '\\' && p[1] != NUL)
10005 ++p;
10006#ifdef FEAT_MBYTE
10007 from = (*mb_ptr2char)(p);
10008#else
10009 from = p[0];
10010#endif
10011 if (p2 == NULL)
10012 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010013 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014 if (p[0] == '\\')
10015 ++p;
10016#ifdef FEAT_MBYTE
10017 to = (*mb_ptr2char)(p);
10018#else
10019 to = p[0];
10020#endif
10021 }
10022 else
10023 {
10024 if (p2[0] == '\\')
10025 ++p2;
10026#ifdef FEAT_MBYTE
10027 to = (*mb_ptr2char)(p2);
10028#else
10029 to = p2[0];
10030#endif
10031 }
10032 if (to == NUL)
10033 {
10034 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10035 transchar(from));
10036 return;
10037 }
10038 langmap_mapchar[from & 255] = to;
10039
10040 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010041 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042 if (p2 == NULL)
10043 {
10044 if (p[0] == ',')
10045 {
10046 ++p;
10047 break;
10048 }
10049 }
10050 else
10051 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010052 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010053 if (*p == ';')
10054 {
10055 p = p2;
10056 if (p[0] != NUL)
10057 {
10058 if (p[0] != ',')
10059 {
10060 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10061 return;
10062 }
10063 ++p;
10064 }
10065 break;
10066 }
10067 }
10068 }
10069 }
10070}
10071#endif
10072
10073/*
10074 * Return TRUE if format option 'x' is in effect.
10075 * Take care of no formatting when 'paste' is set.
10076 */
10077 int
10078has_format_option(x)
10079 int x;
10080{
10081 if (p_paste)
10082 return FALSE;
10083 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10084}
10085
10086/*
10087 * Return TRUE if "x" is present in 'shortmess' option, or
10088 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10089 */
10090 int
10091shortmess(x)
10092 int x;
10093{
10094 return ( vim_strchr(p_shm, x) != NULL
10095 || (vim_strchr(p_shm, 'a') != NULL
10096 && vim_strchr((char_u *)SHM_A, x) != NULL));
10097}
10098
10099/*
10100 * paste_option_changed() - Called after p_paste was set or reset.
10101 */
10102 static void
10103paste_option_changed()
10104{
10105 static int old_p_paste = FALSE;
10106 static int save_sm = 0;
10107#ifdef FEAT_CMDL_INFO
10108 static int save_ru = 0;
10109#endif
10110#ifdef FEAT_RIGHTLEFT
10111 static int save_ri = 0;
10112 static int save_hkmap = 0;
10113#endif
10114 buf_T *buf;
10115
10116 if (p_paste)
10117 {
10118 /*
10119 * Paste switched from off to on.
10120 * Save the current values, so they can be restored later.
10121 */
10122 if (!old_p_paste)
10123 {
10124 /* save options for each buffer */
10125 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10126 {
10127 buf->b_p_tw_nopaste = buf->b_p_tw;
10128 buf->b_p_wm_nopaste = buf->b_p_wm;
10129 buf->b_p_sts_nopaste = buf->b_p_sts;
10130 buf->b_p_ai_nopaste = buf->b_p_ai;
10131 }
10132
10133 /* save global options */
10134 save_sm = p_sm;
10135#ifdef FEAT_CMDL_INFO
10136 save_ru = p_ru;
10137#endif
10138#ifdef FEAT_RIGHTLEFT
10139 save_ri = p_ri;
10140 save_hkmap = p_hkmap;
10141#endif
10142 /* save global values for local buffer options */
10143 p_tw_nopaste = p_tw;
10144 p_wm_nopaste = p_wm;
10145 p_sts_nopaste = p_sts;
10146 p_ai_nopaste = p_ai;
10147 }
10148
10149 /*
10150 * Always set the option values, also when 'paste' is set when it is
10151 * already on.
10152 */
10153 /* set options for each buffer */
10154 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10155 {
10156 buf->b_p_tw = 0; /* textwidth is 0 */
10157 buf->b_p_wm = 0; /* wrapmargin is 0 */
10158 buf->b_p_sts = 0; /* softtabstop is 0 */
10159 buf->b_p_ai = 0; /* no auto-indent */
10160 }
10161
10162 /* set global options */
10163 p_sm = 0; /* no showmatch */
10164#ifdef FEAT_CMDL_INFO
10165# ifdef FEAT_WINDOWS
10166 if (p_ru)
10167 status_redraw_all(); /* redraw to remove the ruler */
10168# endif
10169 p_ru = 0; /* no ruler */
10170#endif
10171#ifdef FEAT_RIGHTLEFT
10172 p_ri = 0; /* no reverse insert */
10173 p_hkmap = 0; /* no Hebrew keyboard */
10174#endif
10175 /* set global values for local buffer options */
10176 p_tw = 0;
10177 p_wm = 0;
10178 p_sts = 0;
10179 p_ai = 0;
10180 }
10181
10182 /*
10183 * Paste switched from on to off: Restore saved values.
10184 */
10185 else if (old_p_paste)
10186 {
10187 /* restore options for each buffer */
10188 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10189 {
10190 buf->b_p_tw = buf->b_p_tw_nopaste;
10191 buf->b_p_wm = buf->b_p_wm_nopaste;
10192 buf->b_p_sts = buf->b_p_sts_nopaste;
10193 buf->b_p_ai = buf->b_p_ai_nopaste;
10194 }
10195
10196 /* restore global options */
10197 p_sm = save_sm;
10198#ifdef FEAT_CMDL_INFO
10199# ifdef FEAT_WINDOWS
10200 if (p_ru != save_ru)
10201 status_redraw_all(); /* redraw to draw the ruler */
10202# endif
10203 p_ru = save_ru;
10204#endif
10205#ifdef FEAT_RIGHTLEFT
10206 p_ri = save_ri;
10207 p_hkmap = save_hkmap;
10208#endif
10209 /* set global values for local buffer options */
10210 p_tw = p_tw_nopaste;
10211 p_wm = p_wm_nopaste;
10212 p_sts = p_sts_nopaste;
10213 p_ai = p_ai_nopaste;
10214 }
10215
10216 old_p_paste = p_paste;
10217}
10218
10219/*
10220 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10221 *
10222 * Reset 'compatible' and set the values for options that didn't get set yet
10223 * to the Vim defaults.
10224 * Don't do this if the 'compatible' option has been set or reset before.
10225 */
10226 void
10227vimrc_found()
10228{
10229 int opt_idx;
10230
10231 if (!option_was_set((char_u *)"cp"))
10232 {
10233 p_cp = FALSE;
10234 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10235 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10236 set_option_default(opt_idx, OPT_FREE, FALSE);
10237 didset_options();
10238 }
10239}
10240
10241/*
10242 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10243 */
10244 void
10245change_compatible(on)
10246 int on;
10247{
10248 if (p_cp != on)
10249 {
10250 p_cp = on;
10251 compatible_set();
10252 }
10253 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
10254}
10255
10256/*
10257 * Return TRUE when option "name" has been set.
10258 */
10259 int
10260option_was_set(name)
10261 char_u *name;
10262{
10263 int idx;
10264
10265 idx = findoption(name);
10266 if (idx < 0) /* unknown option */
10267 return FALSE;
10268 if (options[idx].flags & P_WAS_SET)
10269 return TRUE;
10270 return FALSE;
10271}
10272
10273/*
10274 * compatible_set() - Called when 'compatible' has been set or unset.
10275 *
10276 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10277 * flag) to a Vi compatible value.
10278 * When 'compatible' is unset: Set all options that have a different default
10279 * for Vim (without the P_VI_DEF flag) to that default.
10280 */
10281 static void
10282compatible_set()
10283{
10284 int opt_idx;
10285
10286 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10287 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10288 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10289 set_option_default(opt_idx, OPT_FREE, p_cp);
10290 didset_options();
10291}
10292
10293#ifdef FEAT_LINEBREAK
10294
10295# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10296 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010297 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298# endif
10299
10300/*
10301 * fill_breakat_flags() -- called when 'breakat' changes value.
10302 */
10303 static void
10304fill_breakat_flags()
10305{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010306 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307 int i;
10308
10309 for (i = 0; i < 256; i++)
10310 breakat_flags[i] = FALSE;
10311
10312 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010313 for (p = p_breakat; *p; p++)
10314 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315}
10316
10317# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010318 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319# endif
10320
10321#endif
10322
10323/*
10324 * Check an option that can be a range of string values.
10325 *
10326 * Return OK for correct value, FAIL otherwise.
10327 * Empty is always OK.
10328 */
10329 static int
10330check_opt_strings(val, values, list)
10331 char_u *val;
10332 char **values;
10333 int list; /* when TRUE: accept a list of values */
10334{
10335 return opt_strings_flags(val, values, NULL, list);
10336}
10337
10338/*
10339 * Handle an option that can be a range of string values.
10340 * Set a flag in "*flagp" for each string present.
10341 *
10342 * Return OK for correct value, FAIL otherwise.
10343 * Empty is always OK.
10344 */
10345 static int
10346opt_strings_flags(val, values, flagp, list)
10347 char_u *val; /* new value */
10348 char **values; /* array of valid string values */
10349 unsigned *flagp;
10350 int list; /* when TRUE: accept a list of values */
10351{
10352 int i;
10353 int len;
10354 unsigned new_flags = 0;
10355
10356 while (*val)
10357 {
10358 for (i = 0; ; ++i)
10359 {
10360 if (values[i] == NULL) /* val not found in values[] */
10361 return FAIL;
10362
10363 len = (int)STRLEN(values[i]);
10364 if (STRNCMP(values[i], val, len) == 0
10365 && ((list && val[len] == ',') || val[len] == NUL))
10366 {
10367 val += len + (val[len] == ',');
10368 new_flags |= (1 << i);
10369 break; /* check next item in val list */
10370 }
10371 }
10372 }
10373 if (flagp != NULL)
10374 *flagp = new_flags;
10375
10376 return OK;
10377}
10378
10379/*
10380 * Read the 'wildmode' option, fill wim_flags[].
10381 */
10382 static int
10383check_opt_wim()
10384{
10385 char_u new_wim_flags[4];
10386 char_u *p;
10387 int i;
10388 int idx = 0;
10389
10390 for (i = 0; i < 4; ++i)
10391 new_wim_flags[i] = 0;
10392
10393 for (p = p_wim; *p; ++p)
10394 {
10395 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10396 ;
10397 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10398 return FAIL;
10399 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10400 new_wim_flags[idx] |= WIM_LONGEST;
10401 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10402 new_wim_flags[idx] |= WIM_FULL;
10403 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10404 new_wim_flags[idx] |= WIM_LIST;
10405 else
10406 return FAIL;
10407 p += i;
10408 if (*p == NUL)
10409 break;
10410 if (*p == ',')
10411 {
10412 if (idx == 3)
10413 return FAIL;
10414 ++idx;
10415 }
10416 }
10417
10418 /* fill remaining entries with last flag */
10419 while (idx < 3)
10420 {
10421 new_wim_flags[idx + 1] = new_wim_flags[idx];
10422 ++idx;
10423 }
10424
10425 /* only when there are no errors, wim_flags[] is changed */
10426 for (i = 0; i < 4; ++i)
10427 wim_flags[i] = new_wim_flags[i];
10428 return OK;
10429}
10430
10431/*
10432 * Check if backspacing over something is allowed.
10433 */
10434 int
10435can_bs(what)
10436 int what; /* BS_INDENT, BS_EOL or BS_START */
10437{
10438 switch (*p_bs)
10439 {
10440 case '2': return TRUE;
10441 case '1': return (what != BS_START);
10442 case '0': return FALSE;
10443 }
10444 return vim_strchr(p_bs, what) != NULL;
10445}
10446
10447/*
10448 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10449 * the file must be considered changed when the value is different.
10450 */
10451 void
10452save_file_ff(buf)
10453 buf_T *buf;
10454{
10455 buf->b_start_ffc = *buf->b_p_ff;
10456 buf->b_start_eol = buf->b_p_eol;
10457#ifdef FEAT_MBYTE
10458 /* Only use free/alloc when necessary, they take time. */
10459 if (buf->b_start_fenc == NULL
10460 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10461 {
10462 vim_free(buf->b_start_fenc);
10463 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10464 }
10465#endif
10466}
10467
10468/*
10469 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10470 * from when editing started (save_file_ff() called).
10471 * Also when 'endofline' was changed and 'binary' is set.
10472 * Don't consider a new, empty buffer to be changed.
10473 */
10474 int
10475file_ff_differs(buf)
10476 buf_T *buf;
10477{
10478 if ((buf->b_flags & BF_NEW)
10479 && buf->b_ml.ml_line_count == 1
10480 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10481 return FALSE;
10482 if (buf->b_start_ffc != *buf->b_p_ff)
10483 return TRUE;
10484 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10485 return TRUE;
10486#ifdef FEAT_MBYTE
10487 if (buf->b_start_fenc == NULL)
10488 return (*buf->b_p_fenc != NUL);
10489 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10490#else
10491 return FALSE;
10492#endif
10493}
10494
10495/*
10496 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10497 */
10498 int
10499check_ff_value(p)
10500 char_u *p;
10501{
10502 return check_opt_strings(p, p_ff_values, FALSE);
10503}