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